qbuffer.sip 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // qbuffer.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtCore Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. class QBuffer : public QIODevice
  22. {
  23. %TypeHeaderCode
  24. #include <qbuffer.h>
  25. %End
  26. public:
  27. explicit QBuffer(QObject *parent /TransferThis/ = 0);
  28. QBuffer(QByteArray *byteArray /Constrained/, QObject *parent /TransferThis/ = 0);
  29. virtual ~QBuffer();
  30. QByteArray &buffer();
  31. const QByteArray &data() const;
  32. void setBuffer(QByteArray *a /Constrained/);
  33. void setData(const QByteArray &data);
  34. %If (- Qt_6_5_0)
  35. void setData(const char *adata /Array/, int alen /ArraySize/);
  36. %End
  37. %If (Qt_6_5_0 -)
  38. void setData(const char *data /Array/, qsizetype len /ArraySize/);
  39. %End
  40. virtual bool open(QIODeviceBase::OpenMode openMode);
  41. virtual void close();
  42. virtual qint64 size() const;
  43. virtual qint64 pos() const;
  44. virtual bool seek(qint64 off);
  45. virtual bool atEnd() const;
  46. virtual bool canReadLine() const;
  47. protected:
  48. virtual SIP_PYOBJECT readData(qint64 maxlen) /ReleaseGIL,TypeHint="bytes"/ [qint64 (char *data, qint64 maxlen)];
  49. %MethodCode
  50. // Return the data read or None if there was an error.
  51. if (a0 < 0)
  52. {
  53. PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
  54. sipIsErr = 1;
  55. }
  56. else
  57. {
  58. char *s = new char[a0];
  59. qint64 len;
  60. Py_BEGIN_ALLOW_THREADS
  61. #if defined(SIP_PROTECTED_IS_PUBLIC)
  62. len = sipSelfWasArg ? sipCpp->QBuffer::readData(s, a0) : sipCpp->readData(s, a0);
  63. #else
  64. len = sipCpp->sipProtectVirt_readData(sipSelfWasArg, s, a0);
  65. #endif
  66. Py_END_ALLOW_THREADS
  67. if (len < 0)
  68. {
  69. Py_INCREF(Py_None);
  70. sipRes = Py_None;
  71. }
  72. else
  73. {
  74. sipRes = PyBytes_FromStringAndSize(s, len);
  75. if (!sipRes)
  76. sipIsErr = 1;
  77. }
  78. delete[] s;
  79. }
  80. %End
  81. virtual qint64 writeData(SIP_PYBUFFER) /ReleaseGIL/ [qint64 (const char *data, qint64 len)];
  82. %MethodCode
  83. sipBufferInfoDef bi;
  84. if (sipGetBufferInfo(a0, &bi) > 0)
  85. {
  86. Py_BEGIN_ALLOW_THREADS
  87. #if defined(SIP_PROTECTED_IS_PUBLIC)
  88. sipRes = sipSelfWasArg ?
  89. sipCpp->QBuffer::writeData(reinterpret_cast<char *>(bi.bi_buf), bi.bi_len) :
  90. sipCpp->writeData(reinterpret_cast<char *>(bi.bi_buf), bi.bi_len);
  91. #else
  92. sipRes = sipCpp->sipProtectVirt_writeData(sipSelfWasArg, reinterpret_cast<char *>(bi.bi_buf),
  93. bi.bi_len);
  94. #endif
  95. Py_END_ALLOW_THREADS
  96. sipReleaseBufferInfo(&bi);
  97. }
  98. else
  99. {
  100. sipIsErr = 1;
  101. }
  102. %End
  103. };