SIP4 python bindings for TQt
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

169 líneas
3.7KB

  1. // This is the SIP interface definition for all types based on the TQMemArray
  2. // template.
  3. //
  4. // Copyright (c) 2007
  5. // Riverbank Computing Limited <info@riverbankcomputing.co.uk>
  6. //
  7. // This file is part of PyTQt.
  8. //
  9. // This copy of PyTQt is free software; you can redistribute it and/or modify it
  10. // under the terms of the GNU General Public License as published by the Free
  11. // Software Foundation; either version 2, or (at your option) any later
  12. // version.
  13. //
  14. // PyTQt is supplied in the hope that it will be useful, but WITHOUT ANY
  15. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17. // details.
  18. //
  19. // You should have received a copy of the GNU General Public License along with
  20. // PyTQt; see the file LICENSE. If not, write to the Free Software Foundation,
  21. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. %ExportedDoc
  23. <Sect2><Title>TQMemArray&lt;type&gt; (TQt v3+)</Title>
  24. <Para>
  25. Types based on the <Literal>TQMemArray</Literal> template are automatically
  26. converted to and from Python lists of the type.
  27. </Para>
  28. </Sect2>
  29. %End
  30. %If (TQt_3_0_0 -)
  31. %MappedType TQMemArray<int>
  32. {
  33. %TypeHeaderCode
  34. #include <qmemarray.h>
  35. %End
  36. %ConvertFromTypeCode
  37. // Convert to a Python list of integers.
  38. PyObject *l;
  39. // Create the list.
  40. if ((l = PyList_New(sipCpp -> size())) == NULL)
  41. return NULL;
  42. // Get it.
  43. for (uint i = 0; i < sipCpp -> size(); ++i)
  44. if (PyList_SetItem(l,i,PyInt_FromLong((long)sipCpp -> at(i))) < 0)
  45. {
  46. Py_DECREF(l);
  47. return NULL;
  48. }
  49. return l;
  50. %End
  51. %ConvertToTypeCode
  52. // Convert a Python list of integers to a TQMemArray<int> on the heap.
  53. if (sipIsErr == NULL)
  54. return PyList_Check(sipPy);
  55. TQMemArray<int> *qma = new TQMemArray<int>(PyList_GET_SIZE(sipPy));
  56. PyErr_Clear();
  57. for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
  58. {
  59. (*qma)[i] = (int)PyInt_AsLong(PyList_GET_ITEM(sipPy,i));
  60. if (PyErr_Occurred() != NULL)
  61. {
  62. delete qma;
  63. *sipIsErr = 1;
  64. return 0;
  65. }
  66. }
  67. *sipCppPtr = qma;
  68. return sipGetState(sipTransferObj);
  69. %End
  70. };
  71. template<TYPE>
  72. %MappedType TQMemArray<TYPE>
  73. {
  74. %TypeHeaderCode
  75. #include <qmemarray.h>
  76. %End
  77. %ConvertFromTypeCode
  78. // Create the list.
  79. PyObject *l;
  80. if ((l = PyList_New(sipCpp->size())) == NULL)
  81. return NULL;
  82. // Set the list elements.
  83. for (uint i = 0; i < sipCpp->size(); ++i)
  84. {
  85. TYPE *t = new TYPE(sipCpp->at(i));
  86. PyObject *tobj;
  87. if ((tobj = sipConvertFromNewInstance(t, sipClass_TYPE, sipTransferObj)) == NULL)
  88. {
  89. Py_DECREF(l);
  90. delete t;
  91. return NULL;
  92. }
  93. PyList_SET_ITEM(l, i, tobj);
  94. }
  95. return l;
  96. %End
  97. %ConvertToTypeCode
  98. // Check the type if that is all that is required.
  99. if (sipIsErr == NULL)
  100. {
  101. if (!PyList_Check(sipPy))
  102. return 0;
  103. for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
  104. if (!sipCanConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_TYPE, SIP_NOT_NONE))
  105. return 0;
  106. return 1;
  107. }
  108. TQMemArray<TYPE> *ql = new TQMemArray<TYPE>;
  109. for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
  110. {
  111. int state;
  112. TYPE *t = reinterpret_cast<TYPE *>(sipConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
  113. if (*sipIsErr)
  114. {
  115. sipReleaseInstance(t, sipClass_TYPE, state);
  116. delete ql;
  117. return 0;
  118. }
  119. uint idx = ql->size();
  120. ql->resize(idx + 1);
  121. ql->at(idx) = *t;
  122. sipReleaseInstance(t, sipClass_TYPE, state);
  123. }
  124. *sipCppPtr = ql;
  125. return sipGetState(sipTransferObj);
  126. %End
  127. };
  128. %End