qanystringview.sip 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // This is the SIP interface definition for the QAnyStringView mapped type.
  2. //
  3. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  4. //
  5. // This file is part of PyQt6.
  6. //
  7. // This file may be used under the terms of the GNU General Public License
  8. // version 3.0 as published by the Free Software Foundation and appearing in
  9. // the file LICENSE included in the packaging of this file. Please review the
  10. // following information to ensure the GNU General Public License version 3.0
  11. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  12. //
  13. // If you do not wish to use this file under the terms of the GPL version 3.0
  14. // then you may purchase a commercial license. For more information contact
  15. // info@riverbankcomputing.com.
  16. //
  17. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  18. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. %If (Qt_6_4_0 -)
  20. %MappedType QAnyStringView /AllowNone, TypeHint="Union[QByteArray, QString]",TypeHintValue="''"/
  21. {
  22. %TypeHeaderCode
  23. #include <qanystringview.h>
  24. %End
  25. %TypeCode
  26. struct PyQtAnyStringState
  27. {
  28. const sipTypeDef *instance_type; // The instance's generated type.
  29. void *instance; // Either the QByteArray or QString.
  30. int instance_state; // The state of the instance conversion.
  31. };
  32. %End
  33. %ConvertToTypeCode
  34. if (sipIsErr == NULL)
  35. return sipCanConvertToType(sipPy, sipType_QString, 0) ||
  36. sipCanConvertToType(sipPy, sipType_QByteArray, SIP_NOT_NONE);
  37. PyQtAnyStringState *state = new PyQtAnyStringState;
  38. if (sipCanConvertToType(sipPy, sipType_QString, 0))
  39. {
  40. QString *qs = reinterpret_cast<QString *>(
  41. sipConvertToType(sipPy, sipType_QString, sipTransferObj, 0,
  42. &state->instance_state, sipIsErr));
  43. if (*sipIsErr)
  44. return 0;
  45. *sipCppPtr = new QAnyStringView(*qs);
  46. state->instance_type = sipType_QString;
  47. state->instance = qs;
  48. }
  49. else
  50. {
  51. QByteArray *qba = reinterpret_cast<QByteArray *>(
  52. sipConvertToType(sipPy, sipType_QByteArray, sipTransferObj,
  53. SIP_NOT_NONE, &state->instance_state, sipIsErr));
  54. if (*sipIsErr)
  55. return 0;
  56. *sipCppPtr = new QAnyStringView(*qba);
  57. state->instance_type = sipType_QByteArray;
  58. state->instance = qba;
  59. }
  60. *sipUserStatePtr = state;
  61. return sipGetState(sipTransferObj);
  62. %End
  63. %ConvertFromTypeCode
  64. return qpycore_PyObject_FromQString(sipCpp->toString());
  65. %End
  66. %ReleaseCode
  67. delete sipCpp;
  68. PyQtAnyStringState *state = reinterpret_cast<PyQtAnyStringState *>(sipUserState);
  69. sipReleaseType(state->instance, state->instance_type, state->instance_state);
  70. delete state;
  71. %End
  72. };
  73. %End