qhostaddress.sip 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // qhostaddress.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtNetwork 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 QHostAddress /TypeHintIn="Union[QHostAddress, QHostAddress.SpecialAddress]"/
  22. {
  23. %TypeHeaderCode
  24. #include <qhostaddress.h>
  25. %End
  26. %ConvertToTypeCode
  27. // SIP doesn't support automatic type convertors so we explicitly allow a
  28. // QHostAddress::SpecialAddress to be used whenever a QHostAddress is expected.
  29. bool is_special_address = true;
  30. int special_address = sipConvertToEnum(sipPy, sipType_QHostAddress_SpecialAddress);
  31. if (PyErr_Occurred())
  32. {
  33. PyErr_Clear();
  34. is_special_address = false;
  35. }
  36. if (sipIsErr == NULL)
  37. return (is_special_address ||
  38. sipCanConvertToType(sipPy, sipType_QHostAddress, SIP_NO_CONVERTORS));
  39. if (is_special_address)
  40. {
  41. *sipCppPtr = new QHostAddress(static_cast<QHostAddress::SpecialAddress>(special_address));
  42. return sipGetState(sipTransferObj);
  43. }
  44. *sipCppPtr = reinterpret_cast<QHostAddress *>(sipConvertToType(sipPy, sipType_QHostAddress, sipTransferObj, SIP_NO_CONVERTORS, 0, sipIsErr));
  45. return 0;
  46. %End
  47. public:
  48. enum SpecialAddress
  49. {
  50. Null,
  51. Broadcast,
  52. LocalHost,
  53. LocalHostIPv6,
  54. AnyIPv4,
  55. AnyIPv6,
  56. Any,
  57. };
  58. QHostAddress();
  59. QHostAddress(QHostAddress::SpecialAddress address /Constrained/);
  60. explicit QHostAddress(quint32 ip4Addr);
  61. explicit QHostAddress(const QString &address);
  62. explicit QHostAddress(const Q_IPV6ADDR &ip6Addr);
  63. QHostAddress(const QHostAddress &copy);
  64. ~QHostAddress();
  65. void setAddress(QHostAddress::SpecialAddress address /Constrained/);
  66. void setAddress(quint32 ip4Addr);
  67. bool setAddress(const QString &address);
  68. void setAddress(const Q_IPV6ADDR &ip6Addr);
  69. QAbstractSocket::NetworkLayerProtocol protocol() const;
  70. quint32 toIPv4Address(bool *ok = 0) const;
  71. Q_IPV6ADDR toIPv6Address() const;
  72. QString toString() const;
  73. QString scopeId() const;
  74. void setScopeId(const QString &id);
  75. bool operator==(const QHostAddress &address) const;
  76. bool operator==(QHostAddress::SpecialAddress address) const;
  77. bool operator!=(const QHostAddress &address) const;
  78. bool operator!=(QHostAddress::SpecialAddress address) const;
  79. bool isNull() const;
  80. void clear();
  81. Py_hash_t __hash__() const;
  82. %MethodCode
  83. sipRes = qHash(*sipCpp);
  84. %End
  85. bool isInSubnet(const QHostAddress &subnet, int netmask) const;
  86. bool isInSubnet(const std::pair<QHostAddress, int> &subnet) const;
  87. bool isLoopback() const;
  88. static std::pair<QHostAddress, int> parseSubnet(const QString &subnet);
  89. void swap(QHostAddress &other /Constrained/);
  90. bool isMulticast() const;
  91. enum ConversionModeFlag /BaseType=Flag/
  92. {
  93. ConvertV4MappedToIPv4,
  94. ConvertV4CompatToIPv4,
  95. ConvertUnspecifiedAddress,
  96. ConvertLocalHost,
  97. TolerantConversion,
  98. StrictConversion,
  99. };
  100. typedef QFlags<QHostAddress::ConversionModeFlag> ConversionMode;
  101. bool isEqual(const QHostAddress &address, QHostAddress::ConversionMode mode = QHostAddress::TolerantConversion) const;
  102. bool isGlobal() const;
  103. bool isLinkLocal() const;
  104. bool isSiteLocal() const;
  105. bool isUniqueLocalUnicast() const;
  106. bool isBroadcast() const;
  107. %If (Qt_6_6_0 -)
  108. bool isPrivateUse() const;
  109. %End
  110. };
  111. bool operator==(QHostAddress::SpecialAddress address1, const QHostAddress &address2);
  112. bool operator!=(QHostAddress::SpecialAddress lhs, const QHostAddress &rhs);
  113. QDataStream &operator<<(QDataStream &, const QHostAddress &) /ReleaseGIL/;
  114. QDataStream &operator>>(QDataStream &, QHostAddress &) /ReleaseGIL/;
  115. // Q_IPV6ADDR is implemented as a Python 16-tuple of ints.
  116. %MappedType Q_IPV6ADDR /TypeHint="Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int]"/
  117. {
  118. %TypeHeaderCode
  119. #include <qhostaddress.h>
  120. %End
  121. %ConvertFromTypeCode
  122. // Create the tuple.
  123. PyObject *t;
  124. if ((t = PyTuple_New(16)) == NULL)
  125. return NULL;
  126. // Set the tuple elements.
  127. for (int i = 0; i < 16; ++i)
  128. {
  129. PyObject *pobj;
  130. if ((pobj = PyLong_FromLong((*sipCpp)[i])) == NULL)
  131. {
  132. Py_DECREF(t);
  133. return NULL;
  134. }
  135. PyTuple_SetItem(t, i, pobj);
  136. }
  137. return t;
  138. %End
  139. %ConvertToTypeCode
  140. // Check the type if that is all that is required.
  141. if (sipIsErr == NULL)
  142. return (PySequence_Check(sipPy) && PySequence_Size(sipPy) == 16);
  143. Q_IPV6ADDR *qa = new Q_IPV6ADDR;
  144. for (Py_ssize_t i = 0; i < 16; ++i)
  145. {
  146. PyObject *itm = PySequence_GetItem(sipPy, i);
  147. if (!itm)
  148. {
  149. delete qa;
  150. *sipIsErr = 1;
  151. return 0;
  152. }
  153. (*qa)[i] = PyLong_AsLong(itm);
  154. Py_DECREF(itm);
  155. }
  156. *sipCppPtr = qa;
  157. return sipGetState(sipTransferObj);
  158. %End
  159. };