ctpbee-opt-api 0.1.0__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. ctpbee_api/__init__.py +17 -0
  2. ctpbee_api/ctp/__init__.py +3 -0
  3. ctpbee_api/ctp/ctp_constant.py +1253 -0
  4. ctpbee_api/ctp/generator/concat.py +93 -0
  5. ctpbee_api/ctp/generator/const.py +325 -0
  6. ctpbee_api/ctp/generator/ctp_constant.py +1274 -0
  7. ctpbee_api/ctp/generator/ctp_md_header_define.h +13 -0
  8. ctpbee_api/ctp/generator/ctp_md_header_function.h +6 -0
  9. ctpbee_api/ctp/generator/ctp_md_header_on.h +26 -0
  10. ctpbee_api/ctp/generator/ctp_md_header_process.h +26 -0
  11. ctpbee_api/ctp/generator/ctp_md_source_function.cpp +42 -0
  12. ctpbee_api/ctp/generator/ctp_md_source_module.cpp +18 -0
  13. ctpbee_api/ctp/generator/ctp_md_source_on.cpp +156 -0
  14. ctpbee_api/ctp/generator/ctp_md_source_process.cpp +282 -0
  15. ctpbee_api/ctp/generator/ctp_md_source_switch.cpp +78 -0
  16. ctpbee_api/ctp/generator/ctp_md_source_task.cpp +211 -0
  17. ctpbee_api/ctp/generator/ctp_struct.py +5640 -0
  18. ctpbee_api/ctp/generator/ctp_td_header_define.h +130 -0
  19. ctpbee_api/ctp/generator/ctp_td_header_function.h +174 -0
  20. ctpbee_api/ctp/generator/ctp_td_header_on.h +260 -0
  21. ctpbee_api/ctp/generator/ctp_td_header_process.h +260 -0
  22. ctpbee_api/ctp/generator/ctp_td_source_function.cpp +1456 -0
  23. ctpbee_api/ctp/generator/ctp_td_source_module.cpp +222 -0
  24. ctpbee_api/ctp/generator/ctp_td_source_on.cpp +1572 -0
  25. ctpbee_api/ctp/generator/ctp_td_source_process.cpp +5472 -0
  26. ctpbee_api/ctp/generator/ctp_td_source_switch.cpp +780 -0
  27. ctpbee_api/ctp/generator/ctp_td_source_task.cpp +2444 -0
  28. ctpbee_api/ctp/generator/ctp_typedef.py +800 -0
  29. ctpbee_api/ctp/generator/generate_api_functions.py +345 -0
  30. ctpbee_api/ctp/generator/generate_data_type.py +76 -0
  31. ctpbee_api/ctp/generator/generate_struct.py +84 -0
  32. ctpbee_api/ctp/include/mac/ctp/ThostFtdcMdApi.h +168 -0
  33. ctpbee_api/ctp/include/mac/ctp/ThostFtdcTraderApi.h +770 -0
  34. ctpbee_api/ctp/include/mac/ctp/ThostFtdcUserApiDataType.h +6878 -0
  35. ctpbee_api/ctp/include/mac/ctp/ThostFtdcUserApiStruct.h +10915 -0
  36. ctpbee_api/ctp/include/mac/pybind11/attr.h +690 -0
  37. ctpbee_api/ctp/include/mac/pybind11/buffer_info.h +208 -0
  38. ctpbee_api/ctp/include/mac/pybind11/cast.h +1704 -0
  39. ctpbee_api/ctp/include/mac/pybind11/chrono.h +225 -0
  40. ctpbee_api/ctp/include/mac/pybind11/common.h +2 -0
  41. ctpbee_api/ctp/include/mac/pybind11/complex.h +74 -0
  42. ctpbee_api/ctp/include/mac/pybind11/detail/class.h +743 -0
  43. ctpbee_api/ctp/include/mac/pybind11/detail/common.h +1255 -0
  44. ctpbee_api/ctp/include/mac/pybind11/detail/descr.h +171 -0
  45. ctpbee_api/ctp/include/mac/pybind11/detail/init.h +434 -0
  46. ctpbee_api/ctp/include/mac/pybind11/detail/internals.h +656 -0
  47. ctpbee_api/ctp/include/mac/pybind11/detail/type_caster_base.h +1177 -0
  48. ctpbee_api/ctp/include/mac/pybind11/detail/typeid.h +65 -0
  49. ctpbee_api/ctp/include/mac/pybind11/eigen/common.h +9 -0
  50. ctpbee_api/ctp/include/mac/pybind11/eigen/matrix.h +714 -0
  51. ctpbee_api/ctp/include/mac/pybind11/eigen/tensor.h +516 -0
  52. ctpbee_api/ctp/include/mac/pybind11/eigen.h +12 -0
  53. ctpbee_api/ctp/include/mac/pybind11/embed.h +316 -0
  54. ctpbee_api/ctp/include/mac/pybind11/eval.h +156 -0
  55. ctpbee_api/ctp/include/mac/pybind11/functional.h +137 -0
  56. ctpbee_api/ctp/include/mac/pybind11/gil.h +239 -0
  57. ctpbee_api/ctp/include/mac/pybind11/iostream.h +265 -0
  58. ctpbee_api/ctp/include/mac/pybind11/numpy.h +1998 -0
  59. ctpbee_api/ctp/include/mac/pybind11/operators.h +202 -0
  60. ctpbee_api/ctp/include/mac/pybind11/options.h +92 -0
  61. ctpbee_api/ctp/include/mac/pybind11/pybind11.h +2890 -0
  62. ctpbee_api/ctp/include/mac/pybind11/pytypes.h +2557 -0
  63. ctpbee_api/ctp/include/mac/pybind11/stl/filesystem.h +116 -0
  64. ctpbee_api/ctp/include/mac/pybind11/stl.h +447 -0
  65. ctpbee_api/ctp/include/mac/pybind11/stl_bind.h +851 -0
  66. ctpbee_api/ctp/include/mac/pybind11/type_caster_pyobject_ptr.h +61 -0
  67. ctpbee_api/ctp/include/new/ctp/ThostFtdcMdApi.h +168 -0
  68. ctpbee_api/ctp/include/new/ctp/ThostFtdcTraderApi.h +770 -0
  69. ctpbee_api/ctp/include/new/ctp/ThostFtdcUserApiDataType.h +6878 -0
  70. ctpbee_api/ctp/include/new/ctp/ThostFtdcUserApiStruct.h +10915 -0
  71. ctpbee_api/ctp/include/new/pybind11/attr.h +690 -0
  72. ctpbee_api/ctp/include/new/pybind11/buffer_info.h +208 -0
  73. ctpbee_api/ctp/include/new/pybind11/cast.h +1704 -0
  74. ctpbee_api/ctp/include/new/pybind11/chrono.h +225 -0
  75. ctpbee_api/ctp/include/new/pybind11/common.h +2 -0
  76. ctpbee_api/ctp/include/new/pybind11/complex.h +74 -0
  77. ctpbee_api/ctp/include/new/pybind11/detail/class.h +743 -0
  78. ctpbee_api/ctp/include/new/pybind11/detail/common.h +1255 -0
  79. ctpbee_api/ctp/include/new/pybind11/detail/descr.h +171 -0
  80. ctpbee_api/ctp/include/new/pybind11/detail/init.h +434 -0
  81. ctpbee_api/ctp/include/new/pybind11/detail/internals.h +656 -0
  82. ctpbee_api/ctp/include/new/pybind11/detail/type_caster_base.h +1177 -0
  83. ctpbee_api/ctp/include/new/pybind11/detail/typeid.h +65 -0
  84. ctpbee_api/ctp/include/new/pybind11/eigen/common.h +9 -0
  85. ctpbee_api/ctp/include/new/pybind11/eigen/matrix.h +714 -0
  86. ctpbee_api/ctp/include/new/pybind11/eigen/tensor.h +516 -0
  87. ctpbee_api/ctp/include/new/pybind11/eigen.h +12 -0
  88. ctpbee_api/ctp/include/new/pybind11/embed.h +316 -0
  89. ctpbee_api/ctp/include/new/pybind11/eval.h +156 -0
  90. ctpbee_api/ctp/include/new/pybind11/functional.h +137 -0
  91. ctpbee_api/ctp/include/new/pybind11/gil.h +239 -0
  92. ctpbee_api/ctp/include/new/pybind11/iostream.h +265 -0
  93. ctpbee_api/ctp/include/new/pybind11/numpy.h +1998 -0
  94. ctpbee_api/ctp/include/new/pybind11/operators.h +202 -0
  95. ctpbee_api/ctp/include/new/pybind11/options.h +92 -0
  96. ctpbee_api/ctp/include/new/pybind11/pybind11.h +2890 -0
  97. ctpbee_api/ctp/include/new/pybind11/pytypes.h +2557 -0
  98. ctpbee_api/ctp/include/new/pybind11/stl/filesystem.h +116 -0
  99. ctpbee_api/ctp/include/new/pybind11/stl.h +447 -0
  100. ctpbee_api/ctp/include/new/pybind11/stl_bind.h +851 -0
  101. ctpbee_api/ctp/include/new/pybind11/type_caster_pyobject_ptr.h +61 -0
  102. ctpbee_api/ctp/include/previous/ctp/ThostFtdcMdApi.h +168 -0
  103. ctpbee_api/ctp/include/previous/ctp/ThostFtdcTraderApi.h +770 -0
  104. ctpbee_api/ctp/include/previous/ctp/ThostFtdcUserApiDataType.h +6878 -0
  105. ctpbee_api/ctp/include/previous/ctp/ThostFtdcUserApiStruct.h +10915 -0
  106. ctpbee_api/ctp/include/previous/pybind11/attr.h +489 -0
  107. ctpbee_api/ctp/include/previous/pybind11/buffer_info.h +108 -0
  108. ctpbee_api/ctp/include/previous/pybind11/cast.h +2067 -0
  109. ctpbee_api/ctp/include/previous/pybind11/chrono.h +162 -0
  110. ctpbee_api/ctp/include/previous/pybind11/common.h +2 -0
  111. ctpbee_api/ctp/include/previous/pybind11/complex.h +61 -0
  112. ctpbee_api/ctp/include/previous/pybind11/detail/class.h +626 -0
  113. ctpbee_api/ctp/include/previous/pybind11/detail/common.h +803 -0
  114. ctpbee_api/ctp/include/previous/pybind11/detail/descr.h +185 -0
  115. ctpbee_api/ctp/include/previous/pybind11/detail/init.h +335 -0
  116. ctpbee_api/ctp/include/previous/pybind11/detail/internals.h +285 -0
  117. ctpbee_api/ctp/include/previous/pybind11/detail/typeid.h +53 -0
  118. ctpbee_api/ctp/include/previous/pybind11/eigen.h +604 -0
  119. ctpbee_api/ctp/include/previous/pybind11/embed.h +194 -0
  120. ctpbee_api/ctp/include/previous/pybind11/eval.h +117 -0
  121. ctpbee_api/ctp/include/previous/pybind11/functional.h +85 -0
  122. ctpbee_api/ctp/include/previous/pybind11/iostream.h +200 -0
  123. ctpbee_api/ctp/include/previous/pybind11/numpy.h +1601 -0
  124. ctpbee_api/ctp/include/previous/pybind11/operators.h +168 -0
  125. ctpbee_api/ctp/include/previous/pybind11/options.h +65 -0
  126. ctpbee_api/ctp/include/previous/pybind11/pybind11.h +1965 -0
  127. ctpbee_api/ctp/include/previous/pybind11/pytypes.h +1332 -0
  128. ctpbee_api/ctp/include/previous/pybind11/stl.h +376 -0
  129. ctpbee_api/ctp/include/previous/pybind11/stl_bind.h +599 -0
  130. ctpbee_api/ctp/libs/libcomunicationkey.a +0 -0
  131. ctpbee_api/ctp/libs/libcrypto.a +0 -0
  132. ctpbee_api/ctp/libs/libssl.a +0 -0
  133. ctpbee_api/ctp/libs/thostmduserapi_se.lib +0 -0
  134. ctpbee_api/ctp/libs/thosttraderapi_se.lib +0 -0
  135. ctpbee_api/ctp/libthostmduserapi_se.so +0 -0
  136. ctpbee_api/ctp/libthosttraderapi_se.so +0 -0
  137. ctpbee_api/ctp/thostmduserapi_se.dll +0 -0
  138. ctpbee_api/ctp/thosttraderapi_se.dll +0 -0
  139. ctpbee_api/ctp/vnctp/vnctp.h +189 -0
  140. ctpbee_api/ctp/vnctp/vnctp.sln +41 -0
  141. ctpbee_api/ctp/vnctp/vnctpmd/dllmain.cpp +19 -0
  142. ctpbee_api/ctp/vnctp/vnctpmd/stdafx.cpp +1 -0
  143. ctpbee_api/ctp/vnctp/vnctpmd/stdafx.h +17 -0
  144. ctpbee_api/ctp/vnctp/vnctpmd/targetver.h +8 -0
  145. ctpbee_api/ctp/vnctp/vnctpmd/vnctpmd.cpp +953 -0
  146. ctpbee_api/ctp/vnctp/vnctpmd/vnctpmd.h +209 -0
  147. ctpbee_api/ctp/vnctp/vnctpmd/vnctpmd.vcxproj +200 -0
  148. ctpbee_api/ctp/vnctp/vnctpmd/vnctpmd.vcxproj.filters +54 -0
  149. ctpbee_api/ctp/vnctp/vnctpmd/vnctpmd.vcxproj.user +4 -0
  150. ctpbee_api/ctp/vnctp/vnctptd/dllmain.cpp +19 -0
  151. ctpbee_api/ctp/vnctp/vnctptd/stdafx.cpp +1 -0
  152. ctpbee_api/ctp/vnctp/vnctptd/stdafx.h +16 -0
  153. ctpbee_api/ctp/vnctp/vnctptd/targetver.h +8 -0
  154. ctpbee_api/ctp/vnctp/vnctptd/vnctptd.cpp +12148 -0
  155. ctpbee_api/ctp/vnctp/vnctptd/vnctptd.h +1329 -0
  156. ctpbee_api/ctp/vnctp/vnctptd/vnctptd.vcxproj +198 -0
  157. ctpbee_api/ctp/vnctp/vnctptd/vnctptd.vcxproj.filters +54 -0
  158. ctpbee_api/ctp/vnctp/vnctptd/vnctptd.vcxproj.user +4 -0
  159. ctpbee_api/ctp/vnctpmd.cp312-win_amd64.pyd +0 -0
  160. ctpbee_api/ctp/vnctptd.cp312-win_amd64.pyd +0 -0
  161. ctpbee_api/ctp_mini/__init__.py +3 -0
  162. ctpbee_api/ctp_mini/generator/generate_api_functions.py +343 -0
  163. ctpbee_api/ctp_mini/generator/generate_data_type.py +76 -0
  164. ctpbee_api/ctp_mini/generator/generate_struct.py +85 -0
  165. ctpbee_api/ctp_mini/generator/mini_constant.py +1186 -0
  166. ctpbee_api/ctp_mini/generator/mini_md_header_define.h +13 -0
  167. ctpbee_api/ctp_mini/generator/mini_md_header_function.h +4 -0
  168. ctpbee_api/ctp_mini/generator/mini_md_header_on.h +26 -0
  169. ctpbee_api/ctp_mini/generator/mini_md_header_process.h +26 -0
  170. ctpbee_api/ctp_mini/generator/mini_md_source_function.cpp +29 -0
  171. ctpbee_api/ctp_mini/generator/mini_md_source_module.cpp +17 -0
  172. ctpbee_api/ctp_mini/generator/mini_md_source_on.cpp +156 -0
  173. ctpbee_api/ctp_mini/generator/mini_md_source_process.cpp +264 -0
  174. ctpbee_api/ctp_mini/generator/mini_md_source_switch.cpp +78 -0
  175. ctpbee_api/ctp_mini/generator/mini_md_source_task.cpp +203 -0
  176. ctpbee_api/ctp_mini/generator/mini_struct.py +4599 -0
  177. ctpbee_api/ctp_mini/generator/mini_td_header_define.h +63 -0
  178. ctpbee_api/ctp_mini/generator/mini_td_header_function.h +84 -0
  179. ctpbee_api/ctp_mini/generator/mini_td_header_on.h +126 -0
  180. ctpbee_api/ctp_mini/generator/mini_td_header_process.h +126 -0
  181. ctpbee_api/ctp_mini/generator/mini_td_source_function.cpp +663 -0
  182. ctpbee_api/ctp_mini/generator/mini_td_source_module.cpp +107 -0
  183. ctpbee_api/ctp_mini/generator/mini_td_source_on.cpp +756 -0
  184. ctpbee_api/ctp_mini/generator/mini_td_source_process.cpp +2492 -0
  185. ctpbee_api/ctp_mini/generator/mini_td_source_switch.cpp +378 -0
  186. ctpbee_api/ctp_mini/generator/mini_td_source_task.cpp +1193 -0
  187. ctpbee_api/ctp_mini/generator/mini_typedef.py +755 -0
  188. ctpbee_api/ctp_mini/generator/package/vnminimd.cpp +886 -0
  189. ctpbee_api/ctp_mini/generator/package/vnminimd.h +205 -0
  190. ctpbee_api/ctp_mini/include/new/mini/ThostFtdcMdApi.h +148 -0
  191. ctpbee_api/ctp_mini/include/new/mini/ThostFtdcTraderApi.h +419 -0
  192. ctpbee_api/ctp_mini/include/new/mini/ThostFtdcUserApiDataType.h +6458 -0
  193. ctpbee_api/ctp_mini/include/new/mini/ThostFtdcUserApiStruct.h +8890 -0
  194. ctpbee_api/ctp_mini/include/new/pybind11/attr.h +690 -0
  195. ctpbee_api/ctp_mini/include/new/pybind11/buffer_info.h +208 -0
  196. ctpbee_api/ctp_mini/include/new/pybind11/cast.h +1704 -0
  197. ctpbee_api/ctp_mini/include/new/pybind11/chrono.h +225 -0
  198. ctpbee_api/ctp_mini/include/new/pybind11/common.h +2 -0
  199. ctpbee_api/ctp_mini/include/new/pybind11/complex.h +74 -0
  200. ctpbee_api/ctp_mini/include/new/pybind11/detail/class.h +743 -0
  201. ctpbee_api/ctp_mini/include/new/pybind11/detail/common.h +1255 -0
  202. ctpbee_api/ctp_mini/include/new/pybind11/detail/descr.h +171 -0
  203. ctpbee_api/ctp_mini/include/new/pybind11/detail/init.h +434 -0
  204. ctpbee_api/ctp_mini/include/new/pybind11/detail/internals.h +656 -0
  205. ctpbee_api/ctp_mini/include/new/pybind11/detail/type_caster_base.h +1177 -0
  206. ctpbee_api/ctp_mini/include/new/pybind11/detail/typeid.h +65 -0
  207. ctpbee_api/ctp_mini/include/new/pybind11/eigen/common.h +9 -0
  208. ctpbee_api/ctp_mini/include/new/pybind11/eigen/matrix.h +714 -0
  209. ctpbee_api/ctp_mini/include/new/pybind11/eigen/tensor.h +516 -0
  210. ctpbee_api/ctp_mini/include/new/pybind11/eigen.h +12 -0
  211. ctpbee_api/ctp_mini/include/new/pybind11/embed.h +316 -0
  212. ctpbee_api/ctp_mini/include/new/pybind11/eval.h +156 -0
  213. ctpbee_api/ctp_mini/include/new/pybind11/functional.h +137 -0
  214. ctpbee_api/ctp_mini/include/new/pybind11/gil.h +239 -0
  215. ctpbee_api/ctp_mini/include/new/pybind11/iostream.h +265 -0
  216. ctpbee_api/ctp_mini/include/new/pybind11/numpy.h +1998 -0
  217. ctpbee_api/ctp_mini/include/new/pybind11/operators.h +202 -0
  218. ctpbee_api/ctp_mini/include/new/pybind11/options.h +92 -0
  219. ctpbee_api/ctp_mini/include/new/pybind11/pybind11.h +2890 -0
  220. ctpbee_api/ctp_mini/include/new/pybind11/pytypes.h +2557 -0
  221. ctpbee_api/ctp_mini/include/new/pybind11/stl/filesystem.h +116 -0
  222. ctpbee_api/ctp_mini/include/new/pybind11/stl.h +447 -0
  223. ctpbee_api/ctp_mini/include/new/pybind11/stl_bind.h +851 -0
  224. ctpbee_api/ctp_mini/include/new/pybind11/type_caster_pyobject_ptr.h +61 -0
  225. ctpbee_api/ctp_mini/include/previous/mini/ThostFtdcMdApi.h +148 -0
  226. ctpbee_api/ctp_mini/include/previous/mini/ThostFtdcTraderApi.h +419 -0
  227. ctpbee_api/ctp_mini/include/previous/mini/ThostFtdcUserApiDataType.h +6458 -0
  228. ctpbee_api/ctp_mini/include/previous/mini/ThostFtdcUserApiStruct.h +8890 -0
  229. ctpbee_api/ctp_mini/include/previous/pybind11/attr.h +489 -0
  230. ctpbee_api/ctp_mini/include/previous/pybind11/buffer_info.h +108 -0
  231. ctpbee_api/ctp_mini/include/previous/pybind11/cast.h +2067 -0
  232. ctpbee_api/ctp_mini/include/previous/pybind11/chrono.h +162 -0
  233. ctpbee_api/ctp_mini/include/previous/pybind11/common.h +2 -0
  234. ctpbee_api/ctp_mini/include/previous/pybind11/complex.h +61 -0
  235. ctpbee_api/ctp_mini/include/previous/pybind11/detail/class.h +626 -0
  236. ctpbee_api/ctp_mini/include/previous/pybind11/detail/common.h +803 -0
  237. ctpbee_api/ctp_mini/include/previous/pybind11/detail/descr.h +185 -0
  238. ctpbee_api/ctp_mini/include/previous/pybind11/detail/init.h +335 -0
  239. ctpbee_api/ctp_mini/include/previous/pybind11/detail/internals.h +285 -0
  240. ctpbee_api/ctp_mini/include/previous/pybind11/detail/typeid.h +53 -0
  241. ctpbee_api/ctp_mini/include/previous/pybind11/eigen.h +604 -0
  242. ctpbee_api/ctp_mini/include/previous/pybind11/embed.h +194 -0
  243. ctpbee_api/ctp_mini/include/previous/pybind11/eval.h +117 -0
  244. ctpbee_api/ctp_mini/include/previous/pybind11/functional.h +85 -0
  245. ctpbee_api/ctp_mini/include/previous/pybind11/iostream.h +200 -0
  246. ctpbee_api/ctp_mini/include/previous/pybind11/numpy.h +1601 -0
  247. ctpbee_api/ctp_mini/include/previous/pybind11/operators.h +168 -0
  248. ctpbee_api/ctp_mini/include/previous/pybind11/options.h +65 -0
  249. ctpbee_api/ctp_mini/include/previous/pybind11/pybind11.h +1965 -0
  250. ctpbee_api/ctp_mini/include/previous/pybind11/pytypes.h +1332 -0
  251. ctpbee_api/ctp_mini/include/previous/pybind11/stl.h +376 -0
  252. ctpbee_api/ctp_mini/include/previous/pybind11/stl_bind.h +599 -0
  253. ctpbee_api/ctp_mini/libs/thostmduserapi.lib +0 -0
  254. ctpbee_api/ctp_mini/libs/thosttraderapi.lib +0 -0
  255. ctpbee_api/ctp_mini/libthostmduserapi.so +0 -0
  256. ctpbee_api/ctp_mini/libthosttraderapi.so +0 -0
  257. ctpbee_api/ctp_mini/mini_constant.py +1186 -0
  258. ctpbee_api/ctp_mini/thostmduserapi.dll +0 -0
  259. ctpbee_api/ctp_mini/thosttraderapi.dll +0 -0
  260. ctpbee_api/ctp_mini/vnctp_mini/vnctp_mini.h +146 -0
  261. ctpbee_api/ctp_mini/vnctp_mini/vnctp_mini.sln +41 -0
  262. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minimd/dllmain.cpp +0 -0
  263. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minimd/stdafx.cpp +0 -0
  264. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minimd/stdafx.h +0 -0
  265. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minimd/targetver.h +0 -0
  266. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minimd/vnctp_minimd.cpp +886 -0
  267. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minimd/vnctp_minimd.h +203 -0
  268. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minimd/vnctp_minimd.vcxproj +183 -0
  269. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minimd/vnctp_minimd.vcxproj.filters +54 -0
  270. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minimd/vnctp_minimd.vcxproj.user +4 -0
  271. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minitd/dllmain.cpp +0 -0
  272. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minitd/stdafx.cpp +0 -0
  273. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minitd/stdafx.h +0 -0
  274. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minitd/targetver.h +0 -0
  275. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minitd/vnctp_minitd.cpp +5716 -0
  276. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minitd/vnctp_minitd.h +680 -0
  277. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minitd/vnctp_minitd.vcxproj +180 -0
  278. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minitd/vnctp_minitd.vcxproj.filters +54 -0
  279. ctpbee_api/ctp_mini/vnctp_mini/vnctp_minitd/vnctp_minitd.vcxproj.user +4 -0
  280. ctpbee_api/ctp_mini/vnctp_minimd.cp312-win_amd64.pyd +0 -0
  281. ctpbee_api/ctp_mini/vnctp_minitd.cp312-win_amd64.pyd +0 -0
  282. ctpbee_api/ctp_mini/vnctp_minitd.lib +0 -0
  283. ctpbee_api/rohon/RohonBaseV64.dll +0 -0
  284. ctpbee_api/rohon/WinDataCollect.dll +0 -0
  285. ctpbee_api/rohon/__init__.py +3 -0
  286. ctpbee_api/rohon/generator/generate_api_functions.py +348 -0
  287. ctpbee_api/rohon/generator/generate_data_type.py +76 -0
  288. ctpbee_api/rohon/generator/generate_struct.py +84 -0
  289. ctpbee_api/rohon/generator/rohon_constant.py +1242 -0
  290. ctpbee_api/rohon/generator/rohon_md_header_define.h +13 -0
  291. ctpbee_api/rohon/generator/rohon_md_header_function.h +6 -0
  292. ctpbee_api/rohon/generator/rohon_md_header_on.h +26 -0
  293. ctpbee_api/rohon/generator/rohon_md_header_process.h +26 -0
  294. ctpbee_api/rohon/generator/rohon_md_source_function.cpp +40 -0
  295. ctpbee_api/rohon/generator/rohon_md_source_module.cpp +18 -0
  296. ctpbee_api/rohon/generator/rohon_md_source_on.cpp +156 -0
  297. ctpbee_api/rohon/generator/rohon_md_source_process.cpp +271 -0
  298. ctpbee_api/rohon/generator/rohon_md_source_switch.cpp +78 -0
  299. ctpbee_api/rohon/generator/rohon_md_source_task.cpp +211 -0
  300. ctpbee_api/rohon/generator/rohon_struct.py +4958 -0
  301. ctpbee_api/rohon/generator/rohon_td_header_define.h +125 -0
  302. ctpbee_api/rohon/generator/rohon_td_header_function.h +164 -0
  303. ctpbee_api/rohon/generator/rohon_td_header_on.h +250 -0
  304. ctpbee_api/rohon/generator/rohon_td_header_process.h +250 -0
  305. ctpbee_api/rohon/generator/rohon_td_source_function.cpp +1338 -0
  306. ctpbee_api/rohon/generator/rohon_td_source_module.cpp +209 -0
  307. ctpbee_api/rohon/generator/rohon_td_source_on.cpp +1500 -0
  308. ctpbee_api/rohon/generator/rohon_td_source_process.cpp +5125 -0
  309. ctpbee_api/rohon/generator/rohon_td_source_switch.cpp +750 -0
  310. ctpbee_api/rohon/generator/rohon_td_source_task.cpp +2339 -0
  311. ctpbee_api/rohon/generator/rohon_typedef.py +781 -0
  312. ctpbee_api/rohon/include/new/pybind11/attr.h +690 -0
  313. ctpbee_api/rohon/include/new/pybind11/buffer_info.h +208 -0
  314. ctpbee_api/rohon/include/new/pybind11/cast.h +1704 -0
  315. ctpbee_api/rohon/include/new/pybind11/chrono.h +225 -0
  316. ctpbee_api/rohon/include/new/pybind11/common.h +2 -0
  317. ctpbee_api/rohon/include/new/pybind11/complex.h +74 -0
  318. ctpbee_api/rohon/include/new/pybind11/detail/class.h +743 -0
  319. ctpbee_api/rohon/include/new/pybind11/detail/common.h +1255 -0
  320. ctpbee_api/rohon/include/new/pybind11/detail/descr.h +171 -0
  321. ctpbee_api/rohon/include/new/pybind11/detail/init.h +434 -0
  322. ctpbee_api/rohon/include/new/pybind11/detail/internals.h +656 -0
  323. ctpbee_api/rohon/include/new/pybind11/detail/type_caster_base.h +1177 -0
  324. ctpbee_api/rohon/include/new/pybind11/detail/typeid.h +65 -0
  325. ctpbee_api/rohon/include/new/pybind11/eigen/common.h +9 -0
  326. ctpbee_api/rohon/include/new/pybind11/eigen/matrix.h +714 -0
  327. ctpbee_api/rohon/include/new/pybind11/eigen/tensor.h +516 -0
  328. ctpbee_api/rohon/include/new/pybind11/eigen.h +12 -0
  329. ctpbee_api/rohon/include/new/pybind11/embed.h +316 -0
  330. ctpbee_api/rohon/include/new/pybind11/eval.h +156 -0
  331. ctpbee_api/rohon/include/new/pybind11/functional.h +137 -0
  332. ctpbee_api/rohon/include/new/pybind11/gil.h +239 -0
  333. ctpbee_api/rohon/include/new/pybind11/iostream.h +265 -0
  334. ctpbee_api/rohon/include/new/pybind11/numpy.h +1998 -0
  335. ctpbee_api/rohon/include/new/pybind11/operators.h +202 -0
  336. ctpbee_api/rohon/include/new/pybind11/options.h +92 -0
  337. ctpbee_api/rohon/include/new/pybind11/pybind11.h +2890 -0
  338. ctpbee_api/rohon/include/new/pybind11/pytypes.h +2557 -0
  339. ctpbee_api/rohon/include/new/pybind11/stl/filesystem.h +116 -0
  340. ctpbee_api/rohon/include/new/pybind11/stl.h +447 -0
  341. ctpbee_api/rohon/include/new/pybind11/stl_bind.h +851 -0
  342. ctpbee_api/rohon/include/new/pybind11/type_caster_pyobject_ptr.h +61 -0
  343. ctpbee_api/rohon/include/new/rohon/ThostFtdcMdApi.h +168 -0
  344. ctpbee_api/rohon/include/new/rohon/ThostFtdcTraderApi.h +739 -0
  345. ctpbee_api/rohon/include/new/rohon/ThostFtdcUserApiDataType.h +6708 -0
  346. ctpbee_api/rohon/include/new/rohon/ThostFtdcUserApiStruct.h +9580 -0
  347. ctpbee_api/rohon/include/previous/pybind11/attr.h +489 -0
  348. ctpbee_api/rohon/include/previous/pybind11/buffer_info.h +108 -0
  349. ctpbee_api/rohon/include/previous/pybind11/cast.h +2067 -0
  350. ctpbee_api/rohon/include/previous/pybind11/chrono.h +162 -0
  351. ctpbee_api/rohon/include/previous/pybind11/common.h +2 -0
  352. ctpbee_api/rohon/include/previous/pybind11/complex.h +61 -0
  353. ctpbee_api/rohon/include/previous/pybind11/detail/class.h +626 -0
  354. ctpbee_api/rohon/include/previous/pybind11/detail/common.h +803 -0
  355. ctpbee_api/rohon/include/previous/pybind11/detail/descr.h +185 -0
  356. ctpbee_api/rohon/include/previous/pybind11/detail/init.h +335 -0
  357. ctpbee_api/rohon/include/previous/pybind11/detail/internals.h +285 -0
  358. ctpbee_api/rohon/include/previous/pybind11/detail/typeid.h +53 -0
  359. ctpbee_api/rohon/include/previous/pybind11/eigen.h +604 -0
  360. ctpbee_api/rohon/include/previous/pybind11/embed.h +194 -0
  361. ctpbee_api/rohon/include/previous/pybind11/eval.h +117 -0
  362. ctpbee_api/rohon/include/previous/pybind11/functional.h +85 -0
  363. ctpbee_api/rohon/include/previous/pybind11/iostream.h +200 -0
  364. ctpbee_api/rohon/include/previous/pybind11/numpy.h +1601 -0
  365. ctpbee_api/rohon/include/previous/pybind11/operators.h +168 -0
  366. ctpbee_api/rohon/include/previous/pybind11/options.h +65 -0
  367. ctpbee_api/rohon/include/previous/pybind11/pybind11.h +1965 -0
  368. ctpbee_api/rohon/include/previous/pybind11/pytypes.h +1332 -0
  369. ctpbee_api/rohon/include/previous/pybind11/stl.h +376 -0
  370. ctpbee_api/rohon/include/previous/pybind11/stl_bind.h +599 -0
  371. ctpbee_api/rohon/include/previous/rohon/ThostFtdcMdApi.h +168 -0
  372. ctpbee_api/rohon/include/previous/rohon/ThostFtdcTraderApi.h +739 -0
  373. ctpbee_api/rohon/include/previous/rohon/ThostFtdcUserApiDataType.h +6708 -0
  374. ctpbee_api/rohon/include/previous/rohon/ThostFtdcUserApiStruct.h +9580 -0
  375. ctpbee_api/rohon/libLinuxDataCollect.so +0 -0
  376. ctpbee_api/rohon/librohonbase.so +0 -0
  377. ctpbee_api/rohon/librohonbase.so.1.1 +0 -0
  378. ctpbee_api/rohon/librohonbase.so.1.1.0.1 +0 -0
  379. ctpbee_api/rohon/libs/thostmduserapi_se.lib +0 -0
  380. ctpbee_api/rohon/libs/thosttraderapi_se.lib +0 -0
  381. ctpbee_api/rohon/libthostmduserapi_se.so +0 -0
  382. ctpbee_api/rohon/libthosttraderapi_se.so +0 -0
  383. ctpbee_api/rohon/rohon_constant.py +1242 -0
  384. ctpbee_api/rohon/thostmduserapi_se.dll +0 -0
  385. ctpbee_api/rohon/thosttraderapi_se.dll +0 -0
  386. ctpbee_api/rohon/vnrohon/.vs/vnrohon/v15/.suo +0 -0
  387. ctpbee_api/rohon/vnrohon/.vs/vnrohon/v15/Browse.VC.db +0 -0
  388. ctpbee_api/rohon/vnrohon/.vs/vnrohon/v15/Solution.VC.db +0 -0
  389. ctpbee_api/rohon/vnrohon/vnrohon.h +147 -0
  390. ctpbee_api/rohon/vnrohon/vnrohon.sln +41 -0
  391. ctpbee_api/rohon/vnrohon/vnrohonmd/dllmain.cpp +19 -0
  392. ctpbee_api/rohon/vnrohon/vnrohonmd/framework.h +5 -0
  393. ctpbee_api/rohon/vnrohon/vnrohonmd/pch.cpp +5 -0
  394. ctpbee_api/rohon/vnrohon/vnrohonmd/pch.h +13 -0
  395. ctpbee_api/rohon/vnrohon/vnrohonmd/vnrohonmd.cpp +931 -0
  396. ctpbee_api/rohon/vnrohon/vnrohonmd/vnrohonmd.h +207 -0
  397. ctpbee_api/rohon/vnrohon/vnrohonmd/vnrohonmd.vcxproj +188 -0
  398. ctpbee_api/rohon/vnrohon/vnrohonmd/vnrohonmd.vcxproj.filters +54 -0
  399. ctpbee_api/rohon/vnrohon/vnrohonmd/vnrohonmd.vcxproj.user +4 -0
  400. ctpbee_api/rohon/vnrohon/vnrohontd/dllmain.cpp +19 -0
  401. ctpbee_api/rohon/vnrohon/vnrohontd/framework.h +5 -0
  402. ctpbee_api/rohon/vnrohon/vnrohontd/pch.cpp +5 -0
  403. ctpbee_api/rohon/vnrohon/vnrohontd/pch.h +13 -0
  404. ctpbee_api/rohon/vnrohon/vnrohontd/vnrohontd.cpp +11395 -0
  405. ctpbee_api/rohon/vnrohon/vnrohontd/vnrohontd.h +1259 -0
  406. ctpbee_api/rohon/vnrohon/vnrohontd/vnrohontd.vcxproj +188 -0
  407. ctpbee_api/rohon/vnrohon/vnrohontd/vnrohontd.vcxproj.filters +54 -0
  408. ctpbee_api/rohon/vnrohon/vnrohontd/vnrohontd.vcxproj.user +4 -0
  409. ctpbee_api/rohon/vnrohonmd.cp312-win_amd64.pyd +0 -0
  410. ctpbee_api/rohon/vnrohontd.cp312-win_amd64.pyd +0 -0
  411. ctpbee_opt_api-0.1.0.dist-info/METADATA +46 -0
  412. ctpbee_opt_api-0.1.0.dist-info/RECORD +414 -0
  413. ctpbee_opt_api-0.1.0.dist-info/WHEEL +5 -0
  414. ctpbee_opt_api-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1704 @@
