qpybluetooth_qmultihash.sip 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // This is the SIP interface definition for the QNultiHash based mapped types.
  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_2_0 -)
  20. template<quint16, _TYPE_>
  21. %MappedType QMultiHash<quint16, _TYPE_>
  22. /TypeHint="Dict[int, _TYPE_]", TypeHintValue="{}"/
  23. {
  24. %TypeHeaderCode
  25. #include <QMultiHash>
  26. %End
  27. %ConvertFromTypeCode
  28. PyObject *d = PyDict_New();
  29. if (!d)
  30. return 0;
  31. QMultiHash<quint16, _TYPE_>::const_iterator it = sipCpp->constBegin();
  32. QMultiHash<quint16, _TYPE_>::const_iterator end = sipCpp->constEnd();
  33. while (it != end)
  34. {
  35. PyObject *kobj = PyLong_FromLong(it.key());
  36. if (!kobj)
  37. {
  38. Py_DECREF(d);
  39. return 0;
  40. }
  41. QList<_TYPE_> values = sipCpp->values(it.key());
  42. PyObject *py_values = PyList_New(values.size());
  43. if (!py_values)
  44. {
  45. Py_DECREF(kobj);
  46. Py_DECREF(d);
  47. return 0;
  48. }
  49. int rc = PyDict_SetItem(d, kobj, py_values);
  50. Py_DECREF(py_values);
  51. Py_DECREF(kobj);
  52. if (rc < 0)
  53. {
  54. Py_DECREF(d);
  55. return 0;
  56. }
  57. for (int i = 0; i < values.size(); ++i)
  58. {
  59. _TYPE_ *v = new _TYPE_(values.at(i));
  60. PyObject *vobj = sipConvertFromNewType(v, sipType__TYPE_,
  61. sipTransferObj);
  62. if (!vobj)
  63. {
  64. delete v;
  65. Py_DECREF(d);
  66. return 0;
  67. }
  68. PyList_SetItem(py_values, i, vobj);
  69. }
  70. ++it;
  71. }
  72. return d;
  73. %End
  74. };
  75. %End
  76. %If (Qt_6_3_0 -)
  77. template<_TYPE1_, _TYPE2_>
  78. %MappedType QMultiHash<_TYPE1_, _TYPE2_>
  79. /TypeHint="Dict[_TYPE1_, _TYPE2_]", TypeHintValue="{}"/
  80. {
  81. %TypeHeaderCode
  82. #include <QMultiHash>
  83. %End
  84. %ConvertFromTypeCode
  85. PyObject *d = PyDict_New();
  86. if (!d)
  87. return 0;
  88. QMultiHash<_TYPE1_, _TYPE2_>::const_iterator it = sipCpp->constBegin();
  89. QMultiHash<_TYPE1_, _TYPE2_>::const_iterator end = sipCpp->constEnd();
  90. while (it != end)
  91. {
  92. _TYPE1_ *k = new _TYPE1_(it.key());
  93. PyObject *kobj = sipConvertFromNewType(k, sipType__TYPE1_,
  94. sipTransferObj);
  95. if (!kobj)
  96. {
  97. delete k;
  98. Py_DECREF(d);
  99. return 0;
  100. }
  101. QList<_TYPE2_> values = sipCpp->values(it.key());
  102. PyObject *py_values = PyList_New(values.size());
  103. if (!py_values)
  104. {
  105. Py_DECREF(kobj);
  106. Py_DECREF(d);
  107. return 0;
  108. }
  109. int rc = PyDict_SetItem(d, kobj, py_values);
  110. Py_DECREF(py_values);
  111. Py_DECREF(kobj);
  112. if (rc < 0)
  113. {
  114. Py_DECREF(d);
  115. return 0;
  116. }
  117. for (int i = 0; i < values.size(); ++i)
  118. {
  119. _TYPE2_ *v = new _TYPE2_(values.at(i));
  120. PyObject *vobj = sipConvertFromNewType(v, sipType__TYPE2_,
  121. sipTransferObj);
  122. if (!vobj)
  123. {
  124. delete v;
  125. Py_DECREF(d);
  126. return 0;
  127. }
  128. PyList_SetItem(py_values, i, vobj);
  129. }
  130. ++it;
  131. }
  132. return d;
  133. %End
  134. };
  135. %End