inkcpp_rb 0.1.0

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 (273) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +1 -0
  4. data/Gemfile +10 -0
  5. data/Gemfile.lock +84 -0
  6. data/LICENSE +7 -0
  7. data/README.md +3 -0
  8. data/Rakefile +16 -0
  9. data/bin/console +15 -0
  10. data/bin/setup +10 -0
  11. data/bin/tapioca +29 -0
  12. data/ext/inkcpp_rb/extconf.rb +19 -0
  13. data/ext/inkcpp_rb/inkcpp/.clang-format +99 -0
  14. data/ext/inkcpp_rb/inkcpp/.github/FUNDING.yml +1 -0
  15. data/ext/inkcpp_rb/inkcpp/.github/workflows/build.yml +344 -0
  16. data/ext/inkcpp_rb/inkcpp/.github/workflows/release.yml +49 -0
  17. data/ext/inkcpp_rb/inkcpp/.gitignore +25 -0
  18. data/ext/inkcpp_rb/inkcpp/.gitmodules +9 -0
  19. data/ext/inkcpp_rb/inkcpp/CMakeLists.txt +170 -0
  20. data/ext/inkcpp_rb/inkcpp/CODE_OF_CONDUCT.md +76 -0
  21. data/ext/inkcpp_rb/inkcpp/CONTRIBUTING.md +55 -0
  22. data/ext/inkcpp_rb/inkcpp/Config.cmake.in +2 -0
  23. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/CMakeLists.txt +13 -0
  24. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/main.c +38 -0
  25. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/main.cpp +40 -0
  26. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/test.ink +8 -0
  27. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example/test.ink.json +1 -0
  28. data/ext/inkcpp_rb/inkcpp/Documentation/cmake_example.zip +0 -0
  29. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/InkCPP_DEMO.zip +0 -0
  30. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/CreateThread.png +0 -0
  31. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/HandleChoice.png +0 -0
  32. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/ListElementOf.png +0 -0
  33. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/MinimalRuntime.png +0 -0
  34. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/MinimalThread.png +0 -0
  35. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/ObseverChange.png +0 -0
  36. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/TagListGetValue.png +0 -0
  37. data/ext/inkcpp_rb/inkcpp/Documentation/unreal/imgs/YieldResume.png +0 -0
  38. data/ext/inkcpp_rb/inkcpp/Doxyfile +2825 -0
  39. data/ext/inkcpp_rb/inkcpp/LICENSE.txt +22 -0
  40. data/ext/inkcpp_rb/inkcpp/Minimal.runsettings +8 -0
  41. data/ext/inkcpp_rb/inkcpp/README.md +192 -0
  42. data/ext/inkcpp_rb/inkcpp/inkcpp/CMakeLists.txt +67 -0
  43. data/ext/inkcpp_rb/inkcpp/inkcpp/array.h +481 -0
  44. data/ext/inkcpp_rb/inkcpp/inkcpp/avl_array.h +833 -0
  45. data/ext/inkcpp_rb/inkcpp/inkcpp/casting.h +93 -0
  46. data/ext/inkcpp_rb/inkcpp/inkcpp/choice.cpp +54 -0
  47. data/ext/inkcpp_rb/inkcpp/inkcpp/collections/restorable.cpp +124 -0
  48. data/ext/inkcpp_rb/inkcpp/inkcpp/collections/restorable.h +406 -0
  49. data/ext/inkcpp_rb/inkcpp/inkcpp/container_operations.cpp +52 -0
  50. data/ext/inkcpp_rb/inkcpp/inkcpp/container_operations.h +34 -0
  51. data/ext/inkcpp_rb/inkcpp/inkcpp/executioner.h +179 -0
  52. data/ext/inkcpp_rb/inkcpp/inkcpp/functional.cpp +86 -0
  53. data/ext/inkcpp_rb/inkcpp/inkcpp/functions.cpp +54 -0
  54. data/ext/inkcpp_rb/inkcpp/inkcpp/functions.h +40 -0
  55. data/ext/inkcpp_rb/inkcpp/inkcpp/globals_impl.cpp +289 -0
  56. data/ext/inkcpp_rb/inkcpp/inkcpp/globals_impl.h +149 -0
  57. data/ext/inkcpp_rb/inkcpp/inkcpp/header.cpp +44 -0
  58. data/ext/inkcpp_rb/inkcpp/inkcpp/include/choice.h +106 -0
  59. data/ext/inkcpp_rb/inkcpp/inkcpp/include/functional.h +327 -0
  60. data/ext/inkcpp_rb/inkcpp/inkcpp/include/globals.h +196 -0
  61. data/ext/inkcpp_rb/inkcpp/inkcpp/include/list.h +187 -0
  62. data/ext/inkcpp_rb/inkcpp/inkcpp/include/runner.h +291 -0
  63. data/ext/inkcpp_rb/inkcpp/inkcpp/include/snapshot.h +61 -0
  64. data/ext/inkcpp_rb/inkcpp/inkcpp/include/story.h +219 -0
  65. data/ext/inkcpp_rb/inkcpp/inkcpp/include/story_ptr.h +233 -0
  66. data/ext/inkcpp_rb/inkcpp/inkcpp/include/traits.h +270 -0
  67. data/ext/inkcpp_rb/inkcpp/inkcpp/include/types.h +169 -0
  68. data/ext/inkcpp_rb/inkcpp/inkcpp/list_impl.cpp +79 -0
  69. data/ext/inkcpp_rb/inkcpp/inkcpp/list_impl.h +39 -0
  70. data/ext/inkcpp_rb/inkcpp/inkcpp/list_operations.cpp +276 -0
  71. data/ext/inkcpp_rb/inkcpp/inkcpp/list_operations.h +356 -0
  72. data/ext/inkcpp_rb/inkcpp/inkcpp/list_table.cpp +841 -0
  73. data/ext/inkcpp_rb/inkcpp/inkcpp/list_table.h +450 -0
  74. data/ext/inkcpp_rb/inkcpp/inkcpp/numeric_operations.cpp +40 -0
  75. data/ext/inkcpp_rb/inkcpp/inkcpp/numeric_operations.h +529 -0
  76. data/ext/inkcpp_rb/inkcpp/inkcpp/operation_bases.h +164 -0
  77. data/ext/inkcpp_rb/inkcpp/inkcpp/operations.h +100 -0
  78. data/ext/inkcpp_rb/inkcpp/inkcpp/output.cpp +528 -0
  79. data/ext/inkcpp_rb/inkcpp/inkcpp/output.h +153 -0
  80. data/ext/inkcpp_rb/inkcpp/inkcpp/platform.h +22 -0
  81. data/ext/inkcpp_rb/inkcpp/inkcpp/random.h +38 -0
  82. data/ext/inkcpp_rb/inkcpp/inkcpp/runner_impl.cpp +1396 -0
  83. data/ext/inkcpp_rb/inkcpp/inkcpp/runner_impl.h +336 -0
  84. data/ext/inkcpp_rb/inkcpp/inkcpp/simple_restorable_stack.h +335 -0
  85. data/ext/inkcpp_rb/inkcpp/inkcpp/snapshot_impl.cpp +182 -0
  86. data/ext/inkcpp_rb/inkcpp/inkcpp/snapshot_impl.h +91 -0
  87. data/ext/inkcpp_rb/inkcpp/inkcpp/snapshot_interface.h +57 -0
  88. data/ext/inkcpp_rb/inkcpp/inkcpp/stack.cpp +618 -0
  89. data/ext/inkcpp_rb/inkcpp/inkcpp/stack.h +243 -0
  90. data/ext/inkcpp_rb/inkcpp/inkcpp/story_impl.cpp +361 -0
  91. data/ext/inkcpp_rb/inkcpp/inkcpp/story_impl.h +92 -0
  92. data/ext/inkcpp_rb/inkcpp/inkcpp/story_ptr.cpp +75 -0
  93. data/ext/inkcpp_rb/inkcpp/inkcpp/string_operations.cpp +125 -0
  94. data/ext/inkcpp_rb/inkcpp/inkcpp/string_operations.h +67 -0
  95. data/ext/inkcpp_rb/inkcpp/inkcpp/string_table.cpp +149 -0
  96. data/ext/inkcpp_rb/inkcpp/inkcpp/string_table.h +47 -0
  97. data/ext/inkcpp_rb/inkcpp/inkcpp/string_utils.h +207 -0
  98. data/ext/inkcpp_rb/inkcpp/inkcpp/system.cpp +39 -0
  99. data/ext/inkcpp_rb/inkcpp/inkcpp/tuple.hpp +151 -0
  100. data/ext/inkcpp_rb/inkcpp/inkcpp/value.cpp +279 -0
  101. data/ext/inkcpp_rb/inkcpp/inkcpp/value.h +666 -0
  102. data/ext/inkcpp_rb/inkcpp/inkcpp_c/CMakeLists.txt +62 -0
  103. data/ext/inkcpp_rb/inkcpp/inkcpp_c/include/inkcpp.h +393 -0
  104. data/ext/inkcpp_rb/inkcpp/inkcpp_c/inkcpp.cpp +344 -0
  105. data/ext/inkcpp_rb/inkcpp/inkcpp_c/inkcpp_c.pc.in +10 -0
  106. data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/ExternalFunction.c +56 -0
  107. data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Globals.c +98 -0
  108. data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Lists.c +73 -0
  109. data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Observer.c +36 -0
  110. data/ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Snapshot.c +65 -0
  111. data/ext/inkcpp_rb/inkcpp/inkcpp_cl/CMakeLists.txt +49 -0
  112. data/ext/inkcpp_rb/inkcpp/inkcpp_cl/inkcpp_cl.cpp +215 -0
  113. data/ext/inkcpp_rb/inkcpp/inkcpp_cl/test.cpp +209 -0
  114. data/ext/inkcpp_rb/inkcpp/inkcpp_cl/test.h +8 -0
  115. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/CMakeLists.txt +37 -0
  116. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_emitter.cpp +446 -0
  117. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_emitter.h +70 -0
  118. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_stream.cpp +166 -0
  119. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/binary_stream.h +79 -0
  120. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/command.cpp +107 -0
  121. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/compiler.cpp +96 -0
  122. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/emitter.cpp +62 -0
  123. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/emitter.h +104 -0
  124. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/include/compilation_results.h +22 -0
  125. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/include/compiler.h +44 -0
  126. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/json.hpp +24596 -0
  127. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/json_compiler.cpp +411 -0
  128. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/json_compiler.h +62 -0
  129. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/list_data.cpp +47 -0
  130. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/list_data.h +70 -0
  131. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/reporter.cpp +107 -0
  132. data/ext/inkcpp_rb/inkcpp/inkcpp_compiler/reporter.h +55 -0
  133. data/ext/inkcpp_rb/inkcpp/inkcpp_py/CMakeLists.txt +19 -0
  134. data/ext/inkcpp_rb/inkcpp/inkcpp_py/example.py +78 -0
  135. data/ext/inkcpp_rb/inkcpp/inkcpp_py/src/module.cpp +317 -0
  136. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/conftest.py +53 -0
  137. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_ExternalFunctions.py +35 -0
  138. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Globals.py +40 -0
  139. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Lists.py +43 -0
  140. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Observer.py +27 -0
  141. data/ext/inkcpp_rb/inkcpp/inkcpp_py/tests/test_Snapshot.py +57 -0
  142. data/ext/inkcpp_rb/inkcpp/inkcpp_py/unreal_example.ink +71 -0
  143. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Array.cpp +115 -0
  144. data/ext/inkcpp_rb/inkcpp/inkcpp_test/CMakeLists.txt +117 -0
  145. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Callstack.cpp +392 -0
  146. data/ext/inkcpp_rb/inkcpp/inkcpp_test/EmptyStringForDivert.cpp +36 -0
  147. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ExternalFunctionsExecuteProperly.cpp +34 -0
  148. data/ext/inkcpp_rb/inkcpp/inkcpp_test/FallbackFunction.cpp +77 -0
  149. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Globals.cpp +73 -0
  150. data/ext/inkcpp_rb/inkcpp/inkcpp_test/InkyJson.cpp +34 -0
  151. data/ext/inkcpp_rb/inkcpp/inkcpp_test/LabelCondition.cpp +60 -0
  152. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Lists.cpp +144 -0
  153. data/ext/inkcpp_rb/inkcpp/inkcpp_test/LookaheadSafe.cpp +46 -0
  154. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Main.cpp +7 -0
  155. data/ext/inkcpp_rb/inkcpp/inkcpp_test/MoveTo.cpp +95 -0
  156. data/ext/inkcpp_rb/inkcpp/inkcpp_test/NewLines.cpp +76 -0
  157. data/ext/inkcpp_rb/inkcpp/inkcpp_test/NoEarlyTags.cpp +33 -0
  158. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Observer.cpp +245 -0
  159. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Pointer.cpp +191 -0
  160. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Restorable.cpp +294 -0
  161. data/ext/inkcpp_rb/inkcpp/inkcpp_test/SpaceAfterBracketChoice.cpp +45 -0
  162. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Stack.cpp +224 -0
  163. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Tags.cpp +131 -0
  164. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ThirdTierChoiceAfterBrackets.cpp +38 -0
  165. data/ext/inkcpp_rb/inkcpp/inkcpp_test/UTF8.cpp +56 -0
  166. data/ext/inkcpp_rb/inkcpp/inkcpp_test/Value.cpp +210 -0
  167. data/ext/inkcpp_rb/inkcpp/inkcpp_test/catch.hpp +17970 -0
  168. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/AHF.ink +7 -0
  169. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ChoiceBracketStory.ink +7 -0
  170. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/EmptyStringForDivert.ink +13 -0
  171. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ExternalFunctionsExecuteProperly.ink +11 -0
  172. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/FallBack.ink +15 -0
  173. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/GlobalStory.ink +9 -0
  174. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/LabelConditionStory.ink +5 -0
  175. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/LinesStory.ink +42 -0
  176. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ListLogicStory.ink +40 -0
  177. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ListStory.ink +8 -0
  178. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/LookaheadSafe.ink +14 -0
  179. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/MoveTo.ink +36 -0
  180. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/NoEarlyTags.ink +19 -0
  181. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ObserverStory.ink +8 -0
  182. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/SimpleStoryFlow.ink +65 -0
  183. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/TagsStory.ink +22 -0
  184. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/TheIntercept.ink +1686 -0
  185. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/ThirdTierChoiceAfterBracketsStory.ink +13 -0
  186. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/UTF-8-demo.txt +212 -0
  187. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/UTF8Story.ink +218 -0
  188. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/simple-1.1.1-inklecate.json +154 -0
  189. data/ext/inkcpp_rb/inkcpp/inkcpp_test/ink/simple-1.1.1-inky.json +160 -0
  190. data/ext/inkcpp_rb/inkcpp/notes/ArchitectureNotes.md +54 -0
  191. data/ext/inkcpp_rb/inkcpp/notes/ListNotes.md +69 -0
  192. data/ext/inkcpp_rb/inkcpp/notes/OperationNotes.md +35 -0
  193. data/ext/inkcpp_rb/inkcpp/notes/TagsNotes.md +24 -0
  194. data/ext/inkcpp_rb/inkcpp/notes/WhitespaceNotes.md +28 -0
  195. data/ext/inkcpp_rb/inkcpp/proofing/README.md +3 -0
  196. data/ext/inkcpp_rb/inkcpp/proofing/inkcpp_runtime_driver +12 -0
  197. data/ext/inkcpp_rb/inkcpp/pyproject.toml +63 -0
  198. data/ext/inkcpp_rb/inkcpp/setup.py +166 -0
  199. data/ext/inkcpp_rb/inkcpp/shared/CMakeLists.txt +14 -0
  200. data/ext/inkcpp_rb/inkcpp/shared/private/command.h +172 -0
  201. data/ext/inkcpp_rb/inkcpp/shared/private/header.h +46 -0
  202. data/ext/inkcpp_rb/inkcpp/shared/public/config.h +53 -0
  203. data/ext/inkcpp_rb/inkcpp/shared/public/system.h +307 -0
  204. data/ext/inkcpp_rb/inkcpp/shared/public/version.h +14 -0
  205. data/ext/inkcpp_rb/inkcpp/tests/TestAllSequenceTypes.ink +59 -0
  206. data/ext/inkcpp_rb/inkcpp/tests/TestArithmetic.ink +17 -0
  207. data/ext/inkcpp_rb/inkcpp/tests/TestBasicStringLiterals.ink +8 -0
  208. data/ext/inkcpp_rb/inkcpp/tests/TestBasicTunnel.ink +10 -0
  209. data/ext/inkcpp_rb/inkcpp/tests/TestBlanksInInlineSequences.ink +51 -0
  210. data/ext/inkcpp_rb/inkcpp/tests/TestCallStackEvaluation.ink +15 -0
  211. data/ext/inkcpp_rb/inkcpp/tests/TestChoiceCount.ink +15 -0
  212. data/ext/inkcpp_rb/inkcpp/tests/TestChoiceDivertsToDone.ink +6 -0
  213. data/ext/inkcpp_rb/inkcpp/tests/TestChoiceWithBracketsOnly.ink +9 -0
  214. data/ext/inkcpp_rb/inkcpp/tests/TestCompareDivertTargets.ink +26 -0
  215. data/ext/inkcpp_rb/inkcpp/tests/TestComplexTunnels.ink +22 -0
  216. data/ext/inkcpp_rb/inkcpp/tests/TestConditionalChoiceInWeave.ink +19 -0
  217. data/ext/inkcpp_rb/inkcpp/tests/TestTunnelOnwardsAfterTunnel.ink +17 -0
  218. data/ext/inkcpp_rb/inkcpp/unreal/CMakeLists.txt +51 -0
  219. data/ext/inkcpp_rb/inkcpp/unreal/UE_example.ink +92 -0
  220. data/ext/inkcpp_rb/inkcpp/unreal/blueprint_filter.js +377 -0
  221. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Resources/Icon128.png +0 -0
  222. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkAsset.cpp +47 -0
  223. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkChoice.cpp +40 -0
  224. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkList.cpp +86 -0
  225. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkRuntime.cpp +265 -0
  226. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkThread.cpp +239 -0
  227. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/InkVar.cpp +143 -0
  228. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/TagList.cpp +95 -0
  229. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Private/inkcpp.cpp +13 -0
  230. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkAsset.h +50 -0
  231. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkChoice.h +58 -0
  232. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkDelegates.h +139 -0
  233. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkList.h +102 -0
  234. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkRuntime.h +177 -0
  235. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkSnapshot.h +30 -0
  236. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkThread.h +215 -0
  237. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/InkVar.h +245 -0
  238. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/TagList.h +77 -0
  239. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/Public/inkcpp.h +217 -0
  240. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp/inkcpp.Build.cs +62 -0
  241. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/InkAssetFactory.cpp +237 -0
  242. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/InkAssetFactory.h +43 -0
  243. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/inkcpp_editor.cpp +13 -0
  244. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Private/inklecate_cmd.cpp.in +24 -0
  245. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/Public/inkcpp_editor.h +9 -0
  246. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/Source/inkcpp_editor/inkcpp_editor.Build.cs +61 -0
  247. data/ext/inkcpp_rb/inkcpp/unreal/inkcpp/inkcpp.uplugin +44 -0
  248. data/ext/inkcpp_rb/inkcpp/unreal/render.css +1 -0
  249. data/ext/inkcpp_rb/inkcpp_rb.cpp +321 -0
  250. data/inkcpp_rb.gemspec +54 -0
  251. data/rbi/inkcpp_rb.rbi +211 -0
  252. data/sorbet/config +4 -0
  253. data/sorbet/rbi/annotations/.gitattributes +1 -0
  254. data/sorbet/rbi/annotations/minitest.rbi +119 -0
  255. data/sorbet/rbi/gems/.gitattributes +1 -0
  256. data/sorbet/rbi/gems/benchmark@0.4.0.rbi +618 -0
  257. data/sorbet/rbi/gems/erubi@1.13.1.rbi +155 -0
  258. data/sorbet/rbi/gems/minitest@5.25.4.rbi +1547 -0
  259. data/sorbet/rbi/gems/netrc@0.11.0.rbi +159 -0
  260. data/sorbet/rbi/gems/parallel@1.26.3.rbi +291 -0
  261. data/sorbet/rbi/gems/prism@1.3.0.rbi +40040 -0
  262. data/sorbet/rbi/gems/rake-compiler@1.2.8.rbi +9 -0
  263. data/sorbet/rbi/gems/rake@13.2.1.rbi +3033 -0
  264. data/sorbet/rbi/gems/rbi@0.2.2.rbi +4527 -0
  265. data/sorbet/rbi/gems/rice@4.3.3.rbi +44 -0
  266. data/sorbet/rbi/gems/spoom@1.5.0.rbi +4932 -0
  267. data/sorbet/rbi/gems/tapioca@0.16.7.rbi +3611 -0
  268. data/sorbet/rbi/gems/thor@1.3.2.rbi +4378 -0
  269. data/sorbet/rbi/gems/yard-sorbet@0.9.0.rbi +435 -0
  270. data/sorbet/rbi/gems/yard@0.9.37.rbi +18379 -0
  271. data/sorbet/tapioca/config.yml +13 -0
  272. data/sorbet/tapioca/require.rb +4 -0
  273. metadata +400 -0
