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,1177 @@
1
+ /*
2
+ pybind11/detail/type_caster_base.h (originally first part of pybind11/cast.h)
3
+
4
+ Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5
+
6
+ All rights reserved. Use of this source code is governed by a
7
+ BSD-style license that can be found in the LICENSE file.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include "../pytypes.h"
13
+ #include "common.h"
14
+ #include "descr.h"
15
+ #include "internals.h"
16
+ #include "typeid.h"
17
+
18
+ #include <cstdint>
19
+ #include <iterator>
20
+ #include <new>
21
+ #include <string>
22
+ #include <type_traits>
23
+ #include <typeindex>
24
+ #include <typeinfo>
25
+ #include <unordered_map>
26
+ #include <utility>
27
+ #include <vector>
28
+
29
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
30
+ PYBIND11_NAMESPACE_BEGIN(detail)
31
+
32
+ /// A life support system for temporary objects created by `type_caster::load()`.
33
+ /// Adding a patient will keep it alive up until the enclosing function returns.
34
+ class loader_life_support {
35
+ private:
36
+ loader_life_support *parent = nullptr;
37
+ std::unordered_set<PyObject *> keep_alive;
38
+
39
+ #if defined(WITH_THREAD)
40
+ // Store stack pointer in thread-local storage.
41
+ static PYBIND11_TLS_KEY_REF get_stack_tls_key() {
42
+ # if PYBIND11_INTERNALS_VERSION == 4
43
+ return get_local_internals().loader_life_support_tls_key;
44
+ # else
45
+ return get_internals().loader_life_support_tls_key;
46
+ # endif
47
+ }
48
+ static loader_life_support *get_stack_top() {
49
+ return static_cast<loader_life_support *>(PYBIND11_TLS_GET_VALUE(get_stack_tls_key()));
50
+ }
51
+ static void set_stack_top(loader_life_support *value) {
52
+ PYBIND11_TLS_REPLACE_VALUE(get_stack_tls_key(), value);
53
+ }
54
+ #else
55
+ // Use single global variable for stack.
56
+ static loader_life_support **get_stack_pp() {
57
+ static loader_life_support *global_stack = nullptr;
58
+ return global_stack;
59
+ }
60
+ static loader_life_support *get_stack_top() { return *get_stack_pp(); }
61
+ static void set_stack_top(loader_life_support *value) { *get_stack_pp() = value; }
62
+ #endif
63
+
64
+ public:
65
+ /// A new patient frame is created when a function is entered
66
+ loader_life_support() : parent{get_stack_top()} { set_stack_top(this); }
67
+
68
+ /// ... and destroyed after it returns
69
+ ~loader_life_support() {
70
+ if (get_stack_top() != this) {
71
+ pybind11_fail("loader_life_support: internal error");
72
+ }
73
+ set_stack_top(parent);
74
+ for (auto *item : keep_alive) {
75
+ Py_DECREF(item);
76
+ }
77
+ }
78
+
79
+ /// This can only be used inside a pybind11-bound function, either by `argument_loader`
80
+ /// at argument preparation time or by `py::cast()` at execution time.
81
+ PYBIND11_NOINLINE static void add_patient(handle h) {
82
+ loader_life_support *frame = get_stack_top();
83
+ if (!frame) {
84
+ // NOTE: It would be nice to include the stack frames here, as this indicates
85
+ // use of pybind11::cast<> outside the normal call framework, finding such
86
+ // a location is challenging. Developers could consider printing out
87
+ // stack frame addresses here using something like __builtin_frame_address(0)
88
+ throw cast_error("When called outside a bound function, py::cast() cannot "
89
+ "do Python -> C++ conversions which require the creation "
90
+ "of temporary values");
91
+ }
92
+
93
+ if (frame->keep_alive.insert(h.ptr()).second) {
94
+ Py_INCREF(h.ptr());
95
+ }
96
+ }
97
+ };
98
+
99
+ // Gets the cache entry for the given type, creating it if necessary. The return value is the pair
100
+ // returned by emplace, i.e. an iterator for the entry and a bool set to `true` if the entry was
101
+ // just created.
102
+ inline std::pair<decltype(internals::registered_types_py)::iterator, bool>
103
+ all_type_info_get_cache(PyTypeObject *type);
104
+
105
+ // Populates a just-created cache entry.
106
+ PYBIND11_NOINLINE void all_type_info_populate(PyTypeObject *t, std::vector<type_info *> &bases) {
107
+ std::vector<PyTypeObject *> check;
108
+ for (handle parent : reinterpret_borrow<tuple>(t->tp_bases)) {
109
+ check.push_back((PyTypeObject *) parent.ptr());
110
+ }
111
+
112
+ auto const &type_dict = get_internals().registered_types_py;
113
+ for (size_t i = 0; i < check.size(); i++) {
114
+ auto *type = check[i];
115
+ // Ignore Python2 old-style class super type:
116
+ if (!PyType_Check((PyObject *) type)) {
117
+ continue;
118
+ }
119
+
120
+ // Check `type` in the current set of registered python types:
121
+ auto it = type_dict.find(type);
122
+ if (it != type_dict.end()) {
123
+ // We found a cache entry for it, so it's either pybind-registered or has pre-computed
124
+ // pybind bases, but we have to make sure we haven't already seen the type(s) before:
125
+ // we want to follow Python/virtual C++ rules that there should only be one instance of
126
+ // a common base.
127
+ for (auto *tinfo : it->second) {
128
+ // NB: Could use a second set here, rather than doing a linear search, but since
129
+ // having a large number of immediate pybind11-registered types seems fairly
130
+ // unlikely, that probably isn't worthwhile.
131
+ bool found = false;
132
+ for (auto *known : bases) {
133
+ if (known == tinfo) {
134
+ found = true;
135
+ break;
136
+ }
137
+ }
138
+ if (!found) {
139
+ bases.push_back(tinfo);
140
+ }
141
+ }
142
+ } else if (type->tp_bases) {
143
+ // It's some python type, so keep follow its bases classes to look for one or more
144
+ // registered types
145
+ if (i + 1 == check.size()) {
146
+ // When we're at the end, we can pop off the current element to avoid growing
147
+ // `check` when adding just one base (which is typical--i.e. when there is no
148
+ // multiple inheritance)
149
+ check.pop_back();
150
+ i--;
151
+ }
152
+ for (handle parent : reinterpret_borrow<tuple>(type->tp_bases)) {
153
+ check.push_back((PyTypeObject *) parent.ptr());
154
+ }
155
+ }
156
+ }
157
+ }
158
+
159
+ /**
160
+ * Extracts vector of type_info pointers of pybind-registered roots of the given Python type. Will
161
+ * be just 1 pybind type for the Python type of a pybind-registered class, or for any Python-side
162
+ * derived class that uses single inheritance. Will contain as many types as required for a Python
163
+ * class that uses multiple inheritance to inherit (directly or indirectly) from multiple
164
+ * pybind-registered classes. Will be empty if neither the type nor any base classes are
165
+ * pybind-registered.
166
+ *
167
+ * The value is cached for the lifetime of the Python type.
168
+ */
169
+ inline const std::vector<detail::type_info *> &all_type_info(PyTypeObject *type) {
170
+ auto ins = all_type_info_get_cache(type);
171
+ if (ins.second) {
172
+ // New cache entry: populate it
173
+ all_type_info_populate(type, ins.first->second);
174
+ }
175
+
176
+ return ins.first->second;
177
+ }
178
+
179
+ /**
180
+ * Gets a single pybind11 type info for a python type. Returns nullptr if neither the type nor any
181
+ * ancestors are pybind11-registered. Throws an exception if there are multiple bases--use
182
+ * `all_type_info` instead if you want to support multiple bases.
183
+ */
184
+ PYBIND11_NOINLINE detail::type_info *get_type_info(PyTypeObject *type) {
185
+ const auto &bases = all_type_info(type);
186
+ if (bases.empty()) {
187
+ return nullptr;
188
+ }
189
+ if (bases.size() > 1) {
190
+ pybind11_fail(
191
+ "pybind11::detail::get_type_info: type has multiple pybind11-registered bases");
192
+ }
193
+ return bases.front();
194
+ }
195
+
196
+ inline detail::type_info *get_local_type_info(const std::type_index &tp) {
197
+ auto &locals = get_local_internals().registered_types_cpp;
198
+ auto it = locals.find(tp);
199
+ if (it != locals.end()) {
200
+ return it->second;
201
+ }
202
+ return nullptr;
203
+ }
204
+
205
+ inline detail::type_info *get_global_type_info(const std::type_index &tp) {
206
+ auto &types = get_internals().registered_types_cpp;
207
+ auto it = types.find(tp);
208
+ if (it != types.end()) {
209
+ return it->second;
210
+ }
211
+ return nullptr;
212
+ }
213
+
214
+ /// Return the type info for a given C++ type; on lookup failure can either throw or return
215
+ /// nullptr.
216
+ PYBIND11_NOINLINE detail::type_info *get_type_info(const std::type_index &tp,
217
+ bool throw_if_missing = false) {
218
+ if (auto *ltype = get_local_type_info(tp)) {
219
+ return ltype;
220
+ }
221
+ if (auto *gtype = get_global_type_info(tp)) {
222
+ return gtype;
223
+ }
224
+
225
+ if (throw_if_missing) {
226
+ std::string tname = tp.name();
227
+ detail::clean_type_id(tname);
228
+ pybind11_fail("pybind11::detail::get_type_info: unable to find type info for \""
229
+ + std::move(tname) + '"');
230
+ }
231
+ return nullptr;
232
+ }
233
+
234
+ PYBIND11_NOINLINE handle get_type_handle(const std::type_info &tp, bool throw_if_missing) {
235
+ detail::type_info *type_info = get_type_info(tp, throw_if_missing);
236
+ return handle(type_info ? ((PyObject *) type_info->type) : nullptr);
237
+ }
238
+
239
+ // Searches the inheritance graph for a registered Python instance, using all_type_info().
240
+ PYBIND11_NOINLINE handle find_registered_python_instance(void *src,
241
+ const detail::type_info *tinfo) {
242
+ auto it_instances = get_internals().registered_instances.equal_range(src);
243
+ for (auto it_i = it_instances.first; it_i != it_instances.second; ++it_i) {
244
+ for (auto *instance_type : detail::all_type_info(Py_TYPE(it_i->second))) {
245
+ if (instance_type && same_type(*instance_type->cpptype, *tinfo->cpptype)) {
246
+ return handle((PyObject *) it_i->second).inc_ref();
247
+ }
248
+ }
249
+ }
250
+ return handle();
251
+ }
252
+
253
+ struct value_and_holder {
254
+ instance *inst = nullptr;
255
+ size_t index = 0u;
256
+ const detail::type_info *type = nullptr;
257
+ void **vh = nullptr;
258
+
259
+ // Main constructor for a found value/holder:
260
+ value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
261
+ : inst{i}, index{index}, type{type},
262
+ vh{inst->simple_layout ? inst->simple_value_holder
263
+ : &inst->nonsimple.values_and_holders[vpos]} {}
264
+
265
+ // Default constructor (used to signal a value-and-holder not found by get_value_and_holder())
266
+ value_and_holder() = default;
267
+
268
+ // Used for past-the-end iterator
269
+ explicit value_and_holder(size_t index) : index{index} {}
270
+
271
+ template <typename V = void>
272
+ V *&value_ptr() const {
273
+ return reinterpret_cast<V *&>(vh[0]);
274
+ }
275
+ // True if this `value_and_holder` has a non-null value pointer
276
+ explicit operator bool() const { return value_ptr() != nullptr; }
277
+
278
+ template <typename H>
279
+ H &holder() const {
280
+ return reinterpret_cast<H &>(vh[1]);
281
+ }
282
+ bool holder_constructed() const {
283
+ return inst->simple_layout
284
+ ? inst->simple_holder_constructed
285
+ : (inst->nonsimple.status[index] & instance::status_holder_constructed) != 0u;
286
+ }
287
+ // NOLINTNEXTLINE(readability-make-member-function-const)
288
+ void set_holder_constructed(bool v = true) {
289
+ if (inst->simple_layout) {
290
+ inst->simple_holder_constructed = v;
291
+ } else if (v) {
292
+ inst->nonsimple.status[index] |= instance::status_holder_constructed;
293
+ } else {
294
+ inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
295
+ }
296
+ }
297
+ bool instance_registered() const {
298
+ return inst->simple_layout
299
+ ? inst->simple_instance_registered
300
+ : ((inst->nonsimple.status[index] & instance::status_instance_registered) != 0);
301
+ }
302
+ // NOLINTNEXTLINE(readability-make-member-function-const)
303
+ void set_instance_registered(bool v = true) {
304
+ if (inst->simple_layout) {
305
+ inst->simple_instance_registered = v;
306
+ } else if (v) {
307
+ inst->nonsimple.status[index] |= instance::status_instance_registered;
308
+ } else {
309
+ inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_instance_registered;
310
+ }
311
+ }
312
+ };
313
+
314
+ // Container for accessing and iterating over an instance's values/holders
315
+ struct values_and_holders {
316
+ private:
317
+ instance *inst;
318
+ using type_vec = std::vector<detail::type_info *>;
319
+ const type_vec &tinfo;
320
+
321
+ public:
322
+ explicit values_and_holders(instance *inst)
323
+ : inst{inst}, tinfo(all_type_info(Py_TYPE(inst))) {}
324
+
325
+ struct iterator {
326
+ private:
327
+ instance *inst = nullptr;
328
+ const type_vec *types = nullptr;
329
+ value_and_holder curr;
330
+ friend struct values_and_holders;
331
+ iterator(instance *inst, const type_vec *tinfo)
332
+ : inst{inst}, types{tinfo},
333
+ curr(inst /* instance */,
334
+ types->empty() ? nullptr : (*types)[0] /* type info */,
335
+ 0, /* vpos: (non-simple types only): the first vptr comes first */
336
+ 0 /* index */) {}
337
+ // Past-the-end iterator:
338
+ explicit iterator(size_t end) : curr(end) {}
339
+
340
+ public:
341
+ bool operator==(const iterator &other) const { return curr.index == other.curr.index; }
342
+ bool operator!=(const iterator &other) const { return curr.index != other.curr.index; }
343
+ iterator &operator++() {
344
+ if (!inst->simple_layout) {
345
+ curr.vh += 1 + (*types)[curr.index]->holder_size_in_ptrs;
346
+ }
347
+ ++curr.index;
348
+ curr.type = curr.index < types->size() ? (*types)[curr.index] : nullptr;
349
+ return *this;
350
+ }
351
+ value_and_holder &operator*() { return curr; }
352
+ value_and_holder *operator->() { return &curr; }
353
+ };
354
+
355
+ iterator begin() { return iterator(inst, &tinfo); }
356
+ iterator end() { return iterator(tinfo.size()); }
357
+
358
+ iterator find(const type_info *find_type) {
359
+ auto it = begin(), endit = end();
360
+ while (it != endit && it->type != find_type) {
361
+ ++it;
362
+ }
363
+ return it;
364
+ }
365
+
366
+ size_t size() { return tinfo.size(); }
367
+ };
368
+
369
+ /**
370
+ * Extracts C++ value and holder pointer references from an instance (which may contain multiple
371
+ * values/holders for python-side multiple inheritance) that match the given type. Throws an error
372
+ * if the given type (or ValueType, if omitted) is not a pybind11 base of the given instance. If
373
+ * `find_type` is omitted (or explicitly specified as nullptr) the first value/holder are returned,
374
+ * regardless of type (and the resulting .type will be nullptr).
375
+ *
376
+ * The returned object should be short-lived: in particular, it must not outlive the called-upon
377
+ * instance.
378
+ */
379
+ PYBIND11_NOINLINE value_and_holder
380
+ instance::get_value_and_holder(const type_info *find_type /*= nullptr default in common.h*/,
381
+ bool throw_if_missing /*= true in common.h*/) {
382
+ // Optimize common case:
383
+ if (!find_type || Py_TYPE(this) == find_type->type) {
384
+ return value_and_holder(this, find_type, 0, 0);
385
+ }
386
+
387
+ detail::values_and_holders vhs(this);
388
+ auto it = vhs.find(find_type);
389
+ if (it != vhs.end()) {
390
+ return *it;
391
+ }
392
+
393
+ if (!throw_if_missing) {
394
+ return value_and_holder();
395
+ }
396
+
397
+ #if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
398
+ pybind11_fail("pybind11::detail::instance::get_value_and_holder: `"
399
+ + get_fully_qualified_tp_name(find_type->type)
400
+ + "' is not a pybind11 base of the given `"
401
+ + get_fully_qualified_tp_name(Py_TYPE(this)) + "' instance");
402
+ #else
403
+ pybind11_fail(
404
+ "pybind11::detail::instance::get_value_and_holder: "
405
+ "type is not a pybind11 base of the given instance "
406
+ "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for type details)");
407
+ #endif
408
+ }
409
+
410
+ PYBIND11_NOINLINE void instance::allocate_layout() {
411
+ const auto &tinfo = all_type_info(Py_TYPE(this));
412
+
413
+ const size_t n_types = tinfo.size();
414
+
415
+ if (n_types == 0) {
416
+ pybind11_fail(
417
+ "instance allocation failed: new instance has no pybind11-registered base types");
418
+ }
419
+
420
+ simple_layout
421
+ = n_types == 1 && tinfo.front()->holder_size_in_ptrs <= instance_simple_holder_in_ptrs();
422
+
423
+ // Simple path: no python-side multiple inheritance, and a small-enough holder
424
+ if (simple_layout) {
425
+ simple_value_holder[0] = nullptr;
426
+ simple_holder_constructed = false;
427
+ simple_instance_registered = false;
428
+ } else { // multiple base types or a too-large holder
429
+ // Allocate space to hold: [v1*][h1][v2*][h2]...[bb...] where [vN*] is a value pointer,
430
+ // [hN] is the (uninitialized) holder instance for value N, and [bb...] is a set of bool
431
+ // values that tracks whether each associated holder has been initialized. Each [block] is
432
+ // padded, if necessary, to an integer multiple of sizeof(void *).
433
+ size_t space = 0;
434
+ for (auto *t : tinfo) {
435
+ space += 1; // value pointer
436
+ space += t->holder_size_in_ptrs; // holder instance
437
+ }
438
+ size_t flags_at = space;
439
+ space += size_in_ptrs(n_types); // status bytes (holder_constructed and
440
+ // instance_registered)
441
+
442
+ // Allocate space for flags, values, and holders, and initialize it to 0 (flags and values,
443
+ // in particular, need to be 0). Use Python's memory allocation
444
+ // functions: Python is using pymalloc, which is designed to be
445
+ // efficient for small allocations like the one we're doing here;
446
+ // for larger allocations they are just wrappers around malloc.
447
+ // TODO: is this still true for pure Python 3.6?
448
+ nonsimple.values_and_holders = (void **) PyMem_Calloc(space, sizeof(void *));
449
+ if (!nonsimple.values_and_holders) {
450
+ throw std::bad_alloc();
451
+ }
452
+ nonsimple.status
453
+ = reinterpret_cast<std::uint8_t *>(&nonsimple.values_and_holders[flags_at]);
454
+ }
455
+ owned = true;
456
+ }
457
+
458
+ // NOLINTNEXTLINE(readability-make-member-function-const)
459
+ PYBIND11_NOINLINE void instance::deallocate_layout() {
460
+ if (!simple_layout) {
461
+ PyMem_Free(nonsimple.values_and_holders);
462
+ }
463
+ }
464
+
465
+ PYBIND11_NOINLINE bool isinstance_generic(handle obj, const std::type_info &tp) {
466
+ handle type = detail::get_type_handle(tp, false);
467
+ if (!type) {
468
+ return false;
469
+ }
470
+ return isinstance(obj, type);
471
+ }
472
+
473
+ PYBIND11_NOINLINE handle get_object_handle(const void *ptr, const detail::type_info *type) {
474
+ auto &instances = get_internals().registered_instances;
475
+ auto range = instances.equal_range(ptr);
476
+ for (auto it = range.first; it != range.second; ++it) {
477
+ for (const auto &vh : values_and_holders(it->second)) {
478
+ if (vh.type == type) {
479
+ return handle((PyObject *) it->second);
480
+ }
481
+ }
482
+ }
483
+ return handle();
484
+ }
485
+
486
+ inline PyThreadState *get_thread_state_unchecked() {
487
+ #if defined(PYPY_VERSION)
488
+ return PyThreadState_GET();
489
+ #else
490
+ return _PyThreadState_UncheckedGet();
491
+ #endif
492
+ }
493
+
494
+ // Forward declarations
495
+ void keep_alive_impl(handle nurse, handle patient);
496
+ inline PyObject *make_new_instance(PyTypeObject *type);
497
+
498
+ class type_caster_generic {
499
+ public:
500
+ PYBIND11_NOINLINE explicit type_caster_generic(const std::type_info &type_info)
501
+ : typeinfo(get_type_info(type_info)), cpptype(&type_info) {}
502
+
503
+ explicit type_caster_generic(const type_info *typeinfo)
504
+ : typeinfo(typeinfo), cpptype(typeinfo ? typeinfo->cpptype : nullptr) {}
505
+
506
+ bool load(handle src, bool convert) { return load_impl<type_caster_generic>(src, convert); }
507
+
508
+ PYBIND11_NOINLINE static handle cast(const void *_src,
509
+ return_value_policy policy,
510
+ handle parent,
511
+ const detail::type_info *tinfo,
512
+ void *(*copy_constructor)(const void *),
513
+ void *(*move_constructor)(const void *),
514
+ const void *existing_holder = nullptr) {
515
+ if (!tinfo) { // no type info: error will be set already
516
+ return handle();
517
+ }
518
+
519
+ void *src = const_cast<void *>(_src);
520
+ if (src == nullptr) {
521
+ return none().release();
522
+ }
523
+
524
+ if (handle registered_inst = find_registered_python_instance(src, tinfo)) {
525
+ return registered_inst;
526
+ }
527
+
528
+ auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
529
+ auto *wrapper = reinterpret_cast<instance *>(inst.ptr());
530
+ wrapper->owned = false;
531
+ void *&valueptr = values_and_holders(wrapper).begin()->value_ptr();
532
+
533
+ switch (policy) {
534
+ case return_value_policy::automatic:
535
+ case return_value_policy::take_ownership:
536
+ valueptr = src;
537
+ wrapper->owned = true;
538
+ break;
539
+
540
+ case return_value_policy::automatic_reference:
541
+ case return_value_policy::reference:
542
+ valueptr = src;
543
+ wrapper->owned = false;
544
+ break;
545
+
546
+ case return_value_policy::copy:
547
+ if (copy_constructor) {
548
+ valueptr = copy_constructor(src);
549
+ } else {
550
+ #if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
551
+ std::string type_name(tinfo->cpptype->name());
552
+ detail::clean_type_id(type_name);
553
+ throw cast_error("return_value_policy = copy, but type " + type_name
554
+ + " is non-copyable!");
555
+ #else
556
+ throw cast_error("return_value_policy = copy, but type is "
557
+ "non-copyable! (#define PYBIND11_DETAILED_ERROR_MESSAGES or "
558
+ "compile in debug mode for details)");
559
+ #endif
560
+ }
561
+ wrapper->owned = true;
562
+ break;
563
+
564
+ case return_value_policy::move:
565
+ if (move_constructor) {
566
+ valueptr = move_constructor(src);
567
+ } else if (copy_constructor) {
568
+ valueptr = copy_constructor(src);
569
+ } else {
570
+ #if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
571
+ std::string type_name(tinfo->cpptype->name());
572
+ detail::clean_type_id(type_name);
573
+ throw cast_error("return_value_policy = move, but type " + type_name
574
+ + " is neither movable nor copyable!");
575
+ #else
576
+ throw cast_error("return_value_policy = move, but type is neither "
577
+ "movable nor copyable! "
578
+ "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in "
579
+ "debug mode for details)");
580
+ #endif
581
+ }
582
+ wrapper->owned = true;
583
+ break;
584
+
585
+ case return_value_policy::reference_internal:
586
+ valueptr = src;
587
+ wrapper->owned = false;
588
+ keep_alive_impl(inst, parent);
589
+ break;
590
+
591
+ default:
592
+ throw cast_error("unhandled return_value_policy: should not happen!");
593
+ }
594
+
595
+ tinfo->init_instance(wrapper, existing_holder);
596
+
597
+ return inst.release();
598
+ }
599
+
600
+ // Base methods for generic caster; there are overridden in copyable_holder_caster
601
+ void load_value(value_and_holder &&v_h) {
602
+ auto *&vptr = v_h.value_ptr();
603
+ // Lazy allocation for unallocated values:
604
+ if (vptr == nullptr) {
605
+ const auto *type = v_h.type ? v_h.type : typeinfo;
606
+ if (type->operator_new) {
607
+ vptr = type->operator_new(type->type_size);
608
+ } else {
609
+ #if defined(__cpp_aligned_new) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
610
+ if (type->type_align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
611
+ vptr = ::operator new(type->type_size, std::align_val_t(type->type_align));
612
+ } else {
613
+ vptr = ::operator new(type->type_size);
614
+ }
615
+ #else
616
+ vptr = ::operator new(type->type_size);
617
+ #endif
618
+ }
619
+ }
620
+ value = vptr;
621
+ }
622
+ bool try_implicit_casts(handle src, bool convert) {
623
+ for (const auto &cast : typeinfo->implicit_casts) {
624
+ type_caster_generic sub_caster(*cast.first);
625
+ if (sub_caster.load(src, convert)) {
626
+ value = cast.second(sub_caster.value);
627
+ return true;
628
+ }
629
+ }
630
+ return false;
631
+ }
632
+ bool try_direct_conversions(handle src) {
633
+ for (auto &converter : *typeinfo->direct_conversions) {
634
+ if (converter(src.ptr(), value)) {
635
+ return true;
636
+ }
637
+ }
638
+ return false;
639
+ }
640
+ void check_holder_compat() {}
641
+
642
+ PYBIND11_NOINLINE static void *local_load(PyObject *src, const type_info *ti) {
643
+ auto caster = type_caster_generic(ti);
644
+ if (caster.load(src, false)) {
645
+ return caster.value;
646
+ }
647
+ return nullptr;
648
+ }
649
+
650
+ /// Try to load with foreign typeinfo, if available. Used when there is no
651
+ /// native typeinfo, or when the native one wasn't able to produce a value.
652
+ PYBIND11_NOINLINE bool try_load_foreign_module_local(handle src) {
653
+ constexpr auto *local_key = PYBIND11_MODULE_LOCAL_ID;
654
+ const auto pytype = type::handle_of(src);
655
+ if (!hasattr(pytype, local_key)) {
656
+ return false;
657
+ }
658
+
659
+ type_info *foreign_typeinfo = reinterpret_borrow<capsule>(getattr(pytype, local_key));
660
+ // Only consider this foreign loader if actually foreign and is a loader of the correct cpp
661
+ // type
662
+ if (foreign_typeinfo->module_local_load == &local_load
663
+ || (cpptype && !same_type(*cpptype, *foreign_typeinfo->cpptype))) {
664
+ return false;
665
+ }
666
+
667
+ if (auto *result = foreign_typeinfo->module_local_load(src.ptr(), foreign_typeinfo)) {
668
+ value = result;
669
+ return true;
670
+ }
671
+ return false;
672
+ }
673
+
674
+ // Implementation of `load`; this takes the type of `this` so that it can dispatch the relevant
675
+ // bits of code between here and copyable_holder_caster where the two classes need different
676
+ // logic (without having to resort to virtual inheritance).
677
+ template <typename ThisT>
678
+ PYBIND11_NOINLINE bool load_impl(handle src, bool convert) {
679
+ if (!src) {
680
+ return false;
681
+ }
682
+ if (!typeinfo) {
683
+ return try_load_foreign_module_local(src);
684
+ }
685
+
686
+ auto &this_ = static_cast<ThisT &>(*this);
687
+ this_.check_holder_compat();
688
+
689
+ PyTypeObject *srctype = Py_TYPE(src.ptr());
690
+
691
+ // Case 1: If src is an exact type match for the target type then we can reinterpret_cast
692
+ // the instance's value pointer to the target type:
693
+ if (srctype == typeinfo->type) {
694
+ this_.load_value(reinterpret_cast<instance *>(src.ptr())->get_value_and_holder());
695
+ return true;
696
+ }
697
+ // Case 2: We have a derived class
698
+ if (PyType_IsSubtype(srctype, typeinfo->type)) {
699
+ const auto &bases = all_type_info(srctype);
700
+ bool no_cpp_mi = typeinfo->simple_type;
701
+
702
+ // Case 2a: the python type is a Python-inherited derived class that inherits from just
703
+ // one simple (no MI) pybind11 class, or is an exact match, so the C++ instance is of
704
+ // the right type and we can use reinterpret_cast.
705
+ // (This is essentially the same as case 2b, but because not using multiple inheritance
706
+ // is extremely common, we handle it specially to avoid the loop iterator and type
707
+ // pointer lookup overhead)
708
+ if (bases.size() == 1 && (no_cpp_mi || bases.front()->type == typeinfo->type)) {
709
+ this_.load_value(reinterpret_cast<instance *>(src.ptr())->get_value_and_holder());
710
+ return true;
711
+ }
712
+ // Case 2b: the python type inherits from multiple C++ bases. Check the bases to see
713
+ // if we can find an exact match (or, for a simple C++ type, an inherited match); if
714
+ // so, we can safely reinterpret_cast to the relevant pointer.
715
+ if (bases.size() > 1) {
716
+ for (auto *base : bases) {
717
+ if (no_cpp_mi ? PyType_IsSubtype(base->type, typeinfo->type)
718
+ : base->type == typeinfo->type) {
719
+ this_.load_value(
720
+ reinterpret_cast<instance *>(src.ptr())->get_value_and_holder(base));
721
+ return true;
722
+ }
723
+ }
724
+ }
725
+
726
+ // Case 2c: C++ multiple inheritance is involved and we couldn't find an exact type
727
+ // match in the registered bases, above, so try implicit casting (needed for proper C++
728
+ // casting when MI is involved).
729
+ if (this_.try_implicit_casts(src, convert)) {
730
+ return true;
731
+ }
732
+ }
733
+
734
+ // Perform an implicit conversion
735
+ if (convert) {
736
+ for (const auto &converter : typeinfo->implicit_conversions) {
737
+ auto temp = reinterpret_steal<object>(converter(src.ptr(), typeinfo->type));
738
+ if (load_impl<ThisT>(temp, false)) {
739
+ loader_life_support::add_patient(temp);
740
+ return true;
741
+ }
742
+ }
743
+ if (this_.try_direct_conversions(src)) {
744
+ return true;
745
+ }
746
+ }
747
+
748
+ // Failed to match local typeinfo. Try again with global.
749
+ if (typeinfo->module_local) {
750
+ if (auto *gtype = get_global_type_info(*typeinfo->cpptype)) {
751
+ typeinfo = gtype;
752
+ return load(src, false);
753
+ }
754
+ }
755
+
756
+ // Global typeinfo has precedence over foreign module_local
757
+ if (try_load_foreign_module_local(src)) {
758
+ return true;
759
+ }
760
+
761
+ // Custom converters didn't take None, now we convert None to nullptr.
762
+ if (src.is_none()) {
763
+ // Defer accepting None to other overloads (if we aren't in convert mode):
764
+ if (!convert) {
765
+ return false;
766
+ }
767
+ value = nullptr;
768
+ return true;
769
+ }
770
+
771
+ return false;
772
+ }
773
+
774
+ // Called to do type lookup and wrap the pointer and type in a pair when a dynamic_cast
775
+ // isn't needed or can't be used. If the type is unknown, sets the error and returns a pair
776
+ // with .second = nullptr. (p.first = nullptr is not an error: it becomes None).
777
+ PYBIND11_NOINLINE static std::pair<const void *, const type_info *>
778
+ src_and_type(const void *src,
779
+ const std::type_info &cast_type,
780
+ const std::type_info *rtti_type = nullptr) {
781
+ if (auto *tpi = get_type_info(cast_type)) {
782
+ return {src, const_cast<const type_info *>(tpi)};
783
+ }
784
+
785
+ // Not found, set error:
786
+ std::string tname = rtti_type ? rtti_type->name() : cast_type.name();
787
+ detail::clean_type_id(tname);
788
+ std::string msg = "Unregistered type : " + tname;
789
+ PyErr_SetString(PyExc_TypeError, msg.c_str());
790
+ return {nullptr, nullptr};
791
+ }
792
+
793
+ const type_info *typeinfo = nullptr;
794
+ const std::type_info *cpptype = nullptr;
795
+ void *value = nullptr;
796
+ };
797
+
798
+ /**
799
+ * Determine suitable casting operator for pointer-or-lvalue-casting type casters. The type caster
800
+ * needs to provide `operator T*()` and `operator T&()` operators.
801
+ *
802
+ * If the type supports moving the value away via an `operator T&&() &&` method, it should use
803
+ * `movable_cast_op_type` instead.
804
+ */
805
+ template <typename T>
806
+ using cast_op_type = conditional_t<std::is_pointer<remove_reference_t<T>>::value,
807
+ typename std::add_pointer<intrinsic_t<T>>::type,
808
+ typename std::add_lvalue_reference<intrinsic_t<T>>::type>;
809
+
810
+ /**
811
+ * Determine suitable casting operator for a type caster with a movable value. Such a type caster
812
+ * needs to provide `operator T*()`, `operator T&()`, and `operator T&&() &&`. The latter will be
813
+ * called in appropriate contexts where the value can be moved rather than copied.
814
+ *
815
+ * These operator are automatically provided when using the PYBIND11_TYPE_CASTER macro.
816
+ */
817
+ template <typename T>
818
+ using movable_cast_op_type
819
+ = conditional_t<std::is_pointer<typename std::remove_reference<T>::type>::value,
820
+ typename std::add_pointer<intrinsic_t<T>>::type,
821
+ conditional_t<std::is_rvalue_reference<T>::value,
822
+ typename std::add_rvalue_reference<intrinsic_t<T>>::type,
823
+ typename std::add_lvalue_reference<intrinsic_t<T>>::type>>;
824
+
825
+ // Does the container have a mapped type and is it recursive?
826
+ // Implemented by specializations below.
827
+ template <typename Container, typename SFINAE = void>
828
+ struct container_mapped_type_traits {
829
+ static constexpr bool has_mapped_type = false;
830
+ static constexpr bool has_recursive_mapped_type = false;
831
+ };
832
+
833
+ template <typename Container>
834
+ struct container_mapped_type_traits<
835
+ Container,
836
+ typename std::enable_if<
837
+ std::is_same<typename Container::mapped_type, Container>::value>::type> {
838
+ static constexpr bool has_mapped_type = true;
839
+ static constexpr bool has_recursive_mapped_type = true;
840
+ };
841
+
842
+ template <typename Container>
843
+ struct container_mapped_type_traits<
844
+ Container,
845
+ typename std::enable_if<
846
+ negation<std::is_same<typename Container::mapped_type, Container>>::value>::type> {
847
+ static constexpr bool has_mapped_type = true;
848
+ static constexpr bool has_recursive_mapped_type = false;
849
+ };
850
+
851
+ // Does the container have a value type and is it recursive?
852
+ // Implemented by specializations below.
853
+ template <typename Container, typename SFINAE = void>
854
+ struct container_value_type_traits : std::false_type {
855
+ static constexpr bool has_value_type = false;
856
+ static constexpr bool has_recursive_value_type = false;
857
+ };
858
+
859
+ template <typename Container>
860
+ struct container_value_type_traits<
861
+ Container,
862
+ typename std::enable_if<
863
+ std::is_same<typename Container::value_type, Container>::value>::type> {
864
+ static constexpr bool has_value_type = true;
865
+ static constexpr bool has_recursive_value_type = true;
866
+ };
867
+
868
+ template <typename Container>
869
+ struct container_value_type_traits<
870
+ Container,
871
+ typename std::enable_if<
872
+ negation<std::is_same<typename Container::value_type, Container>>::value>::type> {
873
+ static constexpr bool has_value_type = true;
874
+ static constexpr bool has_recursive_value_type = false;
875
+ };
876
+
877
+ /*
878
+ * Tag to be used for representing the bottom of recursively defined types.
879
+ * Define this tag so we don't have to use void.
880
+ */
881
+ struct recursive_bottom {};
882
+
883
+ /*
884
+ * Implementation detail of `recursive_container_traits` below.
885
+ * `T` is the `value_type` of the container, which might need to be modified to
886
+ * avoid recursive types and const types.
887
+ */
888
+ template <typename T, bool is_this_a_map>
889
+ struct impl_type_to_check_recursively {
890
+ /*
891
+ * If the container is recursive, then no further recursion should be done.
892
+ */
893
+ using if_recursive = recursive_bottom;
894
+ /*
895
+ * Otherwise yield `T` unchanged.
896
+ */
897
+ using if_not_recursive = T;
898
+ };
899
+
900
+ /*
901
+ * For pairs - only as value type of a map -, the first type should remove the `const`.
902
+ * Also, if the map is recursive, then the recursive checking should consider
903
+ * the first type only.
904
+ */
905
+ template <typename A, typename B>
906
+ struct impl_type_to_check_recursively<std::pair<A, B>, /* is_this_a_map = */ true> {
907
+ using if_recursive = typename std::remove_const<A>::type;
908
+ using if_not_recursive = std::pair<typename std::remove_const<A>::type, B>;
909
+ };
910
+
911
+ /*
912
+ * Implementation of `recursive_container_traits` below.
913
+ */
914
+ template <typename Container, typename SFINAE = void>
915
+ struct impl_recursive_container_traits {
916
+ using type_to_check_recursively = recursive_bottom;
917
+ };
918
+
919
+ template <typename Container>
920
+ struct impl_recursive_container_traits<
921
+ Container,
922
+ typename std::enable_if<container_value_type_traits<Container>::has_value_type>::type> {
923
+ static constexpr bool is_recursive
924
+ = container_mapped_type_traits<Container>::has_recursive_mapped_type
925
+ || container_value_type_traits<Container>::has_recursive_value_type;
926
+ /*
927
+ * This member dictates which type Pybind11 should check recursively in traits
928
+ * such as `is_move_constructible`, `is_copy_constructible`, `is_move_assignable`, ...
929
+ * Direct access to `value_type` should be avoided:
930
+ * 1. `value_type` might recursively contain the type again
931
+ * 2. `value_type` of STL map types is `std::pair<A const, B>`, the `const`
932
+ * should be removed.
933
+ *
934
+ */
935
+ using type_to_check_recursively = typename std::conditional<
936
+ is_recursive,
937
+ typename impl_type_to_check_recursively<
938
+ typename Container::value_type,
939
+ container_mapped_type_traits<Container>::has_mapped_type>::if_recursive,
940
+ typename impl_type_to_check_recursively<
941
+ typename Container::value_type,
942
+ container_mapped_type_traits<Container>::has_mapped_type>::if_not_recursive>::type;
943
+ };
944
+
945
+ /*
946
+ * This trait defines the `type_to_check_recursively` which is needed to properly
947
+ * handle recursively defined traits such as `is_move_constructible` without going
948
+ * into an infinite recursion.
949
+ * Should be used instead of directly accessing the `value_type`.
950
+ * It cancels the recursion by returning the `recursive_bottom` tag.
951
+ *
952
+ * The default definition of `type_to_check_recursively` is as follows:
953
+ *
954
+ * 1. By default, it is `recursive_bottom`, so that the recursion is canceled.
955
+ * 2. If the type is non-recursive and defines a `value_type`, then the `value_type` is used.
956
+ * If the `value_type` is a pair and a `mapped_type` is defined,
957
+ * then the `const` is removed from the first type.
958
+ * 3. If the type is recursive and `value_type` is not a pair, then `recursive_bottom` is returned.
959
+ * 4. If the type is recursive and `value_type` is a pair and a `mapped_type` is defined,
960
+ * then `const` is removed from the first type and the first type is returned.
961
+ *
962
+ * This behavior can be extended by the user as seen in test_stl_binders.cpp.
963
+ *
964
+ * This struct is exactly the same as impl_recursive_container_traits.
965
+ * The duplication achieves that user-defined specializations don't compete
966
+ * with internal specializations, but take precedence.
967
+ */
968
+ template <typename Container, typename SFINAE = void>
969
+ struct recursive_container_traits : impl_recursive_container_traits<Container> {};
970
+
971
+ template <typename T>
972
+ struct is_move_constructible
973
+ : all_of<std::is_move_constructible<T>,
974
+ is_move_constructible<
975
+ typename recursive_container_traits<T>::type_to_check_recursively>> {};
976
+
977
+ template <>
978
+ struct is_move_constructible<recursive_bottom> : std::true_type {};
979
+
980
+ // Likewise for std::pair
981
+ // (after C++17 it is mandatory that the move constructor not exist when the two types aren't
982
+ // themselves move constructible, but this can not be relied upon when T1 or T2 are themselves
983
+ // containers).
984
+ template <typename T1, typename T2>
985
+ struct is_move_constructible<std::pair<T1, T2>>
986
+ : all_of<is_move_constructible<T1>, is_move_constructible<T2>> {};
987
+
988
+ // std::is_copy_constructible isn't quite enough: it lets std::vector<T> (and similar) through when
989
+ // T is non-copyable, but code containing such a copy constructor fails to actually compile.
990
+ template <typename T>
991
+ struct is_copy_constructible
992
+ : all_of<std::is_copy_constructible<T>,
993
+ is_copy_constructible<
994
+ typename recursive_container_traits<T>::type_to_check_recursively>> {};
995
+
996
+ template <>
997
+ struct is_copy_constructible<recursive_bottom> : std::true_type {};
998
+
999
+ // Likewise for std::pair
1000
+ // (after C++17 it is mandatory that the copy constructor not exist when the two types aren't
1001
+ // themselves copy constructible, but this can not be relied upon when T1 or T2 are themselves
1002
+ // containers).
1003
+ template <typename T1, typename T2>
1004
+ struct is_copy_constructible<std::pair<T1, T2>>
1005
+ : all_of<is_copy_constructible<T1>, is_copy_constructible<T2>> {};
1006
+
1007
+ // The same problems arise with std::is_copy_assignable, so we use the same workaround.
1008
+ template <typename T>
1009
+ struct is_copy_assignable
1010
+ : all_of<
1011
+ std::is_copy_assignable<T>,
1012
+ is_copy_assignable<typename recursive_container_traits<T>::type_to_check_recursively>> {
1013
+ };
1014
+
1015
+ template <>
1016
+ struct is_copy_assignable<recursive_bottom> : std::true_type {};
1017
+
1018
+ template <typename T1, typename T2>
1019
+ struct is_copy_assignable<std::pair<T1, T2>>
1020
+ : all_of<is_copy_assignable<T1>, is_copy_assignable<T2>> {};
1021
+
1022
+ PYBIND11_NAMESPACE_END(detail)
1023
+
1024
+ // polymorphic_type_hook<itype>::get(src, tinfo) determines whether the object pointed
1025
+ // to by `src` actually is an instance of some class derived from `itype`.
1026
+ // If so, it sets `tinfo` to point to the std::type_info representing that derived
1027
+ // type, and returns a pointer to the start of the most-derived object of that type
1028
+ // (in which `src` is a subobject; this will be the same address as `src` in most
1029
+ // single inheritance cases). If not, or if `src` is nullptr, it simply returns `src`
1030
+ // and leaves `tinfo` at its default value of nullptr.
1031
+ //
1032
+ // The default polymorphic_type_hook just returns src. A specialization for polymorphic
1033
+ // types determines the runtime type of the passed object and adjusts the this-pointer
1034
+ // appropriately via dynamic_cast<void*>. This is what enables a C++ Animal* to appear
1035
+ // to Python as a Dog (if Dog inherits from Animal, Animal is polymorphic, Dog is
1036
+ // registered with pybind11, and this Animal is in fact a Dog).
1037
+ //
1038
+ // You may specialize polymorphic_type_hook yourself for types that want to appear
1039
+ // polymorphic to Python but do not use C++ RTTI. (This is a not uncommon pattern
1040
+ // in performance-sensitive applications, used most notably in LLVM.)
1041
+ //
1042
+ // polymorphic_type_hook_base allows users to specialize polymorphic_type_hook with
1043
+ // std::enable_if. User provided specializations will always have higher priority than
1044
+ // the default implementation and specialization provided in polymorphic_type_hook_base.
1045
+ template <typename itype, typename SFINAE = void>
1046
+ struct polymorphic_type_hook_base {
1047
+ static const void *get(const itype *src, const std::type_info *&) { return src; }
1048
+ };
1049
+ template <typename itype>
1050
+ struct polymorphic_type_hook_base<itype, detail::enable_if_t<std::is_polymorphic<itype>::value>> {
1051
+ static const void *get(const itype *src, const std::type_info *&type) {
1052
+ type = src ? &typeid(*src) : nullptr;
1053
+ return dynamic_cast<const void *>(src);
1054
+ }
1055
+ };
1056
+ template <typename itype, typename SFINAE = void>
1057
+ struct polymorphic_type_hook : public polymorphic_type_hook_base<itype> {};
1058
+
1059
+ PYBIND11_NAMESPACE_BEGIN(detail)
1060
+
1061
+ /// Generic type caster for objects stored on the heap
1062
+ template <typename type>
1063
+ class type_caster_base : public type_caster_generic {
1064
+ using itype = intrinsic_t<type>;
1065
+
1066
+ public:
1067
+ static constexpr auto name = const_name<type>();
1068
+
1069
+ type_caster_base() : type_caster_base(typeid(type)) {}
1070
+ explicit type_caster_base(const std::type_info &info) : type_caster_generic(info) {}
1071
+
1072
+ static handle cast(const itype &src, return_value_policy policy, handle parent) {
1073
+ if (policy == return_value_policy::automatic
1074
+ || policy == return_value_policy::automatic_reference) {
1075
+ policy = return_value_policy::copy;
1076
+ }
1077
+ return cast(&src, policy, parent);
1078
+ }
1079
+
1080
+ static handle cast(itype &&src, return_value_policy, handle parent) {
1081
+ return cast(&src, return_value_policy::move, parent);
1082
+ }
1083
+
1084
+ // Returns a (pointer, type_info) pair taking care of necessary type lookup for a
1085
+ // polymorphic type (using RTTI by default, but can be overridden by specializing
1086
+ // polymorphic_type_hook). If the instance isn't derived, returns the base version.
1087
+ static std::pair<const void *, const type_info *> src_and_type(const itype *src) {
1088
+ const auto &cast_type = typeid(itype);
1089
+ const std::type_info *instance_type = nullptr;
1090
+ const void *vsrc = polymorphic_type_hook<itype>::get(src, instance_type);
1091
+ if (instance_type && !same_type(cast_type, *instance_type)) {
1092
+ // This is a base pointer to a derived type. If the derived type is registered
1093
+ // with pybind11, we want to make the full derived object available.
1094
+ // In the typical case where itype is polymorphic, we get the correct
1095
+ // derived pointer (which may be != base pointer) by a dynamic_cast to
1096
+ // most derived type. If itype is not polymorphic, we won't get here
1097
+ // except via a user-provided specialization of polymorphic_type_hook,
1098
+ // and the user has promised that no this-pointer adjustment is
1099
+ // required in that case, so it's OK to use static_cast.
1100
+ if (const auto *tpi = get_type_info(*instance_type)) {
1101
+ return {vsrc, tpi};
1102
+ }
1103
+ }
1104
+ // Otherwise we have either a nullptr, an `itype` pointer, or an unknown derived pointer,
1105
+ // so don't do a cast
1106
+ return type_caster_generic::src_and_type(src, cast_type, instance_type);
1107
+ }
1108
+
1109
+ static handle cast(const itype *src, return_value_policy policy, handle parent) {
1110
+ auto st = src_and_type(src);
1111
+ return type_caster_generic::cast(st.first,
1112
+ policy,
1113
+ parent,
1114
+ st.second,
1115
+ make_copy_constructor(src),
1116
+ make_move_constructor(src));
1117
+ }
1118
+
1119
+ static handle cast_holder(const itype *src, const void *holder) {
1120
+ auto st = src_and_type(src);
1121
+ return type_caster_generic::cast(st.first,
1122
+ return_value_policy::take_ownership,
1123
+ {},
1124
+ st.second,
1125
+ nullptr,
1126
+ nullptr,
1127
+ holder);
1128
+ }
1129
+
1130
+ template <typename T>
1131
+ using cast_op_type = detail::cast_op_type<T>;
1132
+
1133
+ // NOLINTNEXTLINE(google-explicit-constructor)
1134
+ operator itype *() { return (type *) value; }
1135
+ // NOLINTNEXTLINE(google-explicit-constructor)
1136
+ operator itype &() {
1137
+ if (!value) {
1138
+ throw reference_cast_error();
1139
+ }
1140
+ return *((itype *) value);
1141
+ }
1142
+
1143
+ protected:
1144
+ using Constructor = void *(*) (const void *);
1145
+
1146
+ /* Only enabled when the types are {copy,move}-constructible *and* when the type
1147
+ does not have a private operator new implementation. A comma operator is used in the
1148
+ decltype argument to apply SFINAE to the public copy/move constructors.*/
1149
+ template <typename T, typename = enable_if_t<is_copy_constructible<T>::value>>
1150
+ static auto make_copy_constructor(const T *)
1151
+ -> decltype(new T(std::declval<const T>()), Constructor{}) {
1152
+ return [](const void *arg) -> void * { return new T(*reinterpret_cast<const T *>(arg)); };
1153
+ }
1154
+
1155
+ template <typename T, typename = enable_if_t<is_move_constructible<T>::value>>
1156
+ static auto make_move_constructor(const T *)
1157
+ -> decltype(new T(std::declval<T &&>()), Constructor{}) {
1158
+ return [](const void *arg) -> void * {
1159
+ return new T(std::move(*const_cast<T *>(reinterpret_cast<const T *>(arg))));
1160
+ };
1161
+ }
1162
+
1163
+ static Constructor make_copy_constructor(...) { return nullptr; }
1164
+ static Constructor make_move_constructor(...) { return nullptr; }
1165
+ };
1166
+
1167
+ PYBIND11_NOINLINE std::string type_info_description(const std::type_info &ti) {
1168
+ if (auto *type_data = get_type_info(ti)) {
1169
+ handle th((PyObject *) type_data->type);
1170
+ return th.attr("__module__").cast<std::string>() + '.'
1171
+ + th.attr("__qualname__").cast<std::string>();
1172
+ }
1173
+ return clean_type_id(ti.name());
1174
+ }
1175
+
1176
+ PYBIND11_NAMESPACE_END(detail)
1177
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)