mqt-core 3.3.2__cp313-cp313t-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (537) hide show
  1. mqt/core/__init__.py +89 -0
  2. mqt/core/__main__.py +55 -0
  3. mqt/core/_commands.py +52 -0
  4. mqt/core/_compat/__init__.py +11 -0
  5. mqt/core/_compat/typing.py +29 -0
  6. mqt/core/_version.py +34 -0
  7. mqt/core/_version.pyi +12 -0
  8. mqt/core/bin/mqt-core-algorithms.dll +0 -0
  9. mqt/core/bin/mqt-core-circuit-optimizer.dll +0 -0
  10. mqt/core/bin/mqt-core-dd.dll +0 -0
  11. mqt/core/bin/mqt-core-ds.dll +0 -0
  12. mqt/core/bin/mqt-core-fomac.dll +0 -0
  13. mqt/core/bin/mqt-core-ir.dll +0 -0
  14. mqt/core/bin/mqt-core-na-fomac.dll +0 -0
  15. mqt/core/bin/mqt-core-na.dll +0 -0
  16. mqt/core/bin/mqt-core-qasm.dll +0 -0
  17. mqt/core/bin/mqt-core-qdmi-driver.dll +0 -0
  18. mqt/core/bin/mqt-core-qdmi-na-device.dll +0 -0
  19. mqt/core/bin/mqt-core-zx.dll +0 -0
  20. mqt/core/dd.cp313t-win_amd64.pyd +0 -0
  21. mqt/core/dd.pyi +1016 -0
  22. mqt/core/dd_evaluation.py +368 -0
  23. mqt/core/fomac.cp313t-win_amd64.pyd +0 -0
  24. mqt/core/fomac.pyi +125 -0
  25. mqt/core/include/mqt-core/algorithms/BernsteinVazirani.hpp +39 -0
  26. mqt/core/include/mqt-core/algorithms/GHZState.hpp +18 -0
  27. mqt/core/include/mqt-core/algorithms/Grover.hpp +33 -0
  28. mqt/core/include/mqt-core/algorithms/QFT.hpp +21 -0
  29. mqt/core/include/mqt-core/algorithms/QPE.hpp +30 -0
  30. mqt/core/include/mqt-core/algorithms/RandomCliffordCircuit.hpp +22 -0
  31. mqt/core/include/mqt-core/algorithms/StatePreparation.hpp +43 -0
  32. mqt/core/include/mqt-core/algorithms/WState.hpp +18 -0
  33. mqt/core/include/mqt-core/algorithms/mqt_core_algorithms_export.h +43 -0
  34. mqt/core/include/mqt-core/boost/config/abi/borland_prefix.hpp +27 -0
  35. mqt/core/include/mqt-core/boost/config/abi/borland_suffix.hpp +12 -0
  36. mqt/core/include/mqt-core/boost/config/abi/msvc_prefix.hpp +22 -0
  37. mqt/core/include/mqt-core/boost/config/abi/msvc_suffix.hpp +8 -0
  38. mqt/core/include/mqt-core/boost/config/abi_prefix.hpp +25 -0
  39. mqt/core/include/mqt-core/boost/config/abi_suffix.hpp +25 -0
  40. mqt/core/include/mqt-core/boost/config/assert_cxx03.hpp +211 -0
  41. mqt/core/include/mqt-core/boost/config/assert_cxx11.hpp +212 -0
  42. mqt/core/include/mqt-core/boost/config/assert_cxx14.hpp +47 -0
  43. mqt/core/include/mqt-core/boost/config/assert_cxx17.hpp +65 -0
  44. mqt/core/include/mqt-core/boost/config/assert_cxx20.hpp +59 -0
  45. mqt/core/include/mqt-core/boost/config/assert_cxx23.hpp +41 -0
  46. mqt/core/include/mqt-core/boost/config/assert_cxx98.hpp +23 -0
  47. mqt/core/include/mqt-core/boost/config/auto_link.hpp +525 -0
  48. mqt/core/include/mqt-core/boost/config/compiler/borland.hpp +342 -0
  49. mqt/core/include/mqt-core/boost/config/compiler/clang.hpp +370 -0
  50. mqt/core/include/mqt-core/boost/config/compiler/clang_version.hpp +89 -0
  51. mqt/core/include/mqt-core/boost/config/compiler/codegear.hpp +389 -0
  52. mqt/core/include/mqt-core/boost/config/compiler/comeau.hpp +59 -0
  53. mqt/core/include/mqt-core/boost/config/compiler/common_edg.hpp +185 -0
  54. mqt/core/include/mqt-core/boost/config/compiler/compaq_cxx.hpp +19 -0
  55. mqt/core/include/mqt-core/boost/config/compiler/cray.hpp +446 -0
  56. mqt/core/include/mqt-core/boost/config/compiler/diab.hpp +26 -0
  57. mqt/core/include/mqt-core/boost/config/compiler/digitalmars.hpp +146 -0
  58. mqt/core/include/mqt-core/boost/config/compiler/gcc.hpp +386 -0
  59. mqt/core/include/mqt-core/boost/config/compiler/gcc_xml.hpp +115 -0
  60. mqt/core/include/mqt-core/boost/config/compiler/greenhills.hpp +28 -0
  61. mqt/core/include/mqt-core/boost/config/compiler/hp_acc.hpp +153 -0
  62. mqt/core/include/mqt-core/boost/config/compiler/intel.hpp +577 -0
  63. mqt/core/include/mqt-core/boost/config/compiler/kai.hpp +33 -0
  64. mqt/core/include/mqt-core/boost/config/compiler/metrowerks.hpp +201 -0
  65. mqt/core/include/mqt-core/boost/config/compiler/mpw.hpp +143 -0
  66. mqt/core/include/mqt-core/boost/config/compiler/nvcc.hpp +64 -0
  67. mqt/core/include/mqt-core/boost/config/compiler/pathscale.hpp +141 -0
  68. mqt/core/include/mqt-core/boost/config/compiler/pgi.hpp +23 -0
  69. mqt/core/include/mqt-core/boost/config/compiler/sgi_mipspro.hpp +29 -0
  70. mqt/core/include/mqt-core/boost/config/compiler/sunpro_cc.hpp +225 -0
  71. mqt/core/include/mqt-core/boost/config/compiler/vacpp.hpp +189 -0
  72. mqt/core/include/mqt-core/boost/config/compiler/visualc.hpp +398 -0
  73. mqt/core/include/mqt-core/boost/config/compiler/xlcpp.hpp +303 -0
  74. mqt/core/include/mqt-core/boost/config/compiler/xlcpp_zos.hpp +174 -0
  75. mqt/core/include/mqt-core/boost/config/detail/cxx_composite.hpp +218 -0
  76. mqt/core/include/mqt-core/boost/config/detail/posix_features.hpp +95 -0
  77. mqt/core/include/mqt-core/boost/config/detail/select_compiler_config.hpp +157 -0
  78. mqt/core/include/mqt-core/boost/config/detail/select_platform_config.hpp +147 -0
  79. mqt/core/include/mqt-core/boost/config/detail/select_stdlib_config.hpp +121 -0
  80. mqt/core/include/mqt-core/boost/config/detail/suffix.hpp +1334 -0
  81. mqt/core/include/mqt-core/boost/config/header_deprecated.hpp +26 -0
  82. mqt/core/include/mqt-core/boost/config/helper_macros.hpp +37 -0
  83. mqt/core/include/mqt-core/boost/config/no_tr1/cmath.hpp +28 -0
  84. mqt/core/include/mqt-core/boost/config/no_tr1/complex.hpp +28 -0
  85. mqt/core/include/mqt-core/boost/config/no_tr1/functional.hpp +28 -0
  86. mqt/core/include/mqt-core/boost/config/no_tr1/memory.hpp +28 -0
  87. mqt/core/include/mqt-core/boost/config/no_tr1/utility.hpp +28 -0
  88. mqt/core/include/mqt-core/boost/config/platform/aix.hpp +33 -0
  89. mqt/core/include/mqt-core/boost/config/platform/amigaos.hpp +15 -0
  90. mqt/core/include/mqt-core/boost/config/platform/beos.hpp +26 -0
  91. mqt/core/include/mqt-core/boost/config/platform/bsd.hpp +83 -0
  92. mqt/core/include/mqt-core/boost/config/platform/cloudabi.hpp +18 -0
  93. mqt/core/include/mqt-core/boost/config/platform/cray.hpp +18 -0
  94. mqt/core/include/mqt-core/boost/config/platform/cygwin.hpp +71 -0
  95. mqt/core/include/mqt-core/boost/config/platform/haiku.hpp +31 -0
  96. mqt/core/include/mqt-core/boost/config/platform/hpux.hpp +87 -0
  97. mqt/core/include/mqt-core/boost/config/platform/irix.hpp +31 -0
  98. mqt/core/include/mqt-core/boost/config/platform/linux.hpp +106 -0
  99. mqt/core/include/mqt-core/boost/config/platform/macos.hpp +87 -0
  100. mqt/core/include/mqt-core/boost/config/platform/qnxnto.hpp +31 -0
  101. mqt/core/include/mqt-core/boost/config/platform/solaris.hpp +31 -0
  102. mqt/core/include/mqt-core/boost/config/platform/symbian.hpp +97 -0
  103. mqt/core/include/mqt-core/boost/config/platform/vms.hpp +25 -0
  104. mqt/core/include/mqt-core/boost/config/platform/vxworks.hpp +422 -0
  105. mqt/core/include/mqt-core/boost/config/platform/wasm.hpp +23 -0
  106. mqt/core/include/mqt-core/boost/config/platform/win32.hpp +90 -0
  107. mqt/core/include/mqt-core/boost/config/platform/zos.hpp +32 -0
  108. mqt/core/include/mqt-core/boost/config/pragma_message.hpp +31 -0
  109. mqt/core/include/mqt-core/boost/config/requires_threads.hpp +92 -0
  110. mqt/core/include/mqt-core/boost/config/stdlib/dinkumware.hpp +324 -0
  111. mqt/core/include/mqt-core/boost/config/stdlib/libcomo.hpp +93 -0
  112. mqt/core/include/mqt-core/boost/config/stdlib/libcpp.hpp +180 -0
  113. mqt/core/include/mqt-core/boost/config/stdlib/libstdcpp3.hpp +482 -0
  114. mqt/core/include/mqt-core/boost/config/stdlib/modena.hpp +79 -0
  115. mqt/core/include/mqt-core/boost/config/stdlib/msl.hpp +98 -0
  116. mqt/core/include/mqt-core/boost/config/stdlib/roguewave.hpp +208 -0
  117. mqt/core/include/mqt-core/boost/config/stdlib/sgi.hpp +168 -0
  118. mqt/core/include/mqt-core/boost/config/stdlib/stlport.hpp +258 -0
  119. mqt/core/include/mqt-core/boost/config/stdlib/vacpp.hpp +74 -0
  120. mqt/core/include/mqt-core/boost/config/stdlib/xlcpp_zos.hpp +61 -0
  121. mqt/core/include/mqt-core/boost/config/user.hpp +133 -0
  122. mqt/core/include/mqt-core/boost/config/warning_disable.hpp +47 -0
  123. mqt/core/include/mqt-core/boost/config/workaround.hpp +305 -0
  124. mqt/core/include/mqt-core/boost/config.hpp +67 -0
  125. mqt/core/include/mqt-core/boost/cstdint.hpp +556 -0
  126. mqt/core/include/mqt-core/boost/cxx11_char_types.hpp +70 -0
  127. mqt/core/include/mqt-core/boost/detail/workaround.hpp +10 -0
  128. mqt/core/include/mqt-core/boost/limits.hpp +146 -0
  129. mqt/core/include/mqt-core/boost/multiprecision/complex128.hpp +24 -0
  130. mqt/core/include/mqt-core/boost/multiprecision/complex_adaptor.hpp +1046 -0
  131. mqt/core/include/mqt-core/boost/multiprecision/concepts/mp_number_archetypes.hpp +257 -0
  132. mqt/core/include/mqt-core/boost/multiprecision/cpp_bin_float/io.hpp +698 -0
  133. mqt/core/include/mqt-core/boost/multiprecision/cpp_bin_float/transcendental.hpp +157 -0
  134. mqt/core/include/mqt-core/boost/multiprecision/cpp_bin_float.hpp +2297 -0
  135. mqt/core/include/mqt-core/boost/multiprecision/cpp_complex.hpp +12 -0
  136. mqt/core/include/mqt-core/boost/multiprecision/cpp_dec_float.hpp +3690 -0
  137. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/add.hpp +368 -0
  138. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/add_unsigned.hpp +387 -0
  139. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/bitwise.hpp +889 -0
  140. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/checked.hpp +178 -0
  141. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/comparison.hpp +374 -0
  142. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/cpp_int_config.hpp +161 -0
  143. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/divide.hpp +703 -0
  144. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/import_export.hpp +248 -0
  145. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/intel_intrinsics.hpp +138 -0
  146. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/limits.hpp +282 -0
  147. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/literals.hpp +295 -0
  148. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/misc.hpp +1457 -0
  149. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/multiply.hpp +848 -0
  150. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/serialize.hpp +211 -0
  151. mqt/core/include/mqt-core/boost/multiprecision/cpp_int/value_pack.hpp +42 -0
  152. mqt/core/include/mqt-core/boost/multiprecision/cpp_int.hpp +2360 -0
  153. mqt/core/include/mqt-core/boost/multiprecision/debug_adaptor.hpp +760 -0
  154. mqt/core/include/mqt-core/boost/multiprecision/detail/assert.hpp +29 -0
  155. mqt/core/include/mqt-core/boost/multiprecision/detail/atomic.hpp +62 -0
  156. mqt/core/include/mqt-core/boost/multiprecision/detail/bitscan.hpp +317 -0
  157. mqt/core/include/mqt-core/boost/multiprecision/detail/check_cpp11_config.hpp +64 -0
  158. mqt/core/include/mqt-core/boost/multiprecision/detail/constexpr.hpp +88 -0
  159. mqt/core/include/mqt-core/boost/multiprecision/detail/default_ops.hpp +4052 -0
  160. mqt/core/include/mqt-core/boost/multiprecision/detail/digits.hpp +49 -0
  161. mqt/core/include/mqt-core/boost/multiprecision/detail/dynamic_array.hpp +44 -0
  162. mqt/core/include/mqt-core/boost/multiprecision/detail/empty_value.hpp +87 -0
  163. mqt/core/include/mqt-core/boost/multiprecision/detail/endian.hpp +35 -0
  164. mqt/core/include/mqt-core/boost/multiprecision/detail/et_ops.hpp +1831 -0
  165. mqt/core/include/mqt-core/boost/multiprecision/detail/float128_functions.hpp +95 -0
  166. mqt/core/include/mqt-core/boost/multiprecision/detail/float_string_cvt.hpp +333 -0
  167. mqt/core/include/mqt-core/boost/multiprecision/detail/fpclassify.hpp +101 -0
  168. mqt/core/include/mqt-core/boost/multiprecision/detail/functions/constants.hpp +288 -0
  169. mqt/core/include/mqt-core/boost/multiprecision/detail/functions/pow.hpp +905 -0
  170. mqt/core/include/mqt-core/boost/multiprecision/detail/functions/trig.hpp +1058 -0
  171. mqt/core/include/mqt-core/boost/multiprecision/detail/functions/trunc.hpp +82 -0
  172. mqt/core/include/mqt-core/boost/multiprecision/detail/generic_interconvert.hpp +687 -0
  173. mqt/core/include/mqt-core/boost/multiprecision/detail/hash.hpp +56 -0
  174. mqt/core/include/mqt-core/boost/multiprecision/detail/integer_ops.hpp +474 -0
  175. mqt/core/include/mqt-core/boost/multiprecision/detail/itos.hpp +39 -0
  176. mqt/core/include/mqt-core/boost/multiprecision/detail/min_max.hpp +106 -0
  177. mqt/core/include/mqt-core/boost/multiprecision/detail/no_et_ops.hpp +661 -0
  178. mqt/core/include/mqt-core/boost/multiprecision/detail/no_exceptions_support.hpp +55 -0
  179. mqt/core/include/mqt-core/boost/multiprecision/detail/number_base.hpp +1656 -0
  180. mqt/core/include/mqt-core/boost/multiprecision/detail/number_compare.hpp +848 -0
  181. mqt/core/include/mqt-core/boost/multiprecision/detail/precision.hpp +313 -0
  182. mqt/core/include/mqt-core/boost/multiprecision/detail/rebind.hpp +19 -0
  183. mqt/core/include/mqt-core/boost/multiprecision/detail/standalone_config.hpp +148 -0
  184. mqt/core/include/mqt-core/boost/multiprecision/detail/static_array.hpp +42 -0
  185. mqt/core/include/mqt-core/boost/multiprecision/detail/string_helpers.hpp +48 -0
  186. mqt/core/include/mqt-core/boost/multiprecision/detail/tables.hpp +80 -0
  187. mqt/core/include/mqt-core/boost/multiprecision/detail/ublas_interop.hpp +75 -0
  188. mqt/core/include/mqt-core/boost/multiprecision/detail/uniform_int_distribution.hpp +212 -0
  189. mqt/core/include/mqt-core/boost/multiprecision/detail/utype_helper.hpp +374 -0
  190. mqt/core/include/mqt-core/boost/multiprecision/eigen.hpp +248 -0
  191. mqt/core/include/mqt-core/boost/multiprecision/float128.hpp +920 -0
  192. mqt/core/include/mqt-core/boost/multiprecision/fwd.hpp +268 -0
  193. mqt/core/include/mqt-core/boost/multiprecision/gmp.hpp +4060 -0
  194. mqt/core/include/mqt-core/boost/multiprecision/integer.hpp +363 -0
  195. mqt/core/include/mqt-core/boost/multiprecision/logged_adaptor.hpp +834 -0
  196. mqt/core/include/mqt-core/boost/multiprecision/miller_rabin.hpp +221 -0
  197. mqt/core/include/mqt-core/boost/multiprecision/mpc.hpp +1721 -0
  198. mqt/core/include/mqt-core/boost/multiprecision/mpfi.hpp +2559 -0
  199. mqt/core/include/mqt-core/boost/multiprecision/mpfr.hpp +3644 -0
  200. mqt/core/include/mqt-core/boost/multiprecision/number.hpp +2500 -0
  201. mqt/core/include/mqt-core/boost/multiprecision/random.hpp +23 -0
  202. mqt/core/include/mqt-core/boost/multiprecision/rational_adaptor.hpp +1289 -0
  203. mqt/core/include/mqt-core/boost/multiprecision/tommath.hpp +1034 -0
  204. mqt/core/include/mqt-core/boost/multiprecision/traits/explicit_conversion.hpp +67 -0
  205. mqt/core/include/mqt-core/boost/multiprecision/traits/extract_exponent_type.hpp +28 -0
  206. mqt/core/include/mqt-core/boost/multiprecision/traits/is_backend.hpp +91 -0
  207. mqt/core/include/mqt-core/boost/multiprecision/traits/is_byte_container.hpp +51 -0
  208. mqt/core/include/mqt-core/boost/multiprecision/traits/is_complex.hpp +22 -0
  209. mqt/core/include/mqt-core/boost/multiprecision/traits/is_convertible_arithmetic.hpp +51 -0
  210. mqt/core/include/mqt-core/boost/multiprecision/traits/is_restricted_conversion.hpp +47 -0
  211. mqt/core/include/mqt-core/boost/multiprecision/traits/is_variable_precision.hpp +25 -0
  212. mqt/core/include/mqt-core/boost/multiprecision/traits/max_digits10.hpp +79 -0
  213. mqt/core/include/mqt-core/boost/multiprecision/traits/std_integer_traits.hpp +90 -0
  214. mqt/core/include/mqt-core/boost/multiprecision/traits/transcendental_reduction_type.hpp +21 -0
  215. mqt/core/include/mqt-core/boost/version.hpp +32 -0
  216. mqt/core/include/mqt-core/circuit_optimizer/CircuitOptimizer.hpp +119 -0
  217. mqt/core/include/mqt-core/circuit_optimizer/mqt_core_circuit_optimizer_export.h +43 -0
  218. mqt/core/include/mqt-core/datastructures/DirectedAcyclicGraph.hpp +117 -0
  219. mqt/core/include/mqt-core/datastructures/DirectedGraph.hpp +158 -0
  220. mqt/core/include/mqt-core/datastructures/DisjointSet.hpp +50 -0
  221. mqt/core/include/mqt-core/datastructures/Layer.hpp +172 -0
  222. mqt/core/include/mqt-core/datastructures/SymmetricMatrix.hpp +57 -0
  223. mqt/core/include/mqt-core/datastructures/UndirectedGraph.hpp +227 -0
  224. mqt/core/include/mqt-core/datastructures/mqt_core_ds_export.h +43 -0
  225. mqt/core/include/mqt-core/dd/Approximation.hpp +45 -0
  226. mqt/core/include/mqt-core/dd/CachedEdge.hpp +174 -0
  227. mqt/core/include/mqt-core/dd/Complex.hpp +165 -0
  228. mqt/core/include/mqt-core/dd/ComplexNumbers.hpp +150 -0
  229. mqt/core/include/mqt-core/dd/ComplexValue.hpp +184 -0
  230. mqt/core/include/mqt-core/dd/ComputeTable.hpp +183 -0
  231. mqt/core/include/mqt-core/dd/DDDefinitions.hpp +139 -0
  232. mqt/core/include/mqt-core/dd/DDpackageConfig.hpp +104 -0
  233. mqt/core/include/mqt-core/dd/DensityNoiseTable.hpp +114 -0
  234. mqt/core/include/mqt-core/dd/Edge.hpp +416 -0
  235. mqt/core/include/mqt-core/dd/Export.hpp +438 -0
  236. mqt/core/include/mqt-core/dd/FunctionalityConstruction.hpp +75 -0
  237. mqt/core/include/mqt-core/dd/GateMatrixDefinitions.hpp +43 -0
  238. mqt/core/include/mqt-core/dd/LinkedListBase.hpp +45 -0
  239. mqt/core/include/mqt-core/dd/MemoryManager.hpp +193 -0
  240. mqt/core/include/mqt-core/dd/Node.hpp +223 -0
  241. mqt/core/include/mqt-core/dd/NoiseFunctionality.hpp +144 -0
  242. mqt/core/include/mqt-core/dd/Operations.hpp +306 -0
  243. mqt/core/include/mqt-core/dd/Package.hpp +2036 -0
  244. mqt/core/include/mqt-core/dd/Package_fwd.hpp +22 -0
  245. mqt/core/include/mqt-core/dd/RealNumber.hpp +255 -0
  246. mqt/core/include/mqt-core/dd/RealNumberUniqueTable.hpp +217 -0
  247. mqt/core/include/mqt-core/dd/Simulation.hpp +98 -0
  248. mqt/core/include/mqt-core/dd/StateGeneration.hpp +143 -0
  249. mqt/core/include/mqt-core/dd/StochasticNoiseOperationTable.hpp +88 -0
  250. mqt/core/include/mqt-core/dd/UnaryComputeTable.hpp +121 -0
  251. mqt/core/include/mqt-core/dd/UniqueTable.hpp +243 -0
  252. mqt/core/include/mqt-core/dd/mqt_core_dd_export.h +43 -0
  253. mqt/core/include/mqt-core/dd/statistics/MemoryManagerStatistics.hpp +84 -0
  254. mqt/core/include/mqt-core/dd/statistics/PackageStatistics.hpp +55 -0
  255. mqt/core/include/mqt-core/dd/statistics/Statistics.hpp +48 -0
  256. mqt/core/include/mqt-core/dd/statistics/TableStatistics.hpp +79 -0
  257. mqt/core/include/mqt-core/dd/statistics/UniqueTableStatistics.hpp +31 -0
  258. mqt/core/include/mqt-core/fomac/FoMaC.hpp +568 -0
  259. mqt/core/include/mqt-core/ir/Definitions.hpp +108 -0
  260. mqt/core/include/mqt-core/ir/Permutation.hpp +213 -0
  261. mqt/core/include/mqt-core/ir/QuantumComputation.hpp +596 -0
  262. mqt/core/include/mqt-core/ir/Register.hpp +125 -0
  263. mqt/core/include/mqt-core/ir/mqt_core_ir_export.h +43 -0
  264. mqt/core/include/mqt-core/ir/operations/AodOperation.hpp +92 -0
  265. mqt/core/include/mqt-core/ir/operations/CompoundOperation.hpp +212 -0
  266. mqt/core/include/mqt-core/ir/operations/Control.hpp +142 -0
  267. mqt/core/include/mqt-core/ir/operations/Expression.hpp +847 -0
  268. mqt/core/include/mqt-core/ir/operations/IfElseOperation.hpp +169 -0
  269. mqt/core/include/mqt-core/ir/operations/NonUnitaryOperation.hpp +118 -0
  270. mqt/core/include/mqt-core/ir/operations/OpType.hpp +120 -0
  271. mqt/core/include/mqt-core/ir/operations/OpType.inc +76 -0
  272. mqt/core/include/mqt-core/ir/operations/Operation.hpp +247 -0
  273. mqt/core/include/mqt-core/ir/operations/StandardOperation.hpp +140 -0
  274. mqt/core/include/mqt-core/ir/operations/SymbolicOperation.hpp +144 -0
  275. mqt/core/include/mqt-core/mqt_na_qdmi/device.h +602 -0
  276. mqt/core/include/mqt-core/mqt_na_qdmi/types.h +78 -0
  277. mqt/core/include/mqt-core/na/NAComputation.hpp +185 -0
  278. mqt/core/include/mqt-core/na/device/Device.hpp +410 -0
  279. mqt/core/include/mqt-core/na/device/DeviceMemberInitializers.hpp +724 -0
  280. mqt/core/include/mqt-core/na/device/Generator.hpp +447 -0
  281. mqt/core/include/mqt-core/na/entities/Atom.hpp +62 -0
  282. mqt/core/include/mqt-core/na/entities/Location.hpp +154 -0
  283. mqt/core/include/mqt-core/na/entities/Zone.hpp +95 -0
  284. mqt/core/include/mqt-core/na/fomac/Device.hpp +169 -0
  285. mqt/core/include/mqt-core/na/mqt_core_na_export.h +43 -0
  286. mqt/core/include/mqt-core/na/operations/GlobalCZOp.hpp +38 -0
  287. mqt/core/include/mqt-core/na/operations/GlobalOp.hpp +58 -0
  288. mqt/core/include/mqt-core/na/operations/GlobalRYOp.hpp +42 -0
  289. mqt/core/include/mqt-core/na/operations/LoadOp.hpp +89 -0
  290. mqt/core/include/mqt-core/na/operations/LocalOp.hpp +56 -0
  291. mqt/core/include/mqt-core/na/operations/LocalRZOp.hpp +42 -0
  292. mqt/core/include/mqt-core/na/operations/LocalUOp.hpp +49 -0
  293. mqt/core/include/mqt-core/na/operations/MoveOp.hpp +66 -0
  294. mqt/core/include/mqt-core/na/operations/Op.hpp +62 -0
  295. mqt/core/include/mqt-core/na/operations/ShuttlingOp.hpp +51 -0
  296. mqt/core/include/mqt-core/na/operations/StoreOp.hpp +87 -0
  297. mqt/core/include/mqt-core/qasm3/Exception.hpp +85 -0
  298. mqt/core/include/mqt-core/qasm3/Gate.hpp +65 -0
  299. mqt/core/include/mqt-core/qasm3/Importer.hpp +192 -0
  300. mqt/core/include/mqt-core/qasm3/InstVisitor.hpp +145 -0
  301. mqt/core/include/mqt-core/qasm3/NestedEnvironment.hpp +41 -0
  302. mqt/core/include/mqt-core/qasm3/Parser.hpp +170 -0
  303. mqt/core/include/mqt-core/qasm3/Scanner.hpp +73 -0
  304. mqt/core/include/mqt-core/qasm3/Statement.hpp +486 -0
  305. mqt/core/include/mqt-core/qasm3/Statement_fwd.hpp +39 -0
  306. mqt/core/include/mqt-core/qasm3/StdGates.hpp +232 -0
  307. mqt/core/include/mqt-core/qasm3/Token.hpp +198 -0
  308. mqt/core/include/mqt-core/qasm3/Types.hpp +238 -0
  309. mqt/core/include/mqt-core/qasm3/Types_fwd.hpp +22 -0
  310. mqt/core/include/mqt-core/qasm3/mqt_core_qasm_export.h +43 -0
  311. mqt/core/include/mqt-core/qasm3/passes/CompilerPass.hpp +22 -0
  312. mqt/core/include/mqt-core/qasm3/passes/ConstEvalPass.hpp +102 -0
  313. mqt/core/include/mqt-core/qasm3/passes/TypeCheckPass.hpp +124 -0
  314. mqt/core/include/mqt-core/qdmi/Driver.hpp +431 -0
  315. mqt/core/include/mqt-core/zx/FunctionalityConstruction.hpp +125 -0
  316. mqt/core/include/mqt-core/zx/Rational.hpp +318 -0
  317. mqt/core/include/mqt-core/zx/Rules.hpp +132 -0
  318. mqt/core/include/mqt-core/zx/Simplify.hpp +182 -0
  319. mqt/core/include/mqt-core/zx/Utils.hpp +212 -0
  320. mqt/core/include/mqt-core/zx/ZXDefinitions.hpp +93 -0
  321. mqt/core/include/mqt-core/zx/ZXDiagram.hpp +480 -0
  322. mqt/core/include/mqt-core/zx/mqt_core_zx_export.h +43 -0
  323. mqt/core/include/nlohmann/adl_serializer.hpp +55 -0
  324. mqt/core/include/nlohmann/byte_container_with_subtype.hpp +103 -0
  325. mqt/core/include/nlohmann/detail/abi_macros.hpp +111 -0
  326. mqt/core/include/nlohmann/detail/conversions/from_json.hpp +577 -0
  327. mqt/core/include/nlohmann/detail/conversions/to_chars.hpp +1118 -0
  328. mqt/core/include/nlohmann/detail/conversions/to_json.hpp +479 -0
  329. mqt/core/include/nlohmann/detail/exceptions.hpp +291 -0
  330. mqt/core/include/nlohmann/detail/hash.hpp +129 -0
  331. mqt/core/include/nlohmann/detail/input/binary_reader.hpp +3068 -0
  332. mqt/core/include/nlohmann/detail/input/input_adapters.hpp +549 -0
  333. mqt/core/include/nlohmann/detail/input/json_sax.hpp +986 -0
  334. mqt/core/include/nlohmann/detail/input/lexer.hpp +1643 -0
  335. mqt/core/include/nlohmann/detail/input/parser.hpp +519 -0
  336. mqt/core/include/nlohmann/detail/input/position_t.hpp +37 -0
  337. mqt/core/include/nlohmann/detail/iterators/internal_iterator.hpp +35 -0
  338. mqt/core/include/nlohmann/detail/iterators/iter_impl.hpp +760 -0
  339. mqt/core/include/nlohmann/detail/iterators/iteration_proxy.hpp +235 -0
  340. mqt/core/include/nlohmann/detail/iterators/iterator_traits.hpp +61 -0
  341. mqt/core/include/nlohmann/detail/iterators/json_reverse_iterator.hpp +130 -0
  342. mqt/core/include/nlohmann/detail/iterators/primitive_iterator.hpp +132 -0
  343. mqt/core/include/nlohmann/detail/json_custom_base_class.hpp +39 -0
  344. mqt/core/include/nlohmann/detail/json_pointer.hpp +988 -0
  345. mqt/core/include/nlohmann/detail/json_ref.hpp +78 -0
  346. mqt/core/include/nlohmann/detail/macro_scope.hpp +595 -0
  347. mqt/core/include/nlohmann/detail/macro_unscope.hpp +46 -0
  348. mqt/core/include/nlohmann/detail/meta/call_std/begin.hpp +17 -0
  349. mqt/core/include/nlohmann/detail/meta/call_std/end.hpp +17 -0
  350. mqt/core/include/nlohmann/detail/meta/cpp_future.hpp +171 -0
  351. mqt/core/include/nlohmann/detail/meta/detected.hpp +70 -0
  352. mqt/core/include/nlohmann/detail/meta/identity_tag.hpp +21 -0
  353. mqt/core/include/nlohmann/detail/meta/is_sax.hpp +159 -0
  354. mqt/core/include/nlohmann/detail/meta/std_fs.hpp +29 -0
  355. mqt/core/include/nlohmann/detail/meta/type_traits.hpp +795 -0
  356. mqt/core/include/nlohmann/detail/meta/void_t.hpp +24 -0
  357. mqt/core/include/nlohmann/detail/output/binary_writer.hpp +1850 -0
  358. mqt/core/include/nlohmann/detail/output/output_adapters.hpp +147 -0
  359. mqt/core/include/nlohmann/detail/output/serializer.hpp +988 -0
  360. mqt/core/include/nlohmann/detail/string_concat.hpp +146 -0
  361. mqt/core/include/nlohmann/detail/string_escape.hpp +72 -0
  362. mqt/core/include/nlohmann/detail/string_utils.hpp +37 -0
  363. mqt/core/include/nlohmann/detail/value_t.hpp +118 -0
  364. mqt/core/include/nlohmann/json.hpp +5306 -0
  365. mqt/core/include/nlohmann/json_fwd.hpp +75 -0
  366. mqt/core/include/nlohmann/ordered_map.hpp +359 -0
  367. mqt/core/include/nlohmann/thirdparty/hedley/hedley.hpp +2045 -0
  368. mqt/core/include/nlohmann/thirdparty/hedley/hedley_undef.hpp +158 -0
  369. mqt/core/include/qdmi/qdmi/client.h +990 -0
  370. mqt/core/include/qdmi/qdmi/constants.h +1139 -0
  371. mqt/core/include/qdmi/qdmi/device.h +602 -0
  372. mqt/core/include/qdmi/qdmi/types.h +78 -0
  373. mqt/core/include/spdlog/async.h +99 -0
  374. mqt/core/include/spdlog/async_logger-inl.h +84 -0
  375. mqt/core/include/spdlog/async_logger.h +74 -0
  376. mqt/core/include/spdlog/cfg/argv.h +40 -0
  377. mqt/core/include/spdlog/cfg/env.h +36 -0
  378. mqt/core/include/spdlog/cfg/helpers-inl.h +107 -0
  379. mqt/core/include/spdlog/cfg/helpers.h +29 -0
  380. mqt/core/include/spdlog/common-inl.h +68 -0
  381. mqt/core/include/spdlog/common.h +406 -0
  382. mqt/core/include/spdlog/details/backtracer-inl.h +63 -0
  383. mqt/core/include/spdlog/details/backtracer.h +45 -0
  384. mqt/core/include/spdlog/details/circular_q.h +115 -0
  385. mqt/core/include/spdlog/details/console_globals.h +28 -0
  386. mqt/core/include/spdlog/details/file_helper-inl.h +153 -0
  387. mqt/core/include/spdlog/details/file_helper.h +61 -0
  388. mqt/core/include/spdlog/details/fmt_helper.h +141 -0
  389. mqt/core/include/spdlog/details/log_msg-inl.h +44 -0
  390. mqt/core/include/spdlog/details/log_msg.h +40 -0
  391. mqt/core/include/spdlog/details/log_msg_buffer-inl.h +54 -0
  392. mqt/core/include/spdlog/details/log_msg_buffer.h +32 -0
  393. mqt/core/include/spdlog/details/mpmc_blocking_q.h +177 -0
  394. mqt/core/include/spdlog/details/null_mutex.h +35 -0
  395. mqt/core/include/spdlog/details/os-inl.h +606 -0
  396. mqt/core/include/spdlog/details/os.h +127 -0
  397. mqt/core/include/spdlog/details/periodic_worker-inl.h +26 -0
  398. mqt/core/include/spdlog/details/periodic_worker.h +58 -0
  399. mqt/core/include/spdlog/details/registry-inl.h +270 -0
  400. mqt/core/include/spdlog/details/registry.h +131 -0
  401. mqt/core/include/spdlog/details/synchronous_factory.h +22 -0
  402. mqt/core/include/spdlog/details/tcp_client-windows.h +135 -0
  403. mqt/core/include/spdlog/details/tcp_client.h +127 -0
  404. mqt/core/include/spdlog/details/thread_pool-inl.h +126 -0
  405. mqt/core/include/spdlog/details/thread_pool.h +117 -0
  406. mqt/core/include/spdlog/details/udp_client-windows.h +98 -0
  407. mqt/core/include/spdlog/details/udp_client.h +81 -0
  408. mqt/core/include/spdlog/details/windows_include.h +11 -0
  409. mqt/core/include/spdlog/fmt/bin_to_hex.h +224 -0
  410. mqt/core/include/spdlog/fmt/bundled/args.h +220 -0
  411. mqt/core/include/spdlog/fmt/bundled/base.h +2989 -0
  412. mqt/core/include/spdlog/fmt/bundled/chrono.h +2330 -0
  413. mqt/core/include/spdlog/fmt/bundled/color.h +637 -0
  414. mqt/core/include/spdlog/fmt/bundled/compile.h +539 -0
  415. mqt/core/include/spdlog/fmt/bundled/core.h +5 -0
  416. mqt/core/include/spdlog/fmt/bundled/fmt.license.rst +27 -0
  417. mqt/core/include/spdlog/fmt/bundled/format-inl.h +1948 -0
  418. mqt/core/include/spdlog/fmt/bundled/format.h +4244 -0
  419. mqt/core/include/spdlog/fmt/bundled/os.h +427 -0
  420. mqt/core/include/spdlog/fmt/bundled/ostream.h +167 -0
  421. mqt/core/include/spdlog/fmt/bundled/printf.h +633 -0
  422. mqt/core/include/spdlog/fmt/bundled/ranges.h +850 -0
  423. mqt/core/include/spdlog/fmt/bundled/std.h +728 -0
  424. mqt/core/include/spdlog/fmt/bundled/xchar.h +369 -0
  425. mqt/core/include/spdlog/fmt/chrono.h +23 -0
  426. mqt/core/include/spdlog/fmt/compile.h +23 -0
  427. mqt/core/include/spdlog/fmt/fmt.h +30 -0
  428. mqt/core/include/spdlog/fmt/ostr.h +23 -0
  429. mqt/core/include/spdlog/fmt/ranges.h +23 -0
  430. mqt/core/include/spdlog/fmt/std.h +24 -0
  431. mqt/core/include/spdlog/fmt/xchar.h +23 -0
  432. mqt/core/include/spdlog/formatter.h +17 -0
  433. mqt/core/include/spdlog/fwd.h +18 -0
  434. mqt/core/include/spdlog/logger-inl.h +198 -0
  435. mqt/core/include/spdlog/logger.h +379 -0
  436. mqt/core/include/spdlog/mdc.h +52 -0
  437. mqt/core/include/spdlog/pattern_formatter-inl.h +1340 -0
  438. mqt/core/include/spdlog/pattern_formatter.h +118 -0
  439. mqt/core/include/spdlog/sinks/android_sink.h +137 -0
  440. mqt/core/include/spdlog/sinks/ansicolor_sink-inl.h +142 -0
  441. mqt/core/include/spdlog/sinks/ansicolor_sink.h +116 -0
  442. mqt/core/include/spdlog/sinks/base_sink-inl.h +59 -0
  443. mqt/core/include/spdlog/sinks/base_sink.h +51 -0
  444. mqt/core/include/spdlog/sinks/basic_file_sink-inl.h +48 -0
  445. mqt/core/include/spdlog/sinks/basic_file_sink.h +66 -0
  446. mqt/core/include/spdlog/sinks/callback_sink.h +56 -0
  447. mqt/core/include/spdlog/sinks/daily_file_sink.h +254 -0
  448. mqt/core/include/spdlog/sinks/dist_sink.h +81 -0
  449. mqt/core/include/spdlog/sinks/dup_filter_sink.h +91 -0
  450. mqt/core/include/spdlog/sinks/hourly_file_sink.h +193 -0
  451. mqt/core/include/spdlog/sinks/kafka_sink.h +119 -0
  452. mqt/core/include/spdlog/sinks/mongo_sink.h +108 -0
  453. mqt/core/include/spdlog/sinks/msvc_sink.h +68 -0
  454. mqt/core/include/spdlog/sinks/null_sink.h +41 -0
  455. mqt/core/include/spdlog/sinks/ostream_sink.h +43 -0
  456. mqt/core/include/spdlog/sinks/qt_sinks.h +304 -0
  457. mqt/core/include/spdlog/sinks/ringbuffer_sink.h +67 -0
  458. mqt/core/include/spdlog/sinks/rotating_file_sink-inl.h +179 -0
  459. mqt/core/include/spdlog/sinks/rotating_file_sink.h +93 -0
  460. mqt/core/include/spdlog/sinks/sink-inl.h +22 -0
  461. mqt/core/include/spdlog/sinks/sink.h +34 -0
  462. mqt/core/include/spdlog/sinks/stdout_color_sinks-inl.h +38 -0
  463. mqt/core/include/spdlog/sinks/stdout_color_sinks.h +49 -0
  464. mqt/core/include/spdlog/sinks/stdout_sinks-inl.h +127 -0
  465. mqt/core/include/spdlog/sinks/stdout_sinks.h +84 -0
  466. mqt/core/include/spdlog/sinks/syslog_sink.h +104 -0
  467. mqt/core/include/spdlog/sinks/systemd_sink.h +121 -0
  468. mqt/core/include/spdlog/sinks/tcp_sink.h +75 -0
  469. mqt/core/include/spdlog/sinks/udp_sink.h +69 -0
  470. mqt/core/include/spdlog/sinks/win_eventlog_sink.h +260 -0
  471. mqt/core/include/spdlog/sinks/wincolor_sink-inl.h +172 -0
  472. mqt/core/include/spdlog/sinks/wincolor_sink.h +82 -0
  473. mqt/core/include/spdlog/spdlog-inl.h +96 -0
  474. mqt/core/include/spdlog/spdlog.h +357 -0
  475. mqt/core/include/spdlog/stopwatch.h +66 -0
  476. mqt/core/include/spdlog/tweakme.h +148 -0
  477. mqt/core/include/spdlog/version.h +11 -0
  478. mqt/core/ir/__init__.pyi +2078 -0
  479. mqt/core/ir/operations.pyi +1011 -0
  480. mqt/core/ir/registers.pyi +91 -0
  481. mqt/core/ir/symbolic.pyi +177 -0
  482. mqt/core/ir.cp313t-win_amd64.pyd +0 -0
  483. mqt/core/lib/mqt-core-algorithms.lib +0 -0
  484. mqt/core/lib/mqt-core-circuit-optimizer.lib +0 -0
  485. mqt/core/lib/mqt-core-dd.lib +0 -0
  486. mqt/core/lib/mqt-core-ds.lib +0 -0
  487. mqt/core/lib/mqt-core-fomac.lib +0 -0
  488. mqt/core/lib/mqt-core-ir.lib +0 -0
  489. mqt/core/lib/mqt-core-na-fomac.lib +0 -0
  490. mqt/core/lib/mqt-core-na.lib +0 -0
  491. mqt/core/lib/mqt-core-qasm.lib +0 -0
  492. mqt/core/lib/mqt-core-qdmi-driver.lib +0 -0
  493. mqt/core/lib/mqt-core-qdmi-na-device-gen.lib +0 -0
  494. mqt/core/lib/mqt-core-qdmi-na-device.lib +0 -0
  495. mqt/core/lib/mqt-core-zx.lib +0 -0
  496. mqt/core/lib/pkgconfig/spdlog.pc +13 -0
  497. mqt/core/lib/spdlog.lib +0 -0
  498. mqt/core/na/__init__.py +12 -0
  499. mqt/core/na/fomac.cp313t-win_amd64.pyd +0 -0
  500. mqt/core/na/fomac.pyi +117 -0
  501. mqt/core/nlohmann_json.natvis +278 -0
  502. mqt/core/plugins/__init__.py +9 -0
  503. mqt/core/plugins/qiskit/__init__.py +19 -0
  504. mqt/core/plugins/qiskit/mqt_to_qiskit.py +420 -0
  505. mqt/core/plugins/qiskit/qiskit_to_mqt.py +562 -0
  506. mqt/core/py.typed +2 -0
  507. mqt/core/share/cmake/mqt-core/AddMQTPythonBinding.cmake +55 -0
  508. mqt/core/share/cmake/mqt-core/Cache.cmake +33 -0
  509. mqt/core/share/cmake/mqt-core/FindGMP.cmake +103 -0
  510. mqt/core/share/cmake/mqt-core/PackageAddTest.cmake +46 -0
  511. mqt/core/share/cmake/mqt-core/PreventInSourceBuilds.cmake +25 -0
  512. mqt/core/share/cmake/mqt-core/StandardProjectSettings.cmake +87 -0
  513. mqt/core/share/cmake/mqt-core/mqt-core-config-version.cmake +85 -0
  514. mqt/core/share/cmake/mqt-core/mqt-core-config.cmake +52 -0
  515. mqt/core/share/cmake/mqt-core/mqt-core-targets-release.cmake +141 -0
  516. mqt/core/share/cmake/mqt-core/mqt-core-targets.cmake +445 -0
  517. mqt/core/share/cmake/nlohmann_json/nlohmann_jsonConfig.cmake +15 -0
  518. mqt/core/share/cmake/nlohmann_json/nlohmann_jsonConfigVersion.cmake +20 -0
  519. mqt/core/share/cmake/nlohmann_json/nlohmann_jsonTargets.cmake +110 -0
  520. mqt/core/share/cmake/qdmi/Cache.cmake +44 -0
  521. mqt/core/share/cmake/qdmi/PrefixHandling.cmake +78 -0
  522. mqt/core/share/cmake/qdmi/prefix_defs.txt +26 -0
  523. mqt/core/share/cmake/qdmi/qdmi-config-version.cmake +85 -0
  524. mqt/core/share/cmake/qdmi/qdmi-config.cmake +42 -0
  525. mqt/core/share/cmake/qdmi/qdmi-targets.cmake +129 -0
  526. mqt/core/share/cmake/spdlog/spdlogConfig.cmake +44 -0
  527. mqt/core/share/cmake/spdlog/spdlogConfigTargets-release.cmake +19 -0
  528. mqt/core/share/cmake/spdlog/spdlogConfigTargets.cmake +121 -0
  529. mqt/core/share/cmake/spdlog/spdlogConfigVersion.cmake +65 -0
  530. mqt/core/share/pkgconfig/nlohmann_json.pc +7 -0
  531. mqt_core-3.3.2.dist-info/DELVEWHEEL +2 -0
  532. mqt_core-3.3.2.dist-info/METADATA +210 -0
  533. mqt_core-3.3.2.dist-info/RECORD +537 -0
  534. mqt_core-3.3.2.dist-info/WHEEL +5 -0
  535. mqt_core-3.3.2.dist-info/entry_points.txt +4 -0
  536. mqt_core-3.3.2.dist-info/licenses/LICENSE.md +22 -0
  537. mqt_core.libs/msvcp140.dll +0 -0