@@ -0,0 +1,841 @@
1
+ /* Copyright (c) 2024 Julian Benda
2
+ *
3
+ * This file is part of inkCPP which is released under MIT license.
4
+ * See file LICENSE.txt or go to
5
+ * https://github.com/JBenda/inkcpp for full license details.
6
+ */
7
+ #include "list_table.h"
8
+ #include "system.h"
9
+ #include "traits.h"
10
+ #include "header.h"
11
+ #include "random.h"
12
+ #include "string_utils.h"
13
+ #include "list_impl.h"
14
+
15
+ #ifdef INK_ENABLE_STL
16
+ # include <ostream>
17
+ #endif
18
+
19
+ namespace ink::runtime::internal
20
+ {
21
+
22
+ void list_table::copy_lists(const data_t* src, data_t* dst)
23
+ {
24
+ int len = numLists() / bits_per_data;
25
+ int rest = numLists() % bits_per_data;
26
+ for (int i = 0; i < len; ++i) {
27
+ dst[i] = src[i];
28
+ }
29
+ if (rest) {
30
+ dst[len] |= src[len] & (~static_cast<data_t>(0) << (bits_per_data - rest));
31
+ }
32
+ }
33
+
34
+ list_table::list_table(const char* data, const ink::internal::header& header)
35
+ : _valid{false}
36
+ {
37
+ if (data == nullptr) {
38
+ return;
39
+ }
40
+ list_flag flag;
41
+ const char* ptr = data;
42
+ int start = 0;
43
+ while ((flag = header.read_list_flag(ptr)) != null_flag) {
44
+ // start of new list
45
+ if (_list_end.size() == flag.list_id) {
46
+ start = _list_end.size() == 0 ? 0 : _list_end.back();
47
+ _list_end.push() = start;
48
+ _list_names.push() = ptr;
49
+ while (*ptr) {
50
+ ++ptr;
51
+ }
52
+ ++ptr; // skip string
53
+ }
54
+ _flag_names.push() = ptr;
55
+ _flag_values.push() = flag.flag;
56
+ ++_list_end.back();
57
+ while (*ptr) {
58
+ ++ptr;
59
+ }
60
+ ++ptr; // skip string
61
+ }
62
+ _entrySize = segmentsFromBits(_list_end.size() + _flag_names.size(), sizeof(data_t));
63
+ _valid = true;
64
+ }
65
+
66
+ list_table::list list_table::create()
67
+ {
68
+ for (size_t i = 0; i < _entry_state.size(); ++i) {
69
+ if (_entry_state[i] == state::empty) {
70
+ _entry_state[i] = state::used;
71
+ return list(i);
72
+ }
73
+ }
74
+
75
+ list new_entry(_entry_state.size());
76
+ // TODO: initelized unused?
77
+ _entry_state.push() = state::used;
78
+ for (int i = 0; i < _entrySize; ++i) {
79
+ _data.push() = 0;
80
+ }
81
+ return new_entry;
82
+ }
83
+
84
+ void list_table::clear_usage()
85
+ {
86
+ for (state& s : _entry_state) {
87
+ if (s == state::used) {
88
+ s = state::unused;
89
+ }
90
+ }
91
+ }
92
+
93
+ void list_table::mark_used(list l)
94
+ {
95
+ if (_entry_state[l.lid] == state::unused) {
96
+ _entry_state[l.lid] = state::used;
97
+ }
98
+ }
99
+
100
+ void list_table::gc()
101
+ {
102
+ for (size_t i = 0; i < _entry_state.size(); ++i) {
103
+ if (_entry_state[i] == state::unused) {
104
+ _entry_state[i] = state::empty;
105
+ data_t* entry = getPtr(i);
106
+ for (int j = 0; j != _entrySize; ++j) {
107
+ entry[j] = 0;
108
+ }
109
+ }
110
+ }
111
+ _list_handouts.clear();
112
+ }
113
+
114
+ int list_table::toFid(list_flag e) const { return listBegin(e.list_id) + e.flag; }
115
+
116
+ size_t list_table::stringLen(const list_flag& e) const { return c_str_len(toString(e)); }
117
+
118
+ const char* list_table::toString(const list_flag& e) const
119
+ {
120
+ if (e.list_id < 0 || e.flag < 0) {
121
+ return "";
122
+ }
123
+ const char* res = _flag_names[toFid(e)];
124
+ return res == nullptr ? "" : res;
125
+ }
126
+
127
+ size_t list_table::stringLen(const list& l) const
128
+ {
129
+ size_t len = 0;
130
+ const data_t* entry = getPtr(l.lid);
131
+ bool first = true;
132
+ for (int i = 0; i < numLists(); ++i) {
133
+ if (hasList(entry, i)) {
134
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
135
+ if (hasFlag(entry, j) && _flag_names[j]) {
136
+ if (! first) {
137
+ len += 2; // ', '
138
+ } else {
139
+ first = false;
140
+ }
141
+ len += c_str_len(_flag_names[j]);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ return len;
147
+ }
148
+
149
+ /// @todo check ouput order for explicit valued lists
150
+ /// @sa list_table::write()
151
+ char* list_table::toString(char* out, const list& l) const
152
+ {
153
+ char* itr = out;
154
+
155
+ const data_t* entry = getPtr(l.lid);
156
+ int last_value = 0;
157
+ int last_list = -1;
158
+ bool first = true;
159
+ int min_value = 0;
160
+ int min_id = -1;
161
+ int min_list = -1;
162
+
163
+ while (1) {
164
+ bool change = false;
165
+ for (int i = 0; i < numLists(); ++i) {
166
+ if (hasList(entry, i)) {
167
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
168
+ if (! hasFlag(entry, j)) {
169
+ continue;
170
+ }
171
+ int value = _flag_values[j];
172
+ if (first || value > last_value || (value == last_value && i > last_list)) {
173
+ if (min_id == -1 || value < min_value) {
174
+ change = true;
175
+ min_list = i;
176
+ min_value = value;
177
+ min_id = j;
178
+ }
179
+ break;
180
+ }
181
+ }
182
+ }
183
+ }
184
+ if (! change) {
185
+ break;
186
+ }
187
+ if (! first) {
188
+ *itr++ = ',';
189
+ *itr++ = ' ';
190
+ }
191
+ first = false;
192
+ for (const char* c = _flag_names[min_id]; *c; ++c) {
193
+ *itr++ = *c;
194
+ }
195
+ last_value = min_value;
196
+ last_list = min_list;
197
+ min_id = -1;
198
+ }
199
+ return itr;
200
+ }
201
+
202
+ list_table::list list_table::range(list_table::list l, int min, int max)
203
+ {
204
+ list res = create();
205
+ data_t* in = getPtr(l.lid);
206
+ data_t* out = getPtr(res.lid);
207
+ bool has_any_list = false;
208
+ for (int i = 0; i < numLists(); ++i) {
209
+ if (hasList(in, i)) {
210
+ bool has_flag = false;
211
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
212
+ int value = _flag_values[j];
213
+ if (value < min) {
214
+ continue;
215
+ }
216
+ if (value > max) {
217
+ break;
218
+ }
219
+ if (hasFlag(in, j)) {
220
+ setFlag(out, j);
221
+ has_flag = true;
222
+ }
223
+ }
224
+ if (has_flag) {
225
+ has_any_list = true;
226
+ setList(out, i);
227
+ }
228
+ }
229
+ }
230
+ if (has_any_list) {
231
+ return res;
232
+ }
233
+ copy_lists(in, out);
234
+ return res;
235
+ }
236
+
237
+ list_table::list list_table::add(list_flag lh, list_flag rh)
238
+ {
239
+ list res = create();
240
+ data_t* o = getPtr(res.lid);
241
+ setList(o, lh.list_id);
242
+ setFlag(o, toFid(lh));
243
+ setList(o, rh.list_id);
244
+ setFlag(o, toFid(rh));
245
+ return res;
246
+ }
247
+
248
+ list_table::list list_table::add(list lh, list rh)
249
+ {
250
+ list res = create();
251
+ data_t* l = getPtr(lh.lid);
252
+ data_t* r = getPtr(rh.lid);
253
+ data_t* o = getPtr(res.lid);
254
+ for (int i = 0; i < _entrySize; ++i) {
255
+ o[i] = l[i] | r[i];
256
+ }
257
+ return res;
258
+ }
259
+
260
+ list_table::list list_table::create_permament()
261
+ {
262
+ list res = create();
263
+ _entry_state[res.lid] = state::permanent;
264
+ return res;
265
+ }
266
+
267
+ list_table::list& list_table::add_inplace(list& lh, list_flag rh)
268
+ {
269
+ if (rh.list_id < 0)
270
+ return lh; // empty or null flag (skip)
271
+ data_t* l = getPtr(lh.lid);
272
+ setList(l, rh.list_id);
273
+ if (rh.flag >= 0) { // origin entry
274
+ setFlag(l, toFid(rh));
275
+ }
276
+ return lh;
277
+ }
278
+
279
+ list_table::list list_table::add(list lh, list_flag rh)
280
+ {
281
+ list res = create();
282
+ data_t* l = getPtr(lh.lid);
283
+ data_t* o = getPtr(res.lid);
284
+ for (int i = 0; i < _entrySize; ++i) {
285
+ o[i] = l[i];
286
+ }
287
+ setList(o, rh.list_id);
288
+ setFlag(o, toFid(rh));
289
+ return res;
290
+ }
291
+
292
+ list_table::list list_table::sub(list lh, list rh)
293
+ {
294
+ list res = create();
295
+ data_t* l = getPtr(lh.lid);
296
+ data_t* r = getPtr(rh.lid);
297
+ data_t* o = getPtr(res.lid);
298
+ bool active_flag = false;
299
+ for (int i = 0; i < _entrySize; ++i) {
300
+ o[i] = (l[i] & r[i]) ^ l[i];
301
+ }
302
+
303
+ for (int i = 0; i < numLists(); ++i) {
304
+ if (hasList(r, i)) {
305
+ if (hasList(l, i)) {
306
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
307
+ if (hasFlag(o, j)) {
308
+ setList(o, i);
309
+ active_flag = true;
310
+ break;
311
+ }
312
+ }
313
+ }
314
+ }
315
+ }
316
+ if (active_flag) {
317
+ return res;
318
+ }
319
+ for (int i = 0; i < numLists(); ++i) {
320
+ if (hasList(o, i)) {
321
+ return res;
322
+ }
323
+ }
324
+ copy_lists(l, o);
325
+ return res;
326
+ }
327
+
328
+ list_table::list list_table::sub(list lh, list_flag rh)
329
+ {
330
+ list res = create();
331
+ data_t* l = getPtr(lh.lid);
332
+ data_t* o = getPtr(res.lid);
333
+ for (int i = 0; i < _entrySize; ++i) {
334
+ o[i] = l[i];
335
+ }
336
+ setFlag(o, toFid(rh), false);
337
+ for (int i = listBegin(rh.list_id); i < _list_end[rh.list_id]; ++i) {
338
+ if (hasFlag(o, i)) {
339
+ return res;
340
+ }
341
+ }
342
+ setList(l, rh.list_id, false);
343
+ for (int i = 0; i < numLists(); ++i) {
344
+ if (hasList(o, i)) {
345
+ return res;
346
+ }
347
+ }
348
+ copy_lists(l, o);
349
+ return res;
350
+ }
351
+
352
+ list_flag list_table::sub(list_flag lh, list rh)
353
+ {
354
+ data_t* r = getPtr(rh.lid);
355
+ if (hasList(r, lh.list_id) && hasFlag(r, toFid(lh))) {
356
+ return list_flag{lh.list_id, -1};
357
+ }
358
+ return lh;
359
+ }
360
+
361
+ /// @todo early exit if value + n is outside of range
362
+ list_table::list list_table::add(list arg, int n)
363
+ {
364
+ // TODO: handle i == 0 (for performance only)
365
+ if (n < 0) {
366
+ return sub(arg, -n);
367
+ }
368
+ list res = create();
369
+ data_t* l = getPtr(arg.lid);
370
+ data_t* o = getPtr(res.lid);
371
+ bool active_flag = false;
372
+ ;
373
+ for (int i = 0; i < numLists(); ++i) {
374
+ if (hasList(l, i)) {
375
+ bool has_flag = false;
376
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
377
+ if (hasFlag(l, j)) {
378
+ int value = _flag_values[j] + n;
379
+ for (int k = j + 1; k < _list_end[i]; ++k) {
380
+ if (value == _flag_values[k]) {
381
+ setFlag(o, k);
382
+ has_flag = true;
383
+ break;
384
+ }
385
+ }
386
+ }
387
+ }
388
+ if (has_flag) {
389
+ active_flag = true;
390
+ setList(o, i);
391
+ }
392
+ }
393
+ }
394
+ if (! active_flag) {
395
+ copy_lists(l, o);
396
+ }
397
+ return res;
398
+ }
399
+
400
+ list_flag list_table::add(list_flag arg, int n)
401
+ {
402
+ if (arg == null_flag || arg == empty_flag || arg.flag == -1) {
403
+ return arg;
404
+ }
405
+ int value = _flag_values[arg.flag] + n;
406
+ for (int i = listBegin(arg.list_id); i < _list_end[arg.list_id]; ++i) {
407
+ if (_flag_values[i] == value) {
408
+ arg.flag = i;
409
+ return arg;
410
+ }
411
+ }
412
+ arg.flag = -1;
413
+ return arg;
414
+ }
415
+
416
+ /// @todo early exit if value - n is outside of range
417
+ list_table::list list_table::sub(list arg, int n)
418
+ {
419
+ // TODO: handle i == 0 (for perofrgmance only)
420
+ if (n < 0) {
421
+ return add(arg, -n);
422
+ }
423
+ list res = create();
424
+ data_t* l = getPtr(arg.lid);
425
+ data_t* o = getPtr(res.lid);
426
+ bool active_flag = false;
427
+ for (int i = 0; i < numLists(); ++i) {
428
+ if (hasList(l, i)) {
429
+ bool has_flag = false;
430
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
431
+ if (hasFlag(l, j)) {
432
+ int value = _flag_values[j] - n;
433
+ for (int k = j - 1; k >= listBegin(i); --k) {
434
+ if (_flag_values[k] == value) {
435
+ setFlag(o, k);
436
+ has_flag = true;
437
+ break;
438
+ }
439
+ }
440
+ }
441
+ }
442
+ if (has_flag) {
443
+ active_flag = true;
444
+ setList(o, i);
445
+ }
446
+ }
447
+ }
448
+ if (! active_flag) {
449
+ copy_lists(l, o);
450
+ }
451
+ return res;
452
+ }
453
+
454
+ list_flag list_table::sub(list_flag arg, int i) { return add(arg, -i); }
455
+
456
+ int list_table::count(list_flag lf) const
457
+ {
458
+ if (lf == empty_flag || lf == null_flag || lf.flag == -1) {
459
+ return 0;
460
+ }
461
+ if (_flag_names[toFid(lf)] == nullptr) {
462
+ return 0;
463
+ }
464
+ return 1;
465
+ }
466
+ int list_table::count(list l) const
467
+ {
468
+ int count = 0;
469
+ const data_t* data = getPtr(l.lid);
470
+ for (int i = 0; i < numLists(); ++i) {
471
+ if (hasList(data, i)) {
472
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
473
+ if (_flag_names[j] != nullptr && hasFlag(data, j)) {
474
+ ++count;
475
+ }
476
+ }
477
+ }
478
+ }
479
+ return count;
480
+ }
481
+
482
+ list_flag list_table::min(list l) const
483
+ {
484
+ list_flag res{-1, -1};
485
+ const data_t* data = getPtr(l.lid);
486
+ for (int i = 0; i < numLists(); ++i) {
487
+ if (hasList(data, i)) {
488
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
489
+ if (hasFlag(data, j)) {
490
+ int value = _flag_values[j];
491
+ if (res.flag < 0 || value < res.flag) {
492
+ res.flag = value;
493
+ res.list_id = i;
494
+ }
495
+ break;
496
+ }
497
+ }
498
+ }
499
+ }
500
+ return res;
501
+ }
502
+
503
+ list_flag list_table::max(list l) const
504
+ {
505
+ list_flag res{-1, -1};
506
+ const data_t* data = getPtr(l.lid);
507
+ for (int i = 0; i < numLists(); ++i) {
508
+ if (hasList(data, i)) {
509
+ for (int j = _list_end[i] - 1; j >= listBegin(i); --j) {
510
+ if (hasFlag(data, j)) {
511
+ int value = _flag_values[j];
512
+ if (value > res.flag) {
513
+ res.flag = value;
514
+ res.list_id = i;
515
+ }
516
+ break;
517
+ }
518
+ }
519
+ }
520
+ }
521
+ return res;
522
+ }
523
+
524
+ bool list_table::equal(list lh, list rh) const
525
+ {
526
+ const data_t* l = getPtr(lh.lid);
527
+ const data_t* r = getPtr(rh.lid);
528
+ for (int i = 0; i < numLists(); ++i) {
529
+ if (hasList(l, i) != hasList(r, i)) {
530
+ return false;
531
+ }
532
+ if (hasList(l, i)) {
533
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
534
+ if (hasFlag(l, j) != hasFlag(r, j)) {
535
+ return false;
536
+ }
537
+ }
538
+ }
539
+ }
540
+ return true;
541
+ }
542
+
543
+ bool list_table::equal(list lh, list_flag rh) const
544
+ {
545
+ const data_t* l = getPtr(lh.lid);
546
+ for (int i = 0; i < numLists(); ++i) {
547
+ if (hasList(l, i) != (rh.list_id == i)) {
548
+ return false;
549
+ }
550
+ }
551
+ for (int i = listBegin(rh.list_id); i < _list_end[rh.list_id]; ++i) {
552
+ if (hasFlag(l, i) != (rh.flag == i - listBegin(rh.list_id))) {
553
+ return false;
554
+ }
555
+ }
556
+ return true;
557
+ }
558
+
559
+ list_table::list list_table::all(list arg)
560
+ {
561
+ list res = create();
562
+ data_t* l = getPtr(arg.lid);
563
+ data_t* o = getPtr(res.lid);
564
+ for (int i = 0; i < numLists(); ++i) {
565
+ if (hasList(l, i)) {
566
+ setList(o, i);
567
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
568
+ setFlag(o, j);
569
+ }
570
+ }
571
+ }
572
+ return res;
573
+ }
574
+
575
+ list_table::list list_table::all(list_flag arg)
576
+ {
577
+ list res = create();
578
+ if (arg != null_flag) {
579
+ data_t* o = getPtr(res.lid);
580
+ setList(o, arg.list_id);
581
+ for (int i = listBegin(arg.list_id); i < _list_end[arg.list_id]; ++i) {
582
+ setFlag(o, i);
583
+ }
584
+ }
585
+ return res;
586
+ }
587
+
588
+ // ATTENTION: can produce an list without setted flag list (same behavior than inklecate)
589
+ list_table::list list_table::invert(list arg)
590
+ {
591
+ list res = create();
592
+ data_t* l = getPtr(arg.lid);
593
+ data_t* o = getPtr(res.lid);
594
+ for (int i = 0; i < numLists(); ++i) {
595
+ if (hasList(l, i)) {
596
+ bool hasList = false;
597
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
598
+ bool have = hasFlag(l, j);
599
+ if (! have) {
600
+ hasList = true;
601
+ setFlag(o, j);
602
+ }
603
+ }
604
+ if (hasList) {
605
+ setList(o, i);
606
+ }
607
+ }
608
+ }
609
+ return res;
610
+ }
611
+
612
+ list_table::list list_table::invert(list_flag arg)
613
+ {
614
+ list res = create();
615
+ if (arg != null_flag) {
616
+ data_t* o = getPtr(res.lid);
617
+ for (int i = listBegin(arg.list_id); i < _list_end[arg.list_id]; ++i) {
618
+ setFlag(o, i, i - listBegin(arg.list_id) != arg.flag);
619
+ }
620
+ }
621
+ return res;
622
+ }
623
+
624
+ list_table::list list_table::intersect(list lh, list rh)
625
+ {
626
+ list res = create();
627
+ data_t* l = getPtr(lh.lid);
628
+ data_t* r = getPtr(rh.lid);
629
+ data_t* o = getPtr(res.lid);
630
+ for (int i = 0; i < _entrySize; ++i) {
631
+ o[i] = l[i] & r[i];
632
+ }
633
+ return res;
634
+ }
635
+
636
+ list_flag list_table::intersect(list lh, list_flag rh)
637
+ {
638
+ const data_t* l = getPtr(lh.lid);
639
+ if (hasList(l, rh.list_id) && hasFlag(l, toFid(rh))) {
640
+ return rh;
641
+ }
642
+ return null_flag;
643
+ }
644
+
645
+ bool list_table::has(list lh, list_flag rh) const
646
+ {
647
+ const data_t* l = getPtr(lh.lid);
648
+ return hasList(l, rh.list_id) && hasFlag(l, toFid(rh));
649
+ }
650
+
651
+ list_flag list_table::lrnd(list lh, prng& rng) const
652
+ {
653
+ const data_t* l = getPtr(lh.lid);
654
+ int n = count(lh);
655
+ n = rng.rand(n);
656
+ int count = 0;
657
+ for (int i = 0; i < numLists(); ++i) {
658
+ if (hasList(l, i)) {
659
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
660
+ if (hasFlag(l, j)) {
661
+ if (count++ == n) {
662
+ return list_flag{
663
+ static_cast<decltype(list_flag::list_id)>(i),
664
+ static_cast<decltype(list_flag::flag)>(j - listBegin(i))};
665
+ }
666
+ }
667
+ }
668
+ }
669
+ }
670
+ return null_flag;
671
+ }
672
+
673
+ bool list_table::has(list lh, list rh) const
674
+ {
675
+ const data_t* r = getPtr(rh.lid);
676
+ const data_t* l = getPtr(lh.lid);
677
+ for (int i = 0; i < numLists(); ++i) {
678
+ if (hasList(r, i)) {
679
+ if (! hasList(l, i)) {
680
+ return false;
681
+ }
682
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
683
+ if (hasFlag(r, j) && ! hasFlag(l, j)) {
684
+ return false;
685
+ }
686
+ }
687
+ }
688
+ }
689
+ return true;
690
+ }
691
+
692
+ optional<list_flag> list_table::toFlag(const char* flag_name) const
693
+ {
694
+
695
+ const char* periode = str_find(flag_name, '.');
696
+ if (periode) {
697
+ list_flag list = get_list_id(flag_name); // since flag_name is `list_name.flag_name`
698
+ flag_name = periode + 1;
699
+ int list_begin = list.list_id == 0 ? 0 : _list_end[list.list_id - 1];
700
+ for (int i = list_begin; i != _list_end[list.list_id]; ++i) {
701
+ if (str_equal(flag_name, _flag_names[i])) {
702
+ return {
703
+ list_flag{.list_id = list.list_id, .flag = static_cast<int16_t>(i - list_begin)}
704
+ };
705
+ }
706
+ }
707
+ } else {
708
+ for (auto flag_itr = _flag_names.begin(); flag_itr != _flag_names.end(); ++flag_itr) {
709
+ if (str_equal(*flag_itr, flag_name)) {
710
+ int fid = flag_itr - _flag_names.begin();
711
+ int lid = 0;
712
+ int begin = 0;
713
+ for (auto list_itr = _list_end.begin(); list_itr != _list_end.end(); ++list_itr) {
714
+ if (*list_itr > fid) {
715
+ lid = list_itr - _list_end.begin();
716
+ break;
717
+ }
718
+ begin = *list_itr;
719
+ }
720
+ return {
721
+ list_flag{
722
+ .list_id = static_cast<int16_t>(lid), .flag = static_cast<int16_t>(fid - begin)}
723
+ };
724
+ }
725
+ }
726
+ }
727
+ return nullopt;
728
+ }
729
+
730
+ list_flag list_table::get_list_id(const char* list_name) const
731
+ {
732
+ using int_t = decltype(list_flag::list_id);
733
+ const char* period = str_find(list_name, '.');
734
+ size_t len = period ? period - list_name : c_str_len(list_name);
735
+ for (int_t i = 0; i < static_cast<int_t>(_list_names.size()); ++i) {
736
+ if (str_equal_len(list_name, _list_names[i], len)) {
737
+ return list_flag{i, -1};
738
+ }
739
+ }
740
+ inkAssert(false, "No list with name found!");
741
+ return null_flag;
742
+ }
743
+
744
+ list_table::list list_table::redefine(list lh, list rh)
745
+ {
746
+ data_t* l = getPtr(lh.lid);
747
+ data_t* r = getPtr(rh.lid);
748
+ list res = create();
749
+ data_t* o = getPtr(res.lid);
750
+
751
+ // if the new list has no origin: give it the origin of the old value
752
+ bool has_origin = false;
753
+ for (int i = 0; i < numLists(); ++i) {
754
+ if (hasList(r, i)) {
755
+ has_origin = true;
756
+ break;
757
+ }
758
+ }
759
+ if (! has_origin) {
760
+ copy_lists(l, r);
761
+ }
762
+
763
+ for (int i = 0; i < _entrySize; ++i) {
764
+ o[i] = r[i];
765
+ }
766
+ return res;
767
+ }
768
+
769
+ list_interface* list_table::handout_list(list l)
770
+ {
771
+ static_assert(sizeof(list_interface) == sizeof(list_impl));
772
+ auto& res = _list_handouts.push();
773
+ new (&res) list_impl(*this, l.lid);
774
+ return &res;
775
+ }
776
+
777
+ #ifdef INK_ENABLE_STL
778
+ /// @sa list_table::toString(char*,const list&)
779
+ std::ostream& list_table::write(std::ostream& os, list l) const
780
+ {
781
+ const data_t* entry = getPtr(l.lid);
782
+ int last_value = 0;
783
+ int last_list = -1;
784
+ bool first = true;
785
+ int min_value = 0;
786
+ int min_id = -1;
787
+ int min_list = -1;
788
+
789
+ while (1) {
790
+ bool change = false;
791
+ for (int i = 0; i < numLists(); ++i) {
792
+ if (hasList(entry, i)) {
793
+ for (int j = listBegin(i); j < _list_end[i]; ++j) {
794
+ if (! hasFlag(entry, j)) {
795
+ continue;
796
+ }
797
+ int value = _flag_values[j];
798
+ if (first || value > last_value || (value == last_value && i > last_list)) {
799
+ if (min_id == -1 || value < min_value) {
800
+ min_value = value;
801
+ min_id = j;
802
+ min_list = i;
803
+ change = true;
804
+ }
805
+ break;
806
+ }
807
+ }
808
+ }
809
+ }
810
+ if (! change) {
811
+ break;
812
+ }
813
+ if (! first) {
814
+ os << ", ";
815
+ }
816
+ first = false;
817
+ os << _flag_names[min_id];
818
+ last_value = min_value;
819
+ last_list = min_list;
820
+ min_id = -1;
821
+ }
822
+ return os;
823
+ }
824
+ #endif
825
+
826
+ size_t list_table::snap(unsigned char* data, const snapper& snapper) const
827
+ {
828
+ unsigned char* ptr = data;
829
+ ptr += _data.snap(data ? ptr : nullptr, snapper);
830
+ ptr += _entry_state.snap(data ? ptr : nullptr, snapper);
831
+ return ptr - data;
832
+ }
833
+
834
+ const unsigned char* list_table::snap_load(const unsigned char* ptr, const loader& loader)
835
+ {
836
+ ptr = _data.snap_load(ptr, loader);
837
+ ptr = _entry_state.snap_load(ptr, loader);
838
+ return ptr;
839
+ }
840
+
841
+ } // namespace ink::runtime::internal