xcoll 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.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.

Potentially problematic release.


This version of xcoll might be problematic. Click here for more details.

Files changed (324) hide show
  1. xcoll/__init__.py +2 -1
  2. xcoll/beam_elements/__init__.py +7 -1
  3. xcoll/beam_elements/absorber.py +2 -2
  4. xcoll/beam_elements/base.py +105 -67
  5. xcoll/beam_elements/blowup.py +198 -0
  6. xcoll/beam_elements/{collimators_src → elements_src}/black_absorber.h +21 -3
  7. xcoll/beam_elements/{collimators_src → elements_src}/black_crystal.h +20 -2
  8. xcoll/beam_elements/elements_src/blowup.h +42 -0
  9. xcoll/beam_elements/elements_src/emittance_monitor.h +109 -0
  10. xcoll/beam_elements/{collimators_src → elements_src}/everest_block.h +19 -2
  11. xcoll/beam_elements/{collimators_src → elements_src}/everest_collimator.h +19 -3
  12. xcoll/beam_elements/{collimators_src → elements_src}/everest_crystal.h +30 -9
  13. xcoll/beam_elements/everest.py +5 -6
  14. xcoll/beam_elements/monitor.py +428 -0
  15. xcoll/colldb.py +103 -74
  16. xcoll/general.py +4 -4
  17. xcoll/initial_distribution.py +18 -6
  18. xcoll/install.py +3 -1
  19. xcoll/interaction_record/interaction_record.py +126 -80
  20. xcoll/interaction_record/interaction_record_src/interaction_record.h +43 -43
  21. xcoll/line_tools.py +8 -9
  22. xcoll/lossmap.py +48 -38
  23. xcoll/scattering_routines/everest/amorphous.h +4 -11
  24. xcoll/scattering_routines/everest/channeling.h +3 -8
  25. xcoll/scattering_routines/everest/everest.h +4 -1
  26. xcoll/scattering_routines/everest/jaw.h +4 -3
  27. xcoll/scattering_routines/everest/materials.py +35 -15
  28. xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
  29. xcoll/scattering_routines/everest/nuclear_interaction.h +1 -1
  30. xcoll/scattering_routines/everest/properties.h +6 -1
  31. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
  32. xcoll/scattering_routines/geant4/collimasim/.git +1 -0
  33. xcoll/scattering_routines/geant4/collimasim/.gitignore +12 -0
  34. xcoll/scattering_routines/geant4/collimasim/.gitmodules +3 -0
  35. xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +26 -0
  36. xcoll/scattering_routines/geant4/collimasim/README.md +21 -0
  37. xcoll/scattering_routines/geant4/collimasim/docs/Makefile +20 -0
  38. xcoll/scattering_routines/geant4/collimasim/docs/make.bat +35 -0
  39. xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +10 -0
  40. xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +59 -0
  41. xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +26 -0
  42. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +37 -0
  43. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +19 -0
  44. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +65 -0
  45. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +73 -0
  46. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +1 -0
  47. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +9 -0
  48. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +386 -0
  49. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +45 -0
  50. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +8 -0
  51. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +16 -0
  52. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +8 -0
  53. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +3 -0
  54. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +19 -0
  55. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +969 -0
  56. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +84 -0
  57. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +48 -0
  58. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +16 -0
  59. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +103 -0
  60. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +45 -0
  61. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +151 -0
  62. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +3 -0
  63. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +297 -0
  64. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +29 -0
  65. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +6 -0
  66. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +180 -0
  67. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +23 -0
  68. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +192 -0
  69. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +11 -0
  70. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +81 -0
  71. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +93 -0
  72. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +310 -0
  73. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +109 -0
  74. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +43 -0
  75. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +171 -0
  76. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +251 -0
  77. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +305 -0
  78. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +1297 -0
  79. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +262 -0
  80. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +396 -0
  81. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +568 -0
  82. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +337 -0
  83. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +13 -0
  84. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +463 -0
  85. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +286 -0
  86. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +155 -0
  87. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +174 -0
  88. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +308 -0
  89. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +91 -0
  90. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +95 -0
  91. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +2050 -0
  92. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +542 -0
  93. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +8 -0
  94. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +648 -0
  95. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +381 -0
  96. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +343 -0
  97. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +48 -0
  98. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +105 -0
  99. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +72 -0
  100. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
  101. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
  102. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +427 -0
  103. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
  104. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +427 -0
  105. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +130 -0
  106. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +96 -0
  107. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +8 -0
  108. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +548 -0
  109. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +605 -0
  110. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +144 -0
  111. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +1432 -0
  112. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +213 -0
  113. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +2 -0
  114. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +65 -0
  115. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +709 -0
  116. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +1021 -0
  117. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +104 -0
  118. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +346 -0
  119. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +467 -0
  120. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +978 -0
  121. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +55 -0
  122. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +606 -0
  123. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +284 -0
  124. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +163 -0
  125. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +121 -0
  126. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +193 -0
  127. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +275 -0
  128. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +1741 -0
  129. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +163 -0
  130. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +65 -0
  131. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +2497 -0
  132. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +1879 -0
  133. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +103 -0
  134. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +375 -0
  135. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +747 -0
  136. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +88 -0
  137. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +11 -0
  138. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +52 -0
  139. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +12 -0
  140. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +6 -0
  141. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +21 -0
  142. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
  143. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +482 -0
  144. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +63 -0
  145. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +41 -0
  146. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +56 -0
  147. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +155 -0
  148. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +503 -0
  149. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +208 -0
  150. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +275 -0
  151. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +73 -0
  152. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +33 -0
  153. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
  154. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +279 -0
  155. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
  156. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +143 -0
  157. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +85 -0
  158. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +179 -0
  159. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +151 -0
  160. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +91 -0
  161. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +85 -0
  162. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +19 -0
  163. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +12 -0
  164. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +26 -0
  165. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +25 -0
  166. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +216 -0
  167. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +163 -0
  168. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +286 -0
  169. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +536 -0
  170. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +107 -0
  171. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +248 -0
  172. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +227 -0
  173. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +202 -0
  174. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +84 -0
  175. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +210 -0
  176. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +550 -0
  177. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +473 -0
  178. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +84 -0
  179. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +21 -0
  180. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +28 -0
  181. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +39 -0
  182. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +46 -0
  183. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +6 -0
  184. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +41 -0
  185. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +35 -0
  186. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +41 -0
  187. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +10 -0
  188. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +165 -0
  189. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +53 -0
  190. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +238 -0
  191. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +126 -0
  192. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +141 -0
  193. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +117 -0
  194. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +41 -0
  195. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +50 -0
  196. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +69 -0
  197. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +42 -0
  198. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +348 -0
  199. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +771 -0
  200. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +47 -0
  201. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +22 -0
  202. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +23 -0
  203. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +326 -0
  204. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +15 -0
  205. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +148 -0
  206. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +272 -0
  207. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +119 -0
  208. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +51 -0
  209. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +5 -0
  210. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +285 -0
  211. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +12 -0
  212. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +265 -0
  213. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +397 -0
  214. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +520 -0
  215. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +49 -0
  216. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +94 -0
  217. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +125 -0
  218. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +331 -0
  219. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +153 -0
  220. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +284 -0
  221. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +107 -0
  222. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +257 -0
  223. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +412 -0
  224. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +517 -0
  225. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +102 -0
  226. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +92 -0
  227. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +233 -0
  228. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +360 -0
  229. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +472 -0
  230. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +593 -0
  231. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +524 -0
  232. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +441 -0
  233. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +103 -0
  234. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +267 -0
  235. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +73 -0
  236. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +59 -0
  237. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +235 -0
  238. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +146 -0
  239. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +189 -0
  240. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +82 -0
  241. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +560 -0
  242. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +651 -0
  243. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +500 -0
  244. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +253 -0
  245. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +452 -0
  246. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +318 -0
  247. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +342 -0
  248. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +291 -0
  249. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +131 -0
  250. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +318 -0
  251. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +144 -0
  252. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +29 -0
  253. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +66 -0
  254. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +44 -0
  255. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +22 -0
  256. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +9 -0
  257. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +510 -0
  258. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +408 -0
  259. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +140 -0
  260. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +117 -0
  261. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +70 -0
  262. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +86 -0
  263. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +257 -0
  264. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +44 -0
  265. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +23 -0
  266. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +39 -0
  267. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +64 -0
  268. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +402 -0
  269. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +233 -0
  270. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +276 -0
  271. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +214 -0
  272. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +3 -0
  273. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +65 -0
  274. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +41 -0
  275. xcoll/scattering_routines/geant4/collimasim/pyproject.toml +8 -0
  276. xcoll/scattering_routines/geant4/collimasim/setup.py +144 -0
  277. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +403 -0
  278. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +100 -0
  279. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +763 -0
  280. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +118 -0
  281. xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +8 -0
  282. xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +63 -0
  283. xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +142 -0
  284. xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +556 -0
  285. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +6 -0
  286. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +24 -0
  287. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +1 -0
  288. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +1 -0
  289. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +1 -0
  290. xcoll/scattering_routines/geant4/collimasim/tests/README.md +25 -0
  291. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +25 -0
  292. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +18 -0
  293. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +68 -0
  294. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +15 -0
  295. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +110 -0
  296. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +7 -0
  297. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +3 -0
  298. xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +54 -0
  299. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +3 -0
  300. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +3 -0
  301. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +5 -0
  302. xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +51 -0
  303. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +65 -0
  304. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +59 -0
  305. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +102 -0
  306. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +75 -0
  307. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +74 -0
  308. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +84 -0
  309. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +159 -0
  310. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +99 -0
  311. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +78 -0
  312. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +88 -0
  313. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +80 -0
  314. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +97 -0
  315. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +96 -0
  316. xcoll/scattering_routines/geometry/collimator_geometry.h +9 -10
  317. xcoll/scattering_routines/geometry/crystal_geometry.h +9 -6
  318. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/METADATA +1 -1
  319. xcoll-0.5.0.dist-info/RECORD +413 -0
  320. xcoll/scattering_routines/fluka/build_fluka_input.py +0 -58
  321. xcoll-0.4.0.dist-info/RECORD +0 -126
  322. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/LICENSE +0 -0
  323. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/NOTICE +0 -0
  324. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,452 @@