@@ -0,0 +1,988 @@
1
+ // __ _____ _____ _____
2
+ // __| | __| | | | JSON for Modern C++
3
+ // | | |__ | | | | | | version 3.12.0
4
+ // |_____|_____|_____|_|___| https://github.com/nlohmann/json
5
+ //
6
+ // SPDX-FileCopyrightText: 2008 - 2009 Björn Hoehrmann <bjoern@hoehrmann.de>
7
+ // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
8
+ // SPDX-License-Identifier: MIT
9
+
10
+ #pragma once
11
+
12
+ #include <algorithm> // reverse, remove, fill, find, none_of
13
+ #include <array> // array
14
+ #include <clocale> // localeconv, lconv
15
+ #include <cmath> // labs, isfinite, isnan, signbit
16
+ #include <cstddef> // size_t, ptrdiff_t
17
+ #include <cstdint> // uint8_t
18
+ #include <cstdio> // snprintf
19
+ #include <limits> // numeric_limits
20
+ #include <string> // string, char_traits
21
+ #include <iomanip> // setfill, setw
22
+ #include <type_traits> // is_same
23
+ #include <utility> // move
24
+
25
+ #include <nlohmann/detail/conversions/to_chars.hpp>
26
+ #include <nlohmann/detail/exceptions.hpp>
27
+ #include <nlohmann/detail/macro_scope.hpp>
28
+ #include <nlohmann/detail/meta/cpp_future.hpp>
29
+ #include <nlohmann/detail/output/binary_writer.hpp>
30
+ #include <nlohmann/detail/output/output_adapters.hpp>
31
+ #include <nlohmann/detail/string_concat.hpp>
32
+ #include <nlohmann/detail/value_t.hpp>
33
+
34
+ NLOHMANN_JSON_NAMESPACE_BEGIN
35
+ namespace detail
36
+ {
37
+
38
+ ///////////////////
39
+ // serialization //
40
+ ///////////////////
41
+
42
+ /// how to treat decoding errors
43
+ enum class error_handler_t
44
+ {
45
+ strict, ///< throw a type_error exception in case of invalid UTF-8
46
+ replace, ///< replace invalid UTF-8 sequences with U+FFFD
47
+ ignore ///< ignore invalid UTF-8 sequences
48
+ };
49
+
50
+ template<typename BasicJsonType>
51
+ class serializer
52
+ {
53
+ using string_t = typename BasicJsonType::string_t;
54
+ using number_float_t = typename BasicJsonType::number_float_t;
55
+ using number_integer_t = typename BasicJsonType::number_integer_t;
56
+ using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
57
+ using binary_char_t = typename BasicJsonType::binary_t::value_type;
58
+ static constexpr std::uint8_t UTF8_ACCEPT = 0;
59
+ static constexpr std::uint8_t UTF8_REJECT = 1;
60
+
61
+ public:
62
+ /*!
63
+ @param[in] s output stream to serialize to
64
+ @param[in] ichar indentation character to use
65
+ @param[in] error_handler_ how to react on decoding errors
66
+ */
67
+ serializer(output_adapter_t<char> s, const char ichar,
68
+ error_handler_t error_handler_ = error_handler_t::strict)
69
+ : o(std::move(s))
70
+ , loc(std::localeconv())
71
+ , thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
72
+ , decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
73
+ , indent_char(ichar)
74
+ , indent_string(512, indent_char)
75
+ , error_handler(error_handler_)
76
+ {}
77
+
78
+ // delete because of pointer members
79
+ serializer(const serializer&) = delete;
80
+ serializer& operator=(const serializer&) = delete;
81
+ serializer(serializer&&) = delete;
82
+ serializer& operator=(serializer&&) = delete;
83
+ ~serializer() = default;
84
+
85
+ /*!
86
+ @brief internal implementation of the serialization function
87
+
88
+ This function is called by the public member function dump and organizes
89
+ the serialization internally. The indentation level is propagated as
90
+ additional parameter. In case of arrays and objects, the function is
91
+ called recursively.
92
+
93
+ - strings and object keys are escaped using `escape_string()`
94
+ - integer numbers are converted implicitly via `operator<<`
95
+ - floating-point numbers are converted to a string using `"%g"` format
96
+ - binary values are serialized as objects containing the subtype and the
97
+ byte array
98
+
99
+ @param[in] val value to serialize
100
+ @param[in] pretty_print whether the output shall be pretty-printed
101
+ @param[in] ensure_ascii If @a ensure_ascii is true, all non-ASCII characters
102
+ in the output are escaped with `\uXXXX` sequences, and the result consists
103
+ of ASCII characters only.
104
+ @param[in] indent_step the indent level
105
+ @param[in] current_indent the current indent level (only used internally)
106
+ */
107
+ void dump(const BasicJsonType& val,
108
+ const bool pretty_print,
109
+ const bool ensure_ascii,
110
+ const unsigned int indent_step,
111
+ const unsigned int current_indent = 0)
112
+ {
113
+ switch (val.m_data.m_type)
114
+ {
115
+ case value_t::object:
116
+ {
117
+ if (val.m_data.m_value.object->empty())
118
+ {
119
+ o->write_characters("{}", 2);
120
+ return;
121
+ }
122
+
123
+ if (pretty_print)
124
+ {
125
+ o->write_characters("{\n", 2);
126
+
127
+ // variable to hold indentation for recursive calls
128
+ const auto new_indent = current_indent + indent_step;
129
+ if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
130
+ {
131
+ indent_string.resize(indent_string.size() * 2, ' ');
132
+ }
133
+
134
+ // first n-1 elements
135
+ auto i = val.m_data.m_value.object->cbegin();
136
+ for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
137
+ {
138
+ o->write_characters(indent_string.c_str(), new_indent);
139
+ o->write_character('\"');
140
+ dump_escaped(i->first, ensure_ascii);
141
+ o->write_characters("\": ", 3);
142
+ dump(i->second, true, ensure_ascii, indent_step, new_indent);
143
+ o->write_characters(",\n", 2);
144
+ }
145
+
146
+ // last element
147
+ JSON_ASSERT(i != val.m_data.m_value.object->cend());
148
+ JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
149
+ o->write_characters(indent_string.c_str(), new_indent);
150
+ o->write_character('\"');
151
+ dump_escaped(i->first, ensure_ascii);
152
+ o->write_characters("\": ", 3);
153
+ dump(i->second, true, ensure_ascii, indent_step, new_indent);
154
+
155
+ o->write_character('\n');
156
+ o->write_characters(indent_string.c_str(), current_indent);
157
+ o->write_character('}');
158
+ }
159
+ else
160
+ {
161
+ o->write_character('{');
162
+
163
+ // first n-1 elements
164
+ auto i = val.m_data.m_value.object->cbegin();
165
+ for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
166
+ {
167
+ o->write_character('\"');
168
+ dump_escaped(i->first, ensure_ascii);
169
+ o->write_characters("\":", 2);
170
+ dump(i->second, false, ensure_ascii, indent_step, current_indent);
171
+ o->write_character(',');
172
+ }
173
+
174
+ // last element
175
+ JSON_ASSERT(i != val.m_data.m_value.object->cend());
176
+ JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
177
+ o->write_character('\"');
178
+ dump_escaped(i->first, ensure_ascii);
179
+ o->write_characters("\":", 2);
180
+ dump(i->second, false, ensure_ascii, indent_step, current_indent);
181
+
182
+ o->write_character('}');
183
+ }
184
+
185
+ return;
186
+ }
187
+
188
+ case value_t::array:
189
+ {
190
+ if (val.m_data.m_value.array->empty())
191
+ {
192
+ o->write_characters("[]", 2);
193
+ return;
194
+ }
195
+
196
+ if (pretty_print)
197
+ {
198
+ o->write_characters("[\n", 2);
199
+
200
+ // variable to hold indentation for recursive calls
201
+ const auto new_indent = current_indent + indent_step;
202
+ if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
203
+ {
204
+ indent_string.resize(indent_string.size() * 2, ' ');
205
+ }
206
+
207
+ // first n-1 elements
208
+ for (auto i = val.m_data.m_value.array->cbegin();
209
+ i != val.m_data.m_value.array->cend() - 1; ++i)
210
+ {
211
+ o->write_characters(indent_string.c_str(), new_indent);
212
+ dump(*i, true, ensure_ascii, indent_step, new_indent);
213
+ o->write_characters(",\n", 2);
214
+ }
215
+
216
+ // last element
217
+ JSON_ASSERT(!val.m_data.m_value.array->empty());
218
+ o->write_characters(indent_string.c_str(), new_indent);
219
+ dump(val.m_data.m_value.array->back(), true, ensure_ascii, indent_step, new_indent);
220
+
221
+ o->write_character('\n');
222
+ o->write_characters(indent_string.c_str(), current_indent);
223
+ o->write_character(']');
224
+ }
225
+ else
226
+ {
227
+ o->write_character('[');
228
+
229
+ // first n-1 elements
230
+ for (auto i = val.m_data.m_value.array->cbegin();
231
+ i != val.m_data.m_value.array->cend() - 1; ++i)
232
+ {
233
+ dump(*i, false, ensure_ascii, indent_step, current_indent);
234
+ o->write_character(',');
235
+ }
236
+
237
+ // last element
238
+ JSON_ASSERT(!val.m_data.m_value.array->empty());
239
+ dump(val.m_data.m_value.array->back(), false, ensure_ascii, indent_step, current_indent);
240
+
241
+ o->write_character(']');
242
+ }
243
+
244
+ return;
245
+ }
246
+
247
+ case value_t::string:
248
+ {
249
+ o->write_character('\"');
250
+ dump_escaped(*val.m_data.m_value.string, ensure_ascii);
251
+ o->write_character('\"');
252
+ return;
253
+ }
254
+
255
+ case value_t::binary:
256
+ {
257
+ if (pretty_print)
258
+ {
259
+ o->write_characters("{\n", 2);
260
+
261
+ // variable to hold indentation for recursive calls
262
+ const auto new_indent = current_indent + indent_step;
263
+ if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
264
+ {
265
+ indent_string.resize(indent_string.size() * 2, ' ');
266
+ }
267
+
268
+ o->write_characters(indent_string.c_str(), new_indent);
269
+
270
+ o->write_characters("\"bytes\": [", 10);
271
+
272
+ if (!val.m_data.m_value.binary->empty())
273
+ {
274
+ for (auto i = val.m_data.m_value.binary->cbegin();
275
+ i != val.m_data.m_value.binary->cend() - 1; ++i)
276
+ {
277
+ dump_integer(*i);
278
+ o->write_characters(", ", 2);
279
+ }
280
+ dump_integer(val.m_data.m_value.binary->back());
281
+ }
282
+
283
+ o->write_characters("],\n", 3);
284
+ o->write_characters(indent_string.c_str(), new_indent);
285
+
286
+ o->write_characters("\"subtype\": ", 11);
287
+ if (val.m_data.m_value.binary->has_subtype())
288
+ {
289
+ dump_integer(val.m_data.m_value.binary->subtype());
290
+ }
291
+ else
292
+ {
293
+ o->write_characters("null", 4);
294
+ }
295
+ o->write_character('\n');
296
+ o->write_characters(indent_string.c_str(), current_indent);
297
+ o->write_character('}');
298
+ }
299
+ else
300
+ {
301
+ o->write_characters("{\"bytes\":[", 10);
302
+
303
+ if (!val.m_data.m_value.binary->empty())
304
+ {
305
+ for (auto i = val.m_data.m_value.binary->cbegin();
306
+ i != val.m_data.m_value.binary->cend() - 1; ++i)
307
+ {
308
+ dump_integer(*i);
309
+ o->write_character(',');
310
+ }
311
+ dump_integer(val.m_data.m_value.binary->back());
312
+ }
313
+
314
+ o->write_characters("],\"subtype\":", 12);
315
+ if (val.m_data.m_value.binary->has_subtype())
316
+ {
317
+ dump_integer(val.m_data.m_value.binary->subtype());
318
+ o->write_character('}');
319
+ }
320
+ else
321
+ {
322
+ o->write_characters("null}", 5);
323
+ }
324
+ }
325
+ return;
326
+ }
327
+
328
+ case value_t::boolean:
329
+ {
330
+ if (val.m_data.m_value.boolean)
331
+ {
332
+ o->write_characters("true", 4);
333
+ }
334
+ else
335
+ {
336
+ o->write_characters("false", 5);
337
+ }
338
+ return;
339
+ }
340
+
341
+ case value_t::number_integer:
342
+ {
343
+ dump_integer(val.m_data.m_value.number_integer);
344
+ return;
345
+ }
346
+
347
+ case value_t::number_unsigned:
348
+ {
349
+ dump_integer(val.m_data.m_value.number_unsigned);
350
+ return;
351
+ }
352
+
353
+ case value_t::number_float:
354
+ {
355
+ dump_float(val.m_data.m_value.number_float);
356
+ return;
357
+ }
358
+
359
+ case value_t::discarded:
360
+ {
361
+ o->write_characters("<discarded>", 11);
362
+ return;
363
+ }
364
+
365
+ case value_t::null:
366
+ {
367
+ o->write_characters("null", 4);
368
+ return;
369
+ }
370
+
371
+ default: // LCOV_EXCL_LINE
372
+ JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
373
+ }
374
+ }
375
+
376
+ JSON_PRIVATE_UNLESS_TESTED:
377
+ /*!
378
+ @brief dump escaped string
379
+
380
+ Escape a string by replacing certain special characters by a sequence of an
381
+ escape character (backslash) and another character and other control
382
+ characters by a sequence of "\u" followed by a four-digit hex
383
+ representation. The escaped string is written to output stream @a o.
384
+
385
+ @param[in] s the string to escape
386
+ @param[in] ensure_ascii whether to escape non-ASCII characters with
387
+ \uXXXX sequences
388
+
389
+ @complexity Linear in the length of string @a s.
390
+ */
391
+ void dump_escaped(const string_t& s, const bool ensure_ascii)
392
+ {
393
+ std::uint32_t codepoint{};
394
+ std::uint8_t state = UTF8_ACCEPT;
395
+ std::size_t bytes = 0; // number of bytes written to string_buffer
396
+
397
+ // number of bytes written at the point of the last valid byte
398
+ std::size_t bytes_after_last_accept = 0;
399
+ std::size_t undumped_chars = 0;
400
+
401
+ for (std::size_t i = 0; i < s.size(); ++i)
402
+ {
403
+ const auto byte = static_cast<std::uint8_t>(s[i]);
404
+
405
+ switch (decode(state, codepoint, byte))
406
+ {
407
+ case UTF8_ACCEPT: // decode found a new code point
408
+ {
409
+ switch (codepoint)
410
+ {
411
+ case 0x08: // backspace
412
+ {
413
+ string_buffer[bytes++] = '\\';
414
+ string_buffer[bytes++] = 'b';
415
+ break;
416
+ }
417
+
418
+ case 0x09: // horizontal tab
419
+ {
420
+ string_buffer[bytes++] = '\\';
421
+ string_buffer[bytes++] = 't';
422
+ break;
423
+ }
424
+
425
+ case 0x0A: // newline
426
+ {
427
+ string_buffer[bytes++] = '\\';
428
+ string_buffer[bytes++] = 'n';
429
+ break;
430
+ }
431
+
432
+ case 0x0C: // formfeed
433
+ {
434
+ string_buffer[bytes++] = '\\';
435
+ string_buffer[bytes++] = 'f';
436
+ break;
437
+ }
438
+
439
+ case 0x0D: // carriage return
440
+ {
441
+ string_buffer[bytes++] = '\\';
442
+ string_buffer[bytes++] = 'r';
443
+ break;
444
+ }
445
+
446
+ case 0x22: // quotation mark
447
+ {
448
+ string_buffer[bytes++] = '\\';
449
+ string_buffer[bytes++] = '\"';
450
+ break;
451
+ }
452
+
453
+ case 0x5C: // reverse solidus
454
+ {
455
+ string_buffer[bytes++] = '\\';
456
+ string_buffer[bytes++] = '\\';
457
+ break;
458
+ }
459
+
460
+ default:
461
+ {
462
+ // escape control characters (0x00..0x1F) or, if
463
+ // ensure_ascii parameter is used, non-ASCII characters
464
+ if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
465
+ {
466
+ if (codepoint <= 0xFFFF)
467
+ {
468
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
469
+ static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x",
470
+ static_cast<std::uint16_t>(codepoint)));
471
+ bytes += 6;
472
+ }
473
+ else
474
+ {
475
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
476
+ static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x",
477
+ static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)),
478
+ static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu))));
479
+ bytes += 12;
480
+ }
481
+ }
482
+ else
483
+ {
484
+ // copy byte to buffer (all previous bytes
485
+ // been copied have in default case above)
486
+ string_buffer[bytes++] = s[i];
487
+ }
488
+ break;
489
+ }
490
+ }
491
+
492
+ // write buffer and reset index; there must be 13 bytes
493
+ // left, as this is the maximal number of bytes to be
494
+ // written ("\uxxxx\uxxxx\0") for one code point
495
+ if (string_buffer.size() - bytes < 13)
496
+ {
497
+ o->write_characters(string_buffer.data(), bytes);
498
+ bytes = 0;
499
+ }
500
+
501
+ // remember the byte position of this accept
502
+ bytes_after_last_accept = bytes;
503
+ undumped_chars = 0;
504
+ break;
505
+ }
506
+
507
+ case UTF8_REJECT: // decode found invalid UTF-8 byte
508
+ {
509
+ switch (error_handler)
510
+ {
511
+ case error_handler_t::strict:
512
+ {
513
+ JSON_THROW(type_error::create(316, concat("invalid UTF-8 byte at index ", std::to_string(i), ": 0x", hex_bytes(byte | 0)), nullptr));
514
+ }
515
+
516
+ case error_handler_t::ignore:
517
+ case error_handler_t::replace:
518
+ {
519
+ // in case we saw this character the first time, we
520
+ // would like to read it again, because the byte
521
+ // may be OK for itself, but just not OK for the
522
+ // previous sequence
523
+ if (undumped_chars > 0)
524
+ {
525
+ --i;
526
+ }
527
+
528
+ // reset length buffer to the last accepted index;
529
+ // thus removing/ignoring the invalid characters
530
+ bytes = bytes_after_last_accept;
531
+
532
+ if (error_handler == error_handler_t::replace)
533
+ {
534
+ // add a replacement character
535
+ if (ensure_ascii)
536
+ {
537
+ string_buffer[bytes++] = '\\';
538
+ string_buffer[bytes++] = 'u';
539
+ string_buffer[bytes++] = 'f';
540
+ string_buffer[bytes++] = 'f';
541
+ string_buffer[bytes++] = 'f';
542
+ string_buffer[bytes++] = 'd';
543
+ }
544
+ else
545
+ {
546
+ string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xEF');
547
+ string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xBF');
548
+ string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xBD');
549
+ }
550
+
551
+ // write buffer and reset index; there must be 13 bytes
552
+ // left, as this is the maximal number of bytes to be
553
+ // written ("\uxxxx\uxxxx\0") for one code point
554
+ if (string_buffer.size() - bytes < 13)
555
+ {
556
+ o->write_characters(string_buffer.data(), bytes);
557
+ bytes = 0;
558
+ }
559
+
560
+ bytes_after_last_accept = bytes;
561
+ }
562
+
563
+ undumped_chars = 0;
564
+
565
+ // continue processing the string
566
+ state = UTF8_ACCEPT;
567
+ break;
568
+ }
569
+
570
+ default: // LCOV_EXCL_LINE
571
+ JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
572
+ }
573
+ break;
574
+ }
575
+
576
+ default: // decode found yet incomplete multi-byte code point
577
+ {
578
+ if (!ensure_ascii)
579
+ {
580
+ // code point will not be escaped - copy byte to buffer
581
+ string_buffer[bytes++] = s[i];
582
+ }
583
+ ++undumped_chars;
584
+ break;
585
+ }
586
+ }
587
+ }
588
+
589
+ // we finished processing the string
590
+ if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
591
+ {
592
+ // write buffer
593
+ if (bytes > 0)
594
+ {
595
+ o->write_characters(string_buffer.data(), bytes);
596
+ }
597
+ }
598
+ else
599
+ {
600
+ // we finish reading, but do not accept: string was incomplete
601
+ switch (error_handler)
602
+ {
603
+ case error_handler_t::strict:
604
+ {
605
+ JSON_THROW(type_error::create(316, concat("incomplete UTF-8 string; last byte: 0x", hex_bytes(static_cast<std::uint8_t>(s.back() | 0))), nullptr));
606
+ }
607
+
608
+ case error_handler_t::ignore:
609
+ {
610
+ // write all accepted bytes
611
+ o->write_characters(string_buffer.data(), bytes_after_last_accept);
612
+ break;
613
+ }
614
+
615
+ case error_handler_t::replace:
616
+ {
617
+ // write all accepted bytes
618
+ o->write_characters(string_buffer.data(), bytes_after_last_accept);
619
+ // add a replacement character
620
+ if (ensure_ascii)
621
+ {
622
+ o->write_characters("\\ufffd", 6);
623
+ }
624
+ else
625
+ {
626
+ o->write_characters("\xEF\xBF\xBD", 3);
627
+ }
628
+ break;
629
+ }
630
+
631
+ default: // LCOV_EXCL_LINE
632
+ JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
633
+ }
634
+ }
635
+ }
636
+
637
+ private:
638
+ /*!
639
+ @brief count digits
640
+
641
+ Count the number of decimal (base 10) digits for an input unsigned integer.
642
+
643
+ @param[in] x unsigned integer number to count its digits
644
+ @return number of decimal digits
645
+ */
646
+ unsigned int count_digits(number_unsigned_t x) noexcept
647
+ {
648
+ unsigned int n_digits = 1;
649
+ for (;;)
650
+ {
651
+ if (x < 10)
652
+ {
653
+ return n_digits;
654
+ }
655
+ if (x < 100)
656
+ {
657
+ return n_digits + 1;
658
+ }
659
+ if (x < 1000)
660
+ {
661
+ return n_digits + 2;
662
+ }
663
+ if (x < 10000)
664
+ {
665
+ return n_digits + 3;
666
+ }
667
+ x = x / 10000u;
668
+ n_digits += 4;
669
+ }
670
+ }
671
+
672
+ /*!
673
+ * @brief convert a byte to a uppercase hex representation
674
+ * @param[in] byte byte to represent
675
+ * @return representation ("00".."FF")
676
+ */
677
+ static std::string hex_bytes(std::uint8_t byte)
678
+ {
679
+ std::string result = "FF";
680
+ constexpr const char* nibble_to_hex = "0123456789ABCDEF";
681
+ result[0] = nibble_to_hex[byte / 16];
682
+ result[1] = nibble_to_hex[byte % 16];
683
+ return result;
684
+ }
685
+
686
+ // templates to avoid warnings about useless casts
687
+ template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value, int> = 0>
688
+ bool is_negative_number(NumberType x)
689
+ {
690
+ return x < 0;
691
+ }
692
+
693
+ template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value, int > = 0 >
694
+ bool is_negative_number(NumberType /*unused*/)
695
+ {
696
+ return false;
697
+ }
698
+
699
+ /*!
700
+ @brief dump an integer
701
+
702
+ Dump a given integer to output stream @a o. Works internally with
703
+ @a number_buffer.
704
+
705
+ @param[in] x integer number (signed or unsigned) to dump
706
+ @tparam NumberType either @a number_integer_t or @a number_unsigned_t
707
+ */
708
+ template < typename NumberType, detail::enable_if_t <
709
+ std::is_integral<NumberType>::value ||
710
+ std::is_same<NumberType, number_unsigned_t>::value ||
711
+ std::is_same<NumberType, number_integer_t>::value ||
712
+ std::is_same<NumberType, binary_char_t>::value,
713
+ int > = 0 >
714
+ void dump_integer(NumberType x)
715
+ {
716
+ static constexpr std::array<std::array<char, 2>, 100> digits_to_99
717
+ {
718
+ {
719
+ {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},
720
+ {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
721
+ {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
722
+ {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
723
+ {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
724
+ {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
725
+ {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
726
+ {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
727
+ {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
728
+ {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
729
+ }
730
+ };
731
+
732
+ // special case for "0"
733
+ if (x == 0)
734
+ {
735
+ o->write_character('0');
736
+ return;
737
+ }
738
+
739
+ // use a pointer to fill the buffer
740
+ auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg)
741
+
742
+ number_unsigned_t abs_value;
743
+
744
+ unsigned int n_chars{};
745
+
746
+ if (is_negative_number(x))
747
+ {
748
+ *buffer_ptr = '-';
749
+ abs_value = remove_sign(static_cast<number_integer_t>(x));
750
+
751
+ // account one more byte for the minus sign
752
+ n_chars = 1 + count_digits(abs_value);
753
+ }
754
+ else
755
+ {
756
+ abs_value = static_cast<number_unsigned_t>(x);
757
+ n_chars = count_digits(abs_value);
758
+ }
759
+
760
+ // spare 1 byte for '\0'
761
+ JSON_ASSERT(n_chars < number_buffer.size() - 1);
762
+
763
+ // jump to the end to generate the string from backward,
764
+ // so we later avoid reversing the result
765
+ buffer_ptr += n_chars;
766
+
767
+ // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu
768
+ // See: https://www.youtube.com/watch?v=o4-CwDo2zpg
769
+ while (abs_value >= 100)
770
+ {
771
+ const auto digits_index = static_cast<unsigned>((abs_value % 100));
772
+ abs_value /= 100;
773
+ *(--buffer_ptr) = digits_to_99[digits_index][1];
774
+ *(--buffer_ptr) = digits_to_99[digits_index][0];
775
+ }
776
+
777
+ if (abs_value >= 10)
778
+ {
779
+ const auto digits_index = static_cast<unsigned>(abs_value);
780
+ *(--buffer_ptr) = digits_to_99[digits_index][1];
781
+ *(--buffer_ptr) = digits_to_99[digits_index][0];
782
+ }
783
+ else
784
+ {
785
+ *(--buffer_ptr) = static_cast<char>('0' + abs_value);
786
+ }
787
+
788
+ o->write_characters(number_buffer.data(), n_chars);
789
+ }
790
+
791
+ /*!
792
+ @brief dump a floating-point number
793
+
794
+ Dump a given floating-point number to output stream @a o. Works internally
795
+ with @a number_buffer.
796
+
797
+ @param[in] x floating-point number to dump
798
+ */
799
+ void dump_float(number_float_t x)
800
+ {
801
+ // NaN / inf
802
+ if (!std::isfinite(x))
803
+ {
804
+ o->write_characters("null", 4);
805
+ return;
806
+ }
807
+
808
+ // If number_float_t is an IEEE-754 single or double precision number,
809
+ // use the Grisu2 algorithm to produce short numbers which are
810
+ // guaranteed to round-trip, using strtof and strtod, resp.
811
+ //
812
+ // NB: The test below works if <long double> == <double>.
813
+ static constexpr bool is_ieee_single_or_double
814
+ = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) ||
815
+ (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024);
816
+
817
+ dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
818
+ }
819
+
820
+ void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/)
821
+ {
822
+ auto* begin = number_buffer.data();
823
+ auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
824
+
825
+ o->write_characters(begin, static_cast<size_t>(end - begin));
826
+ }
827
+
828
+ void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/)
829
+ {
830
+ // get number of digits for a float -> text -> float round-trip
831
+ static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
832
+
833
+ // the actual conversion
834
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
835
+ std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
836
+
837
+ // negative value indicates an error
838
+ JSON_ASSERT(len > 0);
839
+ // check if buffer was large enough
840
+ JSON_ASSERT(static_cast<std::size_t>(len) < number_buffer.size());
841
+
842
+ // erase thousands separator
843
+ if (thousands_sep != '\0')
844
+ {
845
+ // NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::remove returns an iterator, see https://github.com/nlohmann/json/issues/3081
846
+ const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);
847
+ std::fill(end, number_buffer.end(), '\0');
848
+ JSON_ASSERT((end - number_buffer.begin()) <= len);
849
+ len = (end - number_buffer.begin());
850
+ }
851
+
852
+ // convert decimal point to '.'
853
+ if (decimal_point != '\0' && decimal_point != '.')
854
+ {
855
+ // NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::find returns an iterator, see https://github.com/nlohmann/json/issues/3081
856
+ const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
857
+ if (dec_pos != number_buffer.end())
858
+ {
859
+ *dec_pos = '.';
860
+ }
861
+ }
862
+
863
+ o->write_characters(number_buffer.data(), static_cast<std::size_t>(len));
864
+
865
+ // determine if we need to append ".0"
866
+ const bool value_is_int_like =
867
+ std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
868
+ [](char c)
869
+ {
870
+ return c == '.' || c == 'e';
871
+ });
872
+
873
+ if (value_is_int_like)
874
+ {
875
+ o->write_characters(".0", 2);
876
+ }
877
+ }
878
+
879
+ /*!
880
+ @brief check whether a string is UTF-8 encoded
881
+
882
+ The function checks each byte of a string whether it is UTF-8 encoded. The
883
+ result of the check is stored in the @a state parameter. The function must
884
+ be called initially with state 0 (accept). State 1 means the string must
885
+ be rejected, because the current byte is not allowed. If the string is
886
+ completely processed, but the state is non-zero, the string ended
887
+ prematurely; that is, the last byte indicated more bytes should have
888
+ followed.
889
+
890
+ @param[in,out] state the state of the decoding
891
+ @param[in,out] codep codepoint (valid only if resulting state is UTF8_ACCEPT)
892
+ @param[in] byte next byte to decode
893
+ @return new state
894
+
895
+ @note The function has been edited: a std::array is used.
896
+
897
+ @copyright Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
898
+ @sa http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
899
+ */
900
+ static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept
901
+ {
902
+ static const std::array<std::uint8_t, 400> utf8d =
903
+ {
904
+ {
905
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1F
906
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20..3F
907
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40..5F
908
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60..7F
909
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 80..9F
910
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // A0..BF
911
+ 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C0..DF
912
+ 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF
913
+ 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF
914
+ 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0
915
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, // s1..s2
916
+ 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // s3..s4
917
+ 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, // s5..s6
918
+ 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // s7..s8
919
+ }
920
+ };
921
+
922
+ JSON_ASSERT(byte < utf8d.size());
923
+ const std::uint8_t type = utf8d[byte];
924
+
925
+ codep = (state != UTF8_ACCEPT)
926
+ ? (byte & 0x3fu) | (codep << 6u)
927
+ : (0xFFu >> type) & (byte);
928
+
929
+ const std::size_t index = 256u + (static_cast<size_t>(state) * 16u) + static_cast<size_t>(type);
930
+ JSON_ASSERT(index < utf8d.size());
931
+ state = utf8d[index];
932
+ return state;
933
+ }
934
+
935
+ /*
936
+ * Overload to make the compiler happy while it is instantiating
937
+ * dump_integer for number_unsigned_t.
938
+ * Must never be called.
939
+ */
940
+ number_unsigned_t remove_sign(number_unsigned_t x)
941
+ {
942
+ JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
943
+ return x; // LCOV_EXCL_LINE
944
+ }
945
+
946
+ /*
947
+ * Helper function for dump_integer
948
+ *
949
+ * This function takes a negative signed integer and returns its absolute
950
+ * value as unsigned integer. The plus/minus shuffling is necessary as we can
951
+ * not directly remove the sign of an arbitrary signed integer as the
952
+ * absolute values of INT_MIN and INT_MAX are usually not the same. See
953
+ * #1708 for details.
954
+ */
955
+ number_unsigned_t remove_sign(number_integer_t x) noexcept
956
+ {
957
+ JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression)
958
+ return static_cast<number_unsigned_t>(-(x + 1)) + 1;
959
+ }
960
+
961
+ private:
962
+ /// the output of the serializer
963
+ output_adapter_t<char> o = nullptr;
964
+
965
+ /// a (hopefully) large enough character buffer
966
+ std::array<char, 64> number_buffer{{}};
967
+
968
+ /// the locale
969
+ const std::lconv* loc = nullptr;
970
+ /// the locale's thousand separator character
971
+ const char thousands_sep = '\0';
972
+ /// the locale's decimal point character
973
+ const char decimal_point = '\0';
974
+
975
+ /// string buffer
976
+ std::array<char, 512> string_buffer{{}};
977
+
978
+ /// the indentation character
979
+ const char indent_char;
980
+ /// the indentation string
981
+ string_t indent_string;
982
+
983
+ /// error_handler how to react on decoding errors
984
+ const error_handler_t error_handler;
985
+ };
986
+
987
+ } // namespace detail
988
+ NLOHMANN_JSON_NAMESPACE_END