amulet-core 2.0a8__cp312-cp312-win_amd64.whl → 2.0.1.0.1297307203.19.43.34808.0a0__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.

Potentially problematic release.


This version of amulet-core might be problematic. Click here for more details.

Files changed (271) hide show
  1. amulet/core/__init__.py +36 -0
  2. amulet/core/__pyinstaller/hook-amulet.core.py +4 -0
  3. amulet/core/_amulet_core.cp312-win_amd64.pyd +0 -0
  4. amulet/core/_amulet_core.pyi +7 -0
  5. amulet/{_version.py → core/_version.py} +3 -3
  6. amulet/core/amulet_core.dll +0 -0
  7. amulet/core/amulet_core.lib +0 -0
  8. amulet/core/amulet_coreConfig.cmake +18 -0
  9. amulet/{biome.pyi → core/biome/__init__.pyi} +3 -3
  10. amulet/core/biome/biome.hpp +53 -0
  11. amulet/{block.pyi → core/block/__init__.pyi} +25 -26
  12. amulet/core/block/block.hpp +156 -0
  13. amulet/{block_entity.pyi → core/block_entity/__init__.pyi} +7 -7
  14. amulet/core/block_entity/block_entity.hpp +84 -0
  15. amulet/{errors.py → core/chunk/__init__.pyi} +37 -33
  16. amulet/core/chunk/chunk.hpp +126 -0
  17. amulet/core/chunk/component/__init__.pyi +18 -0
  18. amulet/core/chunk/component/biome_3d_component.hpp +96 -0
  19. amulet/core/chunk/component/block_component.hpp +101 -0
  20. amulet/core/chunk/component/block_component.pyi +28 -0
  21. amulet/core/chunk/component/block_entity_component.hpp +119 -0
  22. amulet/core/chunk/component/section_array_map.hpp +129 -0
  23. amulet/{chunk_components.pyi → core/chunk/component/section_array_map.pyi} +4 -24
  24. amulet/core/dll.hpp +21 -0
  25. amulet/core/entity/__init__.pyi +105 -0
  26. amulet/core/entity/entity.hpp +100 -0
  27. amulet/{palette → core/palette}/__init__.pyi +2 -2
  28. amulet/core/palette/biome_palette.hpp +65 -0
  29. amulet/{palette → core/palette}/biome_palette.pyi +8 -8
  30. amulet/core/palette/block_palette.hpp +71 -0
  31. amulet/{palette → core/palette}/block_palette.pyi +12 -10
  32. amulet/core/selection/__init__.pyi +8 -0
  33. amulet/core/selection/box.hpp +86 -0
  34. amulet/core/selection/box.pyi +215 -0
  35. amulet/core/selection/group.hpp +80 -0
  36. amulet/core/selection/group.pyi +213 -0
  37. amulet/{version.pyi → core/version/__init__.pyi} +58 -10
  38. amulet/core/version/version.hpp +204 -0
  39. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1.0.1297307203.19.43.34808.0a0.dist-info}/METADATA +25 -20
  40. amulet_core-2.0.1.0.1297307203.19.43.34808.0a0.dist-info/RECORD +45 -0
  41. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1.0.1297307203.19.43.34808.0a0.dist-info}/WHEEL +1 -1
  42. amulet_core-2.0.1.0.1297307203.19.43.34808.0a0.dist-info/entry_points.txt +2 -0
  43. amulet/__init__.cp312-win_amd64.pyd +0 -0
  44. amulet/__init__.py.cpp +0 -45
  45. amulet/__init__.pyi +0 -30
  46. amulet/__pyinstaller/hook-amulet.py +0 -4
  47. amulet/_init.py +0 -26
  48. amulet/biome.cpp +0 -36
  49. amulet/biome.hpp +0 -43
  50. amulet/biome.py.cpp +0 -122
  51. amulet/block.cpp +0 -435
  52. amulet/block.hpp +0 -119
  53. amulet/block.py.cpp +0 -377
  54. amulet/block_entity.cpp +0 -12
  55. amulet/block_entity.hpp +0 -56
  56. amulet/block_entity.py.cpp +0 -115
  57. amulet/chunk.cpp +0 -16
  58. amulet/chunk.hpp +0 -100
  59. amulet/chunk.py.cpp +0 -80
  60. amulet/chunk.pyi +0 -28
  61. amulet/chunk_components/biome_3d_component.cpp +0 -5
  62. amulet/chunk_components/biome_3d_component.hpp +0 -79
  63. amulet/chunk_components/block_component.cpp +0 -41
  64. amulet/chunk_components/block_component.hpp +0 -88
  65. amulet/chunk_components/block_entity_component.cpp +0 -5
  66. amulet/chunk_components/block_entity_component.hpp +0 -147
  67. amulet/chunk_components/section_array_map.cpp +0 -129
  68. amulet/chunk_components/section_array_map.hpp +0 -147
  69. amulet/collections/eq.py.hpp +0 -37
  70. amulet/collections/hash.py.hpp +0 -27
  71. amulet/collections/holder.py.hpp +0 -37
  72. amulet/collections/iterator.py.hpp +0 -80
  73. amulet/collections/mapping.py.hpp +0 -199
  74. amulet/collections/mutable_mapping.py.hpp +0 -226
  75. amulet/collections/sequence.py.hpp +0 -163
  76. amulet/collections.pyi +0 -40
  77. amulet/data_types.py +0 -29
  78. amulet/entity.py +0 -182
  79. amulet/game/__init__.py +0 -7
  80. amulet/game/_game.py +0 -152
  81. amulet/game/_universal/__init__.py +0 -1
  82. amulet/game/_universal/_biome.py +0 -17
  83. amulet/game/_universal/_block.py +0 -47
  84. amulet/game/_universal/_version.py +0 -68
  85. amulet/game/abc/__init__.py +0 -22
  86. amulet/game/abc/_block_specification.py +0 -150
  87. amulet/game/abc/biome.py +0 -213
  88. amulet/game/abc/block.py +0 -331
  89. amulet/game/abc/game_version_container.py +0 -25
  90. amulet/game/abc/json_interface.py +0 -27
  91. amulet/game/abc/version.py +0 -44
  92. amulet/game/bedrock/__init__.py +0 -1
  93. amulet/game/bedrock/_biome.py +0 -35
  94. amulet/game/bedrock/_block.py +0 -42
  95. amulet/game/bedrock/_version.py +0 -165
  96. amulet/game/java/__init__.py +0 -2
  97. amulet/game/java/_biome.py +0 -35
  98. amulet/game/java/_block.py +0 -60
  99. amulet/game/java/_version.py +0 -176
  100. amulet/game/translate/__init__.py +0 -12
  101. amulet/game/translate/_functions/__init__.py +0 -15
  102. amulet/game/translate/_functions/_code_functions/__init__.py +0 -0
  103. amulet/game/translate/_functions/_code_functions/_text.py +0 -553
  104. amulet/game/translate/_functions/_code_functions/banner_pattern.py +0 -67
  105. amulet/game/translate/_functions/_code_functions/bedrock_chest_connection.py +0 -152
  106. amulet/game/translate/_functions/_code_functions/bedrock_moving_block_pos.py +0 -88
  107. amulet/game/translate/_functions/_code_functions/bedrock_sign.py +0 -152
  108. amulet/game/translate/_functions/_code_functions/bedrock_skull_rotation.py +0 -16
  109. amulet/game/translate/_functions/_code_functions/custom_name.py +0 -146
  110. amulet/game/translate/_functions/_frozen.py +0 -66
  111. amulet/game/translate/_functions/_state.py +0 -54
  112. amulet/game/translate/_functions/_typing.py +0 -98
  113. amulet/game/translate/_functions/abc.py +0 -123
  114. amulet/game/translate/_functions/carry_nbt.py +0 -160
  115. amulet/game/translate/_functions/carry_properties.py +0 -80
  116. amulet/game/translate/_functions/code.py +0 -143
  117. amulet/game/translate/_functions/map_block_name.py +0 -66
  118. amulet/game/translate/_functions/map_nbt.py +0 -111
  119. amulet/game/translate/_functions/map_properties.py +0 -93
  120. amulet/game/translate/_functions/multiblock.py +0 -112
  121. amulet/game/translate/_functions/new_block.py +0 -42
  122. amulet/game/translate/_functions/new_entity.py +0 -43
  123. amulet/game/translate/_functions/new_nbt.py +0 -206
  124. amulet/game/translate/_functions/new_properties.py +0 -64
  125. amulet/game/translate/_functions/sequence.py +0 -51
  126. amulet/game/translate/_functions/walk_input_nbt.py +0 -331
  127. amulet/game/translate/_translator.py +0 -433
  128. amulet/img/__init__.py +0 -10
  129. amulet/img/missing_no.png +0 -0
  130. amulet/img/missing_pack.png +0 -0
  131. amulet/img/missing_world.png +0 -0
  132. amulet/io/binary_reader.hpp +0 -45
  133. amulet/io/binary_writer.hpp +0 -30
  134. amulet/item.py +0 -75
  135. amulet/level/__init__.pyi +0 -23
  136. amulet/level/_load.py +0 -100
  137. amulet/level/abc/__init__.py +0 -12
  138. amulet/level/abc/_chunk_handle.py +0 -358
  139. amulet/level/abc/_dimension.py +0 -86
  140. amulet/level/abc/_history/__init__.py +0 -1
  141. amulet/level/abc/_history/_cache.py +0 -224
  142. amulet/level/abc/_history/_history_manager.py +0 -291
  143. amulet/level/abc/_level/__init__.py +0 -5
  144. amulet/level/abc/_level/_compactable_level.py +0 -10
  145. amulet/level/abc/_level/_creatable_level.py +0 -28
  146. amulet/level/abc/_level/_disk_level.py +0 -17
  147. amulet/level/abc/_level/_level.py +0 -449
  148. amulet/level/abc/_level/_loadable_level.py +0 -42
  149. amulet/level/abc/_player_storage.py +0 -7
  150. amulet/level/abc/_raw_level.py +0 -187
  151. amulet/level/abc/_registry.py +0 -40
  152. amulet/level/java/__init__.pyi +0 -16
  153. amulet/level/java/_chunk_handle.py +0 -17
  154. amulet/level/java/_dimension.py +0 -20
  155. amulet/level/java/_level.py +0 -184
  156. amulet/level/java/_raw/__init__.pyi +0 -15
  157. amulet/level/java/_raw/_chunk.pyi +0 -23
  158. amulet/level/java/_raw/_constant.py +0 -9
  159. amulet/level/java/_raw/_data_pack/__init__.py +0 -2
  160. amulet/level/java/_raw/_data_pack/data_pack.py +0 -241
  161. amulet/level/java/_raw/_data_pack/data_pack_manager.py +0 -77
  162. amulet/level/java/_raw/_dimension.py +0 -86
  163. amulet/level/java/_raw/_level.py +0 -507
  164. amulet/level/java/_raw/_typing.py +0 -3
  165. amulet/level/java/_raw/java_chunk_decode.cpp +0 -531
  166. amulet/level/java/_raw/java_chunk_decode.hpp +0 -23
  167. amulet/level/java/_raw/java_chunk_encode.cpp +0 -25
  168. amulet/level/java/_raw/java_chunk_encode.hpp +0 -23
  169. amulet/level/java/anvil/__init__.py +0 -2
  170. amulet/level/java/anvil/_dimension.py +0 -170
  171. amulet/level/java/anvil/_region.py +0 -421
  172. amulet/level/java/anvil/_sector_manager.py +0 -223
  173. amulet/level/java/chunk.pyi +0 -81
  174. amulet/level/java/chunk_/_chunk.py +0 -260
  175. amulet/level/java/chunk_/components/inhabited_time.py +0 -12
  176. amulet/level/java/chunk_/components/last_update.py +0 -12
  177. amulet/level/java/chunk_/components/legacy_version.py +0 -12
  178. amulet/level/java/chunk_/components/light_populated.py +0 -12
  179. amulet/level/java/chunk_/components/named_height_2d.py +0 -37
  180. amulet/level/java/chunk_/components/status.py +0 -11
  181. amulet/level/java/chunk_/components/terrain_populated.py +0 -12
  182. amulet/level/java/chunk_components/data_version_component.cpp +0 -32
  183. amulet/level/java/chunk_components/data_version_component.hpp +0 -31
  184. amulet/level/java/chunk_components/java_raw_chunk_component.cpp +0 -56
  185. amulet/level/java/chunk_components/java_raw_chunk_component.hpp +0 -45
  186. amulet/level/java/chunk_components.pyi +0 -22
  187. amulet/level/java/java_chunk.cpp +0 -170
  188. amulet/level/java/java_chunk.hpp +0 -141
  189. amulet/level/java/long_array.hpp +0 -175
  190. amulet/level/java/long_array.pyi +0 -39
  191. amulet/level/temporary_level/__init__.py +0 -1
  192. amulet/level/temporary_level/_level.py +0 -16
  193. amulet/mesh/__init__.py +0 -0
  194. amulet/mesh/block/__init__.pyi +0 -301
  195. amulet/mesh/block/_cube.py +0 -198
  196. amulet/mesh/block/_missing_block.py +0 -20
  197. amulet/mesh/block/block_mesh.cpp +0 -107
  198. amulet/mesh/block/block_mesh.hpp +0 -207
  199. amulet/mesh/util.py +0 -17
  200. amulet/palette/biome_palette.hpp +0 -85
  201. amulet/palette/block_palette.cpp +0 -32
  202. amulet/palette/block_palette.hpp +0 -93
  203. amulet/player.py +0 -62
  204. amulet/pybind11/collections.hpp +0 -118
  205. amulet/pybind11/numpy.hpp +0 -26
  206. amulet/pybind11/py_module.hpp +0 -34
  207. amulet/pybind11/type_hints.hpp +0 -51
  208. amulet/pybind11/types.hpp +0 -25
  209. amulet/pybind11/typing.hpp +0 -7
  210. amulet/resource_pack/__init__.py +0 -63
  211. amulet/resource_pack/abc/__init__.py +0 -2
  212. amulet/resource_pack/abc/resource_pack.py +0 -38
  213. amulet/resource_pack/abc/resource_pack_manager.py +0 -85
  214. amulet/resource_pack/java/__init__.py +0 -2
  215. amulet/resource_pack/java/download_resources.py +0 -212
  216. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_black.png +0 -0
  217. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_blue.png +0 -0
  218. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_brown.png +0 -0
  219. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_cyan.png +0 -0
  220. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_gray.png +0 -0
  221. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_green.png +0 -0
  222. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_blue.png +0 -0
  223. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_gray.png +0 -0
  224. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_lime.png +0 -0
  225. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_magenta.png +0 -0
  226. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_orange.png +0 -0
  227. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_pink.png +0 -0
  228. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_purple.png +0 -0
  229. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_red.png +0 -0
  230. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_white.png +0 -0
  231. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_yellow.png +0 -0
  232. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/barrier.png +0 -0
  233. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/end_portal.png +0 -0
  234. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/grass.png +0 -0
  235. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/lava.png +0 -0
  236. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/structure_void.png +0 -0
  237. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/water.png +0 -0
  238. amulet/resource_pack/java/java_vanilla_fix/pack.png +0 -0
  239. amulet/resource_pack/java/resource_pack.py +0 -44
  240. amulet/resource_pack/java/resource_pack_manager.py +0 -563
  241. amulet/resource_pack/unknown_resource_pack.py +0 -10
  242. amulet/selection/__init__.py +0 -2
  243. amulet/selection/abstract_selection.py +0 -342
  244. amulet/selection/box.py +0 -852
  245. amulet/selection/group.py +0 -481
  246. amulet/utils/__init__.pyi +0 -23
  247. amulet/utils/call_spec/__init__.py +0 -24
  248. amulet/utils/call_spec/_call_spec.py +0 -257
  249. amulet/utils/cast.py +0 -10
  250. amulet/utils/comment_json.py +0 -188
  251. amulet/utils/format_utils.py +0 -41
  252. amulet/utils/generator.py +0 -18
  253. amulet/utils/matrix.py +0 -243
  254. amulet/utils/numpy.hpp +0 -36
  255. amulet/utils/numpy.pyi +0 -11
  256. amulet/utils/numpy_helpers.py +0 -19
  257. amulet/utils/shareable_lock.py +0 -335
  258. amulet/utils/signal/__init__.py +0 -10
  259. amulet/utils/signal/_signal.py +0 -228
  260. amulet/utils/task_manager.py +0 -235
  261. amulet/utils/typed_property.py +0 -111
  262. amulet/utils/weakref.py +0 -70
  263. amulet/utils/world_utils.py +0 -102
  264. amulet/version.cpp +0 -136
  265. amulet/version.hpp +0 -142
  266. amulet/version.py.cpp +0 -281
  267. amulet_core-2.0a8.dist-info/RECORD +0 -241
  268. amulet_core-2.0a8.dist-info/entry_points.txt +0 -2
  269. /amulet/{__pyinstaller → core/__pyinstaller}/__init__.py +0 -0
  270. /amulet/{py.typed → core/py.typed} +0 -0
  271. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1.0.1297307203.19.43.34808.0a0.dist-info}/top_level.txt +0 -0