1
+ /*
2
+ tests/test_smart_ptr.cpp -- binding classes with custom reference counting,
3
+ implicit conversions between 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
+ #if defined(_MSC_VER) && _MSC_VER < 1910 // VS 2015's MSVC
12
+ # pragma warning(disable: 4702) // unreachable code in system header (xatomic.h(382))
13
+ #endif
14
+
15
+ #include "pybind11_tests.h"
16
+ #include "object.h"
17
+
18
+ namespace {
19
+
20
+ // This is just a wrapper around unique_ptr, but with extra fields to deliberately bloat up the
21
+ // holder size to trigger the non-simple-layout internal instance layout for single inheritance with
22
+ // large holder type:
23
+ template <typename T> class huge_unique_ptr {
24
+ std::unique_ptr<T> ptr;
25
+ uint64_t padding[10];
26
+ public:
27
+ explicit huge_unique_ptr(T *p) : ptr(p) {}
28
+ T *get() { return ptr.get(); }
29
+ };
30
+
31
+ // Simple custom holder that works like unique_ptr
32
+ template <typename T>
33
+ class custom_unique_ptr {
34
+ std::unique_ptr<T> impl;
35
+ public:
36
+ explicit custom_unique_ptr(T *p) : impl(p) {}
37
+ T* get() const { return impl.get(); }
38
+ T* release_ptr() { return impl.release(); }
39
+ };
40
+
41
+ // Simple custom holder that works like shared_ptr and has operator& overload
42
+ // To obtain address of an instance of this holder pybind should use std::addressof
43
+ // Attempt to get address via operator& may leads to segmentation fault
44
+ template <typename T>
45
+ class shared_ptr_with_addressof_operator {
46
+ std::shared_ptr<T> impl;
47
+ public:
48
+ shared_ptr_with_addressof_operator( ) = default;
49
+ explicit shared_ptr_with_addressof_operator(T *p) : impl(p) {}
50
+ T* get() const { return impl.get(); }
51
+ T** operator&() { throw std::logic_error("Call of overloaded operator& is not expected"); }
52
+ };
53
+
54
+ // Simple custom holder that works like unique_ptr and has operator& overload
55
+ // To obtain address of an instance of this holder pybind should use std::addressof
56
+ // Attempt to get address via operator& may leads to segmentation fault
57
+ template <typename T>
58
+ class unique_ptr_with_addressof_operator {
59
+ std::unique_ptr<T> impl;
60
+ public:
61
+ unique_ptr_with_addressof_operator() = default;
62
+ explicit unique_ptr_with_addressof_operator(T *p) : impl(p) {}
63
+ T* get() const { return impl.get(); }
64
+ T* release_ptr() { return impl.release(); }
65
+ T** operator&() { throw std::logic_error("Call of overloaded operator& is not expected"); }
66
+ };
67
+
68
+ // Custom object with builtin reference counting (see 'object.h' for the implementation)
69
+ class MyObject1 : public Object {
70
+ public:
71
+ explicit MyObject1(int value) : value(value) { print_created(this, toString()); }
72
+ std::string toString() const override { return "MyObject1[" + std::to_string(value) + "]"; }
73
+ protected:
74
+ ~MyObject1() override { print_destroyed(this); }
75
+ private:
76
+ int value;
77
+ };
78
+
79
+ // Object managed by a std::shared_ptr<>
80
+ class MyObject2 {
81
+ public:
82
+ MyObject2(const MyObject2 &) = default;
83
+ explicit MyObject2(int value) : value(value) { print_created(this, toString()); }
84
+ std::string toString() const { return "MyObject2[" + std::to_string(value) + "]"; }
85
+ virtual ~MyObject2() { print_destroyed(this); }
86
+ private:
87
+ int value;
88
+ };
89
+
90
+ // Object managed by a std::shared_ptr<>, additionally derives from std::enable_shared_from_this<>
91
+ class MyObject3 : public std::enable_shared_from_this<MyObject3> {
92
+ public:
93
+ MyObject3(const MyObject3 &) = default;
94
+ explicit MyObject3(int value) : value(value) { print_created(this, toString()); }
95
+ std::string toString() const { return "MyObject3[" + std::to_string(value) + "]"; }
96
+ virtual ~MyObject3() { print_destroyed(this); }
97
+ private:
98
+ int value;
99
+ };
100
+
101
+ // test_unique_nodelete
102
+ // Object with a private destructor
103
+ class MyObject4;
104
+ std::unordered_set<MyObject4 *> myobject4_instances;
105
+ class MyObject4 {
106
+ public:
107
+ explicit MyObject4(int value) : value{value} {
108
+ print_created(this);
109
+ myobject4_instances.insert(this);
110
+ }
111
+ int value;
112
+
113
+ static void cleanupAllInstances() {
114
+ auto tmp = std::move(myobject4_instances);
115
+ myobject4_instances.clear();
116
+ for (auto o : tmp)
117
+ delete o;
118
+ }
119
+ private:
120
+ ~MyObject4() {
121
+ myobject4_instances.erase(this);
122
+ print_destroyed(this);
123
+ }
124
+ };
125
+
126
+ // test_unique_deleter
127
+ // Object with std::unique_ptr<T, D> where D is not matching the base class
128
+ // Object with a protected destructor
129
+ class MyObject4a;
130
+ std::unordered_set<MyObject4a *> myobject4a_instances;
131
+ class MyObject4a {
132
+ public:
133
+ explicit MyObject4a(int i) {
134
+ value = i;
135
+ print_created(this);
136
+ myobject4a_instances.insert(this);
137
+ };
138
+ int value;
139
+
140
+ static void cleanupAllInstances() {
141
+ auto tmp = std::move(myobject4a_instances);
142
+ myobject4a_instances.clear();
143
+ for (auto o : tmp)
144
+ delete o;
145
+ }
146
+ protected:
147
+ virtual ~MyObject4a() {
148
+ myobject4a_instances.erase(this);
149
+ print_destroyed(this);
150
+ }
151
+ };
152
+
153
+ // Object derived but with public destructor and no Deleter in default holder
154
+ class MyObject4b : public MyObject4a {
155
+ public:
156
+ explicit MyObject4b(int i) : MyObject4a(i) { print_created(this); }
157
+ ~MyObject4b() override { print_destroyed(this); }
158
+ };
159
+
160
+ // test_large_holder
161
+ class MyObject5 { // managed by huge_unique_ptr
162
+ public:
163
+ explicit MyObject5(int value) : value{value} { print_created(this); }
164
+ ~MyObject5() { print_destroyed(this); }
165
+ int value;
166
+ };
167
+
168
+ // test_shared_ptr_and_references
169
+ struct SharedPtrRef {
170
+ struct A {
171
+ A() { print_created(this); }
172
+ A(const A &) { print_copy_created(this); }
173
+ A(A &&) noexcept { print_move_created(this); }
174
+ ~A() { print_destroyed(this); }
175
+ };
176
+
177
+ A value = {};
178
+ std::shared_ptr<A> shared = std::make_shared<A>();
179
+ };
180
+
181
+ // test_shared_ptr_from_this_and_references
182
+ struct SharedFromThisRef {
183
+ struct B : std::enable_shared_from_this<B> {
184
+ B() { print_created(this); }
185
+ // NOLINTNEXTLINE(bugprone-copy-constructor-init)
186
+ B(const B &) : std::enable_shared_from_this<B>() { print_copy_created(this); }
187
+ B(B &&) noexcept : std::enable_shared_from_this<B>() { print_move_created(this); }
188
+ ~B() { print_destroyed(this); }
189
+ };
190
+
191
+ B value = {};
192
+ std::shared_ptr<B> shared = std::make_shared<B>();
193
+ };
194
+
195
+ // Issue #865: shared_from_this doesn't work with virtual inheritance
196
+ struct SharedFromThisVBase : std::enable_shared_from_this<SharedFromThisVBase> {
197
+ SharedFromThisVBase() = default;
198
+ SharedFromThisVBase(const SharedFromThisVBase &) = default;
199
+ virtual ~SharedFromThisVBase() = default;
200
+ };
201
+ struct SharedFromThisVirt : virtual SharedFromThisVBase {};
202
+
203
+ // test_move_only_holder
204
+ struct C {
205
+ C() { print_created(this); }
206
+ ~C() { print_destroyed(this); }
207
+ };
208
+
209
+ // test_holder_with_addressof_operator
210
+ struct TypeForHolderWithAddressOf {
211
+ TypeForHolderWithAddressOf() { print_created(this); }
212
+ TypeForHolderWithAddressOf(const TypeForHolderWithAddressOf &) { print_copy_created(this); }
213
+ TypeForHolderWithAddressOf(TypeForHolderWithAddressOf &&) noexcept {
214
+ print_move_created(this);
215
+ }
216
+ ~TypeForHolderWithAddressOf() { print_destroyed(this); }
217
+ std::string toString() const {
218
+ return "TypeForHolderWithAddressOf[" + std::to_string(value) + "]";
219
+ }
220
+ int value = 42;
221
+ };
222
+
223
+ // test_move_only_holder_with_addressof_operator
224
+ struct TypeForMoveOnlyHolderWithAddressOf {
225
+ explicit TypeForMoveOnlyHolderWithAddressOf(int value) : value{value} { print_created(this); }
226
+ ~TypeForMoveOnlyHolderWithAddressOf() { print_destroyed(this); }
227
+ std::string toString() const {
228
+ return "MoveOnlyHolderWithAddressOf[" + std::to_string(value) + "]";
229
+ }
230
+ int value;
231
+ };
232
+
233
+ // test_smart_ptr_from_default
234
+ struct HeldByDefaultHolder { };
235
+
236
+ // test_shared_ptr_gc
237
+ // #187: issue involving std::shared_ptr<> return value policy & garbage collection
238
+ struct ElementBase {
239
+ virtual ~ElementBase() = default; /* Force creation of virtual table */
240
+ ElementBase() = default;
241
+ ElementBase(const ElementBase&) = delete;
242
+ };
243
+
244
+ struct ElementA : ElementBase {
245
+ explicit ElementA(int v) : v(v) {}
246
+ int value() const { return v; }
247
+ int v;
248
+ };
249
+
250
+ struct ElementList {
251
+ void add(const std::shared_ptr<ElementBase> &e) { l.push_back(e); }
252
+ std::vector<std::shared_ptr<ElementBase>> l;
253
+ };
254
+
255
+ } // namespace
256
+
257
+ // ref<T> is a wrapper for 'Object' which uses intrusive reference counting
258
+ // It is always possible to construct a ref<T> from an Object* pointer without
259
+ // possible inconsistencies, hence the 'true' argument at the end.
260
+ // Make pybind11 aware of the non-standard getter member function
261
+ namespace pybind11 { namespace detail {
262
+ template <typename T>
263
+ struct holder_helper<ref<T>> {
264
+ static const T *get(const ref<T> &p) { return p.get_ptr(); }
265
+ };
266
+ } // namespace detail
267
+ } // namespace pybind11
268
+
269
+ // Make pybind aware of the ref-counted wrapper type (s):
270
+ PYBIND11_DECLARE_HOLDER_TYPE(T, ref<T>, true);
271
+ // The following is not required anymore for std::shared_ptr, but it should compile without error:
272
+ PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);
273
+ PYBIND11_DECLARE_HOLDER_TYPE(T, huge_unique_ptr<T>);
274
+ PYBIND11_DECLARE_HOLDER_TYPE(T, custom_unique_ptr<T>);
275
+ PYBIND11_DECLARE_HOLDER_TYPE(T, shared_ptr_with_addressof_operator<T>);
276
+ PYBIND11_DECLARE_HOLDER_TYPE(T, unique_ptr_with_addressof_operator<T>);
277
+
278
+ TEST_SUBMODULE(smart_ptr, m) {
279
+ // Please do not interleave `struct` and `class` definitions with bindings code,
280
+ // but implement `struct`s and `class`es in the anonymous namespace above.
281
+ // This helps keeping the smart_holder branch in sync with master.
282
+
283
+ // test_smart_ptr
284
+
285
+ // Object implementation in `object.h`
286
+ py::class_<Object, ref<Object>> obj(m, "Object");
287
+ obj.def("getRefCount", &Object::getRefCount);
288
+
289
+ py::class_<MyObject1, ref<MyObject1>>(m, "MyObject1", obj)
290
+ .def(py::init<int>());
291
+ py::implicitly_convertible<py::int_, MyObject1>();
292
+
293
+ m.def("make_object_1", []() -> Object * { return new MyObject1(1); });
294
+ m.def("make_object_2", []() -> ref<Object> { return ref<Object>(new MyObject1(2)); });
295
+ m.def("make_myobject1_1", []() -> MyObject1 * { return new MyObject1(4); });
296
+ m.def("make_myobject1_2", []() -> ref<MyObject1> { return ref<MyObject1>(new MyObject1(5)); });
297
+ m.def("print_object_1", [](const Object *obj) { py::print(obj->toString()); });
298
+ m.def("print_object_2", [](ref<Object> obj) { py::print(obj->toString()); });
299
+ m.def("print_object_3", [](const ref<Object> &obj) { py::print(obj->toString()); });
300
+ m.def("print_object_4", [](const ref<Object> *obj) { py::print((*obj)->toString()); });
301
+ m.def("print_myobject1_1", [](const MyObject1 *obj) { py::print(obj->toString()); });
302
+ m.def("print_myobject1_2", [](ref<MyObject1> obj) { py::print(obj->toString()); });
303
+ m.def("print_myobject1_3", [](const ref<MyObject1> &obj) { py::print(obj->toString()); });
304
+ m.def("print_myobject1_4", [](const ref<MyObject1> *obj) { py::print((*obj)->toString()); });
305
+
306
+ // Expose constructor stats for the ref type
307
+ m.def("cstats_ref", &ConstructorStats::get<ref_tag>);
308
+
309
+ py::class_<MyObject2, std::shared_ptr<MyObject2>>(m, "MyObject2")
310
+ .def(py::init<int>());
311
+ m.def("make_myobject2_1", []() { return new MyObject2(6); });
312
+ m.def("make_myobject2_2", []() { return std::make_shared<MyObject2>(7); });
313
+ m.def("print_myobject2_1", [](const MyObject2 *obj) { py::print(obj->toString()); });
314
+ // NOLINTNEXTLINE(performance-unnecessary-value-param)
315
+ m.def("print_myobject2_2", [](std::shared_ptr<MyObject2> obj) { py::print(obj->toString()); });
316
+ m.def("print_myobject2_3", [](const std::shared_ptr<MyObject2> &obj) { py::print(obj->toString()); });
317
+ m.def("print_myobject2_4", [](const std::shared_ptr<MyObject2> *obj) { py::print((*obj)->toString()); });
318
+
319
+ py::class_<MyObject3, std::shared_ptr<MyObject3>>(m, "MyObject3")
320
+ .def(py::init<int>());
321
+ m.def("make_myobject3_1", []() { return new MyObject3(8); });
322
+ m.def("make_myobject3_2", []() { return std::make_shared<MyObject3>(9); });
323
+ m.def("print_myobject3_1", [](const MyObject3 *obj) { py::print(obj->toString()); });
324
+ // NOLINTNEXTLINE(performance-unnecessary-value-param)
325
+ m.def("print_myobject3_2", [](std::shared_ptr<MyObject3> obj) { py::print(obj->toString()); });
326
+ m.def("print_myobject3_3", [](const std::shared_ptr<MyObject3> &obj) { py::print(obj->toString()); });
327
+ m.def("print_myobject3_4", [](const std::shared_ptr<MyObject3> *obj) { py::print((*obj)->toString()); });
328
+
329
+ // test_smart_ptr_refcounting
330
+ m.def("test_object1_refcounting", []() {
331
+ auto o = ref<MyObject1>(new MyObject1(0));
332
+ bool good = o->getRefCount() == 1;
333
+ py::object o2 = py::cast(o, py::return_value_policy::reference);
334
+ // always request (partial) ownership for objects with intrusive
335
+ // reference counting even when using the 'reference' RVP
336
+ good &= o->getRefCount() == 2;
337
+ return good;
338
+ });
339
+
340
+ // test_unique_nodelete
341
+ py::class_<MyObject4, std::unique_ptr<MyObject4, py::nodelete>>(m, "MyObject4")
342
+ .def(py::init<int>())
343
+ .def_readwrite("value", &MyObject4::value)
344
+ .def_static("cleanup_all_instances", &MyObject4::cleanupAllInstances);
345
+
346
+ // test_unique_deleter
347
+ py::class_<MyObject4a, std::unique_ptr<MyObject4a, py::nodelete>>(m, "MyObject4a")
348
+ .def(py::init<int>())
349
+ .def_readwrite("value", &MyObject4a::value)
350
+ .def_static("cleanup_all_instances", &MyObject4a::cleanupAllInstances);
351
+
352
+ py::class_<MyObject4b, MyObject4a, std::unique_ptr<MyObject4b>>(m, "MyObject4b")
353
+ .def(py::init<int>());
354
+
355
+ // test_large_holder
356
+ py::class_<MyObject5, huge_unique_ptr<MyObject5>>(m, "MyObject5")
357
+ .def(py::init<int>())
358
+ .def_readwrite("value", &MyObject5::value);
359
+
360
+ // test_shared_ptr_and_references
361
+ using A = SharedPtrRef::A;
362
+ py::class_<A, std::shared_ptr<A>>(m, "A");
363
+ py::class_<SharedPtrRef, std::unique_ptr<SharedPtrRef>>(m, "SharedPtrRef")
364
+ .def(py::init<>())
365
+ .def_readonly("ref", &SharedPtrRef::value)
366
+ .def_property_readonly(
367
+ "copy", [](const SharedPtrRef &s) { return s.value; }, py::return_value_policy::copy)
368
+ .def_readonly("holder_ref", &SharedPtrRef::shared)
369
+ .def_property_readonly(
370
+ "holder_copy",
371
+ [](const SharedPtrRef &s) { return s.shared; },
372
+ py::return_value_policy::copy)
373
+ .def("set_ref", [](SharedPtrRef &, const A &) { return true; })
374
+ // NOLINTNEXTLINE(performance-unnecessary-value-param)
375
+ .def("set_holder", [](SharedPtrRef &, std::shared_ptr<A>) { return true; });
376
+
377
+ // test_shared_ptr_from_this_and_references
378
+ using B = SharedFromThisRef::B;
379
+ py::class_<B, std::shared_ptr<B>>(m, "B");
380
+ py::class_<SharedFromThisRef, std::unique_ptr<SharedFromThisRef>>(m, "SharedFromThisRef")
381
+ .def(py::init<>())
382
+ .def_readonly("bad_wp", &SharedFromThisRef::value)
383
+ .def_property_readonly("ref",
384
+ [](const SharedFromThisRef &s) -> const B & { return *s.shared; })
385
+ .def_property_readonly(
386
+ "copy",
387
+ [](const SharedFromThisRef &s) { return s.value; },
388
+ py::return_value_policy::copy)
389
+ .def_readonly("holder_ref", &SharedFromThisRef::shared)
390
+ .def_property_readonly(
391
+ "holder_copy",
392
+ [](const SharedFromThisRef &s) { return s.shared; },
393
+ py::return_value_policy::copy)
394
+ .def("set_ref", [](SharedFromThisRef &, const B &) { return true; })
395
+ // NOLINTNEXTLINE(performance-unnecessary-value-param)
396
+ .def("set_holder", [](SharedFromThisRef &, std::shared_ptr<B>) { return true; });
397
+
398
+ // Issue #865: shared_from_this doesn't work with virtual inheritance
399
+ static std::shared_ptr<SharedFromThisVirt> sft(new SharedFromThisVirt());
400
+ py::class_<SharedFromThisVirt, std::shared_ptr<SharedFromThisVirt>>(m, "SharedFromThisVirt")
401
+ .def_static("get", []() { return sft.get(); });
402
+
403
+ // test_move_only_holder
404
+ py::class_<C, custom_unique_ptr<C>>(m, "TypeWithMoveOnlyHolder")
405
+ .def_static("make", []() { return custom_unique_ptr<C>(new C); })
406
+ .def_static("make_as_object", []() { return py::cast(custom_unique_ptr<C>(new C)); });
407
+
408
+ // test_holder_with_addressof_operator
409
+ using HolderWithAddressOf = shared_ptr_with_addressof_operator<TypeForHolderWithAddressOf>;
410
+ py::class_<TypeForHolderWithAddressOf, HolderWithAddressOf>(m, "TypeForHolderWithAddressOf")
411
+ .def_static("make", []() { return HolderWithAddressOf(new TypeForHolderWithAddressOf); })
412
+ .def("get", [](const HolderWithAddressOf &self) { return self.get(); })
413
+ .def("print_object_1",
414
+ [](const TypeForHolderWithAddressOf *obj) { py::print(obj->toString()); })
415
+ // NOLINTNEXTLINE(performance-unnecessary-value-param)
416
+ .def("print_object_2", [](HolderWithAddressOf obj) { py::print(obj.get()->toString()); })
417
+ .def("print_object_3",
418
+ [](const HolderWithAddressOf &obj) { py::print(obj.get()->toString()); })
419
+ .def("print_object_4",
420
+ [](const HolderWithAddressOf *obj) { py::print((*obj).get()->toString()); });
421
+
422
+ // test_move_only_holder_with_addressof_operator
423
+ using MoveOnlyHolderWithAddressOf = unique_ptr_with_addressof_operator<TypeForMoveOnlyHolderWithAddressOf>;
424
+ py::class_<TypeForMoveOnlyHolderWithAddressOf, MoveOnlyHolderWithAddressOf>(m, "TypeForMoveOnlyHolderWithAddressOf")
425
+ .def_static("make", []() { return MoveOnlyHolderWithAddressOf(new TypeForMoveOnlyHolderWithAddressOf(0)); })
426
+ .def_readwrite("value", &TypeForMoveOnlyHolderWithAddressOf::value)
427
+ .def("print_object", [](const TypeForMoveOnlyHolderWithAddressOf *obj) { py::print(obj->toString()); });
428
+
429
+ // test_smart_ptr_from_default
430
+ py::class_<HeldByDefaultHolder, std::unique_ptr<HeldByDefaultHolder>>(m, "HeldByDefaultHolder")
431
+ .def(py::init<>())
432
+ // NOLINTNEXTLINE(performance-unnecessary-value-param)
433
+ .def_static("load_shared_ptr", [](std::shared_ptr<HeldByDefaultHolder>) {});
434
+
435
+ // test_shared_ptr_gc
436
+ // #187: issue involving std::shared_ptr<> return value policy & garbage collection
437
+ py::class_<ElementBase, std::shared_ptr<ElementBase>>(m, "ElementBase");
438
+
439
+ py::class_<ElementA, ElementBase, std::shared_ptr<ElementA>>(m, "ElementA")
440
+ .def(py::init<int>())
441
+ .def("value", &ElementA::value);
442
+
443
+ py::class_<ElementList, std::shared_ptr<ElementList>>(m, "ElementList")
444
+ .def(py::init<>())
445
+ .def("add", &ElementList::add)
446
+ .def("get", [](ElementList &el) {
447
+ py::list list;
448
+ for (auto &e : el.l)
449
+ list.append(py::cast(e));
450
+ return list;
451
+ });
452
+ }