1
+ /*
2
+ pybind11/cast.h: Partial template specializations to cast between
3
+ C++ and Python types
4
+
5
+ Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
6
+
7
+ All rights reserved. Use of this source code is governed by a
8
+ BSD-style license that can be found in the LICENSE file.
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include "detail/common.h"
14
+ #include "detail/descr.h"
15
+ #include "detail/type_caster_base.h"
16
+ #include "detail/typeid.h"
17
+ #include "pytypes.h"
18
+
19
+ #include <array>
20
+ #include <cstring>
21
+ #include <functional>
22
+ #include <iosfwd>
23
+ #include <iterator>
24
+ #include <memory>
25
+ #include <string>
26
+ #include <tuple>
27
+ #include <type_traits>
28
+ #include <utility>
29
+ #include <vector>
30
+
31
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
32
+
33
+ PYBIND11_WARNING_DISABLE_MSVC(4127)
34
+
35
+ PYBIND11_NAMESPACE_BEGIN(detail)
36
+
37
+ template <typename type, typename SFINAE = void>
38
+ class type_caster : public type_caster_base<type> {};
39
+ template <typename type>
40
+ using make_caster = type_caster<intrinsic_t<type>>;
41
+
42
+ // Shortcut for calling a caster's `cast_op_type` cast operator for casting a type_caster to a T
43
+ template <typename T>
44
+ typename make_caster<T>::template cast_op_type<T> cast_op(make_caster<T> &caster) {
45
+ return caster.operator typename make_caster<T>::template cast_op_type<T>();
46
+ }
47
+ template <typename T>
48
+ typename make_caster<T>::template cast_op_type<typename std::add_rvalue_reference<T>::type>
49
+ cast_op(make_caster<T> &&caster) {
50
+ return std::move(caster).operator typename make_caster<T>::
51
+ template cast_op_type<typename std::add_rvalue_reference<T>::type>();
52
+ }
53
+
54
+ template <typename type>
55
+ class type_caster<std::reference_wrapper<type>> {
56
+ private:
57
+ using caster_t = make_caster<type>;
58
+ caster_t subcaster;
59
+ using reference_t = type &;
60
+ using subcaster_cast_op_type = typename caster_t::template cast_op_type<reference_t>;
61
+
62
+ static_assert(
63
+ std::is_same<typename std::remove_const<type>::type &, subcaster_cast_op_type>::value
64
+ || std::is_same<reference_t, subcaster_cast_op_type>::value,
65
+ "std::reference_wrapper<T> caster requires T to have a caster with an "
66
+ "`operator T &()` or `operator const T &()`");
67
+
68
+ public:
69
+ bool load(handle src, bool convert) { return subcaster.load(src, convert); }
70
+ static constexpr auto name = caster_t::name;
71
+ static handle
72
+ cast(const std::reference_wrapper<type> &src, return_value_policy policy, handle parent) {
73
+ // It is definitely wrong to take ownership of this pointer, so mask that rvp
74
+ if (policy == return_value_policy::take_ownership
75
+ || policy == return_value_policy::automatic) {
76
+ policy = return_value_policy::automatic_reference;
77
+ }
78
+ return caster_t::cast(&src.get(), policy, parent);
79
+ }
80
+ template <typename T>
81
+ using cast_op_type = std::reference_wrapper<type>;
82
+ explicit operator std::reference_wrapper<type>() { return cast_op<type &>(subcaster); }
83
+ };
84
+
85
+ #define PYBIND11_TYPE_CASTER(type, py_name) \
86
+ protected: \
87
+ type value; \
88
+ \
89
+ public: \
90
+ static constexpr auto name = py_name; \
91
+ template <typename T_, \
92
+ ::pybind11::detail::enable_if_t< \
93
+ std::is_same<type, ::pybind11::detail::remove_cv_t<T_>>::value, \
94
+ int> \
95
+ = 0> \
96
+ static ::pybind11::handle cast( \
97
+ T_ *src, ::pybind11::return_value_policy policy, ::pybind11::handle parent) { \
98
+ if (!src) \
99
+ return ::pybind11::none().release(); \
100
+ if (policy == ::pybind11::return_value_policy::take_ownership) { \
101
+ auto h = cast(std::move(*src), policy, parent); \
102
+ delete src; \
103
+ return h; \
104
+ } \
105
+ return cast(*src, policy, parent); \
106
+ } \
107
+ operator type *() { return &value; } /* NOLINT(bugprone-macro-parentheses) */ \
108
+ operator type &() { return value; } /* NOLINT(bugprone-macro-parentheses) */ \
109
+ operator type &&() && { return std::move(value); } /* NOLINT(bugprone-macro-parentheses) */ \
110
+ template <typename T_> \
111
+ using cast_op_type = ::pybind11::detail::movable_cast_op_type<T_>
112
+
113
+ template <typename CharT>
114
+ using is_std_char_type = any_of<std::is_same<CharT, char>, /* std::string */
115
+ #if defined(PYBIND11_HAS_U8STRING)
116
+ std::is_same<CharT, char8_t>, /* std::u8string */
117
+ #endif
118
+ std::is_same<CharT, char16_t>, /* std::u16string */
119
+ std::is_same<CharT, char32_t>, /* std::u32string */
120
+ std::is_same<CharT, wchar_t> /* std::wstring */
121
+ >;
122
+
123
+ template <typename T>
124
+ struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_type<T>::value>> {
125
+ using _py_type_0 = conditional_t<sizeof(T) <= sizeof(long), long, long long>;
126
+ using _py_type_1 = conditional_t<std::is_signed<T>::value,
127
+ _py_type_0,
128
+ typename std::make_unsigned<_py_type_0>::type>;
129
+ using py_type = conditional_t<std::is_floating_point<T>::value, double, _py_type_1>;
130
+
131
+ public:
132
+ bool load(handle src, bool convert) {
133
+ py_type py_value;
134
+
135
+ if (!src) {
136
+ return false;
137
+ }
138
+
139
+ #if !defined(PYPY_VERSION)
140
+ auto index_check = [](PyObject *o) { return PyIndex_Check(o); };
141
+ #else
142
+ // In PyPy 7.3.3, `PyIndex_Check` is implemented by calling `__index__`,
143
+ // while CPython only considers the existence of `nb_index`/`__index__`.
144
+ auto index_check = [](PyObject *o) { return hasattr(o, "__index__"); };
145
+ #endif
146
+
147
+ if (std::is_floating_point<T>::value) {
148
+ if (convert || PyFloat_Check(src.ptr())) {
149
+ py_value = (py_type) PyFloat_AsDouble(src.ptr());
150
+ } else {
151
+ return false;
152
+ }
153
+ } else if (PyFloat_Check(src.ptr())
154
+ || (!convert && !PYBIND11_LONG_CHECK(src.ptr()) && !index_check(src.ptr()))) {
155
+ return false;
156
+ } else {
157
+ handle src_or_index = src;
158
+ // PyPy: 7.3.7's 3.8 does not implement PyLong_*'s __index__ calls.
159
+ #if PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION)
160
+ object index;
161
+ if (!PYBIND11_LONG_CHECK(src.ptr())) { // So: index_check(src.ptr())
162
+ index = reinterpret_steal<object>(PyNumber_Index(src.ptr()));
163
+ if (!index) {
164
+ PyErr_Clear();
165
+ if (!convert)
166
+ return false;
167
+ } else {
168
+ src_or_index = index;
169
+ }
170
+ }
171
+ #endif
172
+ if (std::is_unsigned<py_type>::value) {
173
+ py_value = as_unsigned<py_type>(src_or_index.ptr());
174
+ } else { // signed integer:
175
+ py_value = sizeof(T) <= sizeof(long)
176
+ ? (py_type) PyLong_AsLong(src_or_index.ptr())
177
+ : (py_type) PYBIND11_LONG_AS_LONGLONG(src_or_index.ptr());
178
+ }
179
+ }
180
+
181
+ // Python API reported an error
182
+ bool py_err = py_value == (py_type) -1 && PyErr_Occurred();
183
+
184
+ // Check to see if the conversion is valid (integers should match exactly)
185
+ // Signed/unsigned checks happen elsewhere
186
+ if (py_err
187
+ || (std::is_integral<T>::value && sizeof(py_type) != sizeof(T)
188
+ && py_value != (py_type) (T) py_value)) {
189
+ PyErr_Clear();
190
+ if (py_err && convert && (PyNumber_Check(src.ptr()) != 0)) {
191
+ auto tmp = reinterpret_steal<object>(std::is_floating_point<T>::value
192
+ ? PyNumber_Float(src.ptr())
193
+ : PyNumber_Long(src.ptr()));
194
+ PyErr_Clear();
195
+ return load(tmp, false);
196
+ }
197
+ return false;
198
+ }
199
+
200
+ value = (T) py_value;
201
+ return true;
202
+ }
203
+
204
+ template <typename U = T>
205
+ static typename std::enable_if<std::is_floating_point<U>::value, handle>::type
206
+ cast(U src, return_value_policy /* policy */, handle /* parent */) {
207
+ return PyFloat_FromDouble((double) src);
208
+ }
209
+
210
+ template <typename U = T>
211
+ static typename std::enable_if<!std::is_floating_point<U>::value && std::is_signed<U>::value
212
+ && (sizeof(U) <= sizeof(long)),
213
+ handle>::type
214
+ cast(U src, return_value_policy /* policy */, handle /* parent */) {
215
+ return PYBIND11_LONG_FROM_SIGNED((long) src);
216
+ }
217
+
218
+ template <typename U = T>
219
+ static typename std::enable_if<!std::is_floating_point<U>::value && std::is_unsigned<U>::value
220
+ && (sizeof(U) <= sizeof(unsigned long)),
221
+ handle>::type
222
+ cast(U src, return_value_policy /* policy */, handle /* parent */) {
223
+ return PYBIND11_LONG_FROM_UNSIGNED((unsigned long) src);
224
+ }
225
+
226
+ template <typename U = T>
227
+ static typename std::enable_if<!std::is_floating_point<U>::value && std::is_signed<U>::value
228
+ && (sizeof(U) > sizeof(long)),
229
+ handle>::type
230
+ cast(U src, return_value_policy /* policy */, handle /* parent */) {
231
+ return PyLong_FromLongLong((long long) src);
232
+ }
233
+
234
+ template <typename U = T>
235
+ static typename std::enable_if<!std::is_floating_point<U>::value && std::is_unsigned<U>::value
236
+ && (sizeof(U) > sizeof(unsigned long)),
237
+ handle>::type
238
+ cast(U src, return_value_policy /* policy */, handle /* parent */) {
239
+ return PyLong_FromUnsignedLongLong((unsigned long long) src);
240
+ }
241
+
242
+ PYBIND11_TYPE_CASTER(T, const_name<std::is_integral<T>::value>("int", "float"));
243
+ };
244
+
245
+ template <typename T>
246
+ struct void_caster {
247
+ public:
248
+ bool load(handle src, bool) {
249
+ if (src && src.is_none()) {
250
+ return true;
251
+ }
252
+ return false;
253
+ }
254
+ static handle cast(T, return_value_policy /* policy */, handle /* parent */) {
255
+ return none().release();
256
+ }
257
+ PYBIND11_TYPE_CASTER(T, const_name("None"));
258
+ };
259
+
260
+ template <>
261
+ class type_caster<void_type> : public void_caster<void_type> {};
262
+
263
+ template <>
264
+ class type_caster<void> : public type_caster<void_type> {
265
+ public:
266
+ using type_caster<void_type>::cast;
267
+
268
+ bool load(handle h, bool) {
269
+ if (!h) {
270
+ return false;
271
+ }
272
+ if (h.is_none()) {
273
+ value = nullptr;
274
+ return true;
275
+ }
276
+
277
+ /* Check if this is a capsule */
278
+ if (isinstance<capsule>(h)) {
279
+ value = reinterpret_borrow<capsule>(h);
280
+ return true;
281
+ }
282
+
283
+ /* Check if this is a C++ type */
284
+ const auto &bases = all_type_info((PyTypeObject *) type::handle_of(h).ptr());
285
+ if (bases.size() == 1) { // Only allowing loading from a single-value type
286
+ value = values_and_holders(reinterpret_cast<instance *>(h.ptr())).begin()->value_ptr();
287
+ return true;
288
+ }
289
+
290
+ /* Fail */
291
+ return false;
292
+ }
293
+
294
+ static handle cast(const void *ptr, return_value_policy /* policy */, handle /* parent */) {
295
+ if (ptr) {
296
+ return capsule(ptr).release();
297
+ }
298
+ return none().release();
299
+ }
300
+
301
+ template <typename T>
302
+ using cast_op_type = void *&;
303
+ explicit operator void *&() { return value; }
304
+ static constexpr auto name = const_name("capsule");
305
+
306
+ private:
307
+ void *value = nullptr;
308
+ };
309
+
310
+ template <>
311
+ class type_caster<std::nullptr_t> : public void_caster<std::nullptr_t> {};
312
+
313
+ template <>
314
+ class type_caster<bool> {
315
+ public:
316
+ bool load(handle src, bool convert) {
317
+ if (!src) {
318
+ return false;
319
+ }
320
+ if (src.ptr() == Py_True) {
321
+ value = true;
322
+ return true;
323
+ }
324
+ if (src.ptr() == Py_False) {
325
+ value = false;
326
+ return true;
327
+ }
328
+ if (convert || (std::strcmp("numpy.bool_", Py_TYPE(src.ptr())->tp_name) == 0)) {
329
+ // (allow non-implicit conversion for numpy booleans)
330
+
331
+ Py_ssize_t res = -1;
332
+ if (src.is_none()) {
333
+ res = 0; // None is implicitly converted to False
334
+ }
335
+ #if defined(PYPY_VERSION)
336
+ // On PyPy, check that "__bool__" attr exists
337
+ else if (hasattr(src, PYBIND11_BOOL_ATTR)) {
338
+ res = PyObject_IsTrue(src.ptr());
339
+ }
340
+ #else
341
+ // Alternate approach for CPython: this does the same as the above, but optimized
342
+ // using the CPython API so as to avoid an unneeded attribute lookup.
343
+ else if (auto *tp_as_number = src.ptr()->ob_type->tp_as_number) {
344
+ if (PYBIND11_NB_BOOL(tp_as_number)) {
345
+ res = (*PYBIND11_NB_BOOL(tp_as_number))(src.ptr());
346
+ }
347
+ }
348
+ #endif
349
+ if (res == 0 || res == 1) {
350
+ value = (res != 0);
351
+ return true;
352
+ }
353
+ PyErr_Clear();
354
+ }
355
+ return false;
356
+ }
357
+ static handle cast(bool src, return_value_policy /* policy */, handle /* parent */) {
358
+ return handle(src ? Py_True : Py_False).inc_ref();
359
+ }
360
+ PYBIND11_TYPE_CASTER(bool, const_name("bool"));
361
+ };
362
+
363
+ // Helper class for UTF-{8,16,32} C++ stl strings:
364
+ template <typename StringType, bool IsView = false>
365
+ struct string_caster {
366
+ using CharT = typename StringType::value_type;
367
+
368
+ // Simplify life by being able to assume standard char sizes (the standard only guarantees
369
+ // minimums, but Python requires exact sizes)
370
+ static_assert(!std::is_same<CharT, char>::value || sizeof(CharT) == 1,
371
+ "Unsupported char size != 1");
372
+ #if defined(PYBIND11_HAS_U8STRING)
373
+ static_assert(!std::is_same<CharT, char8_t>::value || sizeof(CharT) == 1,
374
+ "Unsupported char8_t size != 1");
375
+ #endif
376
+ static_assert(!std::is_same<CharT, char16_t>::value || sizeof(CharT) == 2,
377
+ "Unsupported char16_t size != 2");
378
+ static_assert(!std::is_same<CharT, char32_t>::value || sizeof(CharT) == 4,
379
+ "Unsupported char32_t size != 4");
380
+ // wchar_t can be either 16 bits (Windows) or 32 (everywhere else)
381
+ static_assert(!std::is_same<CharT, wchar_t>::value || sizeof(CharT) == 2 || sizeof(CharT) == 4,
382
+ "Unsupported wchar_t size != 2/4");
383
+ static constexpr size_t UTF_N = 8 * sizeof(CharT);
384
+
385
+ bool load(handle src, bool) {
386
+ handle load_src = src;
387
+ if (!src) {
388
+ return false;
389
+ }
390
+ if (!PyUnicode_Check(load_src.ptr())) {
391
+ return load_raw(load_src);
392
+ }
393
+
394
+ // For UTF-8 we avoid the need for a temporary `bytes` object by using
395
+ // `PyUnicode_AsUTF8AndSize`.
396
+ if (UTF_N == 8) {
397
+ Py_ssize_t size = -1;
398
+ const auto *buffer
399
+ = reinterpret_cast<const CharT *>(PyUnicode_AsUTF8AndSize(load_src.ptr(), &size));
400
+ if (!buffer) {
401
+ PyErr_Clear();
402
+ return false;
403
+ }
404
+ value = StringType(buffer, static_cast<size_t>(size));
405
+ return true;
406
+ }
407
+
408
+ auto utfNbytes
409
+ = reinterpret_steal<object>(PyUnicode_AsEncodedString(load_src.ptr(),
410
+ UTF_N == 8 ? "utf-8"
411
+ : UTF_N == 16 ? "utf-16"
412
+ : "utf-32",
413
+ nullptr));
414
+ if (!utfNbytes) {
415
+ PyErr_Clear();
416
+ return false;
417
+ }
418
+
419
+ const auto *buffer
420
+ = reinterpret_cast<const CharT *>(PYBIND11_BYTES_AS_STRING(utfNbytes.ptr()));
421
+ size_t length = (size_t) PYBIND11_BYTES_SIZE(utfNbytes.ptr()) / sizeof(CharT);
422
+ // Skip BOM for UTF-16/32
423
+ if (UTF_N > 8) {
424
+ buffer++;
425
+ length--;
426
+ }
427
+ value = StringType(buffer, length);
428
+
429
+ // If we're loading a string_view we need to keep the encoded Python object alive:
430
+ if (IsView) {
431
+ loader_life_support::add_patient(utfNbytes);
432
+ }
433
+
434
+ return true;
435
+ }
436
+
437
+ static handle
438
+ cast(const StringType &src, return_value_policy /* policy */, handle /* parent */) {
439
+ const char *buffer = reinterpret_cast<const char *>(src.data());
440
+ auto nbytes = ssize_t(src.size() * sizeof(CharT));
441
+ handle s = decode_utfN(buffer, nbytes);
442
+ if (!s) {
443
+ throw error_already_set();
444
+ }
445
+ return s;
446
+ }
447
+
448
+ PYBIND11_TYPE_CASTER(StringType, const_name(PYBIND11_STRING_NAME));
449
+
450
+ private:
451
+ static handle decode_utfN(const char *buffer, ssize_t nbytes) {
452
+ #if !defined(PYPY_VERSION)
453
+ return UTF_N == 8 ? PyUnicode_DecodeUTF8(buffer, nbytes, nullptr)
454
+ : UTF_N == 16 ? PyUnicode_DecodeUTF16(buffer, nbytes, nullptr, nullptr)
455
+ : PyUnicode_DecodeUTF32(buffer, nbytes, nullptr, nullptr);
456
+ #else
457
+ // PyPy segfaults when on PyUnicode_DecodeUTF16 (and possibly on PyUnicode_DecodeUTF32 as
458
+ // well), so bypass the whole thing by just passing the encoding as a string value, which
459
+ // works properly:
460
+ return PyUnicode_Decode(buffer,
461
+ nbytes,
462
+ UTF_N == 8 ? "utf-8"
463
+ : UTF_N == 16 ? "utf-16"
464
+ : "utf-32",
465
+ nullptr);
466
+ #endif
467
+ }
468
+
469
+ // When loading into a std::string or char*, accept a bytes/bytearray object as-is (i.e.
470
+ // without any encoding/decoding attempt). For other C++ char sizes this is a no-op.
471
+ // which supports loading a unicode from a str, doesn't take this path.
472
+ template <typename C = CharT>
473
+ bool load_raw(enable_if_t<std::is_same<C, char>::value, handle> src) {
474
+ if (PYBIND11_BYTES_CHECK(src.ptr())) {
475
+ // We were passed raw bytes; accept it into a std::string or char*
476
+ // without any encoding attempt.
477
+ const char *bytes = PYBIND11_BYTES_AS_STRING(src.ptr());
478
+ if (!bytes) {
479
+ pybind11_fail("Unexpected PYBIND11_BYTES_AS_STRING() failure.");
480
+ }
481
+ value = StringType(bytes, (size_t) PYBIND11_BYTES_SIZE(src.ptr()));
482
+ return true;
483
+ }
484
+ if (PyByteArray_Check(src.ptr())) {
485
+ // We were passed a bytearray; accept it into a std::string or char*
486
+ // without any encoding attempt.
487
+ const char *bytearray = PyByteArray_AsString(src.ptr());
488
+ if (!bytearray) {
489
+ pybind11_fail("Unexpected PyByteArray_AsString() failure.");
490
+ }
491
+ value = StringType(bytearray, (size_t) PyByteArray_Size(src.ptr()));
492
+ return true;
493
+ }
494
+
495
+ return false;
496
+ }
497
+
498
+ template <typename C = CharT>
499
+ bool load_raw(enable_if_t<!std::is_same<C, char>::value, handle>) {
500
+ return false;
501
+ }
502
+ };
503
+
504
+ template <typename CharT, class Traits, class Allocator>
505
+ struct type_caster<std::basic_string<CharT, Traits, Allocator>,
506
+ enable_if_t<is_std_char_type<CharT>::value>>
507
+ : string_caster<std::basic_string<CharT, Traits, Allocator>> {};
508
+
509
+ #ifdef PYBIND11_HAS_STRING_VIEW
510
+ template <typename CharT, class Traits>
511
+ struct type_caster<std::basic_string_view<CharT, Traits>,
512
+ enable_if_t<is_std_char_type<CharT>::value>>
513
+ : string_caster<std::basic_string_view<CharT, Traits>, true> {};
514
+ #endif
515
+
516
+ // Type caster for C-style strings. We basically use a std::string type caster, but also add the
517
+ // ability to use None as a nullptr char* (which the string caster doesn't allow).
518
+ template <typename CharT>
519
+ struct type_caster<CharT, enable_if_t<is_std_char_type<CharT>::value>> {
520
+ using StringType = std::basic_string<CharT>;
521
+ using StringCaster = make_caster<StringType>;
522
+ StringCaster str_caster;
523
+ bool none = false;
524
+ CharT one_char = 0;
525
+
526
+ public:
527
+ bool load(handle src, bool convert) {
528
+ if (!src) {
529
+ return false;
530
+ }
531
+ if (src.is_none()) {
532
+ // Defer accepting None to other overloads (if we aren't in convert mode):
533
+ if (!convert) {
534
+ return false;
535
+ }
536
+ none = true;
537
+ return true;
538
+ }
539
+ return str_caster.load(src, convert);
540
+ }
541
+
542
+ static handle cast(const CharT *src, return_value_policy policy, handle parent) {
543
+ if (src == nullptr) {
544
+ return pybind11::none().release();
545
+ }
546
+ return StringCaster::cast(StringType(src), policy, parent);
547
+ }
548
+
549
+ static handle cast(CharT src, return_value_policy policy, handle parent) {
550
+ if (std::is_same<char, CharT>::value) {
551
+ handle s = PyUnicode_DecodeLatin1((const char *) &src, 1, nullptr);
552
+ if (!s) {
553
+ throw error_already_set();
554
+ }
555
+ return s;
556
+ }
557
+ return StringCaster::cast(StringType(1, src), policy, parent);
558
+ }
559
+
560
+ explicit operator CharT *() {
561
+ return none ? nullptr : const_cast<CharT *>(static_cast<StringType &>(str_caster).c_str());
562
+ }
563
+ explicit operator CharT &() {
564
+ if (none) {
565
+ throw value_error("Cannot convert None to a character");
566
+ }
567
+
568
+ auto &value = static_cast<StringType &>(str_caster);
569
+ size_t str_len = value.size();
570
+ if (str_len == 0) {
571
+ throw value_error("Cannot convert empty string to a character");
572
+ }
573
+
574
+ // If we're in UTF-8 mode, we have two possible failures: one for a unicode character that
575
+ // is too high, and one for multiple unicode characters (caught later), so we need to
576
+ // figure out how long the first encoded character is in bytes to distinguish between these
577
+ // two errors. We also allow want to allow unicode characters U+0080 through U+00FF, as
578
+ // those can fit into a single char value.
579
+ if (StringCaster::UTF_N == 8 && str_len > 1 && str_len <= 4) {
580
+ auto v0 = static_cast<unsigned char>(value[0]);
581
+ // low bits only: 0-127
582
+ // 0b110xxxxx - start of 2-byte sequence
583
+ // 0b1110xxxx - start of 3-byte sequence
584
+ // 0b11110xxx - start of 4-byte sequence
585
+ size_t char0_bytes = (v0 & 0x80) == 0 ? 1
586
+ : (v0 & 0xE0) == 0xC0 ? 2
587
+ : (v0 & 0xF0) == 0xE0 ? 3
588
+ : 4;
589
+
590
+ if (char0_bytes == str_len) {
591
+ // If we have a 128-255 value, we can decode it into a single char:
592
+ if (char0_bytes == 2 && (v0 & 0xFC) == 0xC0) { // 0x110000xx 0x10xxxxxx
593
+ one_char = static_cast<CharT>(((v0 & 3) << 6)
594
+ + (static_cast<unsigned char>(value[1]) & 0x3F));
595
+ return one_char;
596
+ }
597
+ // Otherwise we have a single character, but it's > U+00FF
598
+ throw value_error("Character code point not in range(0x100)");
599
+ }
600
+ }
601
+
602
+ // UTF-16 is much easier: we can only have a surrogate pair for values above U+FFFF, thus a
603
+ // surrogate pair with total length 2 instantly indicates a range error (but not a "your
604
+ // string was too long" error).
605
+ else if (StringCaster::UTF_N == 16 && str_len == 2) {
606
+ one_char = static_cast<CharT>(value[0]);
607
+ if (one_char >= 0xD800 && one_char < 0xE000) {
608
+ throw value_error("Character code point not in range(0x10000)");
609
+ }
610
+ }
611
+
612
+ if (str_len != 1) {
613
+ throw value_error("Expected a character, but multi-character string found");
614
+ }
615
+
616
+ one_char = value[0];
617
+ return one_char;
618
+ }
619
+
620
+ static constexpr auto name = const_name(PYBIND11_STRING_NAME);
621
+ template <typename _T>
622
+ using cast_op_type = pybind11::detail::cast_op_type<_T>;
623
+ };
624
+
625
+ // Base implementation for std::tuple and std::pair
626
+ template <template <typename...> class Tuple, typename... Ts>
627
+ class tuple_caster {
628
+ using type = Tuple<Ts...>;
629
+ static constexpr auto size = sizeof...(Ts);
630
+ using indices = make_index_sequence<size>;
631
+
632
+ public:
633
+ bool load(handle src, bool convert) {
634
+ if (!isinstance<sequence>(src)) {
635
+ return false;
636
+ }
637
+ const auto seq = reinterpret_borrow<sequence>(src);
638
+ if (seq.size() != size) {
639
+ return false;
640
+ }
641
+ return load_impl(seq, convert, indices{});
642
+ }
643
+
644
+ template <typename T>
645
+ static handle cast(T &&src, return_value_policy policy, handle parent) {
646
+ return cast_impl(std::forward<T>(src), policy, parent, indices{});
647
+ }
648
+
649
+ // copied from the PYBIND11_TYPE_CASTER macro
650
+ template <typename T>
651
+ static handle cast(T *src, return_value_policy policy, handle parent) {
652
+ if (!src) {
653
+ return none().release();
654
+ }
655
+ if (policy == return_value_policy::take_ownership) {
656
+ auto h = cast(std::move(*src), policy, parent);
657
+ delete src;
658
+ return h;
659
+ }
660
+ return cast(*src, policy, parent);
661
+ }
662
+
663
+ static constexpr auto name
664
+ = const_name("Tuple[") + concat(make_caster<Ts>::name...) + const_name("]");
665
+
666
+ template <typename T>
667
+ using cast_op_type = type;
668
+
669
+ explicit operator type() & { return implicit_cast(indices{}); }
670
+ explicit operator type() && { return std::move(*this).implicit_cast(indices{}); }
671
+
672
+ protected:
673
+ template <size_t... Is>
674
+ type implicit_cast(index_sequence<Is...>) & {
675
+ return type(cast_op<Ts>(std::get<Is>(subcasters))...);
676
+ }
677
+ template <size_t... Is>
678
+ type implicit_cast(index_sequence<Is...>) && {
679
+ return type(cast_op<Ts>(std::move(std::get<Is>(subcasters)))...);
680
+ }
681
+
682
+ static constexpr bool load_impl(const sequence &, bool, index_sequence<>) { return true; }
683
+
684
+ template <size_t... Is>
685
+ bool load_impl(const sequence &seq, bool convert, index_sequence<Is...>) {
686
+ #ifdef __cpp_fold_expressions
687
+ if ((... || !std::get<Is>(subcasters).load(seq[Is], convert))) {
688
+ return false;
689
+ }
690
+ #else
691
+ for (bool r : {std::get<Is>(subcasters).load(seq[Is], convert)...}) {
692
+ if (!r) {
693
+ return false;
694
+ }
695
+ }
696
+ #endif
697
+ return true;
698
+ }
699
+
700
+ /* Implementation: Convert a C++ tuple into a Python tuple */
701
+ template <typename T, size_t... Is>
702
+ static handle
703
+ cast_impl(T &&src, return_value_policy policy, handle parent, index_sequence<Is...>) {
704
+ PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(src, policy, parent);
705
+ PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(policy, parent);
706
+ std::array<object, size> entries{{reinterpret_steal<object>(
707
+ make_caster<Ts>::cast(std::get<Is>(std::forward<T>(src)), policy, parent))...}};
708
+ for (const auto &entry : entries) {
709
+ if (!entry) {
710
+ return handle();
711
+ }
712
+ }
713
+ tuple result(size);
714
+ int counter = 0;
715
+ for (auto &entry : entries) {
716
+ PyTuple_SET_ITEM(result.ptr(), counter++, entry.release().ptr());
717
+ }
718
+ return result.release();
719
+ }
720
+
721
+ Tuple<make_caster<Ts>...> subcasters;
722
+ };
723
+
724
+ template <typename T1, typename T2>
725
+ class type_caster<std::pair<T1, T2>> : public tuple_caster<std::pair, T1, T2> {};
726
+
727
+ template <typename... Ts>
728
+ class type_caster<std::tuple<Ts...>> : public tuple_caster<std::tuple, Ts...> {};
729
+
730
+ /// Helper class which abstracts away certain actions. Users can provide specializations for
731
+ /// custom holders, but it's only necessary if the type has a non-standard interface.
732
+ template <typename T>
733
+ struct holder_helper {
734
+ static auto get(const T &p) -> decltype(p.get()) { return p.get(); }
735
+ };
736
+
737
+ /// Type caster for holder types like std::shared_ptr, etc.
738
+ /// The SFINAE hook is provided to help work around the current lack of support
739
+ /// for smart-pointer interoperability. Please consider it an implementation
740
+ /// detail that may change in the future, as formal support for smart-pointer
741
+ /// interoperability is added into pybind11.
742
+ template <typename type, typename holder_type, typename SFINAE = void>
743
+ struct copyable_holder_caster : public type_caster_base<type> {
744
+ public:
745
+ using base = type_caster_base<type>;
746
+ static_assert(std::is_base_of<base, type_caster<type>>::value,
747
+ "Holder classes are only supported for custom types");
748
+ using base::base;
749
+ using base::cast;
750
+ using base::typeinfo;
751
+ using base::value;
752
+
753
+ bool load(handle src, bool convert) {
754
+ return base::template load_impl<copyable_holder_caster<type, holder_type>>(src, convert);
755
+ }
756
+
757
+ explicit operator type *() { return this->value; }
758
+ // static_cast works around compiler error with MSVC 17 and CUDA 10.2
759
+ // see issue #2180
760
+ explicit operator type &() { return *(static_cast<type *>(this->value)); }
761
+ explicit operator holder_type *() { return std::addressof(holder); }
762
+ explicit operator holder_type &() { return holder; }
763
+
764
+ static handle cast(const holder_type &src, return_value_policy, handle) {
765
+ const auto *ptr = holder_helper<holder_type>::get(src);
766
+ return type_caster_base<type>::cast_holder(ptr, &src);
767
+ }
768
+
769
+ protected:
770
+ friend class type_caster_generic;
771
+ void check_holder_compat() {
772
+ if (typeinfo->default_holder) {
773
+ throw cast_error("Unable to load a custom holder type from a default-holder instance");
774
+ }
775
+ }
776
+
777
+ bool load_value(value_and_holder &&v_h) {
778
+ if (v_h.holder_constructed()) {
779
+ value = v_h.value_ptr();
780
+ holder = v_h.template holder<holder_type>();
781
+ return true;
782
+ }
783
+ throw cast_error("Unable to cast from non-held to held instance (T& to Holder<T>) "
784
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
785
+ "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for "
786
+ "type information)");
787
+ #else
788
+ "of type '"
789
+ + type_id<holder_type>() + "''");
790
+ #endif
791
+ }
792
+
793
+ template <typename T = holder_type,
794
+ detail::enable_if_t<!std::is_constructible<T, const T &, type *>::value, int> = 0>
795
+ bool try_implicit_casts(handle, bool) {
796
+ return false;
797
+ }
798
+
799
+ template <typename T = holder_type,
800
+ detail::enable_if_t<std::is_constructible<T, const T &, type *>::value, int> = 0>
801
+ bool try_implicit_casts(handle src, bool convert) {
802
+ for (auto &cast : typeinfo->implicit_casts) {
803
+ copyable_holder_caster sub_caster(*cast.first);
804
+ if (sub_caster.load(src, convert)) {
805
+ value = cast.second(sub_caster.value);
806
+ holder = holder_type(sub_caster.holder, (type *) value);
807
+ return true;
808
+ }
809
+ }
810
+ return false;
811
+ }
812
+
813
+ static bool try_direct_conversions(handle) { return false; }
814
+
815
+ holder_type holder;
816
+ };
817
+
818
+ /// Specialize for the common std::shared_ptr, so users don't need to
819
+ template <typename T>
820
+ class type_caster<std::shared_ptr<T>> : public copyable_holder_caster<T, std::shared_ptr<T>> {};
821
+
822
+ /// Type caster for holder types like std::unique_ptr.
823
+ /// Please consider the SFINAE hook an implementation detail, as explained
824
+ /// in the comment for the copyable_holder_caster.
825
+ template <typename type, typename holder_type, typename SFINAE = void>
826
+ struct move_only_holder_caster {
827
+ static_assert(std::is_base_of<type_caster_base<type>, type_caster<type>>::value,
828
+ "Holder classes are only supported for custom types");
829
+
830
+ static handle cast(holder_type &&src, return_value_policy, handle) {
831
+ auto *ptr = holder_helper<holder_type>::get(src);
832
+ return type_caster_base<type>::cast_holder(ptr, std::addressof(src));
833
+ }
834
+ static constexpr auto name = type_caster_base<type>::name;
835
+ };
836
+
837
+ template <typename type, typename deleter>
838
+ class type_caster<std::unique_ptr<type, deleter>>
839
+ : public move_only_holder_caster<type, std::unique_ptr<type, deleter>> {};
840
+
841
+ template <typename type, typename holder_type>
842
+ using type_caster_holder = conditional_t<is_copy_constructible<holder_type>::value,
843
+ copyable_holder_caster<type, holder_type>,
844
+ move_only_holder_caster<type, holder_type>>;
845
+
846
+ template <typename T, bool Value = false>
847
+ struct always_construct_holder {
848
+ static constexpr bool value = Value;
849
+ };
850
+
851
+ /// Create a specialization for custom holder types (silently ignores std::shared_ptr)
852
+ #define PYBIND11_DECLARE_HOLDER_TYPE(type, holder_type, ...) \
853
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) \
854
+ namespace detail { \
855
+ template <typename type> \
856
+ struct always_construct_holder<holder_type> : always_construct_holder<void, ##__VA_ARGS__> { \
857
+ }; \
858
+ template <typename type> \
859
+ class type_caster<holder_type, enable_if_t<!is_shared_ptr<holder_type>::value>> \
860
+ : public type_caster_holder<type, holder_type> {}; \
861
+ } \
862
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
863
+
864
+ // PYBIND11_DECLARE_HOLDER_TYPE holder types:
865
+ template <typename base, typename holder>
866
+ struct is_holder_type
867
+ : std::is_base_of<detail::type_caster_holder<base, holder>, detail::type_caster<holder>> {};
868
+ // Specialization for always-supported unique_ptr holders:
869
+ template <typename base, typename deleter>
870
+ struct is_holder_type<base, std::unique_ptr<base, deleter>> : std::true_type {};
871
+
872
+ template <typename T>
873
+ struct handle_type_name {
874
+ static constexpr auto name = const_name<T>();
875
+ };
876
+ template <>
877
+ struct handle_type_name<bool_> {
878
+ static constexpr auto name = const_name("bool");
879
+ };
880
+ template <>
881
+ struct handle_type_name<bytes> {
882
+ static constexpr auto name = const_name(PYBIND11_BYTES_NAME);
883
+ };
884
+ template <>
885
+ struct handle_type_name<int_> {
886
+ static constexpr auto name = const_name("int");
887
+ };
888
+ template <>
889
+ struct handle_type_name<iterable> {
890
+ static constexpr auto name = const_name("Iterable");
891
+ };
892
+ template <>
893
+ struct handle_type_name<iterator> {
894
+ static constexpr auto name = const_name("Iterator");
895
+ };
896
+ template <>
897
+ struct handle_type_name<float_> {
898
+ static constexpr auto name = const_name("float");
899
+ };
900
+ template <>
901
+ struct handle_type_name<none> {
902
+ static constexpr auto name = const_name("None");
903
+ };
904
+ template <>
905
+ struct handle_type_name<args> {
906
+ static constexpr auto name = const_name("*args");
907
+ };
908
+ template <>
909
+ struct handle_type_name<kwargs> {
910
+ static constexpr auto name = const_name("**kwargs");
911
+ };
912
+
913
+ template <typename type>
914
+ struct pyobject_caster {
915
+ template <typename T = type, enable_if_t<std::is_same<T, handle>::value, int> = 0>
916
+ pyobject_caster() : value() {}
917
+
918
+ // `type` may not be default constructible (e.g. frozenset, anyset). Initializing `value`
919
+ // to a nil handle is safe since it will only be accessed if `load` succeeds.
920
+ template <typename T = type, enable_if_t<std::is_base_of<object, T>::value, int> = 0>
921
+ pyobject_caster() : value(reinterpret_steal<type>(handle())) {}
922
+
923
+ template <typename T = type, enable_if_t<std::is_same<T, handle>::value, int> = 0>
924
+ bool load(handle src, bool /* convert */) {
925
+ value = src;
926
+ return static_cast<bool>(value);
927
+ }
928
+
929
+ template <typename T = type, enable_if_t<std::is_base_of<object, T>::value, int> = 0>
930
+ bool load(handle src, bool /* convert */) {
931
+ if (!isinstance<type>(src)) {
932
+ return false;
933
+ }
934
+ value = reinterpret_borrow<type>(src);
935
+ return true;
936
+ }
937
+
938
+ static handle cast(const handle &src, return_value_policy /* policy */, handle /* parent */) {
939
+ return src.inc_ref();
940
+ }
941
+ PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name);
942
+ };
943
+
944
+ template <typename T>
945
+ class type_caster<T, enable_if_t<is_pyobject<T>::value>> : public pyobject_caster<T> {};
946
+
947
+ // Our conditions for enabling moving are quite restrictive:
948
+ // At compile time:
949
+ // - T needs to be a non-const, non-pointer, non-reference type
950
+ // - type_caster<T>::operator T&() must exist
951
+ // - the type must be move constructible (obviously)
952
+ // At run-time:
953
+ // - if the type is non-copy-constructible, the object must be the sole owner of the type (i.e. it
954
+ // must have ref_count() == 1)h
955
+ // If any of the above are not satisfied, we fall back to copying.
956
+ template <typename T>
957
+ using move_is_plain_type
958
+ = satisfies_none_of<T, std::is_void, std::is_pointer, std::is_reference, std::is_const>;
959
+ template <typename T, typename SFINAE = void>
960
+ struct move_always : std::false_type {};
961
+ template <typename T>
962
+ struct move_always<
963
+ T,
964
+ enable_if_t<
965
+ all_of<move_is_plain_type<T>,
966
+ negation<is_copy_constructible<T>>,
967
+ is_move_constructible<T>,
968
+ std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>::value>>
969
+ : std::true_type {};
970
+ template <typename T, typename SFINAE = void>
971
+ struct move_if_unreferenced : std::false_type {};
972
+ template <typename T>
973
+ struct move_if_unreferenced<
974
+ T,
975
+ enable_if_t<
976
+ all_of<move_is_plain_type<T>,
977
+ negation<move_always<T>>,
978
+ is_move_constructible<T>,
979
+ std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>::value>>
980
+ : std::true_type {};
981
+ template <typename T>
982
+ using move_never = none_of<move_always<T>, move_if_unreferenced<T>>;
983
+
984
+ // Detect whether returning a `type` from a cast on type's type_caster is going to result in a
985
+ // reference or pointer to a local variable of the type_caster. Basically, only
986
+ // non-reference/pointer `type`s and reference/pointers from a type_caster_generic are safe;
987
+ // everything else returns a reference/pointer to a local variable.
988
+ template <typename type>
989
+ using cast_is_temporary_value_reference
990
+ = bool_constant<(std::is_reference<type>::value || std::is_pointer<type>::value)
991
+ && !std::is_base_of<type_caster_generic, make_caster<type>>::value
992
+ && !std::is_same<intrinsic_t<type>, void>::value>;
993
+
994
+ // When a value returned from a C++ function is being cast back to Python, we almost always want to
995
+ // force `policy = move`, regardless of the return value policy the function/method was declared
996
+ // with.
997
+ template <typename Return, typename SFINAE = void>
998
+ struct return_value_policy_override {
999
+ static return_value_policy policy(return_value_policy p) { return p; }
1000
+ };
1001
+
1002
+ template <typename Return>
1003
+ struct return_value_policy_override<
1004
+ Return,
1005
+ detail::enable_if_t<std::is_base_of<type_caster_generic, make_caster<Return>>::value, void>> {
1006
+ static return_value_policy policy(return_value_policy p) {
1007
+ return !std::is_lvalue_reference<Return>::value && !std::is_pointer<Return>::value
1008
+ ? return_value_policy::move
1009
+ : p;
1010
+ }
1011
+ };
1012
+
1013
+ // Basic python -> C++ casting; throws if casting fails
1014
+ template <typename T, typename SFINAE>
1015
+ type_caster<T, SFINAE> &load_type(type_caster<T, SFINAE> &conv, const handle &handle) {
1016
+ static_assert(!detail::is_pyobject<T>::value,
1017
+ "Internal error: type_caster should only be used for C++ types");
1018
+ if (!conv.load(handle, true)) {
1019
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1020
+ throw cast_error(
1021
+ "Unable to cast Python instance of type "
1022
+ + str(type::handle_of(handle)).cast<std::string>()
1023
+ + " to C++ type '?' (#define "
1024
+ "PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1025
+ #else
1026
+ throw cast_error("Unable to cast Python instance of type "
1027
+ + str(type::handle_of(handle)).cast<std::string>() + " to C++ type '"
1028
+ + type_id<T>() + "'");
1029
+ #endif
1030
+ }
1031
+ return conv;
1032
+ }
1033
+ // Wrapper around the above that also constructs and returns a type_caster
1034
+ template <typename T>
1035
+ make_caster<T> load_type(const handle &handle) {
1036
+ make_caster<T> conv;
1037
+ load_type(conv, handle);
1038
+ return conv;
1039
+ }
1040
+
1041
+ PYBIND11_NAMESPACE_END(detail)
1042
+
1043
+ // pytype -> C++ type
1044
+ template <typename T,
1045
+ detail::enable_if_t<!detail::is_pyobject<T>::value
1046
+ && !detail::is_same_ignoring_cvref<T, PyObject *>::value,
1047
+ int>
1048
+ = 0>
1049
+ T cast(const handle &handle) {
1050
+ using namespace detail;
1051
+ static_assert(!cast_is_temporary_value_reference<T>::value,
1052
+ "Unable to cast type to reference: value is local to type caster");
1053
+ return cast_op<T>(load_type<T>(handle));
1054
+ }
1055
+
1056
+ // pytype -> pytype (calls converting constructor)
1057
+ template <typename T, detail::enable_if_t<detail::is_pyobject<T>::value, int> = 0>
1058
+ T cast(const handle &handle) {
1059
+ return T(reinterpret_borrow<object>(handle));
1060
+ }
1061
+
1062
+ // Note that `cast<PyObject *>(obj)` increments the reference count of `obj`.
1063
+ // This is necessary for the case that `obj` is a temporary, and could
1064
+ // not possibly be different, given
1065
+ // 1. the established convention that the passed `handle` is borrowed, and
1066
+ // 2. we don't want to force all generic code using `cast<T>()` to special-case
1067
+ // handling of `T` = `PyObject *` (to increment the reference count there).
1068
+ // It is the responsibility of the caller to ensure that the reference count
1069
+ // is decremented.
1070
+ template <typename T,
1071
+ typename Handle,
1072
+ detail::enable_if_t<detail::is_same_ignoring_cvref<T, PyObject *>::value
1073
+ && detail::is_same_ignoring_cvref<Handle, handle>::value,
1074
+ int>
1075
+ = 0>
1076
+ T cast(Handle &&handle) {
1077
+ return handle.inc_ref().ptr();
1078
+ }
1079
+ // To optimize way an inc_ref/dec_ref cycle:
1080
+ template <typename T,
1081
+ typename Object,
1082
+ detail::enable_if_t<detail::is_same_ignoring_cvref<T, PyObject *>::value
1083
+ && detail::is_same_ignoring_cvref<Object, object>::value,
1084
+ int>
1085
+ = 0>
1086
+ T cast(Object &&obj) {
1087
+ return obj.release().ptr();
1088
+ }
1089
+
1090
+ // C++ type -> py::object
1091
+ template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0>
1092
+ object cast(T &&value,
1093
+ return_value_policy policy = return_value_policy::automatic_reference,
1094
+ handle parent = handle()) {
1095
+ using no_ref_T = typename std::remove_reference<T>::type;
1096
+ if (policy == return_value_policy::automatic) {
1097
+ policy = std::is_pointer<no_ref_T>::value ? return_value_policy::take_ownership
1098
+ : std::is_lvalue_reference<T>::value ? return_value_policy::copy
1099
+ : return_value_policy::move;
1100
+ } else if (policy == return_value_policy::automatic_reference) {
1101
+ policy = std::is_pointer<no_ref_T>::value ? return_value_policy::reference
1102
+ : std::is_lvalue_reference<T>::value ? return_value_policy::copy
1103
+ : return_value_policy::move;
1104
+ }
1105
+ return reinterpret_steal<object>(
1106
+ detail::make_caster<T>::cast(std::forward<T>(value), policy, parent));
1107
+ }
1108
+
1109
+ template <typename T>
1110
+ T handle::cast() const {
1111
+ return pybind11::cast<T>(*this);
1112
+ }
1113
+ template <>
1114
+ inline void handle::cast() const {
1115
+ return;
1116
+ }
1117
+
1118
+ template <typename T>
1119
+ detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
1120
+ if (obj.ref_count() > 1) {
1121
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1122
+ throw cast_error(
1123
+ "Unable to cast Python " + str(type::handle_of(obj)).cast<std::string>()
1124
+ + " instance to C++ rvalue: instance has multiple references"
1125
+ " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1126
+ #else
1127
+ throw cast_error("Unable to move from Python "
1128
+ + str(type::handle_of(obj)).cast<std::string>() + " instance to C++ "
1129
+ + type_id<T>() + " instance: instance has multiple references");
1130
+ #endif
1131
+ }
1132
+
1133
+ // Move into a temporary and return that, because the reference may be a local value of `conv`
1134
+ T ret = std::move(detail::load_type<T>(obj).operator T &());
1135
+ return ret;
1136
+ }
1137
+
1138
+ // Calling cast() on an rvalue calls pybind11::cast with the object rvalue, which does:
1139
+ // - If we have to move (because T has no copy constructor), do it. This will fail if the moved
1140
+ // object has multiple references, but trying to copy will fail to compile.
1141
+ // - If both movable and copyable, check ref count: if 1, move; otherwise copy
1142
+ // - Otherwise (not movable), copy.
1143
+ template <typename T>
1144
+ detail::enable_if_t<!detail::is_pyobject<T>::value && detail::move_always<T>::value, T>
1145
+ cast(object &&object) {
1146
+ return move<T>(std::move(object));
1147
+ }
1148
+ template <typename T>
1149
+ detail::enable_if_t<!detail::is_pyobject<T>::value && detail::move_if_unreferenced<T>::value, T>
1150
+ cast(object &&object) {
1151
+ if (object.ref_count() > 1) {
1152
+ return cast<T>(object);
1153
+ }
1154
+ return move<T>(std::move(object));
1155
+ }
1156
+ template <typename T>
1157
+ detail::enable_if_t<!detail::is_pyobject<T>::value && detail::move_never<T>::value, T>
1158
+ cast(object &&object) {
1159
+ return cast<T>(object);
1160
+ }
1161
+
1162
+ // pytype rvalue -> pytype (calls converting constructor)
1163
+ template <typename T>
1164
+ detail::enable_if_t<detail::is_pyobject<T>::value, T> cast(object &&object) {
1165
+ return T(std::move(object));
1166
+ }
1167
+
1168
+ template <typename T>
1169
+ T object::cast() const & {
1170
+ return pybind11::cast<T>(*this);
1171
+ }
1172
+ template <typename T>
1173
+ T object::cast() && {
1174
+ return pybind11::cast<T>(std::move(*this));
1175
+ }
1176
+ template <>
1177
+ inline void object::cast() const & {
1178
+ return;
1179
+ }
1180
+ template <>
1181
+ inline void object::cast() && {
1182
+ return;
1183
+ }
1184
+
1185
+ PYBIND11_NAMESPACE_BEGIN(detail)
1186
+
1187
+ // Declared in pytypes.h:
1188
+ template <typename T, enable_if_t<!is_pyobject<T>::value, int>>
1189
+ object object_or_cast(T &&o) {
1190
+ return pybind11::cast(std::forward<T>(o));
1191
+ }
1192
+
1193
+ // Placeholder type for the unneeded (and dead code) static variable in the
1194
+ // PYBIND11_OVERRIDE_OVERRIDE macro
1195
+ struct override_unused {};
1196
+ template <typename ret_type>
1197
+ using override_caster_t = conditional_t<cast_is_temporary_value_reference<ret_type>::value,
1198
+ make_caster<ret_type>,
1199
+ override_unused>;
1200
+
1201
+ // Trampoline use: for reference/pointer types to value-converted values, we do a value cast, then
1202
+ // store the result in the given variable. For other types, this is a no-op.
1203
+ template <typename T>
1204
+ enable_if_t<cast_is_temporary_value_reference<T>::value, T> cast_ref(object &&o,
1205
+ make_caster<T> &caster) {
1206
+ return cast_op<T>(load_type(caster, o));
1207
+ }
1208
+ template <typename T>
1209
+ enable_if_t<!cast_is_temporary_value_reference<T>::value, T> cast_ref(object &&,
1210
+ override_unused &) {
1211
+ pybind11_fail("Internal error: cast_ref fallback invoked");
1212
+ }
1213
+
1214
+ // Trampoline use: Having a pybind11::cast with an invalid reference type is going to
1215
+ // static_assert, even though if it's in dead code, so we provide a "trampoline" to pybind11::cast
1216
+ // that only does anything in cases where pybind11::cast is valid.
1217
+ template <typename T>
1218
+ enable_if_t<cast_is_temporary_value_reference<T>::value, T> cast_safe(object &&) {
1219
+ pybind11_fail("Internal error: cast_safe fallback invoked");
1220
+ }
1221
+ template <typename T>
1222
+ enable_if_t<std::is_void<T>::value, void> cast_safe(object &&) {}
1223
+ template <typename T>
1224
+ enable_if_t<detail::none_of<cast_is_temporary_value_reference<T>, std::is_void<T>>::value, T>
1225
+ cast_safe(object &&o) {
1226
+ return pybind11::cast<T>(std::move(o));
1227
+ }
1228
+
1229
+ PYBIND11_NAMESPACE_END(detail)
1230
+
1231
+ // The overloads could coexist, i.e. the #if is not strictly speaking needed,
1232
+ // but it is an easy minor optimization.
1233
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1234
+ inline cast_error cast_error_unable_to_convert_call_arg(const std::string &name) {
1235
+ return cast_error("Unable to convert call argument '" + name
1236
+ + "' to Python object (#define "
1237
+ "PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1238
+ }
1239
+ #else
1240
+ inline cast_error cast_error_unable_to_convert_call_arg(const std::string &name,
1241
+ const std::string &type) {
1242
+ return cast_error("Unable to convert call argument '" + name + "' of type '" + type
1243
+ + "' to Python object");
1244
+ }
1245
+ #endif
1246
+
1247
+ template <return_value_policy policy = return_value_policy::automatic_reference>
1248
+ tuple make_tuple() {
1249
+ return tuple(0);
1250
+ }
1251
+
1252
+ template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args>
1253
+ tuple make_tuple(Args &&...args_) {
1254
+ constexpr size_t size = sizeof...(Args);
1255
+ std::array<object, size> args{{reinterpret_steal<object>(
1256
+ detail::make_caster<Args>::cast(std::forward<Args>(args_), policy, nullptr))...}};
1257
+ for (size_t i = 0; i < args.size(); i++) {
1258
+ if (!args[i]) {
1259
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1260
+ throw cast_error_unable_to_convert_call_arg(std::to_string(i));
1261
+ #else
1262
+ std::array<std::string, size> argtypes{{type_id<Args>()...}};
1263
+ throw cast_error_unable_to_convert_call_arg(std::to_string(i), argtypes[i]);
1264
+ #endif
1265
+ }
1266
+ }
1267
+ tuple result(size);
1268
+ int counter = 0;
1269
+ for (auto &arg_value : args) {
1270
+ PyTuple_SET_ITEM(result.ptr(), counter++, arg_value.release().ptr());
1271
+ }
1272
+ return result;
1273
+ }
1274
+
1275
+ /// \ingroup annotations
1276
+ /// Annotation for arguments
1277
+ struct arg {
1278
+ /// Constructs an argument with the name of the argument; if null or omitted, this is a
1279
+ /// positional argument.
1280
+ constexpr explicit arg(const char *name = nullptr)
1281
+ : name(name), flag_noconvert(false), flag_none(true) {}
1282
+ /// Assign a value to this argument
1283
+ template <typename T>
1284
+ arg_v operator=(T &&value) const;
1285
+ /// Indicate that the type should not be converted in the type caster
1286
+ arg &noconvert(bool flag = true) {
1287
+ flag_noconvert = flag;
1288
+ return *this;
1289
+ }
1290
+ /// Indicates that the argument should/shouldn't allow None (e.g. for nullable pointer args)
1291
+ arg &none(bool flag = true) {
1292
+ flag_none = flag;
1293
+ return *this;
1294
+ }
1295
+
1296
+ const char *name; ///< If non-null, this is a named kwargs argument
1297
+ bool flag_noconvert : 1; ///< If set, do not allow conversion (requires a supporting type
1298
+ ///< caster!)
1299
+ bool flag_none : 1; ///< If set (the default), allow None to be passed to this argument
1300
+ };
1301
+
1302
+ /// \ingroup annotations
1303
+ /// Annotation for arguments with values
1304
+ struct arg_v : arg {
1305
+ private:
1306
+ template <typename T>
1307
+ arg_v(arg &&base, T &&x, const char *descr = nullptr)
1308
+ : arg(base), value(reinterpret_steal<object>(detail::make_caster<T>::cast(
1309
+ std::forward<T>(x), return_value_policy::automatic, {}))),
1310
+ descr(descr)
1311
+ #if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1312
+ ,
1313
+ type(type_id<T>())
1314
+ #endif
1315
+ {
1316
+ // Workaround! See:
1317
+ // https://github.com/pybind/pybind11/issues/2336
1318
+ // https://github.com/pybind/pybind11/pull/2685#issuecomment-731286700
1319
+ if (PyErr_Occurred()) {
1320
+ PyErr_Clear();
1321
+ }
1322
+ }
1323
+
1324
+ public:
1325
+ /// Direct construction with name, default, and description
1326
+ template <typename T>
1327
+ arg_v(const char *name, T &&x, const char *descr = nullptr)
1328
+ : arg_v(arg(name), std::forward<T>(x), descr) {}
1329
+
1330
+ /// Called internally when invoking `py::arg("a") = value`
1331
+ template <typename T>
1332
+ arg_v(const arg &base, T &&x, const char *descr = nullptr)
1333
+ : arg_v(arg(base), std::forward<T>(x), descr) {}
1334
+
1335
+ /// Same as `arg::noconvert()`, but returns *this as arg_v&, not arg&
1336
+ arg_v &noconvert(bool flag = true) {
1337
+ arg::noconvert(flag);
1338
+ return *this;
1339
+ }
1340
+
1341
+ /// Same as `arg::nonone()`, but returns *this as arg_v&, not arg&
1342
+ arg_v &none(bool flag = true) {
1343
+ arg::none(flag);
1344
+ return *this;
1345
+ }
1346
+
1347
+ /// The default value
1348
+ object value;
1349
+ /// The (optional) description of the default value
1350
+ const char *descr;
1351
+ #if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1352
+ /// The C++ type name of the default value (only available when compiled in debug mode)
1353
+ std::string type;
1354
+ #endif
1355
+ };
1356
+
1357
+ /// \ingroup annotations
1358
+ /// Annotation indicating that all following arguments are keyword-only; the is the equivalent of
1359
+ /// an unnamed '*' argument
1360
+ struct kw_only {};
1361
+
1362
+ /// \ingroup annotations
1363
+ /// Annotation indicating that all previous arguments are positional-only; the is the equivalent of
1364
+ /// an unnamed '/' argument (in Python 3.8)
1365
+ struct pos_only {};
1366
+
1367
+ template <typename T>
1368
+ arg_v arg::operator=(T &&value) const {
1369
+ return {*this, std::forward<T>(value)};
1370
+ }
1371
+
1372
+ /// Alias for backward compatibility -- to be removed in version 2.0
1373
+ template <typename /*unused*/>
1374
+ using arg_t = arg_v;
1375
+
1376
+ inline namespace literals {
1377
+ /** \rst
1378
+ String literal version of `arg`
1379
+ \endrst */
1380
+ constexpr arg operator"" _a(const char *name, size_t) { return arg(name); }
1381
+ } // namespace literals
1382
+
1383
+ PYBIND11_NAMESPACE_BEGIN(detail)
1384
+
1385
+ template <typename T>
1386
+ using is_kw_only = std::is_same<intrinsic_t<T>, kw_only>;
1387
+ template <typename T>
1388
+ using is_pos_only = std::is_same<intrinsic_t<T>, pos_only>;
1389
+
1390
+ // forward declaration (definition in attr.h)
1391
+ struct function_record;
1392
+
1393
+ /// Internal data associated with a single function call
1394
+ struct function_call {
1395
+ function_call(const function_record &f, handle p); // Implementation in attr.h
1396
+
1397
+ /// The function data:
1398
+ const function_record &func;
1399
+
1400
+ /// Arguments passed to the function:
1401
+ std::vector<handle> args;
1402
+
1403
+ /// The `convert` value the arguments should be loaded with
1404
+ std::vector<bool> args_convert;
1405
+
1406
+ /// Extra references for the optional `py::args` and/or `py::kwargs` arguments (which, if
1407
+ /// present, are also in `args` but without a reference).
1408
+ object args_ref, kwargs_ref;
1409
+
1410
+ /// The parent, if any
1411
+ handle parent;
1412
+
1413
+ /// If this is a call to an initializer, this argument contains `self`
1414
+ handle init_self;
1415
+ };
1416
+
1417
+ /// Helper class which loads arguments for C++ functions called from Python
1418
+ template <typename... Args>
1419
+ class argument_loader {
1420
+ using indices = make_index_sequence<sizeof...(Args)>;
1421
+
1422
+ template <typename Arg>
1423
+ using argument_is_args = std::is_same<intrinsic_t<Arg>, args>;
1424
+ template <typename Arg>
1425
+ using argument_is_kwargs = std::is_same<intrinsic_t<Arg>, kwargs>;
1426
+ // Get kwargs argument position, or -1 if not present:
1427
+ static constexpr auto kwargs_pos = constexpr_last<argument_is_kwargs, Args...>();
1428
+
1429
+ static_assert(kwargs_pos == -1 || kwargs_pos == (int) sizeof...(Args) - 1,
1430
+ "py::kwargs is only permitted as the last argument of a function");
1431
+
1432
+ public:
1433
+ static constexpr bool has_kwargs = kwargs_pos != -1;
1434
+
1435
+ // py::args argument position; -1 if not present.
1436
+ static constexpr int args_pos = constexpr_last<argument_is_args, Args...>();
1437
+
1438
+ static_assert(args_pos == -1 || args_pos == constexpr_first<argument_is_args, Args...>(),
1439
+ "py::args cannot be specified more than once");
1440
+
1441
+ static constexpr auto arg_names = concat(type_descr(make_caster<Args>::name)...);
1442
+
1443
+ bool load_args(function_call &call) { return load_impl_sequence(call, indices{}); }
1444
+
1445
+ template <typename Return, typename Guard, typename Func>
1446
+ // NOLINTNEXTLINE(readability-const-return-type)
1447
+ enable_if_t<!std::is_void<Return>::value, Return> call(Func &&f) && {
1448
+ return std::move(*this).template call_impl<remove_cv_t<Return>>(
1449
+ std::forward<Func>(f), indices{}, Guard{});
1450
+ }
1451
+
1452
+ template <typename Return, typename Guard, typename Func>
1453
+ enable_if_t<std::is_void<Return>::value, void_type> call(Func &&f) && {
1454
+ std::move(*this).template call_impl<remove_cv_t<Return>>(
1455
+ std::forward<Func>(f), indices{}, Guard{});
1456
+ return void_type();
1457
+ }
1458
+
1459
+ private:
1460
+ static bool load_impl_sequence(function_call &, index_sequence<>) { return true; }
1461
+
1462
+ template <size_t... Is>
1463
+ bool load_impl_sequence(function_call &call, index_sequence<Is...>) {
1464
+ #ifdef __cpp_fold_expressions
1465
+ if ((... || !std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is]))) {
1466
+ return false;
1467
+ }
1468
+ #else
1469
+ for (bool r : {std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is])...}) {
1470
+ if (!r) {
1471
+ return false;
1472
+ }
1473
+ }
1474
+ #endif
1475
+ return true;
1476
+ }
1477
+
1478
+ template <typename Return, typename Func, size_t... Is, typename Guard>
1479
+ Return call_impl(Func &&f, index_sequence<Is...>, Guard &&) && {
1480
+ return std::forward<Func>(f)(cast_op<Args>(std::move(std::get<Is>(argcasters)))...);
1481
+ }
1482
+
1483
+ std::tuple<make_caster<Args>...> argcasters;
1484
+ };
1485
+
1486
+ /// Helper class which collects only positional arguments for a Python function call.
1487
+ /// A fancier version below can collect any argument, but this one is optimal for simple calls.
1488
+ template <return_value_policy policy>
1489
+ class simple_collector {
1490
+ public:
1491
+ template <typename... Ts>
1492
+ explicit simple_collector(Ts &&...values)
1493
+ : m_args(pybind11::make_tuple<policy>(std::forward<Ts>(values)...)) {}
1494
+
1495
+ const tuple &args() const & { return m_args; }
1496
+ dict kwargs() const { return {}; }
1497
+
1498
+ tuple args() && { return std::move(m_args); }
1499
+
1500
+ /// Call a Python function and pass the collected arguments
1501
+ object call(PyObject *ptr) const {
1502
+ PyObject *result = PyObject_CallObject(ptr, m_args.ptr());
1503
+ if (!result) {
1504
+ throw error_already_set();
1505
+ }
1506
+ return reinterpret_steal<object>(result);
1507
+ }
1508
+
1509
+ private:
1510
+ tuple m_args;
1511
+ };
1512
+
1513
+ /// Helper class which collects positional, keyword, * and ** arguments for a Python function call
1514
+ template <return_value_policy policy>
1515
+ class unpacking_collector {
1516
+ public:
1517
+ template <typename... Ts>
1518
+ explicit unpacking_collector(Ts &&...values) {
1519
+ // Tuples aren't (easily) resizable so a list is needed for collection,
1520
+ // but the actual function call strictly requires a tuple.
1521
+ auto args_list = list();
1522
+ using expander = int[];
1523
+ (void) expander{0, (process(args_list, std::forward<Ts>(values)), 0)...};
1524
+
1525
+ m_args = std::move(args_list);
1526
+ }
1527
+
1528
+ const tuple &args() const & { return m_args; }
1529
+ const dict &kwargs() const & { return m_kwargs; }
1530
+
1531
+ tuple args() && { return std::move(m_args); }
1532
+ dict kwargs() && { return std::move(m_kwargs); }
1533
+
1534
+ /// Call a Python function and pass the collected arguments
1535
+ object call(PyObject *ptr) const {
1536
+ PyObject *result = PyObject_Call(ptr, m_args.ptr(), m_kwargs.ptr());
1537
+ if (!result) {
1538
+ throw error_already_set();
1539
+ }
1540
+ return reinterpret_steal<object>(result);
1541
+ }
1542
+
1543
+ private:
1544
+ template <typename T>
1545
+ void process(list &args_list, T &&x) {
1546
+ auto o = reinterpret_steal<object>(
1547
+ detail::make_caster<T>::cast(std::forward<T>(x), policy, {}));
1548
+ if (!o) {
1549
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1550
+ throw cast_error_unable_to_convert_call_arg(std::to_string(args_list.size()));
1551
+ #else
1552
+ throw cast_error_unable_to_convert_call_arg(std::to_string(args_list.size()),
1553
+ type_id<T>());
1554
+ #endif
1555
+ }
1556
+ args_list.append(std::move(o));
1557
+ }
1558
+
1559
+ void process(list &args_list, detail::args_proxy ap) {
1560
+ for (auto a : ap) {
1561
+ args_list.append(a);
1562
+ }
1563
+ }
1564
+
1565
+ void process(list & /*args_list*/, arg_v a) {
1566
+ if (!a.name) {
1567
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1568
+ nameless_argument_error();
1569
+ #else
1570
+ nameless_argument_error(a.type);
1571
+ #endif
1572
+ }
1573
+ if (m_kwargs.contains(a.name)) {
1574
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1575
+ multiple_values_error();
1576
+ #else
1577
+ multiple_values_error(a.name);
1578
+ #endif
1579
+ }
1580
+ if (!a.value) {
1581
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1582
+ throw cast_error_unable_to_convert_call_arg(a.name);
1583
+ #else
1584
+ throw cast_error_unable_to_convert_call_arg(a.name, a.type);
1585
+ #endif
1586
+ }
1587
+ m_kwargs[a.name] = std::move(a.value);
1588
+ }
1589
+
1590
+ void process(list & /*args_list*/, detail::kwargs_proxy kp) {
1591
+ if (!kp) {
1592
+ return;
1593
+ }
1594
+ for (auto k : reinterpret_borrow<dict>(kp)) {
1595
+ if (m_kwargs.contains(k.first)) {
1596
+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1597
+ multiple_values_error();
1598
+ #else
1599
+ multiple_values_error(str(k.first));
1600
+ #endif
1601
+ }
1602
+ m_kwargs[k.first] = k.second;
1603
+ }
1604
+ }
1605
+
1606
+ [[noreturn]] static void nameless_argument_error() {
1607
+ throw type_error(
1608
+ "Got kwargs without a name; only named arguments "
1609
+ "may be passed via py::arg() to a python function call. "
1610
+ "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1611
+ }
1612
+ [[noreturn]] static void nameless_argument_error(const std::string &type) {
1613
+ throw type_error("Got kwargs without a name of type '" + type
1614
+ + "'; only named "
1615
+ "arguments may be passed via py::arg() to a python function call. ");
1616
+ }
1617
+ [[noreturn]] static void multiple_values_error() {
1618
+ throw type_error(
1619
+ "Got multiple values for keyword argument "
1620
+ "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1621
+ }
1622
+
1623
+ [[noreturn]] static void multiple_values_error(const std::string &name) {
1624
+ throw type_error("Got multiple values for keyword argument '" + name + "'");
1625
+ }
1626
+
1627
+ private:
1628
+ tuple m_args;
1629
+ dict m_kwargs;
1630
+ };
1631
+
1632
+ // [workaround(intel)] Separate function required here
1633
+ // We need to put this into a separate function because the Intel compiler
1634
+ // fails to compile enable_if_t<!all_of<is_positional<Args>...>::value>
1635
+ // (tested with ICC 2021.1 Beta 20200827).
1636
+ template <typename... Args>
1637
+ constexpr bool args_are_all_positional() {
1638
+ return all_of<is_positional<Args>...>::value;
1639
+ }
1640
+
1641
+ /// Collect only positional arguments for a Python function call
1642
+ template <return_value_policy policy,
1643
+ typename... Args,
1644
+ typename = enable_if_t<args_are_all_positional<Args...>()>>
1645
+ simple_collector<policy> collect_arguments(Args &&...args) {
1646
+ return simple_collector<policy>(std::forward<Args>(args)...);
1647
+ }
1648
+
1649
+ /// Collect all arguments, including keywords and unpacking (only instantiated when needed)
1650
+ template <return_value_policy policy,
1651
+ typename... Args,
1652
+ typename = enable_if_t<!args_are_all_positional<Args...>()>>
1653
+ unpacking_collector<policy> collect_arguments(Args &&...args) {
1654
+ // Following argument order rules for generalized unpacking according to PEP 448
1655
+ static_assert(constexpr_last<is_positional, Args...>()
1656
+ < constexpr_first<is_keyword_or_ds, Args...>()
1657
+ && constexpr_last<is_s_unpacking, Args...>()
1658
+ < constexpr_first<is_ds_unpacking, Args...>(),
1659
+ "Invalid function call: positional args must precede keywords and ** unpacking; "
1660
+ "* unpacking must precede ** unpacking");
1661
+ return unpacking_collector<policy>(std::forward<Args>(args)...);
1662
+ }
1663
+
1664
+ template <typename Derived>
1665
+ template <return_value_policy policy, typename... Args>
1666
+ object object_api<Derived>::operator()(Args &&...args) const {
1667
+ #ifndef NDEBUG
1668
+ if (!PyGILState_Check()) {
1669
+ pybind11_fail("pybind11::object_api<>::operator() PyGILState_Check() failure.");
1670
+ }
1671
+ #endif
1672
+ return detail::collect_arguments<policy>(std::forward<Args>(args)...).call(derived().ptr());
1673
+ }
1674
+
1675
+ template <typename Derived>
1676
+ template <return_value_policy policy, typename... Args>
1677
+ object object_api<Derived>::call(Args &&...args) const {
1678
+ return operator()<policy>(std::forward<Args>(args)...);
1679
+ }
1680
+
1681
+ PYBIND11_NAMESPACE_END(detail)
1682
+
1683
+ template <typename T>
1684
+ handle type::handle_of() {
1685
+ static_assert(std::is_base_of<detail::type_caster_generic, detail::make_caster<T>>::value,
1686
+ "py::type::of<T> only supports the case where T is a registered C++ types.");
1687
+
1688
+ return detail::get_type_handle(typeid(T), true);
1689
+ }
1690
+
1691
+ #define PYBIND11_MAKE_OPAQUE(...) \
1692
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) \
1693
+ namespace detail { \
1694
+ template <> \
1695
+ class type_caster<__VA_ARGS__> : public type_caster_base<__VA_ARGS__> {}; \
1696
+ } \
1697
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
1698
+
1699
+ /// Lets you pass a type containing a `,` through a macro parameter without needing a separate
1700
+ /// typedef, e.g.:
1701
+ /// `PYBIND11_OVERRIDE(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)`
1702
+ #define PYBIND11_TYPE(...) __VA_ARGS__
1703
+
1704
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)