@@ -1,147 +0,0 @@
1
- #pragma once
2
-
3
- #include <tuple>
4
- #include <unordered_map>
5
- #include <variant>
6
- #include <cstdint>
7
- #include <vector>
8
- #include <span>
9
- #include <cstdlib>
10
- #include <type_traits>
11
- #include <memory>
12
- #include <stdexcept>
13
-
14
- #include <amulet/io/binary_writer.hpp>
15
- #include <amulet/io/binary_reader.hpp>
16
-
17
-
18
- namespace Amulet {
19
- namespace detail {
20
- template <typename T>
21
- inline std::unique_ptr<T*> new_buffer(size_t count) {
22
- T* buffer = (T*) std::malloc(sizeof(T) * count);
23
- if (buffer == nullptr) {
24
- throw std::runtime_error("Could not allocate buffer");
25
- }
26
- return std::make_unique<T*>(buffer);
27
- }
28
- }
29
-
30
- typedef std::tuple<std::uint16_t, std::uint16_t, std::uint16_t> SectionShape;
31
-
32
- class IndexArray3D {
33
- private:
34
- SectionShape _shape;
35
- size_t _size;
36
- std::unique_ptr<std::uint32_t*> _buffer;
37
- public:
38
- IndexArray3D(const SectionShape& shape) :
39
- _shape(shape),
40
- _size(std::get<0>(shape)* std::get<1>(shape)* std::get<2>(shape)),
41
- _buffer(detail::new_buffer<std::uint32_t>(_size))
42
- {}
43
- IndexArray3D(const SectionShape& shape, std::uint32_t value) :
44
- IndexArray3D(shape) {
45
- std::fill_n(*_buffer, _size, value);
46
- }
47
- IndexArray3D(const IndexArray3D& other):
48
- IndexArray3D(other.get_shape())
49
- {
50
- std::memcpy(*_buffer, *other._buffer, sizeof(std::uint32_t) * other.get_size());
51
- }
52
-
53
- void serialise(BinaryWriter&) const;
54
- static std::shared_ptr<IndexArray3D> deserialise(BinaryReader&);
55
-
56
- const SectionShape& get_shape() const {
57
- return _shape;
58
- }
59
- const size_t& get_size() const { return _size; }
60
- std::uint32_t* get_buffer() const { return *_buffer; }
61
- };
62
-
63
- namespace detail {
64
- inline void validate_array_shape(
65
- const std::shared_ptr<IndexArray3D>& default_array,
66
- const SectionShape& array_shape
67
- ) {
68
- if (default_array->get_shape() != array_shape) {
69
- throw std::invalid_argument("Array shape does not match required shape.");
70
- }
71
- }
72
-
73
- inline void validate_array_shape(
74
- const std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>>& default_array,
75
- const SectionShape& array_shape
76
- ) {
77
- if (std::holds_alternative<std::shared_ptr<IndexArray3D>>(default_array)) {
78
- validate_array_shape(std::get<std::shared_ptr<IndexArray3D>>(default_array), array_shape);
79
- }
80
- }
81
- }
82
-
83
- class SectionArrayMap {
84
- private:
85
- SectionShape _array_shape;
86
- std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> _default_array;
87
- std::unordered_map<std::int64_t, std::shared_ptr<IndexArray3D>> _arrays;
88
- public:
89
- SectionArrayMap(
90
- const SectionShape& array_shape,
91
- std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> default_array
92
- ) : _array_shape(array_shape), _default_array(default_array), _arrays() {
93
- detail::validate_array_shape(_default_array, _array_shape);
94
- }
95
-
96
- void serialise(BinaryWriter&) const;
97
- static std::shared_ptr<SectionArrayMap> deserialise(BinaryReader&);
98
-
99
- const SectionShape& get_array_shape() const { return _array_shape; }
100
-
101
- std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> get_default_array() const { return _default_array; }
102
-
103
- void set_default_array(std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> default_array) {
104
- detail::validate_array_shape(default_array, _array_shape);
105
- _default_array = default_array;
106
- }
107
-
108
- const std::unordered_map<std::int64_t, std::shared_ptr<IndexArray3D>>& get_arrays() const {
109
- return _arrays;
110
- }
111
-
112
- size_t get_size() const { return _arrays.size(); }
113
-
114
- bool contains_section(std::int64_t cy) const {
115
- return _arrays.contains(cy);
116
- }
117
-
118
- std::shared_ptr<IndexArray3D> get_section(std::int64_t cy) const {
119
- return _arrays.at(cy);
120
- }
121
-
122
- void set_section(std::int64_t cy, std::shared_ptr<IndexArray3D> section) {
123
- detail::validate_array_shape(section, _array_shape);
124
- _arrays[cy] = section;
125
- }
126
-
127
- void populate_section(std::int64_t cy) {
128
- if (_arrays.contains(cy)) {
129
- return;
130
- }
131
- std::visit([this, &cy](auto&& arg) {
132
- using T = std::decay_t<decltype(arg)>;
133
- if constexpr (std::is_same_v<T, std::uint32_t>) {
134
- _arrays[cy] = std::make_shared<IndexArray3D>(_array_shape, arg);
135
- }
136
- else {
137
- _arrays[cy] = std::make_shared<IndexArray3D>(*arg);
138
- }
139
- }, _default_array);
140
- }
141
-
142
- void del_section(std::int64_t cy) {
143
- _arrays.erase(cy);
144
- }
145
- };
146
-
147
- }
@@ -1,37 +0,0 @@
1
- #pragma once
2
- // Better type hinting for equality methods that pybind11 has natively
3
-
4
- #include <variant>
5
- #include <amulet/pybind11/types.hpp>
6
-
7
- #include <pybind11/pybind11.h>
8
-
9
- namespace py = pybind11;
10
-
11
- template <typename R, typename clsT>
12
- void Eq(clsT cls) {
13
- cls.def(
14
- "__eq__",
15
- [](const typename clsT::type& self, R other) {
16
- return self == other;
17
- }
18
- );
19
- }
20
-
21
-
22
- template <typename clsT>
23
- void Eq(clsT cls) {
24
- Eq<const typename clsT::type&>(cls);
25
- }
26
-
27
-
28
- template <typename clsT>
29
- void Eq_default(clsT cls) {
30
- py::object NotImplemented = py::module::import("builtins").attr("NotImplemented");
31
- cls.def(
32
- "__eq__",
33
- [NotImplemented](const typename clsT::type& self, py::object other) -> std::variant<bool, Amulet::pybind11::types::NotImplementedType> {
34
- return NotImplemented;
35
- }
36
- );
37
- }
@@ -1,27 +0,0 @@
1
- #pragma once
2
-
3
- #include <pybind11/pybind11.h>
4
-
5
- namespace py = pybind11;
6
-
7
-
8
- template <typename clsT>
9
- void hash_default(clsT cls) {
10
- cls.def(
11
- "__hash__",
12
- [](py::object self) -> py::int_ {
13
- return py::module::import("builtins").attr("id")(self);
14
- }
15
- );
16
- }
17
-
18
-
19
- template <typename clsT>
20
- void hash_disable(clsT cls) {
21
- cls.def(
22
- "__hash__",
23
- [](py::object self) -> size_t {
24
- throw py::type_error("This class is not hashable.");
25
- }
26
- );
27
- }
@@ -1,37 +0,0 @@
1
- #pragma once
2
-
3
- #include <memory>
4
- #include <pybind11/pybind11.h>
5
-
6
- namespace py = pybind11;
7
-
8
- namespace Amulet {
9
- namespace collections {
10
-
11
- // A class to allow python to hold a reference to a smart pointer
12
- class Holder {
13
- public:
14
- virtual ~Holder() {}
15
- };
16
-
17
- template <typename T>
18
- class HolderTemplate: public Holder {
19
- private:
20
- T value;
21
- public:
22
- HolderTemplate(T&& value): value(std::move(value)){}
23
- };
24
-
25
- template <typename T>
26
- static py::object make_holder(T&& value) {
27
- return py::cast(
28
- static_cast<std::unique_ptr<Holder>>(
29
- std::make_unique<HolderTemplate<T>>(
30
- std::move(value)
31
- )
32
- )
33
- );
34
- }
35
-
36
- }
37
- }
@@ -1,80 +0,0 @@
1
- #pragma once
2
- #include <stdexcept>
3
-
4
- #include <pybind11/pybind11.h>
5
-
6
- namespace py = pybind11;
7
-
8
- namespace Amulet {
9
- namespace collections {
10
- class Iterator {
11
- public:
12
- virtual ~Iterator() {};
13
- virtual bool has_next() = 0;
14
- virtual py::object next() = 0;
15
- };
16
-
17
- // An iterator for the collections.abc.Sequence protocol.
18
- class PySequenceIterator: public Iterator {
19
- private:
20
- py::object obj;
21
- size_t index;
22
- std::ptrdiff_t step;
23
- public:
24
- PySequenceIterator(
25
- py::object obj,
26
- size_t start,
27
- std::ptrdiff_t step
28
- ) : obj(obj), index(start), step(step) {};
29
- bool has_next() override{
30
- return 0 <= index && index < py::len(obj);
31
- };
32
- py::object next() override {
33
- py::object item = obj.attr("__getitem__")(index);
34
- index += step;
35
- return item;
36
- };
37
- };
38
-
39
- // An iterator for a C++ map-like object.
40
- template <typename mapT>
41
- class MapIterator: public Iterator {
42
- private:
43
- py::object owner;
44
- const mapT& map;
45
- typename mapT::const_iterator begin;
46
- typename mapT::const_iterator end;
47
- typename mapT::const_iterator pos;
48
- size_t size;
49
-
50
- public:
51
- MapIterator(const mapT& map, py::object owner = py::none()) :
52
- owner(owner),
53
- map(map),
54
- begin(map.begin()),
55
- end(map.end()),
56
- pos(map.begin()),
57
- size(map.size())
58
- {}
59
-
60
- bool has_next() override {
61
- return pos != end;
62
- }
63
-
64
- bool is_valid() {
65
- // This is not fool proof.
66
- // There are cases where this is true but the iterator is invalid.
67
- // The programmer should write good code and this will catch some of the bad cases.
68
- return size == map.size() && begin == map.begin() && end == map.end();
69
- }
70
-
71
- py::object next() override {
72
- if (!is_valid()) {
73
- throw std::runtime_error("map changed size during iteration.");
74
- }
75
- return py::cast((pos++)->first);
76
- }
77
- };
78
-
79
- }
80
- }
@@ -1,199 +0,0 @@
1
- #pragma once
2
-
3
- #include <memory>
4
-
5
- #include <pybind11/pybind11.h>
6
- #include <pybind11/typing.h>
7
-
8
- #include <amulet/pybind11/types.hpp>
9
- #include <amulet/pybind11/type_hints.hpp>
10
- #include <amulet/pybind11/collections.hpp>
11
- #include "iterator.py.hpp"
12
-
13
- namespace py = pybind11;
14
-
15
- namespace Amulet {
16
- namespace collections {
17
- template <typename clsT>
18
- void PyMapping_repr(clsT cls) {
19
- cls.def(
20
- "__repr__",
21
- [](py::object self) {
22
- std::string repr = "{";
23
- bool is_first = true;
24
- for (auto it = self.begin(); it != self.end(); it++) {
25
- if (is_first) {
26
- is_first = false;
27
- }
28
- else {
29
- repr += ", ";
30
- }
31
- repr += py::repr(*it);
32
- repr += ": ";
33
- repr += py::repr(self.attr("__getitem__")(*it));
34
- }
35
- repr += "}";
36
- return repr;
37
- }
38
- );
39
- }
40
-
41
- template <typename KT = py::object, typename clsT>
42
- void PyMapping_contains(clsT cls) {
43
- cls.def(
44
- "__contains__",
45
- [](py::object self, Amulet::pybind11::type_hints::PyObjectCpp<KT> key) {
46
- try {
47
- self.attr("__getitem__")(key);
48
- return true;
49
- }
50
- catch (const py::error_already_set& e) {
51
- if (e.matches(PyExc_KeyError)) {
52
- return false;
53
- }
54
- else {
55
- throw;
56
- }
57
- }
58
- }
59
- );
60
- }
61
-
62
- template <typename KT = py::object, typename clsT>
63
- void PyMapping_keys(clsT cls) {
64
- py::object KeysView = py::module::import("collections.abc").attr("KeysView");
65
- cls.def(
66
- "keys",
67
- [KeysView](py::object self) -> Amulet::pybind11::collections::KeysView<KT> { return KeysView(self); }
68
- );
69
- }
70
-
71
- template <typename VT = py::object, typename clsT>
72
- void PyMapping_values(clsT cls) {
73
- py::object ValuesView = py::module::import("collections.abc").attr("ValuesView");
74
- cls.def(
75
- "values",
76
- [ValuesView](py::object self) -> Amulet::pybind11::collections::ValuesView<VT> { return ValuesView(self); }
77
- );
78
- }
79
-
80
- template <typename KT = py::object, typename VT = py::object, typename clsT>
81
- void PyMapping_items(clsT cls) {
82
- py::object ItemsView = py::module::import("collections.abc").attr("ItemsView");
83
- cls.def(
84
- "items",
85
- [ItemsView](py::object self) -> Amulet::pybind11::collections::ItemsView<KT, VT> { return ItemsView(self); }
86
- );
87
- }
88
-
89
- template <typename KT = py::object, typename VT = py::object, typename clsT>
90
- void PyMapping_get(clsT cls) {
91
- cls.def(
92
- "get",
93
- [](
94
- py::object self,
95
- Amulet::pybind11::type_hints::PyObjectCpp<KT> key,
96
- py::typing::Optional<VT> default_ = py::none()
97
- ) -> py::typing::Optional<VT> {
98
- try {
99
- return self.attr("__getitem__")(key);
100
- }
101
- catch (const py::error_already_set& e) {
102
- if (e.matches(PyExc_KeyError)) {
103
- return default_;
104
- }
105
- else {
106
- throw;
107
- }
108
- }
109
- }
110
- );
111
- }
112
-
113
- template <typename clsT>
114
- void PyMapping_eq(clsT cls) {
115
- py::object dict = py::module::import("builtins").attr("dict");
116
- py::object isinstance = py::module::import("builtins").attr("isinstance");
117
- py::object NotImplemented = py::module::import("builtins").attr("NotImplemented");
118
- py::object PyMapping = py::module::import("collections.abc").attr("Mapping");
119
- cls.def(
120
- "__eq__",
121
- [
122
- dict,
123
- isinstance,
124
- NotImplemented,
125
- PyMapping
126
- ](
127
- py::object self,
128
- py::object other
129
- ) -> std::variant<bool, Amulet::pybind11::types::NotImplementedType> {
130
- if (!isinstance(other, PyMapping)) {
131
- return NotImplemented;
132
- }
133
- return dict(self.attr("items")()).equal(dict(other.attr("items")()).cast<py::dict>());
134
- }
135
- );
136
- }
137
-
138
- template <typename clsT>
139
- void PyMapping_hash(clsT cls) {
140
- cls.def(
141
- "__hash__",
142
- [](
143
- py::object self
144
- ) -> size_t {
145
- throw py::type_error("Mapping is not hashable");
146
- }
147
- );
148
- }
149
-
150
- template <typename clsT>
151
- void PyMapping_register(clsT cls) {
152
- py::module::import("collections.abc").attr("Mapping").attr("register")(cls);
153
- }
154
-
155
- class Mapping {
156
- public:
157
- virtual ~Mapping() {};
158
- virtual py::object getitem(py::object py_key) const = 0;
159
- virtual std::shared_ptr<Iterator> iter() const = 0;
160
- virtual size_t size() const = 0;
161
- virtual bool contains(py::object py_key) const = 0;
162
- };
163
-
164
- template <typename mapT>
165
- class ConstMap : public Mapping {
166
- private:
167
- py::object _owner;
168
- const mapT& _map;
169
- public:
170
- ConstMap(
171
- const mapT& map,
172
- py::object owner = py::none()
173
- ) : _owner(owner), _map(map) {}
174
-
175
- py::object getitem(py::object py_key) const override {
176
- return py::cast(_map.at(py_key.cast<typename mapT::key_type>()));
177
- }
178
- std::shared_ptr<Iterator> iter() const override {
179
- return std::make_shared<MapIterator<mapT>>(_map, _owner);
180
- }
181
- size_t size() const override {
182
- return _map.size();
183
- }
184
- bool contains(py::object py_key) const override {
185
- return _map.contains(py_key.cast<typename mapT::key_type>());
186
- }
187
- };
188
-
189
- template <typename mapT>
190
- static py::object make_const_map(const mapT& value, py::object owner = py::none()) {
191
- return py::cast(
192
- static_cast<std::shared_ptr<Mapping>>(
193
- std::make_shared<ConstMap<mapT>>(value, owner)
194
- )
195
- );
196
- }
197
-
198
- }
199
- }