| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9 |
/****************************************************************************\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10 |
* Note on documentation: The source files contain links to the online * |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11 |
* documentation of the public API at https://json.nlohmann.me. This URL * |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12 |
* contains the most recent documentation and should also be applicable to * |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13 |
* previous versions; documentation for deprecated functions is not * |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14 |
* removed, but marked deprecated. See "Generate documentation" section in * |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15 |
* file docs/README.md. * |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16 |
\****************************************************************************/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18 |
#ifndef INCLUDE_NLOHMANN_JSON_HPP_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19 |
#define INCLUDE_NLOHMANN_JSON_HPP_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21 |
#include <algorithm> // all_of, find, for_each |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22 |
#include <cstddef> // nullptr_t, ptrdiff_t, size_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23 |
#include <functional> // hash, less |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24 |
#include <initializer_list> // initializer_list |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
25 |
#ifndef JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
26 |
#include <iosfwd> // istream, ostream |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
27 |
#endif // JSON_NO_IO |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
28 |
#include <iterator> // random_access_iterator_tag |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
29 |
#include <memory> // unique_ptr |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
30 |
#include <string> // string, stoi, to_string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
31 |
#include <utility> // declval, forward, move, pair, swap |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
32 |
#include <vector> // vector |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
33 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
34 |
// #include <nlohmann/adl_serializer.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
35 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
36 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
37 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
38 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
39 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
40 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
41 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
42 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
43 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
44 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
45 |
#include <utility> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
46 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
47 |
// #include <nlohmann/detail/abi_macros.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
48 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
49 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
50 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
51 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
52 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
53 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
54 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
55 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
56 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
57 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
58 |
// This file contains all macro definitions affecting or depending on the ABI |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
59 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
60 |
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
61 |
#if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
62 |
#if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
63 |
#warning "Already included a different version of the library!" |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
64 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
65 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
66 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
67 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
68 |
#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
69 |
#define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
70 |
#define NLOHMANN_JSON_VERSION_PATCH 3 // NOLINT(modernize-macro-to-enum) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
71 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
72 |
#ifndef JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
73 |
#define JSON_DIAGNOSTICS 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
74 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
75 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
76 |
#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
77 |
#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
78 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
79 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
80 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
81 |
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
82 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
83 |
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
84 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
85 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
86 |
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
87 |
#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
88 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
89 |
#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
90 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
91 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
92 |
#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
93 |
#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
94 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
95 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
96 |
// Construct the namespace ABI tags component |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
97 |
#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
98 |
#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
99 |
NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
100 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
101 |
#define NLOHMANN_JSON_ABI_TAGS \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
102 |
NLOHMANN_JSON_ABI_TAGS_CONCAT( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
103 |
NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
104 |
NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
105 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
106 |
// Construct the namespace version component |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
107 |
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
108 |
_v ## major ## _ ## minor ## _ ## patch |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
109 |
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
110 |
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
111 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
112 |
#if NLOHMANN_JSON_NAMESPACE_NO_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
113 |
#define NLOHMANN_JSON_NAMESPACE_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
114 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
115 |
#define NLOHMANN_JSON_NAMESPACE_VERSION \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
116 |
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
117 |
NLOHMANN_JSON_VERSION_MINOR, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
118 |
NLOHMANN_JSON_VERSION_PATCH) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
119 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
120 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
121 |
// Combine namespace components |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
122 |
#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
123 |
#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
124 |
NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
125 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
126 |
#ifndef NLOHMANN_JSON_NAMESPACE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
127 |
#define NLOHMANN_JSON_NAMESPACE \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
128 |
nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
129 |
NLOHMANN_JSON_ABI_TAGS, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
130 |
NLOHMANN_JSON_NAMESPACE_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
131 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
132 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
133 |
#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
134 |
#define NLOHMANN_JSON_NAMESPACE_BEGIN \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
135 |
namespace nlohmann \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
136 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
137 |
inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
138 |
NLOHMANN_JSON_ABI_TAGS, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
139 |
NLOHMANN_JSON_NAMESPACE_VERSION) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
140 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
141 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
142 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
143 |
#ifndef NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
144 |
#define NLOHMANN_JSON_NAMESPACE_END \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
145 |
} /* namespace (inline namespace) NOLINT(readability/namespace) */ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
146 |
} // namespace nlohmann |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
147 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
148 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
149 |
// #include <nlohmann/detail/conversions/from_json.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
150 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
151 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
152 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
153 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
154 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
155 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
156 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
157 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
158 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
159 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
160 |
#include <algorithm> // transform |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
161 |
#include <array> // array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
162 |
#include <forward_list> // forward_list |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
163 |
#include <iterator> // inserter, front_inserter, end |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
164 |
#include <map> // map |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
165 |
#include <string> // string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
166 |
#include <tuple> // tuple, make_tuple |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
167 |
#include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
168 |
#include <unordered_map> // unordered_map |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
169 |
#include <utility> // pair, declval |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
170 |
#include <valarray> // valarray |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
171 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
172 |
// #include <nlohmann/detail/exceptions.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
173 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
174 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
175 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
176 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
177 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
178 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
179 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
180 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
181 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
182 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
183 |
#include <cstddef> // nullptr_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
184 |
#include <exception> // exception |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
185 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
186 |
#include <numeric> // accumulate |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
187 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
188 |
#include <stdexcept> // runtime_error |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
189 |
#include <string> // to_string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
190 |
#include <vector> // vector |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
191 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
192 |
// #include <nlohmann/detail/value_t.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
193 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
194 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
195 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
196 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
197 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
198 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
199 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
200 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
201 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
202 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
203 |
#include <array> // array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
204 |
#include <cstddef> // size_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
205 |
#include <cstdint> // uint8_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
206 |
#include <string> // string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
207 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
208 |
// #include <nlohmann/detail/macro_scope.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
209 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
210 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
211 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
212 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
213 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
214 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
215 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
216 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
217 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
218 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
219 |
#include <utility> // declval, pair |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
220 |
// #include <nlohmann/detail/meta/detected.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
221 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
222 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
223 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
224 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
225 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
226 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
227 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
228 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
229 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
230 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
231 |
#include <type_traits> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
232 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
233 |
// #include <nlohmann/detail/meta/void_t.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
234 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
235 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
236 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
237 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
238 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
239 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
240 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
241 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
242 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
243 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
244 |
// #include <nlohmann/detail/abi_macros.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
245 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
246 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
247 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
248 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
249 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
250 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
251 |
template<typename ...Ts> struct make_void |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
252 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
253 |
using type = void; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
254 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
255 |
template<typename ...Ts> using void_t = typename make_void<Ts...>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
256 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
257 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
258 |
NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
259 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
260 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
261 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
262 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
263 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
264 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
265 |
// https://en.cppreference.com/w/cpp/experimental/is_detected |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
266 |
struct nonesuch |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
267 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
268 |
nonesuch() = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
269 |
~nonesuch() = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
270 |
nonesuch(nonesuch const&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
271 |
nonesuch(nonesuch const&&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
272 |
void operator=(nonesuch const&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
273 |
void operator=(nonesuch&&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
274 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
275 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
276 |
template<class Default, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
277 |
class AlwaysVoid, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
278 |
template<class...> class Op, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
279 |
class... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
280 |
struct detector |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
281 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
282 |
using value_t = std::false_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
283 |
using type = Default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
284 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
285 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
286 |
template<class Default, template<class...> class Op, class... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
287 |
struct detector<Default, void_t<Op<Args...>>, Op, Args...> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
288 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
289 |
using value_t = std::true_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
290 |
using type = Op<Args...>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
291 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
292 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
293 |
template<template<class...> class Op, class... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
294 |
using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
295 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
296 |
template<template<class...> class Op, class... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
297 |
struct is_detected_lazy : is_detected<Op, Args...> { }; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
298 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
299 |
template<template<class...> class Op, class... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
300 |
using detected_t = typename detector<nonesuch, void, Op, Args...>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
301 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
302 |
template<class Default, template<class...> class Op, class... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
303 |
using detected_or = detector<Default, void, Op, Args...>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
304 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
305 |
template<class Default, template<class...> class Op, class... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
306 |
using detected_or_t = typename detected_or<Default, Op, Args...>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
307 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
308 |
template<class Expected, template<class...> class Op, class... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
309 |
using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
310 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
311 |
template<class To, template<class...> class Op, class... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
312 |
using is_detected_convertible = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
313 |
std::is_convertible<detected_t<Op, Args...>, To>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
314 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
315 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
316 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
317 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
318 |
// #include <nlohmann/thirdparty/hedley/hedley.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
319 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
320 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
321 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
322 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
323 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
324 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
325 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
326 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
327 |
// SPDX-FileCopyrightText: 2016-2021 Evan Nemerson <evan@nemerson.com> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
328 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
329 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
330 |
/* Hedley - https://nemequ.github.io/hedley |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
331 |
* Created by Evan Nemerson <evan@nemerson.com> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
332 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
333 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
334 |
#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
335 |
#if defined(JSON_HEDLEY_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
336 |
#undef JSON_HEDLEY_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
337 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
338 |
#define JSON_HEDLEY_VERSION 15 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
339 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
340 |
#if defined(JSON_HEDLEY_STRINGIFY_EX) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
341 |
#undef JSON_HEDLEY_STRINGIFY_EX |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
342 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
343 |
#define JSON_HEDLEY_STRINGIFY_EX(x) #x |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
344 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
345 |
#if defined(JSON_HEDLEY_STRINGIFY) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
346 |
#undef JSON_HEDLEY_STRINGIFY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
347 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
348 |
#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
349 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
350 |
#if defined(JSON_HEDLEY_CONCAT_EX) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
351 |
#undef JSON_HEDLEY_CONCAT_EX |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
352 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
353 |
#define JSON_HEDLEY_CONCAT_EX(a,b) a##b |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
354 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
355 |
#if defined(JSON_HEDLEY_CONCAT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
356 |
#undef JSON_HEDLEY_CONCAT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
357 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
358 |
#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
359 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
360 |
#if defined(JSON_HEDLEY_CONCAT3_EX) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
361 |
#undef JSON_HEDLEY_CONCAT3_EX |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
362 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
363 |
#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
364 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
365 |
#if defined(JSON_HEDLEY_CONCAT3) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
366 |
#undef JSON_HEDLEY_CONCAT3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
367 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
368 |
#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
369 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
370 |
#if defined(JSON_HEDLEY_VERSION_ENCODE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
371 |
#undef JSON_HEDLEY_VERSION_ENCODE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
372 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
373 |
#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
374 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
375 |
#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
376 |
#undef JSON_HEDLEY_VERSION_DECODE_MAJOR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
377 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
378 |
#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
379 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
380 |
#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
381 |
#undef JSON_HEDLEY_VERSION_DECODE_MINOR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
382 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
383 |
#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
384 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
385 |
#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
386 |
#undef JSON_HEDLEY_VERSION_DECODE_REVISION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
387 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
388 |
#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
389 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
390 |
#if defined(JSON_HEDLEY_GNUC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
391 |
#undef JSON_HEDLEY_GNUC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
392 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
393 |
#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
394 |
#define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
395 |
#elif defined(__GNUC__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
396 |
#define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
397 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
398 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
399 |
#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
400 |
#undef JSON_HEDLEY_GNUC_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
401 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
402 |
#if defined(JSON_HEDLEY_GNUC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
403 |
#define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
404 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
405 |
#define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
406 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
407 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
408 |
#if defined(JSON_HEDLEY_MSVC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
409 |
#undef JSON_HEDLEY_MSVC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
410 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
411 |
#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
412 |
#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
413 |
#elif defined(_MSC_FULL_VER) && !defined(__ICL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
414 |
#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
415 |
#elif defined(_MSC_VER) && !defined(__ICL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
416 |
#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
417 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
418 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
419 |
#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
420 |
#undef JSON_HEDLEY_MSVC_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
421 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
422 |
#if !defined(JSON_HEDLEY_MSVC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
423 |
#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
424 |
#elif defined(_MSC_VER) && (_MSC_VER >= 1400) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
425 |
#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
426 |
#elif defined(_MSC_VER) && (_MSC_VER >= 1200) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
427 |
#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
428 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
429 |
#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
430 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
431 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
432 |
#if defined(JSON_HEDLEY_INTEL_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
433 |
#undef JSON_HEDLEY_INTEL_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
434 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
435 |
#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
436 |
#define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
437 |
#elif defined(__INTEL_COMPILER) && !defined(__ICL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
438 |
#define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
439 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
440 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
441 |
#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
442 |
#undef JSON_HEDLEY_INTEL_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
443 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
444 |
#if defined(JSON_HEDLEY_INTEL_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
445 |
#define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
446 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
447 |
#define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
448 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
449 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
450 |
#if defined(JSON_HEDLEY_INTEL_CL_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
451 |
#undef JSON_HEDLEY_INTEL_CL_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
452 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
453 |
#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
454 |
#define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
455 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
456 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
457 |
#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
458 |
#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
459 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
460 |
#if defined(JSON_HEDLEY_INTEL_CL_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
461 |
#define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
462 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
463 |
#define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
464 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
465 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
466 |
#if defined(JSON_HEDLEY_PGI_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
467 |
#undef JSON_HEDLEY_PGI_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
468 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
469 |
#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
470 |
#define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
471 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
472 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
473 |
#if defined(JSON_HEDLEY_PGI_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
474 |
#undef JSON_HEDLEY_PGI_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
475 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
476 |
#if defined(JSON_HEDLEY_PGI_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
477 |
#define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
478 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
479 |
#define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
480 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
481 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
482 |
#if defined(JSON_HEDLEY_SUNPRO_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
483 |
#undef JSON_HEDLEY_SUNPRO_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
484 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
485 |
#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
486 |
#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
487 |
#elif defined(__SUNPRO_C) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
488 |
#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
489 |
#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
490 |
#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
491 |
#elif defined(__SUNPRO_CC) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
492 |
#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
493 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
494 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
495 |
#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
496 |
#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
497 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
498 |
#if defined(JSON_HEDLEY_SUNPRO_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
499 |
#define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
500 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
501 |
#define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
502 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
503 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
504 |
#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
505 |
#undef JSON_HEDLEY_EMSCRIPTEN_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
506 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
507 |
#if defined(__EMSCRIPTEN__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
508 |
#define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
509 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
510 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
511 |
#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
512 |
#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
513 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
514 |
#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
515 |
#define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
516 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
517 |
#define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
518 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
519 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
520 |
#if defined(JSON_HEDLEY_ARM_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
521 |
#undef JSON_HEDLEY_ARM_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
522 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
523 |
#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
524 |
#define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
525 |
#elif defined(__CC_ARM) && defined(__ARMCC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
526 |
#define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
527 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
528 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
529 |
#if defined(JSON_HEDLEY_ARM_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
530 |
#undef JSON_HEDLEY_ARM_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
531 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
532 |
#if defined(JSON_HEDLEY_ARM_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
533 |
#define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
534 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
535 |
#define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
536 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
537 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
538 |
#if defined(JSON_HEDLEY_IBM_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
539 |
#undef JSON_HEDLEY_IBM_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
540 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
541 |
#if defined(__ibmxl__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
542 |
#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
543 |
#elif defined(__xlC__) && defined(__xlC_ver__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
544 |
#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
545 |
#elif defined(__xlC__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
546 |
#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
547 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
548 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
549 |
#if defined(JSON_HEDLEY_IBM_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
550 |
#undef JSON_HEDLEY_IBM_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
551 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
552 |
#if defined(JSON_HEDLEY_IBM_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
553 |
#define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
554 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
555 |
#define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
556 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
557 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
558 |
#if defined(JSON_HEDLEY_TI_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
559 |
#undef JSON_HEDLEY_TI_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
560 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
561 |
#if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
562 |
defined(__TI_COMPILER_VERSION__) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
563 |
( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
564 |
defined(__TMS470__) || defined(__TI_ARM__) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
565 |
defined(__MSP430__) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
566 |
defined(__TMS320C2000__) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
567 |
) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
568 |
#if (__TI_COMPILER_VERSION__ >= 16000000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
569 |
#define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
570 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
571 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
572 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
573 |
#if defined(JSON_HEDLEY_TI_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
574 |
#undef JSON_HEDLEY_TI_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
575 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
576 |
#if defined(JSON_HEDLEY_TI_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
577 |
#define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
578 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
579 |
#define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
580 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
581 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
582 |
#if defined(JSON_HEDLEY_TI_CL2000_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
583 |
#undef JSON_HEDLEY_TI_CL2000_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
584 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
585 |
#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
586 |
#define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
587 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
588 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
589 |
#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
590 |
#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
591 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
592 |
#if defined(JSON_HEDLEY_TI_CL2000_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
593 |
#define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
594 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
595 |
#define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
596 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
597 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
598 |
#if defined(JSON_HEDLEY_TI_CL430_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
599 |
#undef JSON_HEDLEY_TI_CL430_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
600 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
601 |
#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
602 |
#define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
603 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
604 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
605 |
#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
606 |
#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
607 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
608 |
#if defined(JSON_HEDLEY_TI_CL430_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
609 |
#define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
610 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
611 |
#define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
612 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
613 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
614 |
#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
615 |
#undef JSON_HEDLEY_TI_ARMCL_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
616 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
617 |
#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
618 |
#define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
619 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
620 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
621 |
#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
622 |
#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
623 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
624 |
#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
625 |
#define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
626 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
627 |
#define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
628 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
629 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
630 |
#if defined(JSON_HEDLEY_TI_CL6X_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
631 |
#undef JSON_HEDLEY_TI_CL6X_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
632 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
633 |
#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
634 |
#define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
635 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
636 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
637 |
#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
638 |
#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
639 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
640 |
#if defined(JSON_HEDLEY_TI_CL6X_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
641 |
#define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
642 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
643 |
#define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
644 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
645 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
646 |
#if defined(JSON_HEDLEY_TI_CL7X_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
647 |
#undef JSON_HEDLEY_TI_CL7X_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
648 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
649 |
#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
650 |
#define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
651 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
652 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
653 |
#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
654 |
#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
655 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
656 |
#if defined(JSON_HEDLEY_TI_CL7X_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
657 |
#define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
658 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
659 |
#define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
660 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
661 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
662 |
#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
663 |
#undef JSON_HEDLEY_TI_CLPRU_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
664 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
665 |
#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
666 |
#define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
667 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
668 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
669 |
#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
670 |
#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
671 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
672 |
#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
673 |
#define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
674 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
675 |
#define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
676 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
677 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
678 |
#if defined(JSON_HEDLEY_CRAY_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
679 |
#undef JSON_HEDLEY_CRAY_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
680 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
681 |
#if defined(_CRAYC) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
682 |
#if defined(_RELEASE_PATCHLEVEL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
683 |
#define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
684 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
685 |
#define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
686 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
687 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
688 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
689 |
#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
690 |
#undef JSON_HEDLEY_CRAY_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
691 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
692 |
#if defined(JSON_HEDLEY_CRAY_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
693 |
#define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
694 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
695 |
#define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
696 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
697 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
698 |
#if defined(JSON_HEDLEY_IAR_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
699 |
#undef JSON_HEDLEY_IAR_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
700 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
701 |
#if defined(__IAR_SYSTEMS_ICC__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
702 |
#if __VER__ > 1000 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
703 |
#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
704 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
705 |
#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
706 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
707 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
708 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
709 |
#if defined(JSON_HEDLEY_IAR_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
710 |
#undef JSON_HEDLEY_IAR_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
711 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
712 |
#if defined(JSON_HEDLEY_IAR_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
713 |
#define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
714 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
715 |
#define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
716 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
717 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
718 |
#if defined(JSON_HEDLEY_TINYC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
719 |
#undef JSON_HEDLEY_TINYC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
720 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
721 |
#if defined(__TINYC__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
722 |
#define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
723 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
724 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
725 |
#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
726 |
#undef JSON_HEDLEY_TINYC_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
727 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
728 |
#if defined(JSON_HEDLEY_TINYC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
729 |
#define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
730 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
731 |
#define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
732 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
733 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
734 |
#if defined(JSON_HEDLEY_DMC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
735 |
#undef JSON_HEDLEY_DMC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
736 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
737 |
#if defined(__DMC__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
738 |
#define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
739 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
740 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
741 |
#if defined(JSON_HEDLEY_DMC_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
742 |
#undef JSON_HEDLEY_DMC_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
743 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
744 |
#if defined(JSON_HEDLEY_DMC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
745 |
#define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
746 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
747 |
#define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
748 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
749 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
750 |
#if defined(JSON_HEDLEY_COMPCERT_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
751 |
#undef JSON_HEDLEY_COMPCERT_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
752 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
753 |
#if defined(__COMPCERT_VERSION__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
754 |
#define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
755 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
756 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
757 |
#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
758 |
#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
759 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
760 |
#if defined(JSON_HEDLEY_COMPCERT_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
761 |
#define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
762 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
763 |
#define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
764 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
765 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
766 |
#if defined(JSON_HEDLEY_PELLES_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
767 |
#undef JSON_HEDLEY_PELLES_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
768 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
769 |
#if defined(__POCC__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
770 |
#define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
771 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
772 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
773 |
#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
774 |
#undef JSON_HEDLEY_PELLES_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
775 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
776 |
#if defined(JSON_HEDLEY_PELLES_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
777 |
#define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
778 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
779 |
#define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
780 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
781 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
782 |
#if defined(JSON_HEDLEY_MCST_LCC_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
783 |
#undef JSON_HEDLEY_MCST_LCC_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
784 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
785 |
#if defined(__LCC__) && defined(__LCC_MINOR__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
786 |
#define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
787 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
788 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
789 |
#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
790 |
#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
791 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
792 |
#if defined(JSON_HEDLEY_MCST_LCC_VERSION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
793 |
#define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
794 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
795 |
#define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
796 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
797 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
798 |
#if defined(JSON_HEDLEY_GCC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
799 |
#undef JSON_HEDLEY_GCC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
800 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
801 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
802 |
defined(JSON_HEDLEY_GNUC_VERSION) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
803 |
!defined(__clang__) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
804 |
!defined(JSON_HEDLEY_INTEL_VERSION) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
805 |
!defined(JSON_HEDLEY_PGI_VERSION) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
806 |
!defined(JSON_HEDLEY_ARM_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
807 |
!defined(JSON_HEDLEY_CRAY_VERSION) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
808 |
!defined(JSON_HEDLEY_TI_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
809 |
!defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
810 |
!defined(JSON_HEDLEY_TI_CL430_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
811 |
!defined(JSON_HEDLEY_TI_CL2000_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
812 |
!defined(JSON_HEDLEY_TI_CL6X_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
813 |
!defined(JSON_HEDLEY_TI_CL7X_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
814 |
!defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
815 |
!defined(__COMPCERT__) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
816 |
!defined(JSON_HEDLEY_MCST_LCC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
817 |
#define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
818 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
819 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
820 |
#if defined(JSON_HEDLEY_GCC_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
821 |
#undef JSON_HEDLEY_GCC_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
822 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
823 |
#if defined(JSON_HEDLEY_GCC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
824 |
#define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
825 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
826 |
#define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
827 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
828 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
829 |
#if defined(JSON_HEDLEY_HAS_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
830 |
#undef JSON_HEDLEY_HAS_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
831 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
832 |
#if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
833 |
defined(__has_attribute) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
834 |
( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
835 |
(!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
836 |
) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
837 |
# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
838 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
839 |
# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
840 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
841 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
842 |
#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
843 |
#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
844 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
845 |
#if defined(__has_attribute) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
846 |
#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
847 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
848 |
#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
849 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
850 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
851 |
#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
852 |
#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
853 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
854 |
#if defined(__has_attribute) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
855 |
#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
856 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
857 |
#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
858 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
859 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
860 |
#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
861 |
#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
862 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
863 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
864 |
defined(__has_cpp_attribute) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
865 |
defined(__cplusplus) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
866 |
(!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
867 |
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
868 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
869 |
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
870 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
871 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
872 |
#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
873 |
#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
874 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
875 |
#if !defined(__cplusplus) || !defined(__has_cpp_attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
876 |
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
877 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
878 |
!defined(JSON_HEDLEY_PGI_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
879 |
!defined(JSON_HEDLEY_IAR_VERSION) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
880 |
(!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
881 |
(!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
882 |
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
883 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
884 |
#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
885 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
886 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
887 |
#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
888 |
#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
889 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
890 |
#if defined(__has_cpp_attribute) && defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
891 |
#define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
892 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
893 |
#define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
894 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
895 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
896 |
#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
897 |
#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
898 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
899 |
#if defined(__has_cpp_attribute) && defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
900 |
#define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
901 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
902 |
#define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
903 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
904 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
905 |
#if defined(JSON_HEDLEY_HAS_BUILTIN) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
906 |
#undef JSON_HEDLEY_HAS_BUILTIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
907 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
908 |
#if defined(__has_builtin) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
909 |
#define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
910 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
911 |
#define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
912 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
913 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
914 |
#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
915 |
#undef JSON_HEDLEY_GNUC_HAS_BUILTIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
916 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
917 |
#if defined(__has_builtin) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
918 |
#define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
919 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
920 |
#define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
921 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
922 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
923 |
#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
924 |
#undef JSON_HEDLEY_GCC_HAS_BUILTIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
925 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
926 |
#if defined(__has_builtin) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
927 |
#define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
928 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
929 |
#define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
930 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
931 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
932 |
#if defined(JSON_HEDLEY_HAS_FEATURE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
933 |
#undef JSON_HEDLEY_HAS_FEATURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
934 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
935 |
#if defined(__has_feature) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
936 |
#define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
937 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
938 |
#define JSON_HEDLEY_HAS_FEATURE(feature) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
939 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
940 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
941 |
#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
942 |
#undef JSON_HEDLEY_GNUC_HAS_FEATURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
943 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
944 |
#if defined(__has_feature) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
945 |
#define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
946 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
947 |
#define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
948 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
949 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
950 |
#if defined(JSON_HEDLEY_GCC_HAS_FEATURE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
951 |
#undef JSON_HEDLEY_GCC_HAS_FEATURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
952 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
953 |
#if defined(__has_feature) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
954 |
#define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
955 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
956 |
#define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
957 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
958 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
959 |
#if defined(JSON_HEDLEY_HAS_EXTENSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
960 |
#undef JSON_HEDLEY_HAS_EXTENSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
961 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
962 |
#if defined(__has_extension) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
963 |
#define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
964 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
965 |
#define JSON_HEDLEY_HAS_EXTENSION(extension) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
966 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
967 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
968 |
#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
969 |
#undef JSON_HEDLEY_GNUC_HAS_EXTENSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
970 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
971 |
#if defined(__has_extension) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
972 |
#define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
973 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
974 |
#define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
975 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
976 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
977 |
#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
978 |
#undef JSON_HEDLEY_GCC_HAS_EXTENSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
979 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
980 |
#if defined(__has_extension) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
981 |
#define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
982 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
983 |
#define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
984 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
985 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
986 |
#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
987 |
#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
988 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
989 |
#if defined(__has_declspec_attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
990 |
#define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
991 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
992 |
#define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
993 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
994 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
995 |
#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
996 |
#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
997 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
998 |
#if defined(__has_declspec_attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
999 |
#define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1000 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1001 |
#define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1002 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1003 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1004 |
#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1005 |
#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1006 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1007 |
#if defined(__has_declspec_attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1008 |
#define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1009 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1010 |
#define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1011 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1012 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1013 |
#if defined(JSON_HEDLEY_HAS_WARNING) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1014 |
#undef JSON_HEDLEY_HAS_WARNING |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1015 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1016 |
#if defined(__has_warning) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1017 |
#define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1018 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1019 |
#define JSON_HEDLEY_HAS_WARNING(warning) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1020 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1021 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1022 |
#if defined(JSON_HEDLEY_GNUC_HAS_WARNING) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1023 |
#undef JSON_HEDLEY_GNUC_HAS_WARNING |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1024 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1025 |
#if defined(__has_warning) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1026 |
#define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1027 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1028 |
#define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1029 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1030 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1031 |
#if defined(JSON_HEDLEY_GCC_HAS_WARNING) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1032 |
#undef JSON_HEDLEY_GCC_HAS_WARNING |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1033 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1034 |
#if defined(__has_warning) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1035 |
#define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1036 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1037 |
#define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1038 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1039 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1040 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1041 |
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1042 |
defined(__clang__) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1043 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1044 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1045 |
JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1046 |
JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1047 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1048 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1049 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1050 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1051 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1052 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1053 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1054 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1055 |
JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1056 |
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1057 |
JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1058 |
(JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1059 |
#define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1060 |
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1061 |
#define JSON_HEDLEY_PRAGMA(value) __pragma(value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1062 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1063 |
#define JSON_HEDLEY_PRAGMA(value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1064 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1065 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1066 |
#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1067 |
#undef JSON_HEDLEY_DIAGNOSTIC_PUSH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1068 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1069 |
#if defined(JSON_HEDLEY_DIAGNOSTIC_POP) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1070 |
#undef JSON_HEDLEY_DIAGNOSTIC_POP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1071 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1072 |
#if defined(__clang__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1073 |
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1074 |
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1075 |
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1076 |
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1077 |
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1078 |
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1079 |
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1080 |
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1081 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1082 |
JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1083 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1084 |
#define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1085 |
#define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1086 |
#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1087 |
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1088 |
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1089 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1090 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1091 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1092 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1093 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1094 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1095 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1096 |
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1097 |
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1098 |
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1099 |
#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1100 |
#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1101 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1102 |
#define JSON_HEDLEY_DIAGNOSTIC_PUSH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1103 |
#define JSON_HEDLEY_DIAGNOSTIC_POP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1104 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1105 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1106 |
/* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1107 |
HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1108 |
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1109 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1110 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1111 |
#if defined(__cplusplus) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1112 |
# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1113 |
# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1114 |
# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1115 |
# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1116 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1117 |
_Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1118 |
_Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1119 |
_Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1120 |
xpr \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1121 |
JSON_HEDLEY_DIAGNOSTIC_POP |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1122 |
# else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1123 |
# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1124 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1125 |
_Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1126 |
_Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1127 |
xpr \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1128 |
JSON_HEDLEY_DIAGNOSTIC_POP |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1129 |
# endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1130 |
# else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1131 |
# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1132 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1133 |
_Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1134 |
xpr \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1135 |
JSON_HEDLEY_DIAGNOSTIC_POP |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1136 |
# endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1137 |
# endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1138 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1139 |
#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1140 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1141 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1142 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1143 |
#if defined(JSON_HEDLEY_CONST_CAST) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1144 |
#undef JSON_HEDLEY_CONST_CAST |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1145 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1146 |
#if defined(__cplusplus) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1147 |
# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1148 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1149 |
JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1150 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1151 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1152 |
# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1153 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1154 |
JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1155 |
((T) (expr)); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1156 |
JSON_HEDLEY_DIAGNOSTIC_POP \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1157 |
})) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1158 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1159 |
# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1160 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1161 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1162 |
#if defined(JSON_HEDLEY_REINTERPRET_CAST) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1163 |
#undef JSON_HEDLEY_REINTERPRET_CAST |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1164 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1165 |
#if defined(__cplusplus) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1166 |
#define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1167 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1168 |
#define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1169 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1170 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1171 |
#if defined(JSON_HEDLEY_STATIC_CAST) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1172 |
#undef JSON_HEDLEY_STATIC_CAST |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1173 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1174 |
#if defined(__cplusplus) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1175 |
#define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1176 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1177 |
#define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1178 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1179 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1180 |
#if defined(JSON_HEDLEY_CPP_CAST) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1181 |
#undef JSON_HEDLEY_CPP_CAST |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1182 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1183 |
#if defined(__cplusplus) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1184 |
# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1185 |
# define JSON_HEDLEY_CPP_CAST(T, expr) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1186 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1187 |
_Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1188 |
((T) (expr)) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1189 |
JSON_HEDLEY_DIAGNOSTIC_POP |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1190 |
# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1191 |
# define JSON_HEDLEY_CPP_CAST(T, expr) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1192 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1193 |
_Pragma("diag_suppress=Pe137") \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1194 |
JSON_HEDLEY_DIAGNOSTIC_POP |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1195 |
# else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1196 |
# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1197 |
# endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1198 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1199 |
# define JSON_HEDLEY_CPP_CAST(T, expr) (expr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1200 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1201 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1202 |
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1203 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1204 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1205 |
#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1206 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1207 |
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1208 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1209 |
#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1210 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1211 |
#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1212 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1213 |
#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1214 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1215 |
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1216 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1217 |
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1218 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1219 |
#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1220 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1221 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1222 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1223 |
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1224 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1225 |
(JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1226 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1227 |
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1228 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1229 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1230 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1231 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1232 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1233 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1234 |
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1235 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1236 |
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1237 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1238 |
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1239 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1240 |
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1241 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1242 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1243 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1244 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1245 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1246 |
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1247 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1248 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1249 |
#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1250 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1251 |
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1252 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1253 |
#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1254 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1255 |
#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1256 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1257 |
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1258 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1259 |
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1260 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1261 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1262 |
JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1263 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1264 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1265 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1266 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1267 |
#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1268 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1269 |
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1270 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1271 |
#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1272 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1273 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1274 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1275 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1276 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1277 |
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1278 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1279 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1280 |
#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1281 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1282 |
#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1283 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1284 |
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1285 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1286 |
#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1287 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1288 |
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1289 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1290 |
#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1291 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1292 |
#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1293 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1294 |
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1295 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1296 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1297 |
JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1298 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1299 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1300 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1301 |
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1302 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1303 |
#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1304 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1305 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1306 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1307 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1308 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1309 |
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1310 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1311 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1312 |
#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1313 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1314 |
#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1315 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1316 |
#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1317 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1318 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1319 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1320 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1321 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1322 |
#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1323 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1324 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1325 |
#if JSON_HEDLEY_HAS_WARNING("-Wunused-function") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1326 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1327 |
#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1328 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1329 |
#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1330 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1331 |
#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1332 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1333 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1334 |
#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1335 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1336 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1337 |
#if defined(JSON_HEDLEY_DEPRECATED) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1338 |
#undef JSON_HEDLEY_DEPRECATED |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1339 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1340 |
#if defined(JSON_HEDLEY_DEPRECATED_FOR) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1341 |
#undef JSON_HEDLEY_DEPRECATED_FOR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1342 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1343 |
#if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1344 |
JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1345 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1346 |
#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1347 |
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1348 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1349 |
(JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1350 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1351 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1352 |
JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1353 |
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1354 |
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1355 |
JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1356 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1357 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1358 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1359 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1360 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1361 |
#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1362 |
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1363 |
#elif defined(__cplusplus) && (__cplusplus >= 201402L) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1364 |
#define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1365 |
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1366 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1367 |
JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1368 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1369 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1370 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1371 |
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1372 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1373 |
(JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1374 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1375 |
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1376 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1377 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1378 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1379 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1380 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1381 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1382 |
JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1383 |
#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1384 |
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1385 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1386 |
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1387 |
JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1388 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1389 |
#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1390 |
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1391 |
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1392 |
#define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1393 |
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1394 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1395 |
#define JSON_HEDLEY_DEPRECATED(since) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1396 |
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1397 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1398 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1399 |
#if defined(JSON_HEDLEY_UNAVAILABLE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1400 |
#undef JSON_HEDLEY_UNAVAILABLE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1401 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1402 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1403 |
JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1404 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1405 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1406 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1407 |
#define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1408 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1409 |
#define JSON_HEDLEY_UNAVAILABLE(available_since) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1410 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1411 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1412 |
#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1413 |
#undef JSON_HEDLEY_WARN_UNUSED_RESULT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1414 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1415 |
#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1416 |
#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1417 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1418 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1419 |
JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1420 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1421 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1422 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1423 |
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1424 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1425 |
(JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1426 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1427 |
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1428 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1429 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1430 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1431 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1432 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1433 |
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1434 |
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1435 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1436 |
#define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1437 |
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1438 |
#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1439 |
#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1440 |
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]]) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1441 |
#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1442 |
#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1443 |
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1444 |
#elif defined(_Check_return_) /* SAL */ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1445 |
#define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1446 |
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1447 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1448 |
#define JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1449 |
#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1450 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1451 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1452 |
#if defined(JSON_HEDLEY_SENTINEL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1453 |
#undef JSON_HEDLEY_SENTINEL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1454 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1455 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1456 |
JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1457 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1458 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1459 |
JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1460 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1461 |
#define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1462 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1463 |
#define JSON_HEDLEY_SENTINEL(position) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1464 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1465 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1466 |
#if defined(JSON_HEDLEY_NO_RETURN) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1467 |
#undef JSON_HEDLEY_NO_RETURN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1468 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1469 |
#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1470 |
#define JSON_HEDLEY_NO_RETURN __noreturn |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1471 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1472 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1473 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1474 |
#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1475 |
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1476 |
#define JSON_HEDLEY_NO_RETURN _Noreturn |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1477 |
#elif defined(__cplusplus) && (__cplusplus >= 201103L) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1478 |
#define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1479 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1480 |
JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1481 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1482 |
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1483 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1484 |
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1485 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1486 |
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1487 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1488 |
(JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1489 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1490 |
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1491 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1492 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1493 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1494 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1495 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1496 |
JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1497 |
#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1498 |
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1499 |
#define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1500 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1501 |
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1502 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1503 |
#define JSON_HEDLEY_NO_RETURN __declspec(noreturn) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1504 |
#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1505 |
#define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1506 |
#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1507 |
#define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1508 |
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1509 |
#define JSON_HEDLEY_NO_RETURN __declspec(noreturn) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1510 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1511 |
#define JSON_HEDLEY_NO_RETURN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1512 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1513 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1514 |
#if defined(JSON_HEDLEY_NO_ESCAPE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1515 |
#undef JSON_HEDLEY_NO_ESCAPE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1516 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1517 |
#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1518 |
#define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1519 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1520 |
#define JSON_HEDLEY_NO_ESCAPE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1521 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1522 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1523 |
#if defined(JSON_HEDLEY_UNREACHABLE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1524 |
#undef JSON_HEDLEY_UNREACHABLE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1525 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1526 |
#if defined(JSON_HEDLEY_UNREACHABLE_RETURN) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1527 |
#undef JSON_HEDLEY_UNREACHABLE_RETURN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1528 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1529 |
#if defined(JSON_HEDLEY_ASSUME) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1530 |
#undef JSON_HEDLEY_ASSUME |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1531 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1532 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1533 |
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1534 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1535 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1536 |
#define JSON_HEDLEY_ASSUME(expr) __assume(expr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1537 |
#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1538 |
#define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1539 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1540 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1541 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1542 |
#if defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1543 |
#define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1544 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1545 |
#define JSON_HEDLEY_ASSUME(expr) _nassert(expr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1546 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1547 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1548 |
#if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1549 |
(JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1550 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1551 |
JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1552 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1553 |
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1554 |
JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1555 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1556 |
#define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1557 |
#elif defined(JSON_HEDLEY_ASSUME) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1558 |
#define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1559 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1560 |
#if !defined(JSON_HEDLEY_ASSUME) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1561 |
#if defined(JSON_HEDLEY_UNREACHABLE) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1562 |
#define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1563 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1564 |
#define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1565 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1566 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1567 |
#if defined(JSON_HEDLEY_UNREACHABLE) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1568 |
#if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1569 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1570 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1571 |
#define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1572 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1573 |
#define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1574 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1575 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1576 |
#define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1577 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1578 |
#if !defined(JSON_HEDLEY_UNREACHABLE) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1579 |
#define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1580 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1581 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1582 |
JSON_HEDLEY_DIAGNOSTIC_PUSH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1583 |
#if JSON_HEDLEY_HAS_WARNING("-Wpedantic") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1584 |
#pragma clang diagnostic ignored "-Wpedantic" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1585 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1586 |
#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1587 |
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1588 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1589 |
#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1590 |
#if defined(__clang__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1591 |
#pragma clang diagnostic ignored "-Wvariadic-macros" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1592 |
#elif defined(JSON_HEDLEY_GCC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1593 |
#pragma GCC diagnostic ignored "-Wvariadic-macros" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1594 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1595 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1596 |
#if defined(JSON_HEDLEY_NON_NULL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1597 |
#undef JSON_HEDLEY_NON_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1598 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1599 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1600 |
JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1601 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1602 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1603 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1604 |
#define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1605 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1606 |
#define JSON_HEDLEY_NON_NULL(...) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1607 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1608 |
JSON_HEDLEY_DIAGNOSTIC_POP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1609 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1610 |
#if defined(JSON_HEDLEY_PRINTF_FORMAT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1611 |
#undef JSON_HEDLEY_PRINTF_FORMAT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1612 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1613 |
#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1614 |
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1615 |
#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1616 |
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1617 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1618 |
JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1619 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1620 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1621 |
JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1622 |
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1623 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1624 |
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1625 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1626 |
(JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1627 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1628 |
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1629 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1630 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1631 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1632 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1633 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1634 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1635 |
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1636 |
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1637 |
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1638 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1639 |
#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1640 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1641 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1642 |
#if defined(JSON_HEDLEY_CONSTEXPR) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1643 |
#undef JSON_HEDLEY_CONSTEXPR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1644 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1645 |
#if defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1646 |
#if __cplusplus >= 201103L |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1647 |
#define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1648 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1649 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1650 |
#if !defined(JSON_HEDLEY_CONSTEXPR) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1651 |
#define JSON_HEDLEY_CONSTEXPR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1652 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1653 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1654 |
#if defined(JSON_HEDLEY_PREDICT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1655 |
#undef JSON_HEDLEY_PREDICT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1656 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1657 |
#if defined(JSON_HEDLEY_LIKELY) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1658 |
#undef JSON_HEDLEY_LIKELY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1659 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1660 |
#if defined(JSON_HEDLEY_UNLIKELY) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1661 |
#undef JSON_HEDLEY_UNLIKELY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1662 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1663 |
#if defined(JSON_HEDLEY_UNPREDICTABLE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1664 |
#undef JSON_HEDLEY_UNPREDICTABLE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1665 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1666 |
#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1667 |
#define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1668 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1669 |
#if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1670 |
(JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1671 |
JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1672 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1673 |
# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1674 |
# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1675 |
# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1676 |
# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 ) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1677 |
# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 ) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1678 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1679 |
(JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1680 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1681 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1682 |
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1683 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1684 |
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1685 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1686 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1687 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1688 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1689 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1690 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1691 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1692 |
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1693 |
JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1694 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1695 |
# define JSON_HEDLEY_PREDICT(expr, expected, probability) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1696 |
(((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1697 |
# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1698 |
(__extension__ ({ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1699 |
double hedley_probability_ = (probability); \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1700 |
((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1701 |
})) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1702 |
# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1703 |
(__extension__ ({ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1704 |
double hedley_probability_ = (probability); \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1705 |
((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1706 |
})) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1707 |
# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1708 |
# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1709 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1710 |
# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1711 |
# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1712 |
# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1713 |
# define JSON_HEDLEY_LIKELY(expr) (!!(expr)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1714 |
# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1715 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1716 |
#if !defined(JSON_HEDLEY_UNPREDICTABLE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1717 |
#define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1718 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1719 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1720 |
#if defined(JSON_HEDLEY_MALLOC) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1721 |
#undef JSON_HEDLEY_MALLOC |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1722 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1723 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1724 |
JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1725 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1726 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1727 |
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1728 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1729 |
JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1730 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1731 |
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1732 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1733 |
(JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1734 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1735 |
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1736 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1737 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1738 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1739 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1740 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1741 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1742 |
#define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1743 |
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1744 |
#define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1745 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1746 |
JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1747 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1748 |
#define JSON_HEDLEY_MALLOC __declspec(restrict) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1749 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1750 |
#define JSON_HEDLEY_MALLOC |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1751 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1752 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1753 |
#if defined(JSON_HEDLEY_PURE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1754 |
#undef JSON_HEDLEY_PURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1755 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1756 |
#if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1757 |
JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1758 |
JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1759 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1760 |
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1761 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1762 |
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1763 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1764 |
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1765 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1766 |
(JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1767 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1768 |
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1769 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1770 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1771 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1772 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1773 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1774 |
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1775 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1776 |
# define JSON_HEDLEY_PURE __attribute__((__pure__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1777 |
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1778 |
# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1779 |
#elif defined(__cplusplus) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1780 |
( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1781 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1782 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1783 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1784 |
) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1785 |
# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1786 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1787 |
# define JSON_HEDLEY_PURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1788 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1789 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1790 |
#if defined(JSON_HEDLEY_CONST) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1791 |
#undef JSON_HEDLEY_CONST |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1792 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1793 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1794 |
JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1795 |
JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1796 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1797 |
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1798 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1799 |
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1800 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1801 |
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1802 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1803 |
(JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1804 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1805 |
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1806 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1807 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1808 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1809 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1810 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1811 |
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1812 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1813 |
#define JSON_HEDLEY_CONST __attribute__((__const__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1814 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1815 |
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1816 |
#define JSON_HEDLEY_CONST _Pragma("no_side_effect") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1817 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1818 |
#define JSON_HEDLEY_CONST JSON_HEDLEY_PURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1819 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1820 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1821 |
#if defined(JSON_HEDLEY_RESTRICT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1822 |
#undef JSON_HEDLEY_RESTRICT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1823 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1824 |
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1825 |
#define JSON_HEDLEY_RESTRICT restrict |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1826 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1827 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1828 |
JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1829 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1830 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1831 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1832 |
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1833 |
JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1834 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1835 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1836 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1837 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1838 |
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1839 |
JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1840 |
defined(__clang__) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1841 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1842 |
#define JSON_HEDLEY_RESTRICT __restrict |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1843 |
#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1844 |
#define JSON_HEDLEY_RESTRICT _Restrict |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1845 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1846 |
#define JSON_HEDLEY_RESTRICT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1847 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1848 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1849 |
#if defined(JSON_HEDLEY_INLINE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1850 |
#undef JSON_HEDLEY_INLINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1851 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1852 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1853 |
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1854 |
(defined(__cplusplus) && (__cplusplus >= 199711L)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1855 |
#define JSON_HEDLEY_INLINE inline |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1856 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1857 |
defined(JSON_HEDLEY_GCC_VERSION) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1858 |
JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1859 |
#define JSON_HEDLEY_INLINE __inline__ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1860 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1861 |
JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1862 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1863 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1864 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1865 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1866 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1867 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1868 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1869 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1870 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1871 |
#define JSON_HEDLEY_INLINE __inline |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1872 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1873 |
#define JSON_HEDLEY_INLINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1874 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1875 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1876 |
#if defined(JSON_HEDLEY_ALWAYS_INLINE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1877 |
#undef JSON_HEDLEY_ALWAYS_INLINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1878 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1879 |
#if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1880 |
JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1881 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1882 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1883 |
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1884 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1885 |
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1886 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1887 |
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1888 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1889 |
(JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1890 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1891 |
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1892 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1893 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1894 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1895 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1896 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1897 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1898 |
JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1899 |
# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1900 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1901 |
JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1902 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1903 |
# define JSON_HEDLEY_ALWAYS_INLINE __forceinline |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1904 |
#elif defined(__cplusplus) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1905 |
( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1906 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1907 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1908 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1909 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1910 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1911 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1912 |
) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1913 |
# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1914 |
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1915 |
# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1916 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1917 |
# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1918 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1919 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1920 |
#if defined(JSON_HEDLEY_NEVER_INLINE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1921 |
#undef JSON_HEDLEY_NEVER_INLINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1922 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1923 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1924 |
JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1925 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1926 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1927 |
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1928 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1929 |
JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1930 |
JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1931 |
(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1932 |
JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1933 |
(JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1934 |
JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1935 |
(JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1936 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1937 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1938 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1939 |
JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1940 |
JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1941 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1942 |
JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1943 |
#define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1944 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1945 |
JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1946 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1947 |
#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1948 |
#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1949 |
#define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1950 |
#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1951 |
#define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1952 |
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1953 |
#define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1954 |
#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1955 |
#define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1956 |
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1957 |
#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1958 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1959 |
#define JSON_HEDLEY_NEVER_INLINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1960 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1961 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1962 |
#if defined(JSON_HEDLEY_PRIVATE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1963 |
#undef JSON_HEDLEY_PRIVATE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1964 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1965 |
#if defined(JSON_HEDLEY_PUBLIC) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1966 |
#undef JSON_HEDLEY_PUBLIC |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1967 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1968 |
#if defined(JSON_HEDLEY_IMPORT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1969 |
#undef JSON_HEDLEY_IMPORT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1970 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1971 |
#if defined(_WIN32) || defined(__CYGWIN__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1972 |
# define JSON_HEDLEY_PRIVATE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1973 |
# define JSON_HEDLEY_PUBLIC __declspec(dllexport) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1974 |
# define JSON_HEDLEY_IMPORT __declspec(dllimport) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1975 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1976 |
# if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1977 |
JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1978 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1979 |
JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1980 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1981 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1982 |
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1983 |
( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1984 |
defined(__TI_EABI__) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1985 |
( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1986 |
(JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1987 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1988 |
) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1989 |
) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1990 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1991 |
# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1992 |
# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1993 |
# else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1994 |
# define JSON_HEDLEY_PRIVATE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1995 |
# define JSON_HEDLEY_PUBLIC |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1996 |
# endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
1997 |
# define JSON_HEDLEY_IMPORT extern |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1998 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
1999 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2000 |
#if defined(JSON_HEDLEY_NO_THROW) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2001 |
#undef JSON_HEDLEY_NO_THROW |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2002 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2003 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2004 |
JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2005 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2006 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2007 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2008 |
#define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2009 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2010 |
JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2011 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2012 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2013 |
#define JSON_HEDLEY_NO_THROW __declspec(nothrow) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2014 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2015 |
#define JSON_HEDLEY_NO_THROW |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2016 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2017 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2018 |
#if defined(JSON_HEDLEY_FALL_THROUGH) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2019 |
#undef JSON_HEDLEY_FALL_THROUGH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2020 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2021 |
#if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2022 |
JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2023 |
JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2024 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2025 |
#define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2026 |
#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2027 |
#define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2028 |
#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2029 |
#define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2030 |
#elif defined(__fallthrough) /* SAL */ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2031 |
#define JSON_HEDLEY_FALL_THROUGH __fallthrough |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2032 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2033 |
#define JSON_HEDLEY_FALL_THROUGH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2034 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2035 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2036 |
#if defined(JSON_HEDLEY_RETURNS_NON_NULL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2037 |
#undef JSON_HEDLEY_RETURNS_NON_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2038 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2039 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2040 |
JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2041 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2042 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2043 |
#define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2044 |
#elif defined(_Ret_notnull_) /* SAL */ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2045 |
#define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2046 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2047 |
#define JSON_HEDLEY_RETURNS_NON_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2048 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2049 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2050 |
#if defined(JSON_HEDLEY_ARRAY_PARAM) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2051 |
#undef JSON_HEDLEY_ARRAY_PARAM |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2052 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2053 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2054 |
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2055 |
!defined(__STDC_NO_VLA__) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2056 |
!defined(__cplusplus) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2057 |
!defined(JSON_HEDLEY_PGI_VERSION) && \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2058 |
!defined(JSON_HEDLEY_TINYC_VERSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2059 |
#define JSON_HEDLEY_ARRAY_PARAM(name) (name) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2060 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2061 |
#define JSON_HEDLEY_ARRAY_PARAM(name) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2062 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2063 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2064 |
#if defined(JSON_HEDLEY_IS_CONSTANT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2065 |
#undef JSON_HEDLEY_IS_CONSTANT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2066 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2067 |
#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2068 |
#undef JSON_HEDLEY_REQUIRE_CONSTEXPR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2069 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2070 |
/* JSON_HEDLEY_IS_CONSTEXPR_ is for |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2071 |
HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2072 |
#if defined(JSON_HEDLEY_IS_CONSTEXPR_) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2073 |
#undef JSON_HEDLEY_IS_CONSTEXPR_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2074 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2075 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2076 |
JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2077 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2078 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2079 |
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2080 |
JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2081 |
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2082 |
JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2083 |
(JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2084 |
JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2085 |
JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2086 |
#define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2087 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2088 |
#if !defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2089 |
# if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2090 |
JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2091 |
JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2092 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2093 |
JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2094 |
JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2095 |
JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2096 |
JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2097 |
#if defined(__INTPTR_TYPE__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2098 |
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2099 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2100 |
#include <stdint.h> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2101 |
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2102 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2103 |
# elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2104 |
( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2105 |
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2106 |
!defined(JSON_HEDLEY_SUNPRO_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2107 |
!defined(JSON_HEDLEY_PGI_VERSION) && \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2108 |
!defined(JSON_HEDLEY_IAR_VERSION)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2109 |
(JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2110 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2111 |
JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2112 |
JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2113 |
JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2114 |
#if defined(__INTPTR_TYPE__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2115 |
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2116 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2117 |
#include <stdint.h> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2118 |
#define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2119 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2120 |
# elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2121 |
defined(JSON_HEDLEY_GCC_VERSION) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2122 |
defined(JSON_HEDLEY_INTEL_VERSION) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2123 |
defined(JSON_HEDLEY_TINYC_VERSION) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2124 |
defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2125 |
JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2126 |
defined(JSON_HEDLEY_TI_CL2000_VERSION) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2127 |
defined(JSON_HEDLEY_TI_CL6X_VERSION) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2128 |
defined(JSON_HEDLEY_TI_CL7X_VERSION) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2129 |
defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2130 |
defined(__clang__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2131 |
# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2132 |
sizeof(void) != \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2133 |
sizeof(*( \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2134 |
1 ? \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2135 |
((void*) ((expr) * 0L) ) : \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2136 |
((struct { char v[sizeof(void) * 2]; } *) 1) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2137 |
) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2138 |
) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2139 |
) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2140 |
# endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2141 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2142 |
#if defined(JSON_HEDLEY_IS_CONSTEXPR_) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2143 |
#if !defined(JSON_HEDLEY_IS_CONSTANT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2144 |
#define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2145 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2146 |
#define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2147 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2148 |
#if !defined(JSON_HEDLEY_IS_CONSTANT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2149 |
#define JSON_HEDLEY_IS_CONSTANT(expr) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2150 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2151 |
#define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2152 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2153 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2154 |
#if defined(JSON_HEDLEY_BEGIN_C_DECLS) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2155 |
#undef JSON_HEDLEY_BEGIN_C_DECLS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2156 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2157 |
#if defined(JSON_HEDLEY_END_C_DECLS) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2158 |
#undef JSON_HEDLEY_END_C_DECLS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2159 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2160 |
#if defined(JSON_HEDLEY_C_DECL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2161 |
#undef JSON_HEDLEY_C_DECL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2162 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2163 |
#if defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2164 |
#define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2165 |
#define JSON_HEDLEY_END_C_DECLS } |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2166 |
#define JSON_HEDLEY_C_DECL extern "C" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2167 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2168 |
#define JSON_HEDLEY_BEGIN_C_DECLS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2169 |
#define JSON_HEDLEY_END_C_DECLS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2170 |
#define JSON_HEDLEY_C_DECL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2171 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2172 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2173 |
#if defined(JSON_HEDLEY_STATIC_ASSERT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2174 |
#undef JSON_HEDLEY_STATIC_ASSERT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2175 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2176 |
#if \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2177 |
!defined(__cplusplus) && ( \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2178 |
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2179 |
(JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2180 |
JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2181 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2182 |
defined(_Static_assert) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2183 |
) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2184 |
# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2185 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2186 |
(defined(__cplusplus) && (__cplusplus >= 201103L)) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2187 |
JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2188 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2189 |
# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2190 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2191 |
# define JSON_HEDLEY_STATIC_ASSERT(expr, message) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2192 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2193 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2194 |
#if defined(JSON_HEDLEY_NULL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2195 |
#undef JSON_HEDLEY_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2196 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2197 |
#if defined(__cplusplus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2198 |
#if __cplusplus >= 201103L |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2199 |
#define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2200 |
#elif defined(NULL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2201 |
#define JSON_HEDLEY_NULL NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2202 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2203 |
#define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2204 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2205 |
#elif defined(NULL) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2206 |
#define JSON_HEDLEY_NULL NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2207 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2208 |
#define JSON_HEDLEY_NULL ((void*) 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2209 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2210 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2211 |
#if defined(JSON_HEDLEY_MESSAGE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2212 |
#undef JSON_HEDLEY_MESSAGE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2213 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2214 |
#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2215 |
# define JSON_HEDLEY_MESSAGE(msg) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2216 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2217 |
JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2218 |
JSON_HEDLEY_PRAGMA(message msg) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2219 |
JSON_HEDLEY_DIAGNOSTIC_POP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2220 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2221 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2222 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2223 |
# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2224 |
#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2225 |
# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2226 |
#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2227 |
# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2228 |
#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2229 |
# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2230 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2231 |
# define JSON_HEDLEY_MESSAGE(msg) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2232 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2233 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2234 |
#if defined(JSON_HEDLEY_WARNING) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2235 |
#undef JSON_HEDLEY_WARNING |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2236 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2237 |
#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2238 |
# define JSON_HEDLEY_WARNING(msg) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2239 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2240 |
JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2241 |
JSON_HEDLEY_PRAGMA(clang warning msg) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2242 |
JSON_HEDLEY_DIAGNOSTIC_POP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2243 |
#elif \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2244 |
JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2245 |
JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2246 |
JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2247 |
# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2248 |
#elif \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2249 |
JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2250 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2251 |
# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2252 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2253 |
# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2254 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2255 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2256 |
#if defined(JSON_HEDLEY_REQUIRE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2257 |
#undef JSON_HEDLEY_REQUIRE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2258 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2259 |
#if defined(JSON_HEDLEY_REQUIRE_MSG) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2260 |
#undef JSON_HEDLEY_REQUIRE_MSG |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2261 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2262 |
#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2263 |
# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2264 |
# define JSON_HEDLEY_REQUIRE(expr) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2265 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2266 |
_Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2267 |
__attribute__((diagnose_if(!(expr), #expr, "error"))) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2268 |
JSON_HEDLEY_DIAGNOSTIC_POP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2269 |
# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2270 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2271 |
_Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2272 |
__attribute__((diagnose_if(!(expr), msg, "error"))) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2273 |
JSON_HEDLEY_DIAGNOSTIC_POP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2274 |
# else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2275 |
# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2276 |
# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error"))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2277 |
# endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2278 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2279 |
# define JSON_HEDLEY_REQUIRE(expr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2280 |
# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2281 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2282 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2283 |
#if defined(JSON_HEDLEY_FLAGS) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2284 |
#undef JSON_HEDLEY_FLAGS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2285 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2286 |
#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion")) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2287 |
#define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2288 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2289 |
#define JSON_HEDLEY_FLAGS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2290 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2291 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2292 |
#if defined(JSON_HEDLEY_FLAGS_CAST) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2293 |
#undef JSON_HEDLEY_FLAGS_CAST |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2294 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2295 |
#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2296 |
# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2297 |
JSON_HEDLEY_DIAGNOSTIC_PUSH \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2298 |
_Pragma("warning(disable:188)") \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2299 |
((T) (expr)); \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2300 |
JSON_HEDLEY_DIAGNOSTIC_POP \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2301 |
})) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2302 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2303 |
# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2304 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2305 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2306 |
#if defined(JSON_HEDLEY_EMPTY_BASES) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2307 |
#undef JSON_HEDLEY_EMPTY_BASES |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2308 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2309 |
#if \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2310 |
(JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2311 |
JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2312 |
#define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2313 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2314 |
#define JSON_HEDLEY_EMPTY_BASES |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2315 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2316 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2317 |
/* Remaining macros are deprecated. */ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2318 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2319 |
#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2320 |
#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2321 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2322 |
#if defined(__clang__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2323 |
#define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2324 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2325 |
#define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2326 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2327 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2328 |
#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2329 |
#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2330 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2331 |
#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2332 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2333 |
#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2334 |
#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2335 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2336 |
#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2337 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2338 |
#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2339 |
#undef JSON_HEDLEY_CLANG_HAS_BUILTIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2340 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2341 |
#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2342 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2343 |
#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2344 |
#undef JSON_HEDLEY_CLANG_HAS_FEATURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2345 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2346 |
#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2347 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2348 |
#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2349 |
#undef JSON_HEDLEY_CLANG_HAS_EXTENSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2350 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2351 |
#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2352 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2353 |
#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2354 |
#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2355 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2356 |
#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2357 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2358 |
#if defined(JSON_HEDLEY_CLANG_HAS_WARNING) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2359 |
#undef JSON_HEDLEY_CLANG_HAS_WARNING |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2360 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2361 |
#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2362 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2363 |
#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2364 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2365 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2366 |
// This file contains all internal macro definitions (except those affecting ABI) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2367 |
// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2368 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2369 |
// #include <nlohmann/detail/abi_macros.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2370 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2371 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2372 |
// exclude unsupported compilers |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2373 |
#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2374 |
#if defined(__clang__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2375 |
#if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2376 |
#error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2377 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2378 |
#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2379 |
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2380 |
#error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2381 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2382 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2383 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2384 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2385 |
// C++ language standard detection |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2386 |
// if the user manually specified the used c++ version this is skipped |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2387 |
#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2388 |
#if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2389 |
#define JSON_HAS_CPP_20 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2390 |
#define JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2391 |
#define JSON_HAS_CPP_14 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2392 |
#elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2393 |
#define JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2394 |
#define JSON_HAS_CPP_14 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2395 |
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2396 |
#define JSON_HAS_CPP_14 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2397 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2398 |
// the cpp 11 flag is always specified because it is the minimal required version |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2399 |
#define JSON_HAS_CPP_11 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2400 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2401 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2402 |
#ifdef __has_include |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2403 |
#if __has_include(<version>) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2404 |
#include <version> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2405 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2406 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2407 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2408 |
#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2409 |
#ifdef JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2410 |
#if defined(__cpp_lib_filesystem) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2411 |
#define JSON_HAS_FILESYSTEM 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2412 |
#elif defined(__cpp_lib_experimental_filesystem) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2413 |
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2414 |
#elif !defined(__has_include) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2415 |
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2416 |
#elif __has_include(<filesystem>) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2417 |
#define JSON_HAS_FILESYSTEM 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2418 |
#elif __has_include(<experimental/filesystem>) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2419 |
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2420 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2421 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2422 |
// std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2423 |
#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2424 |
#undef JSON_HAS_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2425 |
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2426 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2427 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2428 |
// no filesystem support before GCC 8: https://en.cppreference.com/w/cpp/compiler_support |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2429 |
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2430 |
#undef JSON_HAS_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2431 |
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2432 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2433 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2434 |
// no filesystem support before Clang 7: https://en.cppreference.com/w/cpp/compiler_support |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2435 |
#if defined(__clang_major__) && __clang_major__ < 7 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2436 |
#undef JSON_HAS_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2437 |
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2438 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2439 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2440 |
// no filesystem support before MSVC 19.14: https://en.cppreference.com/w/cpp/compiler_support |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2441 |
#if defined(_MSC_VER) && _MSC_VER < 1914 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2442 |
#undef JSON_HAS_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2443 |
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2444 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2445 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2446 |
// no filesystem support before iOS 13 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2447 |
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2448 |
#undef JSON_HAS_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2449 |
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2450 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2451 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2452 |
// no filesystem support before macOS Catalina |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2453 |
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2454 |
#undef JSON_HAS_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2455 |
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2456 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2457 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2458 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2459 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2460 |
#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2461 |
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2462 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2463 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2464 |
#ifndef JSON_HAS_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2465 |
#define JSON_HAS_FILESYSTEM 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2466 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2467 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2468 |
#ifndef JSON_HAS_THREE_WAY_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2469 |
#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2470 |
&& defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2471 |
#define JSON_HAS_THREE_WAY_COMPARISON 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2472 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2473 |
#define JSON_HAS_THREE_WAY_COMPARISON 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2474 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2475 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2476 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2477 |
#ifndef JSON_HAS_RANGES |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2478 |
// ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2479 |
#if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2480 |
#define JSON_HAS_RANGES 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2481 |
#elif defined(__cpp_lib_ranges) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2482 |
#define JSON_HAS_RANGES 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2483 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2484 |
#define JSON_HAS_RANGES 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2485 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2486 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2487 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2488 |
#ifndef JSON_HAS_STATIC_RTTI |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2489 |
#if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2490 |
#define JSON_HAS_STATIC_RTTI 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2491 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2492 |
#define JSON_HAS_STATIC_RTTI 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2493 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2494 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2495 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2496 |
#ifdef JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2497 |
#define JSON_INLINE_VARIABLE inline |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2498 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2499 |
#define JSON_INLINE_VARIABLE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2500 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2501 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2502 |
#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2503 |
#define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2504 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2505 |
#define JSON_NO_UNIQUE_ADDRESS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2506 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2507 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2508 |
// disable documentation warnings on clang |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2509 |
#if defined(__clang__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2510 |
#pragma clang diagnostic push |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2511 |
#pragma clang diagnostic ignored "-Wdocumentation" |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2512 |
#pragma clang diagnostic ignored "-Wdocumentation-unknown-command" |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2513 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2514 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2515 |
// allow disabling exceptions |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2516 |
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2517 |
#define JSON_THROW(exception) throw exception |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2518 |
#define JSON_TRY try |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2519 |
#define JSON_CATCH(exception) catch(exception) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2520 |
#define JSON_INTERNAL_CATCH(exception) catch(exception) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2521 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2522 |
#include <cstdlib> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2523 |
#define JSON_THROW(exception) std::abort() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2524 |
#define JSON_TRY if(true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2525 |
#define JSON_CATCH(exception) if(false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2526 |
#define JSON_INTERNAL_CATCH(exception) if(false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2527 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2528 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2529 |
// override exception macros |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2530 |
#if defined(JSON_THROW_USER) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2531 |
#undef JSON_THROW |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2532 |
#define JSON_THROW JSON_THROW_USER |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2533 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2534 |
#if defined(JSON_TRY_USER) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2535 |
#undef JSON_TRY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2536 |
#define JSON_TRY JSON_TRY_USER |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2537 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2538 |
#if defined(JSON_CATCH_USER) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2539 |
#undef JSON_CATCH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2540 |
#define JSON_CATCH JSON_CATCH_USER |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2541 |
#undef JSON_INTERNAL_CATCH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2542 |
#define JSON_INTERNAL_CATCH JSON_CATCH_USER |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2543 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2544 |
#if defined(JSON_INTERNAL_CATCH_USER) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2545 |
#undef JSON_INTERNAL_CATCH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2546 |
#define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2547 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2548 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2549 |
// allow overriding assert |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2550 |
#if !defined(JSON_ASSERT) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2551 |
#include <cassert> // assert |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2552 |
#define JSON_ASSERT(x) assert(x) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2553 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2554 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2555 |
// allow to access some private functions (needed by the test suite) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2556 |
#if defined(JSON_TESTS_PRIVATE) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2557 |
#define JSON_PRIVATE_UNLESS_TESTED public |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2558 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2559 |
#define JSON_PRIVATE_UNLESS_TESTED private |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2560 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2561 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2562 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2563 |
@brief macro to briefly define a mapping between an enum and JSON |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2564 |
@def NLOHMANN_JSON_SERIALIZE_ENUM |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2565 |
@since version 3.4.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2566 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2567 |
#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2568 |
template<typename BasicJsonType> \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2569 |
inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2570 |
{ \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2571 |
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2572 |
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2573 |
auto it = std::find_if(std::begin(m), std::end(m), \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2574 |
[e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2575 |
{ \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2576 |
return ej_pair.first == e; \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2577 |
}); \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2578 |
j = ((it != std::end(m)) ? it : std::begin(m))->second; \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2579 |
} \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2580 |
template<typename BasicJsonType> \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2581 |
inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2582 |
{ \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2583 |
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2584 |
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2585 |
auto it = std::find_if(std::begin(m), std::end(m), \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2586 |
[&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2587 |
{ \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2588 |
return ej_pair.second == j; \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2589 |
}); \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2590 |
e = ((it != std::end(m)) ? it : std::begin(m))->first; \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2591 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2592 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2593 |
// Ugly macros to avoid uglier copy-paste when specializing basic_json. They |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2594 |
// may be removed in the future once the class is split. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2595 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2596 |
#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2597 |
template<template<typename, typename, typename...> class ObjectType, \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2598 |
template<typename, typename...> class ArrayType, \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2599 |
class StringType, class BooleanType, class NumberIntegerType, \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2600 |
class NumberUnsignedType, class NumberFloatType, \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2601 |
template<typename> class AllocatorType, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2602 |
template<typename, typename = void> class JSONSerializer, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2603 |
class BinaryType, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2604 |
class CustomBaseClass> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2605 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2606 |
#define NLOHMANN_BASIC_JSON_TPL \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2607 |
basic_json<ObjectType, ArrayType, StringType, BooleanType, \ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2608 |
NumberIntegerType, NumberUnsignedType, NumberFloatType, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2609 |
AllocatorType, JSONSerializer, BinaryType, CustomBaseClass> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2610 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2611 |
// Macros to simplify conversion from/to types |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2612 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2613 |
#define NLOHMANN_JSON_EXPAND( x ) x |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2614 |
#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2615 |
#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2616 |
NLOHMANN_JSON_PASTE64, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2617 |
NLOHMANN_JSON_PASTE63, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2618 |
NLOHMANN_JSON_PASTE62, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2619 |
NLOHMANN_JSON_PASTE61, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2620 |
NLOHMANN_JSON_PASTE60, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2621 |
NLOHMANN_JSON_PASTE59, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2622 |
NLOHMANN_JSON_PASTE58, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2623 |
NLOHMANN_JSON_PASTE57, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2624 |
NLOHMANN_JSON_PASTE56, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2625 |
NLOHMANN_JSON_PASTE55, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2626 |
NLOHMANN_JSON_PASTE54, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2627 |
NLOHMANN_JSON_PASTE53, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2628 |
NLOHMANN_JSON_PASTE52, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2629 |
NLOHMANN_JSON_PASTE51, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2630 |
NLOHMANN_JSON_PASTE50, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2631 |
NLOHMANN_JSON_PASTE49, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2632 |
NLOHMANN_JSON_PASTE48, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2633 |
NLOHMANN_JSON_PASTE47, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2634 |
NLOHMANN_JSON_PASTE46, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2635 |
NLOHMANN_JSON_PASTE45, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2636 |
NLOHMANN_JSON_PASTE44, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2637 |
NLOHMANN_JSON_PASTE43, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2638 |
NLOHMANN_JSON_PASTE42, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2639 |
NLOHMANN_JSON_PASTE41, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2640 |
NLOHMANN_JSON_PASTE40, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2641 |
NLOHMANN_JSON_PASTE39, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2642 |
NLOHMANN_JSON_PASTE38, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2643 |
NLOHMANN_JSON_PASTE37, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2644 |
NLOHMANN_JSON_PASTE36, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2645 |
NLOHMANN_JSON_PASTE35, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2646 |
NLOHMANN_JSON_PASTE34, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2647 |
NLOHMANN_JSON_PASTE33, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2648 |
NLOHMANN_JSON_PASTE32, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2649 |
NLOHMANN_JSON_PASTE31, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2650 |
NLOHMANN_JSON_PASTE30, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2651 |
NLOHMANN_JSON_PASTE29, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2652 |
NLOHMANN_JSON_PASTE28, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2653 |
NLOHMANN_JSON_PASTE27, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2654 |
NLOHMANN_JSON_PASTE26, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2655 |
NLOHMANN_JSON_PASTE25, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2656 |
NLOHMANN_JSON_PASTE24, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2657 |
NLOHMANN_JSON_PASTE23, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2658 |
NLOHMANN_JSON_PASTE22, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2659 |
NLOHMANN_JSON_PASTE21, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2660 |
NLOHMANN_JSON_PASTE20, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2661 |
NLOHMANN_JSON_PASTE19, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2662 |
NLOHMANN_JSON_PASTE18, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2663 |
NLOHMANN_JSON_PASTE17, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2664 |
NLOHMANN_JSON_PASTE16, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2665 |
NLOHMANN_JSON_PASTE15, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2666 |
NLOHMANN_JSON_PASTE14, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2667 |
NLOHMANN_JSON_PASTE13, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2668 |
NLOHMANN_JSON_PASTE12, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2669 |
NLOHMANN_JSON_PASTE11, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2670 |
NLOHMANN_JSON_PASTE10, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2671 |
NLOHMANN_JSON_PASTE9, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2672 |
NLOHMANN_JSON_PASTE8, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2673 |
NLOHMANN_JSON_PASTE7, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2674 |
NLOHMANN_JSON_PASTE6, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2675 |
NLOHMANN_JSON_PASTE5, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2676 |
NLOHMANN_JSON_PASTE4, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2677 |
NLOHMANN_JSON_PASTE3, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2678 |
NLOHMANN_JSON_PASTE2, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2679 |
NLOHMANN_JSON_PASTE1)(__VA_ARGS__)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2680 |
#define NLOHMANN_JSON_PASTE2(func, v1) func(v1) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2681 |
#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2682 |
#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2683 |
#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2684 |
#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2685 |
#define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2686 |
#define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2687 |
#define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2688 |
#define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2689 |
#define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2690 |
#define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2691 |
#define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2692 |
#define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2693 |
#define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2694 |
#define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2695 |
#define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2696 |
#define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2697 |
#define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2698 |
#define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2699 |
#define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2700 |
#define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2701 |
#define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2702 |
#define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2703 |
#define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2704 |
#define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2705 |
#define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2706 |
#define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2707 |
#define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2708 |
#define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2709 |
#define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2710 |
#define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2711 |
#define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2712 |
#define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2713 |
#define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2714 |
#define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2715 |
#define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2716 |
#define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2717 |
#define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2718 |
#define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2719 |
#define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2720 |
#define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2721 |
#define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2722 |
#define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2723 |
#define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2724 |
#define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2725 |
#define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2726 |
#define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2727 |
#define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2728 |
#define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2729 |
#define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2730 |
#define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2731 |
#define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2732 |
#define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2733 |
#define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2734 |
#define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2735 |
#define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2736 |
#define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2737 |
#define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2738 |
#define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2739 |
#define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2740 |
#define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2741 |
#define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2742 |
#define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2743 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2744 |
#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2745 |
#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2746 |
#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2747 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2748 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2749 |
@brief macro |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2750 |
@def NLOHMANN_DEFINE_TYPE_INTRUSIVE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2751 |
@since version 3.9.0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2752 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2753 |
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2754 |
friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2755 |
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2756 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2757 |
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2758 |
friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2759 |
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2760 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2761 |
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2762 |
friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2763 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2764 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2765 |
@brief macro |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2766 |
@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2767 |
@since version 3.9.0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2768 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2769 |
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2770 |
inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2771 |
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2772 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2773 |
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2774 |
inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2775 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2776 |
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2777 |
inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2778 |
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2779 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2780 |
// inspired from https://stackoverflow.com/a/26745591 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2781 |
// allows to call any std function as if (e.g. with begin): |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2782 |
// using std::begin; begin(x); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2783 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2784 |
// it allows using the detected idiom to retrieve the return type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2785 |
// of such an expression |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2786 |
#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2787 |
namespace detail { \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2788 |
using std::std_name; \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2789 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2790 |
template<typename... T> \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2791 |
using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2792 |
} \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2793 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2794 |
namespace detail2 { \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2795 |
struct std_name##_tag \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2796 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2797 |
}; \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2798 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2799 |
template<typename... T> \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2800 |
std_name##_tag std_name(T&&...); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2801 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2802 |
template<typename... T> \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2803 |
using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2804 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2805 |
template<typename... T> \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2806 |
struct would_call_std_##std_name \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2807 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2808 |
static constexpr auto const value = ::nlohmann::detail:: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2809 |
is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2810 |
}; \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2811 |
} /* namespace detail2 */ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2812 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2813 |
template<typename... T> \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2814 |
struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2815 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2816 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2817 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2818 |
#ifndef JSON_USE_IMPLICIT_CONVERSIONS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2819 |
#define JSON_USE_IMPLICIT_CONVERSIONS 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2820 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2821 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2822 |
#if JSON_USE_IMPLICIT_CONVERSIONS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2823 |
#define JSON_EXPLICIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2824 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2825 |
#define JSON_EXPLICIT explicit |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2826 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2827 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2828 |
#ifndef JSON_DISABLE_ENUM_SERIALIZATION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2829 |
#define JSON_DISABLE_ENUM_SERIALIZATION 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2830 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2831 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2832 |
#ifndef JSON_USE_GLOBAL_UDLS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2833 |
#define JSON_USE_GLOBAL_UDLS 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2834 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2835 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2836 |
#if JSON_HAS_THREE_WAY_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2837 |
#include <compare> // partial_ordering |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2838 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2839 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2840 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2841 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2842 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2843 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2844 |
/////////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2845 |
// JSON type enumeration // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2846 |
/////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2847 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2848 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2849 |
@brief the JSON type enumeration |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2850 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2851 |
This enumeration collects the different JSON types. It is internally used to |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2852 |
distinguish the stored values, and the functions @ref basic_json::is_null(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2853 |
@ref basic_json::is_object(), @ref basic_json::is_array(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2854 |
@ref basic_json::is_string(), @ref basic_json::is_boolean(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2855 |
@ref basic_json::is_number() (with @ref basic_json::is_number_integer(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2856 |
@ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2857 |
@ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2858 |
@ref basic_json::is_structured() rely on it. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2859 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2860 |
@note There are three enumeration entries (number_integer, number_unsigned, and |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2861 |
number_float), because the library distinguishes these three types for numbers: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2862 |
@ref basic_json::number_unsigned_t is used for unsigned integers, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2863 |
@ref basic_json::number_integer_t is used for signed integers, and |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2864 |
@ref basic_json::number_float_t is used for floating-point numbers or to |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2865 |
approximate integers which do not fit in the limits of their respective type. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2866 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2867 |
@sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2868 |
value with the default value for a given type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2869 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2870 |
@since version 1.0.0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2871 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2872 |
enum class value_t : std::uint8_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2873 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2874 |
null, ///< null value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2875 |
object, ///< object (unordered set of name/value pairs) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2876 |
array, ///< array (ordered collection of values) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2877 |
string, ///< string value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2878 |
boolean, ///< boolean value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2879 |
number_integer, ///< number value (signed integer) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2880 |
number_unsigned, ///< number value (unsigned integer) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2881 |
number_float, ///< number value (floating-point) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2882 |
binary, ///< binary array (ordered collection of bytes) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2883 |
discarded ///< discarded by the parser callback function |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2884 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2885 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2886 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2887 |
@brief comparison operator for JSON types |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2888 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2889 |
Returns an ordering that is similar to Python: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2890 |
- order: null < boolean < number < object < array < string < binary |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2891 |
- furthermore, each type is not smaller than itself |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2892 |
- discarded values are not comparable |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2893 |
- binary is represented as a b"" string in python and directly comparable to a |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2894 |
string; however, making a binary array directly comparable with a string would |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2895 |
be surprising behavior in a JSON file. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2896 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2897 |
@since version 1.0.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2898 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2899 |
#if JSON_HAS_THREE_WAY_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2900 |
inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2901 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2902 |
inline bool operator<(const value_t lhs, const value_t rhs) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2903 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2904 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2905 |
static constexpr std::array<std::uint8_t, 9> order = {{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2906 |
0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2907 |
1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2908 |
6 /* binary */ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2909 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2910 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2911 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2912 |
const auto l_index = static_cast<std::size_t>(lhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2913 |
const auto r_index = static_cast<std::size_t>(rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2914 |
#if JSON_HAS_THREE_WAY_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2915 |
if (l_index < order.size() && r_index < order.size()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2916 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2917 |
return order[l_index] <=> order[r_index]; // *NOPAD* |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2918 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2919 |
return std::partial_ordering::unordered; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2920 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2921 |
return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2922 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2923 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2924 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2925 |
// GCC selects the built-in operator< over an operator rewritten from |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2926 |
// a user-defined spaceship operator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2927 |
// Clang, MSVC, and ICC select the rewritten candidate |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2928 |
// (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2929 |
#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2930 |
inline bool operator<(const value_t lhs, const value_t rhs) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2931 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2932 |
return std::is_lt(lhs <=> rhs); // *NOPAD* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2933 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2934 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2935 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2936 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2937 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2938 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2939 |
// #include <nlohmann/detail/string_escape.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2940 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2941 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2942 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2943 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2944 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2945 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2946 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2947 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2948 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2949 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2950 |
// #include <nlohmann/detail/abi_macros.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2951 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2952 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2953 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2954 |
namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2955 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2956 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2957 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2958 |
@brief replace all occurrences of a substring by another string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2959 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2960 |
@param[in,out] s the string to manipulate; changed so that all |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2961 |
occurrences of @a f are replaced with @a t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2962 |
@param[in] f the substring to replace with @a t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2963 |
@param[in] t the string to replace @a f |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2964 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2965 |
@pre The search string @a f must not be empty. **This precondition is |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2966 |
enforced with an assertion.** |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2967 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2968 |
@since version 2.0.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2969 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2970 |
template<typename StringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2971 |
inline void replace_substring(StringType& s, const StringType& f, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2972 |
const StringType& t) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2973 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2974 |
JSON_ASSERT(!f.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2975 |
for (auto pos = s.find(f); // find first occurrence of f |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2976 |
pos != StringType::npos; // make sure f was found |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2977 |
s.replace(pos, f.size(), t), // replace with t, and |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2978 |
pos = s.find(f, pos + t.size())) // find next occurrence of f |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2979 |
{} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2980 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2981 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2982 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2983 |
* @brief string escaping as described in RFC 6901 (Sect. 4) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2984 |
* @param[in] s string to escape |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2985 |
* @return escaped string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2986 |
* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2987 |
* Note the order of escaping "~" to "~0" and "/" to "~1" is important. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2988 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2989 |
template<typename StringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2990 |
inline StringType escape(StringType s) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2991 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2992 |
replace_substring(s, StringType{"~"}, StringType{"~0"}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2993 |
replace_substring(s, StringType{"/"}, StringType{"~1"}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2994 |
return s; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2995 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2996 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
2997 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2998 |
* @brief string unescaping as described in RFC 6901 (Sect. 4) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
2999 |
* @param[in] s string to unescape |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3000 |
* @return unescaped string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3001 |
* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3002 |
* Note the order of escaping "~1" to "/" and "~0" to "~" is important. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3003 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3004 |
template<typename StringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3005 |
static void unescape(StringType& s) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3006 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3007 |
replace_substring(s, StringType{"~1"}, StringType{"/"}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3008 |
replace_substring(s, StringType{"~0"}, StringType{"~"}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3009 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3010 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3011 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3012 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3013 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3014 |
// #include <nlohmann/detail/input/position_t.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3015 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3016 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3017 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3018 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3019 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3020 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3021 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3022 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3023 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3024 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3025 |
#include <cstddef> // size_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3026 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3027 |
// #include <nlohmann/detail/abi_macros.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3028 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3029 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3030 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3031 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3032 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3033 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3034 |
/// struct to capture the start position of the current token |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3035 |
struct position_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3036 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3037 |
/// the total number of characters read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3038 |
std::size_t chars_read_total = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3039 |
/// the number of characters read in the current line |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3040 |
std::size_t chars_read_current_line = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3041 |
/// the number of lines read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3042 |
std::size_t lines_read = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3043 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3044 |
/// conversion to size_t to preserve SAX interface |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3045 |
constexpr operator size_t() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3046 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3047 |
return chars_read_total; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3048 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3049 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3050 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3051 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3052 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3053 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3054 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3055 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3056 |
// #include <nlohmann/detail/meta/cpp_future.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3057 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3058 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3059 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3060 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3061 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3062 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3063 |
// SPDX-FileCopyrightText: 2018 The Abseil Authors |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3064 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3065 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3066 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3067 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3068 |
#include <array> // array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3069 |
#include <cstddef> // size_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3070 |
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3071 |
#include <utility> // index_sequence, make_index_sequence, index_sequence_for |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3072 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3073 |
// #include <nlohmann/detail/macro_scope.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3074 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3075 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3076 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3077 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3078 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3079 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3080 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3081 |
using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3082 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3083 |
#ifdef JSON_HAS_CPP_14 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3084 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3085 |
// the following utilities are natively available in C++14 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3086 |
using std::enable_if_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3087 |
using std::index_sequence; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3088 |
using std::make_index_sequence; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3089 |
using std::index_sequence_for; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3090 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3091 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3092 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3093 |
// alias templates to reduce boilerplate |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3094 |
template<bool B, typename T = void> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3095 |
using enable_if_t = typename std::enable_if<B, T>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3096 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3097 |
// The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3098 |
// which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3099 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3100 |
//// START OF CODE FROM GOOGLE ABSEIL |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3101 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3102 |
// integer_sequence |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3103 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3104 |
// Class template representing a compile-time integer sequence. An instantiation |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3105 |
// of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3106 |
// type through its template arguments (which is a common need when |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3107 |
// working with C++11 variadic templates). `absl::integer_sequence` is designed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3108 |
// to be a drop-in replacement for C++14's `std::integer_sequence`. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3109 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3110 |
// Example: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3111 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3112 |
// template< class T, T... Ints > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3113 |
// void user_function(integer_sequence<T, Ints...>); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3114 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3115 |
// int main() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3116 |
// { |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3117 |
// // user_function's `T` will be deduced to `int` and `Ints...` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3118 |
// // will be deduced to `0, 1, 2, 3, 4`. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3119 |
// user_function(make_integer_sequence<int, 5>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3120 |
// } |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3121 |
template <typename T, T... Ints> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3122 |
struct integer_sequence |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3123 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3124 |
using value_type = T; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3125 |
static constexpr std::size_t size() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3126 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3127 |
return sizeof...(Ints); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3128 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3129 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3130 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3131 |
// index_sequence |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3132 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3133 |
// A helper template for an `integer_sequence` of `size_t`, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3134 |
// `absl::index_sequence` is designed to be a drop-in replacement for C++14's |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3135 |
// `std::index_sequence`. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3136 |
template <size_t... Ints> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3137 |
using index_sequence = integer_sequence<size_t, Ints...>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3138 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3139 |
namespace utility_internal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3140 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3141 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3142 |
template <typename Seq, size_t SeqSize, size_t Rem> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3143 |
struct Extend; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3144 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3145 |
// Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3146 |
template <typename T, T... Ints, size_t SeqSize> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3147 |
struct Extend<integer_sequence<T, Ints...>, SeqSize, 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3148 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3149 |
using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3150 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3151 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3152 |
template <typename T, T... Ints, size_t SeqSize> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3153 |
struct Extend<integer_sequence<T, Ints...>, SeqSize, 1> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3154 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3155 |
using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3156 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3157 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3158 |
// Recursion helper for 'make_integer_sequence<T, N>'. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3159 |
// 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3160 |
template <typename T, size_t N> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3161 |
struct Gen |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3162 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3163 |
using type = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3164 |
typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3165 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3166 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3167 |
template <typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3168 |
struct Gen<T, 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3169 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3170 |
using type = integer_sequence<T>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3171 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3172 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3173 |
} // namespace utility_internal |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3174 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3175 |
// Compile-time sequences of integers |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3176 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3177 |
// make_integer_sequence |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3178 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3179 |
// This template alias is equivalent to |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3180 |
// `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3181 |
// replacement for C++14's `std::make_integer_sequence`. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3182 |
template <typename T, T N> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3183 |
using make_integer_sequence = typename utility_internal::Gen<T, N>::type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3184 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3185 |
// make_index_sequence |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3186 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3187 |
// This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3188 |
// and is designed to be a drop-in replacement for C++14's |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3189 |
// `std::make_index_sequence`. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3190 |
template <size_t N> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3191 |
using make_index_sequence = make_integer_sequence<size_t, N>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3192 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3193 |
// index_sequence_for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3194 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3195 |
// Converts a typename pack into an index sequence of the same length, and |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3196 |
// is designed to be a drop-in replacement for C++14's |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3197 |
// `std::index_sequence_for()` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3198 |
template <typename... Ts> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3199 |
using index_sequence_for = make_index_sequence<sizeof...(Ts)>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3200 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3201 |
//// END OF CODE FROM GOOGLE ABSEIL |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3202 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3203 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3204 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3205 |
// dispatch utility (taken from ranges-v3) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3206 |
template<unsigned N> struct priority_tag : priority_tag < N - 1 > {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3207 |
template<> struct priority_tag<0> {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3208 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3209 |
// taken from ranges-v3 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3210 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3211 |
struct static_const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3212 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3213 |
static JSON_INLINE_VARIABLE constexpr T value{}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3214 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3215 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3216 |
#ifndef JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3217 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3218 |
constexpr T static_const<T>::value; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3219 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3220 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3221 |
template<typename T, typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3222 |
inline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3223 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3224 |
return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3225 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3226 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3227 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3228 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3229 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3230 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3231 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3232 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3233 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3234 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3235 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3236 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3237 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3238 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3239 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3240 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3241 |
#include <limits> // numeric_limits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3242 |
#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3243 |
#include <utility> // declval |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3244 |
#include <tuple> // tuple |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3245 |
#include <string> // char_traits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3246 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3247 |
// #include <nlohmann/detail/iterators/iterator_traits.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3248 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3249 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3250 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3251 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3252 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3253 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3254 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3255 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3256 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3257 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3258 |
#include <iterator> // random_access_iterator_tag |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3259 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3260 |
// #include <nlohmann/detail/abi_macros.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3261 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3262 |
// #include <nlohmann/detail/meta/void_t.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3263 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3264 |
// #include <nlohmann/detail/meta/cpp_future.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3265 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3266 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3267 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3268 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3269 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3270 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3271 |
template<typename It, typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3272 |
struct iterator_types {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3273 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3274 |
template<typename It> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3275 |
struct iterator_types < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3276 |
It, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3277 |
void_t<typename It::difference_type, typename It::value_type, typename It::pointer, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3278 |
typename It::reference, typename It::iterator_category >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3279 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3280 |
using difference_type = typename It::difference_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3281 |
using value_type = typename It::value_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3282 |
using pointer = typename It::pointer; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3283 |
using reference = typename It::reference; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3284 |
using iterator_category = typename It::iterator_category; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3285 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3286 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3287 |
// This is required as some compilers implement std::iterator_traits in a way that |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3288 |
// doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3289 |
template<typename T, typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3290 |
struct iterator_traits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3291 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3292 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3293 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3294 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3295 |
struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3296 |
: iterator_types<T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3297 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3298 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3299 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3300 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3301 |
struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3302 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3303 |
using iterator_category = std::random_access_iterator_tag; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3304 |
using value_type = T; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3305 |
using difference_type = ptrdiff_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3306 |
using pointer = T*; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3307 |
using reference = T&; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3308 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3309 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3310 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3311 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3312 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3313 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3314 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3315 |
// #include <nlohmann/detail/meta/call_std/begin.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3316 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3317 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3318 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3319 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3320 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3321 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3322 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3323 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3324 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3325 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3326 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3327 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3328 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3329 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3330 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3331 |
NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3332 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3333 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3334 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3335 |
// #include <nlohmann/detail/meta/call_std/end.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3336 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3337 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3338 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3339 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3340 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3341 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3342 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3343 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3344 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3345 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3346 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3347 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3348 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3349 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3350 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3351 |
NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3352 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3353 |
NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3354 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3355 |
// #include <nlohmann/detail/meta/cpp_future.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3356 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3357 |
// #include <nlohmann/detail/meta/detected.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3358 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3359 |
// #include <nlohmann/json_fwd.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3360 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3361 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3362 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3363 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3364 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3365 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3366 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3367 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3368 |
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3369 |
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3370 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3371 |
#include <cstdint> // int64_t, uint64_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3372 |
#include <map> // map |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3373 |
#include <memory> // allocator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3374 |
#include <string> // string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3375 |
#include <vector> // vector |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3376 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3377 |
// #include <nlohmann/detail/abi_macros.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3378 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3379 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3380 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3381 |
@brief namespace for Niels Lohmann |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3382 |
@see https://github.com/nlohmann |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3383 |
@since version 1.0.0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3384 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3385 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3386 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3387 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3388 |
@brief default JSONSerializer template argument |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3389 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3390 |
This serializer ignores the template arguments and uses ADL |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3391 |
([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3392 |
for serialization. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3393 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3394 |
template<typename T = void, typename SFINAE = void> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3395 |
struct adl_serializer; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3396 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3397 |
/// a class to store JSON values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3398 |
/// @sa https://json.nlohmann.me/api/basic_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3399 |
template<template<typename U, typename V, typename... Args> class ObjectType = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3400 |
std::map, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3401 |
template<typename U, typename... Args> class ArrayType = std::vector, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3402 |
class StringType = std::string, class BooleanType = bool, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3403 |
class NumberIntegerType = std::int64_t, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3404 |
class NumberUnsignedType = std::uint64_t, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3405 |
class NumberFloatType = double, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3406 |
template<typename U> class AllocatorType = std::allocator, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3407 |
template<typename T, typename SFINAE = void> class JSONSerializer = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3408 |
adl_serializer, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3409 |
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3410 |
class CustomBaseClass = void> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3411 |
class basic_json; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3412 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3413 |
/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3414 |
/// @sa https://json.nlohmann.me/api/json_pointer/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3415 |
template<typename RefStringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3416 |
class json_pointer; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3417 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3418 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3419 |
@brief default specialization |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3420 |
@sa https://json.nlohmann.me/api/json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3421 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3422 |
using json = basic_json<>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3423 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3424 |
/// @brief a minimal map-like container that preserves insertion order |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3425 |
/// @sa https://json.nlohmann.me/api/ordered_map/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3426 |
template<class Key, class T, class IgnoredLess, class Allocator> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3427 |
struct ordered_map; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3428 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3429 |
/// @brief specialization that maintains the insertion order of object keys |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3430 |
/// @sa https://json.nlohmann.me/api/ordered_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3431 |
using ordered_json = basic_json<nlohmann::ordered_map>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3432 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3433 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3434 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3435 |
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3436 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3437 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3438 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3439 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3440 |
@brief detail namespace with internal helper functions |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3441 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3442 |
This namespace collects functions that should not be exposed, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3443 |
implementations of some @ref basic_json methods, and meta-programming helpers. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3444 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3445 |
@since version 2.1.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3446 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3447 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3448 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3449 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3450 |
///////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3451 |
// helpers // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3452 |
///////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3453 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3454 |
// Note to maintainers: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3455 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3456 |
// Every trait in this file expects a non CV-qualified type. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3457 |
// The only exceptions are in the 'aliases for detected' section |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3458 |
// (i.e. those of the form: decltype(T::member_function(std::declval<T>()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3459 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3460 |
// In this case, T has to be properly CV-qualified to constraint the function arguments |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3461 |
// (e.g. to_json(BasicJsonType&, const T&)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3462 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3463 |
template<typename> struct is_basic_json : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3464 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3465 |
NLOHMANN_BASIC_JSON_TPL_DECLARATION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3466 |
struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3467 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3468 |
// used by exceptions create() member functions |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3469 |
// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3470 |
// false_type otherwise |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3471 |
template<typename BasicJsonContext> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3472 |
struct is_basic_json_context : |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3473 |
std::integral_constant < bool, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3474 |
is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3475 |
|| std::is_same<BasicJsonContext, std::nullptr_t>::value > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3476 |
{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3477 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3478 |
////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3479 |
// json_ref helpers // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3480 |
////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3481 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3482 |
template<typename> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3483 |
class json_ref; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3484 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3485 |
template<typename> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3486 |
struct is_json_ref : std::false_type {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3487 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3488 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3489 |
struct is_json_ref<json_ref<T>> : std::true_type {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3490 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3491 |
////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3492 |
// aliases for detected // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3493 |
////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3494 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3495 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3496 |
using mapped_type_t = typename T::mapped_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3497 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3498 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3499 |
using key_type_t = typename T::key_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3500 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3501 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3502 |
using value_type_t = typename T::value_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3503 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3504 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3505 |
using difference_type_t = typename T::difference_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3506 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3507 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3508 |
using pointer_t = typename T::pointer; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3509 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3510 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3511 |
using reference_t = typename T::reference; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3512 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3513 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3514 |
using iterator_category_t = typename T::iterator_category; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3515 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3516 |
template<typename T, typename... Args> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3517 |
using to_json_function = decltype(T::to_json(std::declval<Args>()...)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3518 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3519 |
template<typename T, typename... Args> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3520 |
using from_json_function = decltype(T::from_json(std::declval<Args>()...)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3521 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3522 |
template<typename T, typename U> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3523 |
using get_template_function = decltype(std::declval<T>().template get<U>()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3524 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3525 |
// trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3526 |
template<typename BasicJsonType, typename T, typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3527 |
struct has_from_json : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3528 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3529 |
// trait checking if j.get<T> is valid |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3530 |
// use this trait instead of std::is_constructible or std::is_convertible, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3531 |
// both rely on, or make use of implicit conversions, and thus fail when T |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3532 |
// has several constructors/operator= (see https://github.com/nlohmann/json/issues/958) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3533 |
template <typename BasicJsonType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3534 |
struct is_getable |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3535 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3536 |
static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3537 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3538 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3539 |
template<typename BasicJsonType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3540 |
struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3541 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3542 |
using serializer = typename BasicJsonType::template json_serializer<T, void>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3543 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3544 |
static constexpr bool value = |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3545 |
is_detected_exact<void, from_json_function, serializer, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3546 |
const BasicJsonType&, T&>::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3547 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3548 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3549 |
// This trait checks if JSONSerializer<T>::from_json(json const&) exists |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3550 |
// this overload is used for non-default-constructible user-defined-types |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3551 |
template<typename BasicJsonType, typename T, typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3552 |
struct has_non_default_from_json : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3553 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3554 |
template<typename BasicJsonType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3555 |
struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3556 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3557 |
using serializer = typename BasicJsonType::template json_serializer<T, void>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3558 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3559 |
static constexpr bool value = |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3560 |
is_detected_exact<T, from_json_function, serializer, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3561 |
const BasicJsonType&>::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3562 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3563 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3564 |
// This trait checks if BasicJsonType::json_serializer<T>::to_json exists |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3565 |
// Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3566 |
template<typename BasicJsonType, typename T, typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3567 |
struct has_to_json : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3568 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3569 |
template<typename BasicJsonType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3570 |
struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3571 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3572 |
using serializer = typename BasicJsonType::template json_serializer<T, void>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3573 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3574 |
static constexpr bool value = |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3575 |
is_detected_exact<void, to_json_function, serializer, BasicJsonType&, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3576 |
T>::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3577 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3578 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3579 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3580 |
using detect_key_compare = typename T::key_compare; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3581 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3582 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3583 |
struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3584 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3585 |
// obtains the actual object key comparator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3586 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3587 |
struct actual_object_comparator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3588 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3589 |
using object_t = typename BasicJsonType::object_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3590 |
using object_comparator_t = typename BasicJsonType::default_object_comparator_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3591 |
using type = typename std::conditional < has_key_compare<object_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3592 |
typename object_t::key_compare, object_comparator_t>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3593 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3594 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3595 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3596 |
using actual_object_comparator_t = typename actual_object_comparator<BasicJsonType>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3597 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3598 |
///////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3599 |
// char_traits // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3600 |
///////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3601 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3602 |
// Primary template of char_traits calls std char_traits |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3603 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3604 |
struct char_traits : std::char_traits<T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3605 |
{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3606 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3607 |
// Explicitly define char traits for unsigned char since it is not standard |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3608 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3609 |
struct char_traits<unsigned char> : std::char_traits<char> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3610 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3611 |
using char_type = unsigned char; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3612 |
using int_type = uint64_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3613 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3614 |
// Redefine to_int_type function |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3615 |
static int_type to_int_type(char_type c) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3616 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3617 |
return static_cast<int_type>(c); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3618 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3619 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3620 |
static char_type to_char_type(int_type i) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3621 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3622 |
return static_cast<char_type>(i); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3623 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3624 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3625 |
static constexpr int_type eof() noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3626 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3627 |
return static_cast<int_type>(EOF); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3628 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3629 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3630 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3631 |
// Explicitly define char traits for signed char since it is not standard |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3632 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3633 |
struct char_traits<signed char> : std::char_traits<char> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3634 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3635 |
using char_type = signed char; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3636 |
using int_type = uint64_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3637 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3638 |
// Redefine to_int_type function |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3639 |
static int_type to_int_type(char_type c) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3640 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3641 |
return static_cast<int_type>(c); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3642 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3643 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3644 |
static char_type to_char_type(int_type i) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3645 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3646 |
return static_cast<char_type>(i); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3647 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3648 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3649 |
static constexpr int_type eof() noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3650 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3651 |
return static_cast<int_type>(EOF); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3652 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3653 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3654 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3655 |
/////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3656 |
// is_ functions // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3657 |
/////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3658 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3659 |
// https://en.cppreference.com/w/cpp/types/conjunction |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3660 |
template<class...> struct conjunction : std::true_type { }; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3661 |
template<class B> struct conjunction<B> : B { }; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3662 |
template<class B, class... Bn> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3663 |
struct conjunction<B, Bn...> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3664 |
: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3665 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3666 |
// https://en.cppreference.com/w/cpp/types/negation |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3667 |
template<class B> struct negation : std::integral_constant < bool, !B::value > { }; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3668 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3669 |
// Reimplementation of is_constructible and is_default_constructible, due to them being broken for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3670 |
// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367). |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3671 |
// This causes compile errors in e.g. clang 3.5 or gcc 4.9. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3672 |
template <typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3673 |
struct is_default_constructible : std::is_default_constructible<T> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3674 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3675 |
template <typename T1, typename T2> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3676 |
struct is_default_constructible<std::pair<T1, T2>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3677 |
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3678 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3679 |
template <typename T1, typename T2> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3680 |
struct is_default_constructible<const std::pair<T1, T2>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3681 |
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3682 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3683 |
template <typename... Ts> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3684 |
struct is_default_constructible<std::tuple<Ts...>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3685 |
: conjunction<is_default_constructible<Ts>...> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3686 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3687 |
template <typename... Ts> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3688 |
struct is_default_constructible<const std::tuple<Ts...>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3689 |
: conjunction<is_default_constructible<Ts>...> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3690 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3691 |
template <typename T, typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3692 |
struct is_constructible : std::is_constructible<T, Args...> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3693 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3694 |
template <typename T1, typename T2> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3695 |
struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3696 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3697 |
template <typename T1, typename T2> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3698 |
struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3699 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3700 |
template <typename... Ts> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3701 |
struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3702 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3703 |
template <typename... Ts> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3704 |
struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3705 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3706 |
template<typename T, typename = void> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3707 |
struct is_iterator_traits : std::false_type {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3708 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3709 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3710 |
struct is_iterator_traits<iterator_traits<T>> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3711 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3712 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3713 |
using traits = iterator_traits<T>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3714 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3715 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3716 |
static constexpr auto value = |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3717 |
is_detected<value_type_t, traits>::value && |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3718 |
is_detected<difference_type_t, traits>::value && |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3719 |
is_detected<pointer_t, traits>::value && |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3720 |
is_detected<iterator_category_t, traits>::value && |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3721 |
is_detected<reference_t, traits>::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3722 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3723 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3724 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3725 |
struct is_range |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3726 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3727 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3728 |
using t_ref = typename std::add_lvalue_reference<T>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3729 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3730 |
using iterator = detected_t<result_of_begin, t_ref>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3731 |
using sentinel = detected_t<result_of_end, t_ref>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3732 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3733 |
// to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3734 |
// and https://en.cppreference.com/w/cpp/iterator/sentinel_for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3735 |
// but reimplementing these would be too much work, as a lot of other concepts are used underneath |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3736 |
static constexpr auto is_iterator_begin = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3737 |
is_iterator_traits<iterator_traits<iterator>>::value; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3738 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3739 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3740 |
static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3741 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3742 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3743 |
template<typename R> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3744 |
using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3745 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3746 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3747 |
using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3748 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3749 |
// The following implementation of is_complete_type is taken from |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3750 |
// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3751 |
// and is written by Xiang Fan who agreed to using it in this library. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3752 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3753 |
template<typename T, typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3754 |
struct is_complete_type : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3755 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3756 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3757 |
struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3758 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3759 |
template<typename BasicJsonType, typename CompatibleObjectType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3760 |
typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3761 |
struct is_compatible_object_type_impl : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3762 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3763 |
template<typename BasicJsonType, typename CompatibleObjectType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3764 |
struct is_compatible_object_type_impl < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3765 |
BasicJsonType, CompatibleObjectType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3766 |
enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&& |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3767 |
is_detected<key_type_t, CompatibleObjectType>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3768 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3769 |
using object_t = typename BasicJsonType::object_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3770 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3771 |
// macOS's is_constructible does not play well with nonesuch... |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3772 |
static constexpr bool value = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3773 |
is_constructible<typename object_t::key_type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3774 |
typename CompatibleObjectType::key_type>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3775 |
is_constructible<typename object_t::mapped_type, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3776 |
typename CompatibleObjectType::mapped_type>::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3777 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3778 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3779 |
template<typename BasicJsonType, typename CompatibleObjectType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3780 |
struct is_compatible_object_type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3781 |
: is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3782 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3783 |
template<typename BasicJsonType, typename ConstructibleObjectType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3784 |
typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3785 |
struct is_constructible_object_type_impl : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3786 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3787 |
template<typename BasicJsonType, typename ConstructibleObjectType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3788 |
struct is_constructible_object_type_impl < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3789 |
BasicJsonType, ConstructibleObjectType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3790 |
enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&& |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3791 |
is_detected<key_type_t, ConstructibleObjectType>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3792 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3793 |
using object_t = typename BasicJsonType::object_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3794 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3795 |
static constexpr bool value = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3796 |
(is_default_constructible<ConstructibleObjectType>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3797 |
(std::is_move_assignable<ConstructibleObjectType>::value || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3798 |
std::is_copy_assignable<ConstructibleObjectType>::value) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3799 |
(is_constructible<typename ConstructibleObjectType::key_type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3800 |
typename object_t::key_type>::value && |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3801 |
std::is_same < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3802 |
typename object_t::mapped_type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3803 |
typename ConstructibleObjectType::mapped_type >::value)) || |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3804 |
(has_from_json<BasicJsonType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3805 |
typename ConstructibleObjectType::mapped_type>::value || |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3806 |
has_non_default_from_json < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3807 |
BasicJsonType, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3808 |
typename ConstructibleObjectType::mapped_type >::value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3809 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3810 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3811 |
template<typename BasicJsonType, typename ConstructibleObjectType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3812 |
struct is_constructible_object_type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3813 |
: is_constructible_object_type_impl<BasicJsonType, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3814 |
ConstructibleObjectType> {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3815 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3816 |
template<typename BasicJsonType, typename CompatibleStringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3817 |
struct is_compatible_string_type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3818 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3819 |
static constexpr auto value = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3820 |
is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3821 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3822 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3823 |
template<typename BasicJsonType, typename ConstructibleStringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3824 |
struct is_constructible_string_type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3825 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3826 |
// launder type through decltype() to fix compilation failure on ICPC |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3827 |
#ifdef __INTEL_COMPILER |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3828 |
using laundered_type = decltype(std::declval<ConstructibleStringType>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3829 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3830 |
using laundered_type = ConstructibleStringType; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3831 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3832 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3833 |
static constexpr auto value = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3834 |
conjunction < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3835 |
is_constructible<laundered_type, typename BasicJsonType::string_t>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3836 |
is_detected_exact<typename BasicJsonType::string_t::value_type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3837 |
value_type_t, laundered_type >>::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3838 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3839 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3840 |
template<typename BasicJsonType, typename CompatibleArrayType, typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3841 |
struct is_compatible_array_type_impl : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3842 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3843 |
template<typename BasicJsonType, typename CompatibleArrayType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3844 |
struct is_compatible_array_type_impl < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3845 |
BasicJsonType, CompatibleArrayType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3846 |
enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3847 |
is_detected<iterator_t, CompatibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3848 |
is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3849 |
// special case for types like std::filesystem::path whose iterator's value_type are themselves |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3850 |
// c.f. https://github.com/nlohmann/json/pull/3073 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3851 |
!std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3852 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3853 |
static constexpr bool value = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3854 |
is_constructible<BasicJsonType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3855 |
range_value_t<CompatibleArrayType>>::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3856 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3857 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3858 |
template<typename BasicJsonType, typename CompatibleArrayType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3859 |
struct is_compatible_array_type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3860 |
: is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3861 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3862 |
template<typename BasicJsonType, typename ConstructibleArrayType, typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3863 |
struct is_constructible_array_type_impl : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3864 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3865 |
template<typename BasicJsonType, typename ConstructibleArrayType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3866 |
struct is_constructible_array_type_impl < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3867 |
BasicJsonType, ConstructibleArrayType, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3868 |
enable_if_t<std::is_same<ConstructibleArrayType, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3869 |
typename BasicJsonType::value_type>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3870 |
: std::true_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3871 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3872 |
template<typename BasicJsonType, typename ConstructibleArrayType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3873 |
struct is_constructible_array_type_impl < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3874 |
BasicJsonType, ConstructibleArrayType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3875 |
enable_if_t < !std::is_same<ConstructibleArrayType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3876 |
typename BasicJsonType::value_type>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3877 |
!is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3878 |
is_default_constructible<ConstructibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3879 |
(std::is_move_assignable<ConstructibleArrayType>::value || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3880 |
std::is_copy_assignable<ConstructibleArrayType>::value)&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3881 |
is_detected<iterator_t, ConstructibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3882 |
is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3883 |
is_detected<range_value_t, ConstructibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3884 |
// special case for types like std::filesystem::path whose iterator's value_type are themselves |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3885 |
// c.f. https://github.com/nlohmann/json/pull/3073 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3886 |
!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3887 |
is_complete_type < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3888 |
detected_t<range_value_t, ConstructibleArrayType >>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3889 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3890 |
using value_type = range_value_t<ConstructibleArrayType>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3891 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3892 |
static constexpr bool value = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3893 |
std::is_same<value_type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3894 |
typename BasicJsonType::array_t::value_type>::value || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3895 |
has_from_json<BasicJsonType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3896 |
value_type>::value || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3897 |
has_non_default_from_json < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3898 |
BasicJsonType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3899 |
value_type >::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3900 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3901 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3902 |
template<typename BasicJsonType, typename ConstructibleArrayType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3903 |
struct is_constructible_array_type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3904 |
: is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3905 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3906 |
template<typename RealIntegerType, typename CompatibleNumberIntegerType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3907 |
typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3908 |
struct is_compatible_integer_type_impl : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3909 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3910 |
template<typename RealIntegerType, typename CompatibleNumberIntegerType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3911 |
struct is_compatible_integer_type_impl < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3912 |
RealIntegerType, CompatibleNumberIntegerType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3913 |
enable_if_t < std::is_integral<RealIntegerType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3914 |
std::is_integral<CompatibleNumberIntegerType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3915 |
!std::is_same<bool, CompatibleNumberIntegerType>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3916 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3917 |
// is there an assert somewhere on overflows? |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3918 |
using RealLimits = std::numeric_limits<RealIntegerType>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3919 |
using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3920 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3921 |
static constexpr auto value = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3922 |
is_constructible<RealIntegerType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3923 |
CompatibleNumberIntegerType>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3924 |
CompatibleLimits::is_integer && |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3925 |
RealLimits::is_signed == CompatibleLimits::is_signed; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3926 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3927 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3928 |
template<typename RealIntegerType, typename CompatibleNumberIntegerType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3929 |
struct is_compatible_integer_type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3930 |
: is_compatible_integer_type_impl<RealIntegerType, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3931 |
CompatibleNumberIntegerType> {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3932 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3933 |
template<typename BasicJsonType, typename CompatibleType, typename = void> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3934 |
struct is_compatible_type_impl: std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3935 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3936 |
template<typename BasicJsonType, typename CompatibleType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3937 |
struct is_compatible_type_impl < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3938 |
BasicJsonType, CompatibleType, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3939 |
enable_if_t<is_complete_type<CompatibleType>::value >> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3940 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3941 |
static constexpr bool value = |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3942 |
has_to_json<BasicJsonType, CompatibleType>::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3943 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3944 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3945 |
template<typename BasicJsonType, typename CompatibleType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3946 |
struct is_compatible_type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3947 |
: is_compatible_type_impl<BasicJsonType, CompatibleType> {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3948 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3949 |
template<typename T1, typename T2> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3950 |
struct is_constructible_tuple : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3951 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3952 |
template<typename T1, typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3953 |
struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3954 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3955 |
template<typename BasicJsonType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3956 |
struct is_json_iterator_of : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3957 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3958 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3959 |
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : std::true_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3960 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3961 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3962 |
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3963 |
{}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3964 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3965 |
// checks if a given type T is a template specialization of Primary |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3966 |
template<template <typename...> class Primary, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3967 |
struct is_specialization_of : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3968 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3969 |
template<template <typename...> class Primary, typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3970 |
struct is_specialization_of<Primary, Primary<Args...>> : std::true_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3971 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3972 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3973 |
using is_json_pointer = is_specialization_of<::nlohmann::json_pointer, uncvref_t<T>>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3974 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3975 |
// checks if A and B are comparable using Compare functor |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3976 |
template<typename Compare, typename A, typename B, typename = void> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3977 |
struct is_comparable : std::false_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3978 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3979 |
template<typename Compare, typename A, typename B> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3980 |
struct is_comparable<Compare, A, B, void_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3981 |
decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3982 |
decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3983 |
>> : std::true_type {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
3984 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3985 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3986 |
using detect_is_transparent = typename T::is_transparent; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3987 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3988 |
// type trait to check if KeyType can be used as object key (without a BasicJsonType) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3989 |
// see is_usable_as_basic_json_key_type below |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3990 |
template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3991 |
bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3992 |
using is_usable_as_key_type = typename std::conditional < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3993 |
is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3994 |
&& !(ExcludeObjectKeyType && std::is_same<KeyType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3995 |
ObjectKeyType>::value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3996 |
&& (!RequireTransparentComparator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3997 |
|| is_detected <detect_is_transparent, Comparator>::value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3998 |
&& !is_json_pointer<KeyType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
3999 |
std::true_type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4000 |
std::false_type >::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4001 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4002 |
// type trait to check if KeyType can be used as object key |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4003 |
// true if: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4004 |
// - KeyType is comparable with BasicJsonType::object_t::key_type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4005 |
// - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4006 |
// - the comparator is transparent or RequireTransparentComparator is false |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4007 |
// - KeyType is not a JSON iterator or json_pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4008 |
template<typename BasicJsonType, typename KeyTypeCVRef, bool RequireTransparentComparator = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4009 |
bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4010 |
using is_usable_as_basic_json_key_type = typename std::conditional < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4011 |
is_usable_as_key_type<typename BasicJsonType::object_comparator_t, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4012 |
typename BasicJsonType::object_t::key_type, KeyTypeCVRef, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4013 |
RequireTransparentComparator, ExcludeObjectKeyType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4014 |
&& !is_json_iterator_of<BasicJsonType, KeyType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4015 |
std::true_type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4016 |
std::false_type >::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4017 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4018 |
template<typename ObjectType, typename KeyType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4019 |
using detect_erase_with_key_type = decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4020 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4021 |
// type trait to check if object_t has an erase() member functions accepting KeyType |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4022 |
template<typename BasicJsonType, typename KeyType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4023 |
using has_erase_with_key_type = typename std::conditional < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4024 |
is_detected < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4025 |
detect_erase_with_key_type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4026 |
typename BasicJsonType::object_t, KeyType >::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4027 |
std::true_type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4028 |
std::false_type >::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4029 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4030 |
// a naive helper to check if a type is an ordered_map (exploits the fact that |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4031 |
// ordered_map inherits capacity() from std::vector) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4032 |
template <typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4033 |
struct is_ordered_map |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4034 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4035 |
using one = char; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4036 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4037 |
struct two |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4038 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4039 |
char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4040 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4041 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4042 |
template <typename C> static one test( decltype(&C::capacity) ) ; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4043 |
template <typename C> static two test(...); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4044 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4045 |
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4046 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4047 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4048 |
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4049 |
template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4050 |
T conditional_static_cast(U value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4051 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4052 |
return static_cast<T>(value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4053 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4054 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4055 |
template<typename T, typename U, enable_if_t<std::is_same<T, U>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4056 |
T conditional_static_cast(U value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4057 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4058 |
return value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4059 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4060 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4061 |
template<typename... Types> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4062 |
using all_integral = conjunction<std::is_integral<Types>...>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4063 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4064 |
template<typename... Types> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4065 |
using all_signed = conjunction<std::is_signed<Types>...>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4066 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4067 |
template<typename... Types> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4068 |
using all_unsigned = conjunction<std::is_unsigned<Types>...>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4069 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4070 |
// there's a disjunction trait in another PR; replace when merged |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4071 |
template<typename... Types> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4072 |
using same_sign = std::integral_constant < bool, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4073 |
all_signed<Types...>::value || all_unsigned<Types...>::value >; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4074 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4075 |
template<typename OfType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4076 |
using never_out_of_range = std::integral_constant < bool, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4077 |
(std::is_signed<OfType>::value && (sizeof(T) < sizeof(OfType))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4078 |
|| (same_sign<OfType, T>::value && sizeof(OfType) == sizeof(T)) >; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4079 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4080 |
template<typename OfType, typename T, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4081 |
bool OfTypeSigned = std::is_signed<OfType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4082 |
bool TSigned = std::is_signed<T>::value> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4083 |
struct value_in_range_of_impl2; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4084 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4085 |
template<typename OfType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4086 |
struct value_in_range_of_impl2<OfType, T, false, false> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4087 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4088 |
static constexpr bool test(T val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4089 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4090 |
using CommonType = typename std::common_type<OfType, T>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4091 |
return static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4092 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4093 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4094 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4095 |
template<typename OfType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4096 |
struct value_in_range_of_impl2<OfType, T, true, false> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4097 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4098 |
static constexpr bool test(T val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4099 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4100 |
using CommonType = typename std::common_type<OfType, T>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4101 |
return static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4102 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4103 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4104 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4105 |
template<typename OfType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4106 |
struct value_in_range_of_impl2<OfType, T, false, true> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4107 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4108 |
static constexpr bool test(T val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4109 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4110 |
using CommonType = typename std::common_type<OfType, T>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4111 |
return val >= 0 && static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4112 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4113 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4114 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4115 |
template<typename OfType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4116 |
struct value_in_range_of_impl2<OfType, T, true, true> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4117 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4118 |
static constexpr bool test(T val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4119 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4120 |
using CommonType = typename std::common_type<OfType, T>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4121 |
return static_cast<CommonType>(val) >= static_cast<CommonType>((std::numeric_limits<OfType>::min)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4122 |
&& static_cast<CommonType>(val) <= static_cast<CommonType>((std::numeric_limits<OfType>::max)()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4123 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4124 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4125 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4126 |
template<typename OfType, typename T, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4127 |
bool NeverOutOfRange = never_out_of_range<OfType, T>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4128 |
typename = detail::enable_if_t<all_integral<OfType, T>::value>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4129 |
struct value_in_range_of_impl1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4130 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4131 |
template<typename OfType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4132 |
struct value_in_range_of_impl1<OfType, T, false> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4133 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4134 |
static constexpr bool test(T val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4135 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4136 |
return value_in_range_of_impl2<OfType, T>::test(val); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4137 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4138 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4139 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4140 |
template<typename OfType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4141 |
struct value_in_range_of_impl1<OfType, T, true> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4142 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4143 |
static constexpr bool test(T /*val*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4144 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4145 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4146 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4147 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4148 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4149 |
template<typename OfType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4150 |
inline constexpr bool value_in_range_of(T val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4151 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4152 |
return value_in_range_of_impl1<OfType, T>::test(val); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4153 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4154 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4155 |
template<bool Value> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4156 |
using bool_constant = std::integral_constant<bool, Value>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4157 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4158 |
/////////////////////////////////////////////////////////////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4159 |
// is_c_string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4160 |
/////////////////////////////////////////////////////////////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4161 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4162 |
namespace impl |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4163 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4164 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4165 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4166 |
inline constexpr bool is_c_string() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4167 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4168 |
using TUnExt = typename std::remove_extent<T>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4169 |
using TUnCVExt = typename std::remove_cv<TUnExt>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4170 |
using TUnPtr = typename std::remove_pointer<T>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4171 |
using TUnCVPtr = typename std::remove_cv<TUnPtr>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4172 |
return |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4173 |
(std::is_array<T>::value && std::is_same<TUnCVExt, char>::value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4174 |
|| (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4175 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4176 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4177 |
} // namespace impl |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4178 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4179 |
// checks whether T is a [cv] char */[cv] char[] C string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4180 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4181 |
struct is_c_string : bool_constant<impl::is_c_string<T>()> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4182 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4183 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4184 |
using is_c_string_uncvref = is_c_string<uncvref_t<T>>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4185 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4186 |
/////////////////////////////////////////////////////////////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4187 |
// is_transparent |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4188 |
/////////////////////////////////////////////////////////////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4189 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4190 |
namespace impl |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4191 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4192 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4193 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4194 |
inline constexpr bool is_transparent() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4195 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4196 |
return is_detected<detect_is_transparent, T>::value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4197 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4198 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4199 |
} // namespace impl |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4200 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4201 |
// checks whether T has a member named is_transparent |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4202 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4203 |
struct is_transparent : bool_constant<impl::is_transparent<T>()> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4204 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4205 |
/////////////////////////////////////////////////////////////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4206 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4207 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4208 |
NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4209 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4210 |
// #include <nlohmann/detail/string_concat.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4211 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4212 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4213 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4214 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4215 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4216 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4217 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4218 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4219 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4220 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4221 |
#include <cstring> // strlen |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4222 |
#include <string> // string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4223 |
#include <utility> // forward |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4224 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4225 |
// #include <nlohmann/detail/meta/cpp_future.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4226 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4227 |
// #include <nlohmann/detail/meta/detected.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4228 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4229 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4230 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4231 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4232 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4233 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4234 |
inline std::size_t concat_length() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4235 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4236 |
return 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4237 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4238 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4239 |
template<typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4240 |
inline std::size_t concat_length(const char* cstr, const Args& ... rest); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4241 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4242 |
template<typename StringType, typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4243 |
inline std::size_t concat_length(const StringType& str, const Args& ... rest); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4244 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4245 |
template<typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4246 |
inline std::size_t concat_length(const char /*c*/, const Args& ... rest) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4247 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4248 |
return 1 + concat_length(rest...); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4249 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4250 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4251 |
template<typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4252 |
inline std::size_t concat_length(const char* cstr, const Args& ... rest) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4253 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4254 |
// cppcheck-suppress ignoredReturnValue |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4255 |
return ::strlen(cstr) + concat_length(rest...); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4256 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4257 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4258 |
template<typename StringType, typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4259 |
inline std::size_t concat_length(const StringType& str, const Args& ... rest) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4260 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4261 |
return str.size() + concat_length(rest...); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4262 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4263 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4264 |
template<typename OutStringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4265 |
inline void concat_into(OutStringType& /*out*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4266 |
{} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4267 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4268 |
template<typename StringType, typename Arg> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4269 |
using string_can_append = decltype(std::declval<StringType&>().append(std::declval < Arg && > ())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4270 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4271 |
template<typename StringType, typename Arg> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4272 |
using detect_string_can_append = is_detected<string_can_append, StringType, Arg>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4273 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4274 |
template<typename StringType, typename Arg> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4275 |
using string_can_append_op = decltype(std::declval<StringType&>() += std::declval < Arg && > ()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4276 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4277 |
template<typename StringType, typename Arg> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4278 |
using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4279 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4280 |
template<typename StringType, typename Arg> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4281 |
using string_can_append_iter = decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4282 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4283 |
template<typename StringType, typename Arg> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4284 |
using detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4285 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4286 |
template<typename StringType, typename Arg> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4287 |
using string_can_append_data = decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4288 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4289 |
template<typename StringType, typename Arg> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4290 |
using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4291 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4292 |
template < typename OutStringType, typename Arg, typename... Args, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4293 |
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4294 |
&& detect_string_can_append_op<OutStringType, Arg>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4295 |
inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4296 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4297 |
template < typename OutStringType, typename Arg, typename... Args, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4298 |
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4299 |
&& !detect_string_can_append_op<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4300 |
&& detect_string_can_append_iter<OutStringType, Arg>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4301 |
inline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4302 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4303 |
template < typename OutStringType, typename Arg, typename... Args, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4304 |
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4305 |
&& !detect_string_can_append_op<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4306 |
&& !detect_string_can_append_iter<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4307 |
&& detect_string_can_append_data<OutStringType, Arg>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4308 |
inline void concat_into(OutStringType& out, const Arg& arg, Args && ... rest); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4309 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4310 |
template<typename OutStringType, typename Arg, typename... Args, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4311 |
enable_if_t<detect_string_can_append<OutStringType, Arg>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4312 |
inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4313 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4314 |
out.append(std::forward<Arg>(arg)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4315 |
concat_into(out, std::forward<Args>(rest)...); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4316 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4317 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4318 |
template < typename OutStringType, typename Arg, typename... Args, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4319 |
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4320 |
&& detect_string_can_append_op<OutStringType, Arg>::value, int > > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4321 |
inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4322 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4323 |
out += std::forward<Arg>(arg); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4324 |
concat_into(out, std::forward<Args>(rest)...); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4325 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4326 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4327 |
template < typename OutStringType, typename Arg, typename... Args, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4328 |
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4329 |
&& !detect_string_can_append_op<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4330 |
&& detect_string_can_append_iter<OutStringType, Arg>::value, int > > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4331 |
inline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4332 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4333 |
out.append(arg.begin(), arg.end()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4334 |
concat_into(out, std::forward<Args>(rest)...); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4335 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4336 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4337 |
template < typename OutStringType, typename Arg, typename... Args, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4338 |
enable_if_t < !detect_string_can_append<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4339 |
&& !detect_string_can_append_op<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4340 |
&& !detect_string_can_append_iter<OutStringType, Arg>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4341 |
&& detect_string_can_append_data<OutStringType, Arg>::value, int > > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4342 |
inline void concat_into(OutStringType& out, const Arg& arg, Args&& ... rest) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4343 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4344 |
out.append(arg.data(), arg.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4345 |
concat_into(out, std::forward<Args>(rest)...); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4346 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4347 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4348 |
template<typename OutStringType = std::string, typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4349 |
inline OutStringType concat(Args && ... args) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4350 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4351 |
OutStringType str; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4352 |
str.reserve(concat_length(args...)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4353 |
concat_into(str, std::forward<Args>(args)...); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4354 |
return str; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4355 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4356 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4357 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4358 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4359 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4360 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4361 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4362 |
namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4363 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4364 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4365 |
//////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4366 |
// exceptions // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4367 |
//////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4368 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4369 |
/// @brief general exception of the @ref basic_json class |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4370 |
/// @sa https://json.nlohmann.me/api/basic_json/exception/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4371 |
class exception : public std::exception |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4372 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4373 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4374 |
/// returns the explanatory string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4375 |
const char* what() const noexcept override |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4376 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4377 |
return m.what(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4378 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4379 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4380 |
/// the id of the exception |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4381 |
const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4382 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4383 |
protected: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4384 |
JSON_HEDLEY_NON_NULL(3) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4385 |
exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} // NOLINT(bugprone-throw-keyword-missing) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4386 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4387 |
static std::string name(const std::string& ename, int id_) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4388 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4389 |
return concat("[json.exception.", ename, '.', std::to_string(id_), "] "); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4390 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4391 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4392 |
static std::string diagnostics(std::nullptr_t /*leaf_element*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4393 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4394 |
return ""; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4395 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4396 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4397 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4398 |
static std::string diagnostics(const BasicJsonType* leaf_element) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4399 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4400 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4401 |
std::vector<std::string> tokens; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4402 |
for (const auto* current = leaf_element; current != nullptr && current->m_parent != nullptr; current = current->m_parent) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4403 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4404 |
switch (current->m_parent->type()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4405 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4406 |
case value_t::array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4407 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4408 |
for (std::size_t i = 0; i < current->m_parent->m_data.m_value.array->size(); ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4409 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4410 |
if (¤t->m_parent->m_data.m_value.array->operator[](i) == current) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4411 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4412 |
tokens.emplace_back(std::to_string(i)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4413 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4414 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4415 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4416 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4417 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4418 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4419 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4420 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4421 |
for (const auto& element : *current->m_parent->m_data.m_value.object) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4422 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4423 |
if (&element.second == current) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4424 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4425 |
tokens.emplace_back(element.first.c_str()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4426 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4427 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4428 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4429 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4430 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4431 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4432 |
case value_t::null: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4433 |
case value_t::string: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4434 |
case value_t::boolean: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4435 |
case value_t::number_integer: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4436 |
case value_t::number_unsigned: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4437 |
case value_t::number_float: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4438 |
case value_t::binary: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4439 |
case value_t::discarded: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4440 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4441 |
break; // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4442 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4443 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4444 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4445 |
if (tokens.empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4446 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4447 |
return ""; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4448 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4449 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4450 |
auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4451 |
[](const std::string & a, const std::string & b) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4452 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4453 |
return concat(a, '/', detail::escape(b)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4454 |
}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4455 |
return concat('(', str, ") "); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4456 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4457 |
static_cast<void>(leaf_element); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4458 |
return ""; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4459 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4460 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4461 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4462 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4463 |
/// an exception object as storage for error messages |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4464 |
std::runtime_error m; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4465 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4466 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4467 |
/// @brief exception indicating a parse error |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4468 |
/// @sa https://json.nlohmann.me/api/basic_json/parse_error/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4469 |
class parse_error : public exception |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4470 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4471 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4472 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4473 |
@brief create a parse error exception |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4474 |
@param[in] id_ the id of the exception |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4475 |
@param[in] pos the position where the error occurred (or with |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4476 |
chars_read_total=0 if the position cannot be |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4477 |
determined) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4478 |
@param[in] what_arg the explanatory string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4479 |
@return parse_error object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4480 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4481 |
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4482 |
static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4483 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4484 |
const std::string w = concat(exception::name("parse_error", id_), "parse error", |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4485 |
position_string(pos), ": ", exception::diagnostics(context), what_arg); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4486 |
return {id_, pos.chars_read_total, w.c_str()}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4487 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4488 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4489 |
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4490 |
static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4491 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4492 |
const std::string w = concat(exception::name("parse_error", id_), "parse error", |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4493 |
(byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4494 |
": ", exception::diagnostics(context), what_arg); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4495 |
return {id_, byte_, w.c_str()}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4496 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4497 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4498 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4499 |
@brief byte index of the parse error |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4500 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4501 |
The byte index of the last read character in the input file. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4502 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4503 |
@note For an input with n bytes, 1 is the index of the first character and |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4504 |
n+1 is the index of the terminating null byte or the end of file. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4505 |
This also holds true when reading a byte vector (CBOR or MessagePack). |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4506 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4507 |
const std::size_t byte; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4508 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4509 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4510 |
parse_error(int id_, std::size_t byte_, const char* what_arg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4511 |
: exception(id_, what_arg), byte(byte_) {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4512 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4513 |
static std::string position_string(const position_t& pos) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4514 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4515 |
return concat(" at line ", std::to_string(pos.lines_read + 1), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4516 |
", column ", std::to_string(pos.chars_read_current_line)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4517 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4518 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4519 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4520 |
/// @brief exception indicating errors with iterators |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4521 |
/// @sa https://json.nlohmann.me/api/basic_json/invalid_iterator/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4522 |
class invalid_iterator : public exception |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4523 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4524 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4525 |
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4526 |
static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4527 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4528 |
const std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4529 |
return {id_, w.c_str()}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4530 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4531 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4532 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4533 |
JSON_HEDLEY_NON_NULL(3) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4534 |
invalid_iterator(int id_, const char* what_arg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4535 |
: exception(id_, what_arg) {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4536 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4537 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4538 |
/// @brief exception indicating executing a member function with a wrong type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4539 |
/// @sa https://json.nlohmann.me/api/basic_json/type_error/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4540 |
class type_error : public exception |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4541 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4542 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4543 |
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4544 |
static type_error create(int id_, const std::string& what_arg, BasicJsonContext context) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4545 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4546 |
const std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4547 |
return {id_, w.c_str()}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4548 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4549 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4550 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4551 |
JSON_HEDLEY_NON_NULL(3) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4552 |
type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4553 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4554 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4555 |
/// @brief exception indicating access out of the defined range |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4556 |
/// @sa https://json.nlohmann.me/api/basic_json/out_of_range/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4557 |
class out_of_range : public exception |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4558 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4559 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4560 |
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4561 |
static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4562 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4563 |
const std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4564 |
return {id_, w.c_str()}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4565 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4566 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4567 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4568 |
JSON_HEDLEY_NON_NULL(3) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4569 |
out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4570 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4571 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4572 |
/// @brief exception indicating other library errors |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4573 |
/// @sa https://json.nlohmann.me/api/basic_json/other_error/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4574 |
class other_error : public exception |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4575 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4576 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4577 |
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4578 |
static other_error create(int id_, const std::string& what_arg, BasicJsonContext context) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4579 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4580 |
const std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4581 |
return {id_, w.c_str()}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4582 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4583 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4584 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4585 |
JSON_HEDLEY_NON_NULL(3) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4586 |
other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4587 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4588 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4589 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4590 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4591 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4592 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4593 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4594 |
// #include <nlohmann/detail/meta/cpp_future.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4595 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4596 |
// #include <nlohmann/detail/meta/identity_tag.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4597 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4598 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4599 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4600 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4601 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4602 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4603 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4604 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4605 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4606 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4607 |
// #include <nlohmann/detail/abi_macros.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4608 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4609 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4610 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4611 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4612 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4613 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4614 |
// dispatching helper struct |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4615 |
template <class T> struct identity_tag {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4616 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4617 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4618 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4619 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4620 |
// #include <nlohmann/detail/meta/std_fs.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4621 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4622 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4623 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4624 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4625 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4626 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4627 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4628 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4629 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4630 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4631 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4632 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4633 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4634 |
#if JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4635 |
#include <experimental/filesystem> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4636 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4637 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4638 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4639 |
namespace std_fs = std::experimental::filesystem; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4640 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4641 |
NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4642 |
#elif JSON_HAS_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4643 |
#include <filesystem> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4644 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4645 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4646 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4647 |
namespace std_fs = std::filesystem; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4648 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4649 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4650 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4651 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4652 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4653 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4654 |
// #include <nlohmann/detail/string_concat.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4655 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4656 |
// #include <nlohmann/detail/value_t.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4657 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4658 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4659 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4660 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4661 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4662 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4663 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4664 |
inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4665 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4666 |
if (JSON_HEDLEY_UNLIKELY(!j.is_null())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4667 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4668 |
JSON_THROW(type_error::create(302, concat("type must be null, but is ", j.type_name()), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4669 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4670 |
n = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4671 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4672 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4673 |
// overloads for basic_json template parameters |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4674 |
template < typename BasicJsonType, typename ArithmeticType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4675 |
enable_if_t < std::is_arithmetic<ArithmeticType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4676 |
!std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4677 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4678 |
void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4679 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4680 |
switch (static_cast<value_t>(j)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4681 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4682 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4683 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4684 |
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4685 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4686 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4687 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4688 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4689 |
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4690 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4691 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4692 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4693 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4694 |
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4695 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4696 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4697 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4698 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4699 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4700 |
case value_t::array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4701 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4702 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4703 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4704 |
case value_t::discarded: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4705 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4706 |
JSON_THROW(type_error::create(302, concat("type must be number, but is ", j.type_name()), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4707 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4708 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4709 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4710 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4711 |
inline void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4712 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4713 |
if (JSON_HEDLEY_UNLIKELY(!j.is_boolean())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4714 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4715 |
JSON_THROW(type_error::create(302, concat("type must be boolean, but is ", j.type_name()), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4716 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4717 |
b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4718 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4719 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4720 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4721 |
inline void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4722 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4723 |
if (JSON_HEDLEY_UNLIKELY(!j.is_string())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4724 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4725 |
JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4726 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4727 |
s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4728 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4729 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4730 |
template < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4731 |
typename BasicJsonType, typename StringType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4732 |
enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4733 |
std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4734 |
&& is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4735 |
&& !std::is_same<typename BasicJsonType::string_t, StringType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4736 |
&& !is_json_ref<StringType>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4737 |
inline void from_json(const BasicJsonType& j, StringType& s) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4738 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4739 |
if (JSON_HEDLEY_UNLIKELY(!j.is_string())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4740 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4741 |
JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4742 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4743 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4744 |
s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4745 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4746 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4747 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4748 |
inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4749 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4750 |
get_arithmetic_value(j, val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4751 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4752 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4753 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4754 |
inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_unsigned_t& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4755 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4756 |
get_arithmetic_value(j, val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4757 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4758 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4759 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4760 |
inline void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4761 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4762 |
get_arithmetic_value(j, val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4763 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4764 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4765 |
#if !JSON_DISABLE_ENUM_SERIALIZATION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4766 |
template<typename BasicJsonType, typename EnumType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4767 |
enable_if_t<std::is_enum<EnumType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4768 |
inline void from_json(const BasicJsonType& j, EnumType& e) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4769 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4770 |
typename std::underlying_type<EnumType>::type val; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4771 |
get_arithmetic_value(j, val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4772 |
e = static_cast<EnumType>(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4773 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4774 |
#endif // JSON_DISABLE_ENUM_SERIALIZATION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4775 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4776 |
// forward_list doesn't have an insert method |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4777 |
template<typename BasicJsonType, typename T, typename Allocator, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4778 |
enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4779 |
inline void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4780 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4781 |
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4782 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4783 |
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4784 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4785 |
l.clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4786 |
std::transform(j.rbegin(), j.rend(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4787 |
std::front_inserter(l), [](const BasicJsonType & i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4788 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4789 |
return i.template get<T>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4790 |
}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4791 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4792 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4793 |
// valarray doesn't have an insert method |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4794 |
template<typename BasicJsonType, typename T, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4795 |
enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4796 |
inline void from_json(const BasicJsonType& j, std::valarray<T>& l) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4797 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4798 |
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4799 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4800 |
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4801 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4802 |
l.resize(j.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4803 |
std::transform(j.begin(), j.end(), std::begin(l), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4804 |
[](const BasicJsonType & elem) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4805 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4806 |
return elem.template get<T>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4807 |
}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4808 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4809 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4810 |
template<typename BasicJsonType, typename T, std::size_t N> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4811 |
auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4812 |
-> decltype(j.template get<T>(), void()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4813 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4814 |
for (std::size_t i = 0; i < N; ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4815 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4816 |
arr[i] = j.at(i).template get<T>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4817 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4818 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4819 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4820 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4821 |
inline void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4822 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4823 |
arr = *j.template get_ptr<const typename BasicJsonType::array_t*>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4824 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4825 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4826 |
template<typename BasicJsonType, typename T, std::size_t N> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4827 |
auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4828 |
priority_tag<2> /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4829 |
-> decltype(j.template get<T>(), void()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4830 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4831 |
for (std::size_t i = 0; i < N; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4832 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4833 |
arr[i] = j.at(i).template get<T>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4834 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4835 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4836 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4837 |
template<typename BasicJsonType, typename ConstructibleArrayType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4838 |
enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4839 |
std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4840 |
int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4841 |
auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4842 |
-> decltype( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4843 |
arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4844 |
j.template get<typename ConstructibleArrayType::value_type>(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4845 |
void()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4846 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4847 |
using std::end; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4848 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4849 |
ConstructibleArrayType ret; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4850 |
ret.reserve(j.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4851 |
std::transform(j.begin(), j.end(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4852 |
std::inserter(ret, end(ret)), [](const BasicJsonType & i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4853 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4854 |
// get<BasicJsonType>() returns *this, this won't call a from_json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4855 |
// method when value_type is BasicJsonType |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4856 |
return i.template get<typename ConstructibleArrayType::value_type>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4857 |
}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4858 |
arr = std::move(ret); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4859 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4860 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4861 |
template<typename BasicJsonType, typename ConstructibleArrayType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4862 |
enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4863 |
std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4864 |
int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4865 |
inline void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4866 |
priority_tag<0> /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4867 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4868 |
using std::end; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4869 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4870 |
ConstructibleArrayType ret; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4871 |
std::transform( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4872 |
j.begin(), j.end(), std::inserter(ret, end(ret)), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4873 |
[](const BasicJsonType & i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4874 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4875 |
// get<BasicJsonType>() returns *this, this won't call a from_json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4876 |
// method when value_type is BasicJsonType |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4877 |
return i.template get<typename ConstructibleArrayType::value_type>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4878 |
}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4879 |
arr = std::move(ret); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4880 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4881 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4882 |
template < typename BasicJsonType, typename ConstructibleArrayType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4883 |
enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4884 |
is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4885 |
!is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4886 |
!is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4887 |
!std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4888 |
!is_basic_json<ConstructibleArrayType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4889 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4890 |
auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4891 |
-> decltype(from_json_array_impl(j, arr, priority_tag<3> {}), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4892 |
j.template get<typename ConstructibleArrayType::value_type>(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4893 |
void()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4894 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4895 |
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4896 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4897 |
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4898 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4899 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4900 |
from_json_array_impl(j, arr, priority_tag<3> {}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4901 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4902 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4903 |
template < typename BasicJsonType, typename T, std::size_t... Idx > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4904 |
std::array<T, sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4905 |
identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4906 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4907 |
return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } }; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4908 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4909 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4910 |
template < typename BasicJsonType, typename T, std::size_t N > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4911 |
auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4912 |
-> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {})) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4913 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4914 |
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4915 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4916 |
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4917 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4918 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4919 |
return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4920 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4921 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4922 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4923 |
inline void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4924 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4925 |
if (JSON_HEDLEY_UNLIKELY(!j.is_binary())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4926 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4927 |
JSON_THROW(type_error::create(302, concat("type must be binary, but is ", j.type_name()), &j)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4928 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4929 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4930 |
bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4931 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4932 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4933 |
template<typename BasicJsonType, typename ConstructibleObjectType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4934 |
enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4935 |
inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4936 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4937 |
if (JSON_HEDLEY_UNLIKELY(!j.is_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4938 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4939 |
JSON_THROW(type_error::create(302, concat("type must be object, but is ", j.type_name()), &j)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4940 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4941 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4942 |
ConstructibleObjectType ret; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4943 |
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4944 |
using value_type = typename ConstructibleObjectType::value_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4945 |
std::transform( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4946 |
inner_object->begin(), inner_object->end(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4947 |
std::inserter(ret, ret.begin()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4948 |
[](typename BasicJsonType::object_t::value_type const & p) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4949 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4950 |
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4951 |
}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4952 |
obj = std::move(ret); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4953 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4954 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4955 |
// overload for arithmetic types, not chosen for basic_json template arguments |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4956 |
// (BooleanType, etc..); note: Is it really necessary to provide explicit |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4957 |
// overloads for boolean_t etc. in case of a custom BooleanType which is not |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4958 |
// an arithmetic type? |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4959 |
template < typename BasicJsonType, typename ArithmeticType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4960 |
enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4961 |
std::is_arithmetic<ArithmeticType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4962 |
!std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4963 |
!std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4964 |
!std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4965 |
!std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4966 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4967 |
inline void from_json(const BasicJsonType& j, ArithmeticType& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
4968 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4969 |
switch (static_cast<value_t>(j)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4970 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4971 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4972 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4973 |
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4974 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4975 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4976 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4977 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4978 |
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4979 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4980 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4981 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4982 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4983 |
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4984 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4985 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4986 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4987 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4988 |
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4989 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4990 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4991 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4992 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4993 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4994 |
case value_t::array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4995 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4996 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4997 |
case value_t::discarded: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4998 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
4999 |
JSON_THROW(type_error::create(302, concat("type must be number, but is ", j.type_name()), &j)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5000 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5001 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5002 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5003 |
template<typename BasicJsonType, typename... Args, std::size_t... Idx> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5004 |
std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5005 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5006 |
return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).template get<Args>()...); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5007 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5008 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5009 |
template < typename BasicJsonType, class A1, class A2 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5010 |
std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5011 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5012 |
return {std::forward<BasicJsonType>(j).at(0).template get<A1>(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5013 |
std::forward<BasicJsonType>(j).at(1).template get<A2>()}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5014 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5015 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5016 |
template<typename BasicJsonType, typename A1, typename A2> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5017 |
inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5018 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5019 |
p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5020 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5021 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5022 |
template<typename BasicJsonType, typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5023 |
std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> /*unused*/, priority_tag<2> /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5024 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5025 |
return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5026 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5027 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5028 |
template<typename BasicJsonType, typename... Args> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5029 |
inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5030 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5031 |
t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5032 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5033 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5034 |
template<typename BasicJsonType, typename TupleRelated> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5035 |
auto from_json(BasicJsonType&& j, TupleRelated&& t) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5036 |
-> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {})) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5037 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5038 |
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5039 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5040 |
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5041 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5042 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5043 |
return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5044 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5045 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5046 |
template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5047 |
typename = enable_if_t < !std::is_constructible < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5048 |
typename BasicJsonType::string_t, Key >::value >> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5049 |
inline void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5050 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5051 |
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5052 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5053 |
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5054 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5055 |
m.clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5056 |
for (const auto& p : j) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5057 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5058 |
if (JSON_HEDLEY_UNLIKELY(!p.is_array())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5059 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5060 |
JSON_THROW(type_error::create(302, concat("type must be array, but is ", p.type_name()), &j)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5061 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5062 |
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5063 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5064 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5065 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5066 |
template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5067 |
typename = enable_if_t < !std::is_constructible < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5068 |
typename BasicJsonType::string_t, Key >::value >> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5069 |
inline void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5070 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5071 |
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5072 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5073 |
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5074 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5075 |
m.clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5076 |
for (const auto& p : j) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5077 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5078 |
if (JSON_HEDLEY_UNLIKELY(!p.is_array())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5079 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5080 |
JSON_THROW(type_error::create(302, concat("type must be array, but is ", p.type_name()), &j)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5081 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5082 |
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5083 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5084 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5085 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5086 |
#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5087 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5088 |
inline void from_json(const BasicJsonType& j, std_fs::path& p) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5089 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5090 |
if (JSON_HEDLEY_UNLIKELY(!j.is_string())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5091 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5092 |
JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5093 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5094 |
p = *j.template get_ptr<const typename BasicJsonType::string_t*>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5095 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5096 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5097 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5098 |
struct from_json_fn |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5099 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5100 |
template<typename BasicJsonType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5101 |
auto operator()(const BasicJsonType& j, T&& val) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5102 |
noexcept(noexcept(from_json(j, std::forward<T>(val)))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5103 |
-> decltype(from_json(j, std::forward<T>(val))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5104 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5105 |
return from_json(j, std::forward<T>(val)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5106 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5107 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5108 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5109 |
} // namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5110 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5111 |
#ifndef JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5112 |
/// namespace to hold default `from_json` function |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5113 |
/// to see why this is required: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5114 |
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5115 |
namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5116 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5117 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5118 |
JSON_INLINE_VARIABLE constexpr const auto& from_json = // NOLINT(misc-definitions-in-headers) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5119 |
detail::static_const<detail::from_json_fn>::value; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5120 |
#ifndef JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5121 |
} // namespace |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5122 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5123 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5124 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5125 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5126 |
// #include <nlohmann/detail/conversions/to_json.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5127 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5128 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5129 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5130 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5131 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5132 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5133 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5134 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5135 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5136 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5137 |
#include <algorithm> // copy |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5138 |
#include <iterator> // begin, end |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5139 |
#include <string> // string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5140 |
#include <tuple> // tuple, get |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5141 |
#include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5142 |
#include <utility> // move, forward, declval, pair |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5143 |
#include <valarray> // valarray |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5144 |
#include <vector> // vector |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5145 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5146 |
// #include <nlohmann/detail/iterators/iteration_proxy.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5147 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5148 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5149 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5150 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5151 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5152 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5153 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5154 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5155 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5156 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5157 |
#include <cstddef> // size_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5158 |
#include <iterator> // input_iterator_tag |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5159 |
#include <string> // string, to_string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5160 |
#include <tuple> // tuple_size, get, tuple_element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5161 |
#include <utility> // move |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5162 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5163 |
#if JSON_HAS_RANGES |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5164 |
#include <ranges> // enable_borrowed_range |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5165 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5166 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5167 |
// #include <nlohmann/detail/abi_macros.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5168 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5169 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5170 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5171 |
// #include <nlohmann/detail/value_t.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5172 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5173 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5174 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5175 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5176 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5177 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5178 |
template<typename string_type> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5179 |
void int_to_string( string_type& target, std::size_t value ) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5180 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5181 |
// For ADL |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5182 |
using std::to_string; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5183 |
target = to_string(value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5184 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5185 |
template<typename IteratorType> class iteration_proxy_value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5186 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5187 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5188 |
using difference_type = std::ptrdiff_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5189 |
using value_type = iteration_proxy_value; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5190 |
using pointer = value_type *; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5191 |
using reference = value_type &; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5192 |
using iterator_category = std::input_iterator_tag; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5193 |
using string_type = typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5194 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5195 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5196 |
/// the iterator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5197 |
IteratorType anchor{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5198 |
/// an index for arrays (used to create key names) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5199 |
std::size_t array_index = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5200 |
/// last stringified array index |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5201 |
mutable std::size_t array_index_last = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5202 |
/// a string representation of the array index |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5203 |
mutable string_type array_index_str = "0"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5204 |
/// an empty string (to return a reference for primitive values) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5205 |
string_type empty_str{}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5206 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5207 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5208 |
explicit iteration_proxy_value() = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5209 |
explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5210 |
noexcept(std::is_nothrow_move_constructible<IteratorType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5211 |
&& std::is_nothrow_default_constructible<string_type>::value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5212 |
: anchor(std::move(it)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5213 |
, array_index(array_index_) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5214 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5215 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5216 |
iteration_proxy_value(iteration_proxy_value const&) = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5217 |
iteration_proxy_value& operator=(iteration_proxy_value const&) = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5218 |
// older GCCs are a bit fussy and require explicit noexcept specifiers on defaulted functions |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5219 |
iteration_proxy_value(iteration_proxy_value&&) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5220 |
noexcept(std::is_nothrow_move_constructible<IteratorType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5221 |
&& std::is_nothrow_move_constructible<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5222 |
iteration_proxy_value& operator=(iteration_proxy_value&&) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5223 |
noexcept(std::is_nothrow_move_assignable<IteratorType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5224 |
&& std::is_nothrow_move_assignable<string_type>::value) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor,cppcoreguidelines-noexcept-move-operations) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5225 |
~iteration_proxy_value() = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5226 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5227 |
/// dereference operator (needed for range-based for) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5228 |
const iteration_proxy_value& operator*() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5229 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5230 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5231 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5232 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5233 |
/// increment operator (needed for range-based for) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5234 |
iteration_proxy_value& operator++() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5235 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5236 |
++anchor; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5237 |
++array_index; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5238 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5239 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5240 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5241 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5242 |
iteration_proxy_value operator++(int)& // NOLINT(cert-dcl21-cpp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5243 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5244 |
auto tmp = iteration_proxy_value(anchor, array_index); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5245 |
++anchor; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5246 |
++array_index; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5247 |
return tmp; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5248 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5249 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5250 |
/// equality operator (needed for InputIterator) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5251 |
bool operator==(const iteration_proxy_value& o) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5252 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5253 |
return anchor == o.anchor; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5254 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5255 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5256 |
/// inequality operator (needed for range-based for) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5257 |
bool operator!=(const iteration_proxy_value& o) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5258 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5259 |
return anchor != o.anchor; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5260 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5261 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5262 |
/// return key of the iterator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5263 |
const string_type& key() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5264 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5265 |
JSON_ASSERT(anchor.m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5266 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5267 |
switch (anchor.m_object->type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5268 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5269 |
// use integer array index as key |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5270 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5271 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5272 |
if (array_index != array_index_last) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5273 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5274 |
int_to_string( array_index_str, array_index ); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5275 |
array_index_last = array_index; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5276 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5277 |
return array_index_str; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5278 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5279 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5280 |
// use key from the object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5281 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5282 |
return anchor.key(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5283 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5284 |
// use an empty key for all primitive types |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5285 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5286 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5287 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5288 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5289 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5290 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5291 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5292 |
case value_t::discarded: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5293 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5294 |
return empty_str; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5295 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5296 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5297 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5298 |
/// return value of the iterator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5299 |
typename IteratorType::reference value() const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5300 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5301 |
return anchor.value(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5302 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5303 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5304 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5305 |
/// proxy class for the items() function |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5306 |
template<typename IteratorType> class iteration_proxy |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5307 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5308 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5309 |
/// the container to iterate |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5310 |
typename IteratorType::pointer container = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5311 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5312 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5313 |
explicit iteration_proxy() = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5314 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5315 |
/// construct iteration proxy from a container |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5316 |
explicit iteration_proxy(typename IteratorType::reference cont) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5317 |
: container(&cont) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5318 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5319 |
iteration_proxy(iteration_proxy const&) = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5320 |
iteration_proxy& operator=(iteration_proxy const&) = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5321 |
iteration_proxy(iteration_proxy&&) noexcept = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5322 |
iteration_proxy& operator=(iteration_proxy&&) noexcept = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5323 |
~iteration_proxy() = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5324 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5325 |
/// return iterator begin (needed for range-based for) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5326 |
iteration_proxy_value<IteratorType> begin() const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5327 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5328 |
return iteration_proxy_value<IteratorType>(container->begin()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5329 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5330 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5331 |
/// return iterator end (needed for range-based for) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5332 |
iteration_proxy_value<IteratorType> end() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5333 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5334 |
return iteration_proxy_value<IteratorType>(container->end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5335 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5336 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5337 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5338 |
// Structured Bindings Support |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5339 |
// For further reference see https://blog.tartanllama.xyz/structured-bindings/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5340 |
// And see https://github.com/nlohmann/json/pull/1391 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5341 |
template<std::size_t N, typename IteratorType, enable_if_t<N == 0, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5342 |
auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5343 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5344 |
return i.key(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5345 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5346 |
// Structured Bindings Support |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5347 |
// For further reference see https://blog.tartanllama.xyz/structured-bindings/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5348 |
// And see https://github.com/nlohmann/json/pull/1391 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5349 |
template<std::size_t N, typename IteratorType, enable_if_t<N == 1, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5350 |
auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5351 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5352 |
return i.value(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5353 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5354 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5355 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5356 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5357 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5358 |
// The Addition to the STD Namespace is required to add |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5359 |
// Structured Bindings Support to the iteration_proxy_value class |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5360 |
// For further reference see https://blog.tartanllama.xyz/structured-bindings/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5361 |
// And see https://github.com/nlohmann/json/pull/1391 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5362 |
namespace std |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5363 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5364 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5365 |
#if defined(__clang__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5366 |
// Fix: https://github.com/nlohmann/json/issues/1401 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5367 |
#pragma clang diagnostic push |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5368 |
#pragma clang diagnostic ignored "-Wmismatched-tags" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5369 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5370 |
template<typename IteratorType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5371 |
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5372 |
: public std::integral_constant<std::size_t, 2> {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5373 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5374 |
template<std::size_t N, typename IteratorType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5375 |
class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5376 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5377 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5378 |
using type = decltype( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5379 |
get<N>(std::declval < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5380 |
::nlohmann::detail::iteration_proxy_value<IteratorType >> ())); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5381 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5382 |
#if defined(__clang__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5383 |
#pragma clang diagnostic pop |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5384 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5385 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5386 |
} // namespace std |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5387 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5388 |
#if JSON_HAS_RANGES |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5389 |
template <typename IteratorType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5390 |
inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5391 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5392 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5393 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5394 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5395 |
// #include <nlohmann/detail/meta/cpp_future.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5396 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5397 |
// #include <nlohmann/detail/meta/std_fs.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5398 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5399 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5400 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5401 |
// #include <nlohmann/detail/value_t.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5402 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5403 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5404 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5405 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5406 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5407 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5408 |
////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5409 |
// constructors // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5410 |
////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5411 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5412 |
/* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5413 |
* Note all external_constructor<>::construct functions need to call |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5414 |
* j.m_data.m_value.destroy(j.m_data.m_type) to avoid a memory leak in case j contains an |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5415 |
* allocated value (e.g., a string). See bug issue |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5416 |
* https://github.com/nlohmann/json/issues/2865 for more information. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5417 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5418 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5419 |
template<value_t> struct external_constructor; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5420 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5421 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5422 |
struct external_constructor<value_t::boolean> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5423 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5424 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5425 |
static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5426 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5427 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5428 |
j.m_data.m_type = value_t::boolean; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5429 |
j.m_data.m_value = b; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5430 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5431 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5432 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5433 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5434 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5435 |
struct external_constructor<value_t::string> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5436 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5437 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5438 |
static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5439 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5440 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5441 |
j.m_data.m_type = value_t::string; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5442 |
j.m_data.m_value = s; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5443 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5444 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5445 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5446 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5447 |
static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5448 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5449 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5450 |
j.m_data.m_type = value_t::string; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5451 |
j.m_data.m_value = std::move(s); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5452 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5453 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5454 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5455 |
template < typename BasicJsonType, typename CompatibleStringType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5456 |
enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5457 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5458 |
static void construct(BasicJsonType& j, const CompatibleStringType& str) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5459 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5460 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5461 |
j.m_data.m_type = value_t::string; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5462 |
j.m_data.m_value.string = j.template create<typename BasicJsonType::string_t>(str); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5463 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5464 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5465 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5466 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5467 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5468 |
struct external_constructor<value_t::binary> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5469 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5470 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5471 |
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5472 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5473 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5474 |
j.m_data.m_type = value_t::binary; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5475 |
j.m_data.m_value = typename BasicJsonType::binary_t(b); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5476 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5477 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5478 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5479 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5480 |
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5481 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5482 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5483 |
j.m_data.m_type = value_t::binary; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5484 |
j.m_data.m_value = typename BasicJsonType::binary_t(std::move(b)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5485 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5486 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5487 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5488 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5489 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5490 |
struct external_constructor<value_t::number_float> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5491 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5492 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5493 |
static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5494 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5495 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5496 |
j.m_data.m_type = value_t::number_float; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5497 |
j.m_data.m_value = val; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5498 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5499 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5500 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5501 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5502 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5503 |
struct external_constructor<value_t::number_unsigned> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5504 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5505 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5506 |
static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5507 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5508 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5509 |
j.m_data.m_type = value_t::number_unsigned; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5510 |
j.m_data.m_value = val; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5511 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5512 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5513 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5514 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5515 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5516 |
struct external_constructor<value_t::number_integer> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5517 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5518 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5519 |
static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5520 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5521 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5522 |
j.m_data.m_type = value_t::number_integer; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5523 |
j.m_data.m_value = val; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5524 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5525 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5526 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5527 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5528 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5529 |
struct external_constructor<value_t::array> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5530 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5531 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5532 |
static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5533 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5534 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5535 |
j.m_data.m_type = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5536 |
j.m_data.m_value = arr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5537 |
j.set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5538 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5539 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5540 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5541 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5542 |
static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5543 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5544 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5545 |
j.m_data.m_type = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5546 |
j.m_data.m_value = std::move(arr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5547 |
j.set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5548 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5549 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5550 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5551 |
template < typename BasicJsonType, typename CompatibleArrayType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5552 |
enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5553 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5554 |
static void construct(BasicJsonType& j, const CompatibleArrayType& arr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5555 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5556 |
using std::begin; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5557 |
using std::end; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5558 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5559 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5560 |
j.m_data.m_type = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5561 |
j.m_data.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5562 |
j.set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5563 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5564 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5565 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5566 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5567 |
static void construct(BasicJsonType& j, const std::vector<bool>& arr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5568 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5569 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5570 |
j.m_data.m_type = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5571 |
j.m_data.m_value = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5572 |
j.m_data.m_value.array->reserve(arr.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5573 |
for (const bool x : arr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5574 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5575 |
j.m_data.m_value.array->push_back(x); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5576 |
j.set_parent(j.m_data.m_value.array->back()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5577 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5578 |
j.assert_invariant(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5579 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5580 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5581 |
template<typename BasicJsonType, typename T, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5582 |
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5583 |
static void construct(BasicJsonType& j, const std::valarray<T>& arr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5584 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5585 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5586 |
j.m_data.m_type = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5587 |
j.m_data.m_value = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5588 |
j.m_data.m_value.array->resize(arr.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5589 |
if (arr.size() > 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5590 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5591 |
std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5592 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5593 |
j.set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5594 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5595 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5596 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5597 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5598 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5599 |
struct external_constructor<value_t::object> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5600 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5601 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5602 |
static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5603 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5604 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5605 |
j.m_data.m_type = value_t::object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5606 |
j.m_data.m_value = obj; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5607 |
j.set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5608 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5609 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5610 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5611 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5612 |
static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5613 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5614 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5615 |
j.m_data.m_type = value_t::object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5616 |
j.m_data.m_value = std::move(obj); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5617 |
j.set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5618 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5619 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5620 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5621 |
template < typename BasicJsonType, typename CompatibleObjectType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5622 |
enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5623 |
static void construct(BasicJsonType& j, const CompatibleObjectType& obj) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5624 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5625 |
using std::begin; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5626 |
using std::end; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5627 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5628 |
j.m_data.m_value.destroy(j.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5629 |
j.m_data.m_type = value_t::object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5630 |
j.m_data.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5631 |
j.set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5632 |
j.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5633 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5634 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5635 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5636 |
///////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5637 |
// to_json // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5638 |
///////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5639 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5640 |
template<typename BasicJsonType, typename T, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5641 |
enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5642 |
inline void to_json(BasicJsonType& j, T b) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5643 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5644 |
external_constructor<value_t::boolean>::construct(j, b); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5645 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5646 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5647 |
template < typename BasicJsonType, typename BoolRef, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5648 |
enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5649 |
((std::is_same<std::vector<bool>::reference, BoolRef>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5650 |
&& !std::is_same <std::vector<bool>::reference, typename BasicJsonType::boolean_t&>::value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5651 |
|| (std::is_same<std::vector<bool>::const_reference, BoolRef>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5652 |
&& !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5653 |
typename BasicJsonType::boolean_t >::value)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5654 |
&& std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5655 |
inline void to_json(BasicJsonType& j, const BoolRef& b) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5656 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5657 |
external_constructor<value_t::boolean>::construct(j, static_cast<typename BasicJsonType::boolean_t>(b)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5658 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5659 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5660 |
template<typename BasicJsonType, typename CompatibleString, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5661 |
enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5662 |
inline void to_json(BasicJsonType& j, const CompatibleString& s) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5663 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5664 |
external_constructor<value_t::string>::construct(j, s); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5665 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5666 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5667 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5668 |
inline void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5669 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5670 |
external_constructor<value_t::string>::construct(j, std::move(s)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5671 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5672 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5673 |
template<typename BasicJsonType, typename FloatType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5674 |
enable_if_t<std::is_floating_point<FloatType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5675 |
inline void to_json(BasicJsonType& j, FloatType val) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5676 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5677 |
external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5678 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5679 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5680 |
template<typename BasicJsonType, typename CompatibleNumberUnsignedType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5681 |
enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5682 |
inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5683 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5684 |
external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5685 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5686 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5687 |
template<typename BasicJsonType, typename CompatibleNumberIntegerType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5688 |
enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5689 |
inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5690 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5691 |
external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5692 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5693 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5694 |
#if !JSON_DISABLE_ENUM_SERIALIZATION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5695 |
template<typename BasicJsonType, typename EnumType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5696 |
enable_if_t<std::is_enum<EnumType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5697 |
inline void to_json(BasicJsonType& j, EnumType e) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5698 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5699 |
using underlying_type = typename std::underlying_type<EnumType>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5700 |
external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5701 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5702 |
#endif // JSON_DISABLE_ENUM_SERIALIZATION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5703 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5704 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5705 |
inline void to_json(BasicJsonType& j, const std::vector<bool>& e) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5706 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5707 |
external_constructor<value_t::array>::construct(j, e); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5708 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5709 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5710 |
template < typename BasicJsonType, typename CompatibleArrayType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5711 |
enable_if_t < is_compatible_array_type<BasicJsonType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5712 |
CompatibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5713 |
!is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5714 |
!is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5715 |
!std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5716 |
!is_basic_json<CompatibleArrayType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5717 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5718 |
inline void to_json(BasicJsonType& j, const CompatibleArrayType& arr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5719 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5720 |
external_constructor<value_t::array>::construct(j, arr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5721 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5722 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5723 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5724 |
inline void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5725 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5726 |
external_constructor<value_t::binary>::construct(j, bin); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5727 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5728 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5729 |
template<typename BasicJsonType, typename T, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5730 |
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5731 |
inline void to_json(BasicJsonType& j, const std::valarray<T>& arr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5732 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5733 |
external_constructor<value_t::array>::construct(j, std::move(arr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5734 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5735 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5736 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5737 |
inline void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5738 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5739 |
external_constructor<value_t::array>::construct(j, std::move(arr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5740 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5741 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5742 |
template < typename BasicJsonType, typename CompatibleObjectType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5743 |
enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5744 |
inline void to_json(BasicJsonType& j, const CompatibleObjectType& obj) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5745 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5746 |
external_constructor<value_t::object>::construct(j, obj); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5747 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5748 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5749 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5750 |
inline void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5751 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5752 |
external_constructor<value_t::object>::construct(j, std::move(obj)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5753 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5754 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5755 |
template < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5756 |
typename BasicJsonType, typename T, std::size_t N, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5757 |
enable_if_t < !std::is_constructible<typename BasicJsonType::string_t, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5758 |
const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5759 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5760 |
inline void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5761 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5762 |
external_constructor<value_t::array>::construct(j, arr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5763 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5764 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5765 |
template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5766 |
inline void to_json(BasicJsonType& j, const std::pair<T1, T2>& p) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5767 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5768 |
j = { p.first, p.second }; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5769 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5770 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5771 |
// for https://github.com/nlohmann/json/pull/1134 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5772 |
template<typename BasicJsonType, typename T, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5773 |
enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5774 |
inline void to_json(BasicJsonType& j, const T& b) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5775 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5776 |
j = { {b.key(), b.value()} }; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5777 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5778 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5779 |
template<typename BasicJsonType, typename Tuple, std::size_t... Idx> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5780 |
inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5781 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5782 |
j = { std::get<Idx>(t)... }; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5783 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5784 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5785 |
template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int > = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5786 |
inline void to_json(BasicJsonType& j, const T& t) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5787 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5788 |
to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5789 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5790 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5791 |
#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5792 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5793 |
inline void to_json(BasicJsonType& j, const std_fs::path& p) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5794 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5795 |
j = p.string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5796 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5797 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5798 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5799 |
struct to_json_fn |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5800 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5801 |
template<typename BasicJsonType, typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5802 |
auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward<T>(val)))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5803 |
-> decltype(to_json(j, std::forward<T>(val)), void()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5804 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5805 |
return to_json(j, std::forward<T>(val)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5806 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5807 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5808 |
} // namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5809 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5810 |
#ifndef JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5811 |
/// namespace to hold default `to_json` function |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5812 |
/// to see why this is required: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5813 |
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5814 |
namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5815 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5816 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5817 |
JSON_INLINE_VARIABLE constexpr const auto& to_json = // NOLINT(misc-definitions-in-headers) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5818 |
detail::static_const<detail::to_json_fn>::value; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5819 |
#ifndef JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5820 |
} // namespace |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5821 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5822 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5823 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5824 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5825 |
// #include <nlohmann/detail/meta/identity_tag.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5826 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5827 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5828 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5829 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5830 |
/// @sa https://json.nlohmann.me/api/adl_serializer/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5831 |
template<typename ValueType, typename> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5832 |
struct adl_serializer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5833 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5834 |
/// @brief convert a JSON value to any value type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5835 |
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5836 |
template<typename BasicJsonType, typename TargetType = ValueType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5837 |
static auto from_json(BasicJsonType && j, TargetType& val) noexcept( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5838 |
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5839 |
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5840 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5841 |
::nlohmann::from_json(std::forward<BasicJsonType>(j), val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5842 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5843 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5844 |
/// @brief convert a JSON value to any value type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5845 |
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5846 |
template<typename BasicJsonType, typename TargetType = ValueType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5847 |
static auto from_json(BasicJsonType && j) noexcept( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5848 |
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5849 |
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5850 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5851 |
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5852 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5853 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5854 |
/// @brief convert any value type to a JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5855 |
/// @sa https://json.nlohmann.me/api/adl_serializer/to_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5856 |
template<typename BasicJsonType, typename TargetType = ValueType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5857 |
static auto to_json(BasicJsonType& j, TargetType && val) noexcept( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5858 |
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val)))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5859 |
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5860 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5861 |
::nlohmann::to_json(j, std::forward<TargetType>(val)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5862 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5863 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5864 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5865 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5866 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5867 |
// #include <nlohmann/byte_container_with_subtype.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5868 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5869 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5870 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5871 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5872 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5873 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5874 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5875 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5876 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5877 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5878 |
#include <cstdint> // uint8_t, uint64_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5879 |
#include <tuple> // tie |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5880 |
#include <utility> // move |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5881 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5882 |
// #include <nlohmann/detail/abi_macros.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5883 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5884 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5885 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5886 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5887 |
/// @brief an internal type for a backed binary type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5888 |
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5889 |
template<typename BinaryType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5890 |
class byte_container_with_subtype : public BinaryType |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5891 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5892 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5893 |
using container_type = BinaryType; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5894 |
using subtype_type = std::uint64_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5895 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5896 |
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5897 |
byte_container_with_subtype() noexcept(noexcept(container_type())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5898 |
: container_type() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5899 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5900 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5901 |
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5902 |
byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5903 |
: container_type(b) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5904 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5905 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5906 |
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5907 |
byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b)))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5908 |
: container_type(std::move(b)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5909 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5910 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5911 |
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5912 |
byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5913 |
: container_type(b) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5914 |
, m_subtype(subtype_) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5915 |
, m_has_subtype(true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5916 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5917 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5918 |
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5919 |
byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b)))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5920 |
: container_type(std::move(b)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5921 |
, m_subtype(subtype_) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5922 |
, m_has_subtype(true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5923 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5924 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5925 |
bool operator==(const byte_container_with_subtype& rhs) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5926 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5927 |
return std::tie(static_cast<const BinaryType&>(*this), m_subtype, m_has_subtype) == |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5928 |
std::tie(static_cast<const BinaryType&>(rhs), rhs.m_subtype, rhs.m_has_subtype); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5929 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5930 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5931 |
bool operator!=(const byte_container_with_subtype& rhs) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5932 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5933 |
return !(rhs == *this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5934 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5935 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5936 |
/// @brief sets the binary subtype |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5937 |
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/set_subtype/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5938 |
void set_subtype(subtype_type subtype_) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5939 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5940 |
m_subtype = subtype_; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5941 |
m_has_subtype = true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5942 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5943 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5944 |
/// @brief return the binary subtype |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5945 |
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/subtype/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5946 |
constexpr subtype_type subtype() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5947 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5948 |
return m_has_subtype ? m_subtype : static_cast<subtype_type>(-1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5949 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5950 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5951 |
/// @brief return whether the value has a subtype |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5952 |
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/has_subtype/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5953 |
constexpr bool has_subtype() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5954 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5955 |
return m_has_subtype; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5956 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5957 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5958 |
/// @brief clears the binary subtype |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5959 |
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/clear_subtype/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5960 |
void clear_subtype() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5961 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5962 |
m_subtype = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5963 |
m_has_subtype = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5964 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5965 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5966 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5967 |
subtype_type m_subtype = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5968 |
bool m_has_subtype = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5969 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5970 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5971 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5972 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5973 |
// #include <nlohmann/detail/conversions/from_json.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5974 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5975 |
// #include <nlohmann/detail/conversions/to_json.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5976 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5977 |
// #include <nlohmann/detail/exceptions.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5978 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5979 |
// #include <nlohmann/detail/hash.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5980 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5981 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5982 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5983 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5984 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5985 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5986 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5987 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5988 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5989 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5990 |
#include <cstdint> // uint8_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5991 |
#include <cstddef> // size_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5992 |
#include <functional> // hash |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
5993 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5994 |
// #include <nlohmann/detail/abi_macros.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5995 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5996 |
// #include <nlohmann/detail/value_t.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5997 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5998 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
5999 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6000 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6001 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6002 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6003 |
// boost::hash_combine |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6004 |
inline std::size_t combine(std::size_t seed, std::size_t h) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6005 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6006 |
seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6007 |
return seed; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6008 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6009 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6010 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6011 |
@brief hash a JSON value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6012 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6013 |
The hash function tries to rely on std::hash where possible. Furthermore, the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6014 |
type of the JSON value is taken into account to have different hash values for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6015 |
null, 0, 0U, and false, etc. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6016 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6017 |
@tparam BasicJsonType basic_json specialization |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6018 |
@param j JSON value to hash |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6019 |
@return hash value of j |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6020 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6021 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6022 |
std::size_t hash(const BasicJsonType& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6023 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6024 |
using string_t = typename BasicJsonType::string_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6025 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6026 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6027 |
using number_float_t = typename BasicJsonType::number_float_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6028 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6029 |
const auto type = static_cast<std::size_t>(j.type()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6030 |
switch (j.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6031 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6032 |
case BasicJsonType::value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6033 |
case BasicJsonType::value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6034 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6035 |
return combine(type, 0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6036 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6037 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6038 |
case BasicJsonType::value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6039 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6040 |
auto seed = combine(type, j.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6041 |
for (const auto& element : j.items()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6042 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6043 |
const auto h = std::hash<string_t> {}(element.key()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6044 |
seed = combine(seed, h); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6045 |
seed = combine(seed, hash(element.value())); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6046 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6047 |
return seed; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6048 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6049 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6050 |
case BasicJsonType::value_t::array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6051 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6052 |
auto seed = combine(type, j.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6053 |
for (const auto& element : j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6054 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6055 |
seed = combine(seed, hash(element)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6056 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6057 |
return seed; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6058 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6059 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6060 |
case BasicJsonType::value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6061 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6062 |
const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6063 |
return combine(type, h); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6064 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6065 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6066 |
case BasicJsonType::value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6067 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6068 |
const auto h = std::hash<bool> {}(j.template get<bool>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6069 |
return combine(type, h); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6070 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6071 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6072 |
case BasicJsonType::value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6073 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6074 |
const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6075 |
return combine(type, h); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6076 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6077 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6078 |
case BasicJsonType::value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6079 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6080 |
const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6081 |
return combine(type, h); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6082 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6083 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6084 |
case BasicJsonType::value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6085 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6086 |
const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6087 |
return combine(type, h); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6088 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6089 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6090 |
case BasicJsonType::value_t::binary: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6091 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6092 |
auto seed = combine(type, j.get_binary().size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6093 |
const auto h = std::hash<bool> {}(j.get_binary().has_subtype()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6094 |
seed = combine(seed, h); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6095 |
seed = combine(seed, static_cast<std::size_t>(j.get_binary().subtype())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6096 |
for (const auto byte : j.get_binary()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6097 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6098 |
seed = combine(seed, std::hash<std::uint8_t> {}(byte)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6099 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6100 |
return seed; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6101 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6102 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6103 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6104 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6105 |
return 0; // LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6106 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6107 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6108 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6109 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6110 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6111 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6112 |
// #include <nlohmann/detail/input/binary_reader.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6113 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6114 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6115 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6116 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6117 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6118 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6119 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6120 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6121 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6122 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6123 |
#include <algorithm> // generate_n |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6124 |
#include <array> // array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6125 |
#include <cmath> // ldexp |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6126 |
#include <cstddef> // size_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6127 |
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6128 |
#include <cstdio> // snprintf |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6129 |
#include <cstring> // memcpy |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6130 |
#include <iterator> // back_inserter |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6131 |
#include <limits> // numeric_limits |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6132 |
#include <string> // char_traits, string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6133 |
#include <utility> // make_pair, move |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6134 |
#include <vector> // vector |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6135 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6136 |
// #include <nlohmann/detail/exceptions.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6137 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6138 |
// #include <nlohmann/detail/input/input_adapters.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6139 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6140 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6141 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6142 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6143 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6144 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6145 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6146 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6147 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6148 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6149 |
#include <array> // array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6150 |
#include <cstddef> // size_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6151 |
#include <cstring> // strlen |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6152 |
#include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6153 |
#include <memory> // shared_ptr, make_shared, addressof |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6154 |
#include <numeric> // accumulate |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6155 |
#include <string> // string, char_traits |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6156 |
#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6157 |
#include <utility> // pair, declval |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6158 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6159 |
#ifndef JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6160 |
#include <cstdio> // FILE * |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6161 |
#include <istream> // istream |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6162 |
#endif // JSON_NO_IO |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6163 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6164 |
// #include <nlohmann/detail/iterators/iterator_traits.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6165 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6166 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6167 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6168 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6169 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6170 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6171 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6172 |
namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6173 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6174 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6175 |
/// the supported input formats |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6176 |
enum class input_format_t { json, cbor, msgpack, ubjson, bson, bjdata }; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6177 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6178 |
//////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6179 |
// input adapters // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6180 |
//////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6181 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6182 |
#ifndef JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6183 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6184 |
Input adapter for stdio file access. This adapter read only 1 byte and do not use any |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6185 |
buffer. This adapter is a very low level adapter. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6186 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6187 |
class file_input_adapter |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6188 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6189 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6190 |
using char_type = char; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6191 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6192 |
JSON_HEDLEY_NON_NULL(2) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6193 |
explicit file_input_adapter(std::FILE* f) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6194 |
: m_file(f) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6195 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6196 |
JSON_ASSERT(m_file != nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6197 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6198 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6199 |
// make class move-only |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6200 |
file_input_adapter(const file_input_adapter&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6201 |
file_input_adapter(file_input_adapter&&) noexcept = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6202 |
file_input_adapter& operator=(const file_input_adapter&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6203 |
file_input_adapter& operator=(file_input_adapter&&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6204 |
~file_input_adapter() = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6205 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6206 |
std::char_traits<char>::int_type get_character() noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6207 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6208 |
return std::fgetc(m_file); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6209 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6210 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6211 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6212 |
/// the file pointer to read from |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6213 |
std::FILE* m_file; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6214 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6215 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6216 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6217 |
Input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6218 |
beginning of input. Does not support changing the underlying std::streambuf |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6219 |
in mid-input. Maintains underlying std::istream and std::streambuf to support |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6220 |
subsequent use of standard std::istream operations to process any input |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6221 |
characters following those used in parsing the JSON input. Clears the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6222 |
std::istream flags; any input errors (e.g., EOF) will be detected by the first |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6223 |
subsequent call for input from the std::istream. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6224 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6225 |
class input_stream_adapter |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6226 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6227 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6228 |
using char_type = char; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6229 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6230 |
~input_stream_adapter() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6231 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6232 |
// clear stream flags; we use underlying streambuf I/O, do not |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6233 |
// maintain ifstream flags, except eof |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6234 |
if (is != nullptr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6235 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6236 |
is->clear(is->rdstate() & std::ios::eofbit); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6237 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6238 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6239 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6240 |
explicit input_stream_adapter(std::istream& i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6241 |
: is(&i), sb(i.rdbuf()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6242 |
{} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6243 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6244 |
// delete because of pointer members |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6245 |
input_stream_adapter(const input_stream_adapter&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6246 |
input_stream_adapter& operator=(input_stream_adapter&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6247 |
input_stream_adapter& operator=(input_stream_adapter&&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6248 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6249 |
input_stream_adapter(input_stream_adapter&& rhs) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6250 |
: is(rhs.is), sb(rhs.sb) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6251 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6252 |
rhs.is = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6253 |
rhs.sb = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6254 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6255 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6256 |
// std::istream/std::streambuf use std::char_traits<char>::to_int_type, to |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6257 |
// ensure that std::char_traits<char>::eof() and the character 0xFF do not |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6258 |
// end up as the same value, e.g. 0xFFFFFFFF. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6259 |
std::char_traits<char>::int_type get_character() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6260 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6261 |
auto res = sb->sbumpc(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6262 |
// set eof manually, as we don't use the istream interface. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6263 |
if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6264 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6265 |
is->clear(is->rdstate() | std::ios::eofbit); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6266 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6267 |
return res; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6268 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6269 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6270 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6271 |
/// the associated input stream |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6272 |
std::istream* is = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6273 |
std::streambuf* sb = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6274 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6275 |
#endif // JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6276 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6277 |
// General-purpose iterator-based adapter. It might not be as fast as |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6278 |
// theoretically possible for some containers, but it is extremely versatile. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6279 |
template<typename IteratorType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6280 |
class iterator_input_adapter |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6281 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6282 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6283 |
using char_type = typename std::iterator_traits<IteratorType>::value_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6284 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6285 |
iterator_input_adapter(IteratorType first, IteratorType last) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6286 |
: current(std::move(first)), end(std::move(last)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6287 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6288 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6289 |
typename char_traits<char_type>::int_type get_character() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6290 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6291 |
if (JSON_HEDLEY_LIKELY(current != end)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6292 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6293 |
auto result = char_traits<char_type>::to_int_type(*current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6294 |
std::advance(current, 1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6295 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6296 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6297 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6298 |
return char_traits<char_type>::eof(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6299 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6300 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6301 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6302 |
IteratorType current; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6303 |
IteratorType end; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6304 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6305 |
template<typename BaseInputAdapter, size_t T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6306 |
friend struct wide_string_input_helper; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6307 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6308 |
bool empty() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6309 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6310 |
return current == end; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6311 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6312 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6313 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6314 |
template<typename BaseInputAdapter, size_t T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6315 |
struct wide_string_input_helper; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6316 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6317 |
template<typename BaseInputAdapter> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6318 |
struct wide_string_input_helper<BaseInputAdapter, 4> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6319 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6320 |
// UTF-32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6321 |
static void fill_buffer(BaseInputAdapter& input, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6322 |
std::array<std::char_traits<char>::int_type, 4>& utf8_bytes, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6323 |
size_t& utf8_bytes_index, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6324 |
size_t& utf8_bytes_filled) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6325 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6326 |
utf8_bytes_index = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6327 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6328 |
if (JSON_HEDLEY_UNLIKELY(input.empty())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6329 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6330 |
utf8_bytes[0] = std::char_traits<char>::eof(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6331 |
utf8_bytes_filled = 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6332 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6333 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6334 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6335 |
// get the current character |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6336 |
const auto wc = input.get_character(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6337 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6338 |
// UTF-32 to UTF-8 encoding |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6339 |
if (wc < 0x80) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6340 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6341 |
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6342 |
utf8_bytes_filled = 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6343 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6344 |
else if (wc <= 0x7FF) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6345 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6346 |
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u) & 0x1Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6347 |
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6348 |
utf8_bytes_filled = 2; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6349 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6350 |
else if (wc <= 0xFFFF) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6351 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6352 |
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u) & 0x0Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6353 |
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6354 |
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6355 |
utf8_bytes_filled = 3; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6356 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6357 |
else if (wc <= 0x10FFFF) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6358 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6359 |
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | ((static_cast<unsigned int>(wc) >> 18u) & 0x07u)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6360 |
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 12u) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6361 |
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6362 |
utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6363 |
utf8_bytes_filled = 4; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6364 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6365 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6366 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6367 |
// unknown character |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6368 |
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6369 |
utf8_bytes_filled = 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6370 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6371 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6372 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6373 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6374 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6375 |
template<typename BaseInputAdapter> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6376 |
struct wide_string_input_helper<BaseInputAdapter, 2> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6377 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6378 |
// UTF-16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6379 |
static void fill_buffer(BaseInputAdapter& input, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6380 |
std::array<std::char_traits<char>::int_type, 4>& utf8_bytes, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6381 |
size_t& utf8_bytes_index, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6382 |
size_t& utf8_bytes_filled) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6383 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6384 |
utf8_bytes_index = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6385 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6386 |
if (JSON_HEDLEY_UNLIKELY(input.empty())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6387 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6388 |
utf8_bytes[0] = std::char_traits<char>::eof(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6389 |
utf8_bytes_filled = 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6390 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6391 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6392 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6393 |
// get the current character |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6394 |
const auto wc = input.get_character(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6395 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6396 |
// UTF-16 to UTF-8 encoding |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6397 |
if (wc < 0x80) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6398 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6399 |
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6400 |
utf8_bytes_filled = 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6401 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6402 |
else if (wc <= 0x7FF) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6403 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6404 |
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6405 |
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6406 |
utf8_bytes_filled = 2; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6407 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6408 |
else if (0xD800 > wc || wc >= 0xE000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6409 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6410 |
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6411 |
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6412 |
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6413 |
utf8_bytes_filled = 3; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6414 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6415 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6416 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6417 |
if (JSON_HEDLEY_UNLIKELY(!input.empty())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6418 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6419 |
const auto wc2 = static_cast<unsigned int>(input.get_character()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6420 |
const auto charcode = 0x10000u + (((static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6421 |
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | (charcode >> 18u)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6422 |
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 12u) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6423 |
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 6u) & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6424 |
utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (charcode & 0x3Fu)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6425 |
utf8_bytes_filled = 4; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6426 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6427 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6428 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6429 |
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6430 |
utf8_bytes_filled = 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6431 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6432 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6433 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6434 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6435 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6436 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6437 |
// Wraps another input adapter to convert wide character types into individual bytes. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6438 |
template<typename BaseInputAdapter, typename WideCharType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6439 |
class wide_string_input_adapter |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6440 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6441 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6442 |
using char_type = char; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6443 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6444 |
wide_string_input_adapter(BaseInputAdapter base) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6445 |
: base_adapter(base) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6446 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6447 |
typename std::char_traits<char>::int_type get_character() noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6448 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6449 |
// check if buffer needs to be filled |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6450 |
if (utf8_bytes_index == utf8_bytes_filled) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6451 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6452 |
fill_buffer<sizeof(WideCharType)>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6453 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6454 |
JSON_ASSERT(utf8_bytes_filled > 0); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6455 |
JSON_ASSERT(utf8_bytes_index == 0); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6456 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6457 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6458 |
// use buffer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6459 |
JSON_ASSERT(utf8_bytes_filled > 0); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6460 |
JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6461 |
return utf8_bytes[utf8_bytes_index++]; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6462 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6463 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6464 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6465 |
BaseInputAdapter base_adapter; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6466 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6467 |
template<size_t T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6468 |
void fill_buffer() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6469 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6470 |
wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6471 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6472 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6473 |
/// a buffer for UTF-8 bytes |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6474 |
std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6475 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6476 |
/// index to the utf8_codes array for the next valid byte |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6477 |
std::size_t utf8_bytes_index = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6478 |
/// number of valid bytes in the utf8_codes array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6479 |
std::size_t utf8_bytes_filled = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6480 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6481 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6482 |
template<typename IteratorType, typename Enable = void> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6483 |
struct iterator_input_adapter_factory |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6484 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6485 |
using iterator_type = IteratorType; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6486 |
using char_type = typename std::iterator_traits<iterator_type>::value_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6487 |
using adapter_type = iterator_input_adapter<iterator_type>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6488 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6489 |
static adapter_type create(IteratorType first, IteratorType last) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6490 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6491 |
return adapter_type(std::move(first), std::move(last)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6492 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6493 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6494 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6495 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6496 |
struct is_iterator_of_multibyte |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6497 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6498 |
using value_type = typename std::iterator_traits<T>::value_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6499 |
enum |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6500 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6501 |
value = sizeof(value_type) > 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6502 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6503 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6504 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6505 |
template<typename IteratorType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6506 |
struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6507 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6508 |
using iterator_type = IteratorType; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6509 |
using char_type = typename std::iterator_traits<iterator_type>::value_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6510 |
using base_adapter_type = iterator_input_adapter<iterator_type>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6511 |
using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6512 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6513 |
static adapter_type create(IteratorType first, IteratorType last) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6514 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6515 |
return adapter_type(base_adapter_type(std::move(first), std::move(last))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6516 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6517 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6518 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6519 |
// General purpose iterator-based input |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6520 |
template<typename IteratorType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6521 |
typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6522 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6523 |
using factory_type = iterator_input_adapter_factory<IteratorType>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6524 |
return factory_type::create(first, last); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6525 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6526 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6527 |
// Convenience shorthand from container to iterator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6528 |
// Enables ADL on begin(container) and end(container) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6529 |
// Encloses the using declarations in namespace for not to leak them to outside scope |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6530 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6531 |
namespace container_input_adapter_factory_impl |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6532 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6533 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6534 |
using std::begin; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6535 |
using std::end; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6536 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6537 |
template<typename ContainerType, typename Enable = void> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6538 |
struct container_input_adapter_factory {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6539 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6540 |
template<typename ContainerType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6541 |
struct container_input_adapter_factory< ContainerType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6542 |
void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6543 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6544 |
using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6545 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6546 |
static adapter_type create(const ContainerType& container) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6547 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6548 |
return input_adapter(begin(container), end(container)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6549 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6550 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6551 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6552 |
} // namespace container_input_adapter_factory_impl |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6553 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6554 |
template<typename ContainerType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6555 |
typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(const ContainerType& container) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6556 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6557 |
return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6558 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6559 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6560 |
#ifndef JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6561 |
// Special cases with fast paths |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6562 |
inline file_input_adapter input_adapter(std::FILE* file) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6563 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6564 |
return file_input_adapter(file); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6565 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6566 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6567 |
inline input_stream_adapter input_adapter(std::istream& stream) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6568 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6569 |
return input_stream_adapter(stream); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6570 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6571 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6572 |
inline input_stream_adapter input_adapter(std::istream&& stream) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6573 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6574 |
return input_stream_adapter(stream); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6575 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6576 |
#endif // JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6577 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6578 |
using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6579 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6580 |
// Null-delimited strings, and the like. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6581 |
template < typename CharT, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6582 |
typename std::enable_if < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6583 |
std::is_pointer<CharT>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6584 |
!std::is_array<CharT>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6585 |
std::is_integral<typename std::remove_pointer<CharT>::type>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6586 |
sizeof(typename std::remove_pointer<CharT>::type) == 1, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6587 |
int >::type = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6588 |
contiguous_bytes_input_adapter input_adapter(CharT b) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6589 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6590 |
auto length = std::strlen(reinterpret_cast<const char*>(b)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6591 |
const auto* ptr = reinterpret_cast<const char*>(b); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6592 |
return input_adapter(ptr, ptr + length); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6593 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6594 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6595 |
template<typename T, std::size_t N> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6596 |
auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6597 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6598 |
return input_adapter(array, array + N); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6599 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6600 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6601 |
// This class only handles inputs of input_buffer_adapter type. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6602 |
// It's required so that expressions like {ptr, len} can be implicitly cast |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6603 |
// to the correct adapter. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6604 |
class span_input_adapter |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6605 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6606 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6607 |
template < typename CharT, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6608 |
typename std::enable_if < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6609 |
std::is_pointer<CharT>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6610 |
std::is_integral<typename std::remove_pointer<CharT>::type>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6611 |
sizeof(typename std::remove_pointer<CharT>::type) == 1, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6612 |
int >::type = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6613 |
span_input_adapter(CharT b, std::size_t l) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6614 |
: ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6615 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6616 |
template<class IteratorType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6617 |
typename std::enable_if< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6618 |
std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6619 |
int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6620 |
span_input_adapter(IteratorType first, IteratorType last) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6621 |
: ia(input_adapter(first, last)) {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6622 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6623 |
contiguous_bytes_input_adapter&& get() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6624 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6625 |
return std::move(ia); // NOLINT(hicpp-move-const-arg,performance-move-const-arg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6626 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6627 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6628 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6629 |
contiguous_bytes_input_adapter ia; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6630 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6631 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6632 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6633 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6634 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6635 |
// #include <nlohmann/detail/input/json_sax.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6636 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6637 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6638 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6639 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6640 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6641 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6642 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6643 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6644 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6645 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6646 |
#include <cstddef> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6647 |
#include <string> // string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6648 |
#include <utility> // move |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6649 |
#include <vector> // vector |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6650 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6651 |
// #include <nlohmann/detail/exceptions.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6652 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6653 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6654 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6655 |
// #include <nlohmann/detail/string_concat.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6656 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6657 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6658 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6659 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6660 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6661 |
@brief SAX interface |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6662 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6663 |
This class describes the SAX interface used by @ref nlohmann::json::sax_parse. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6664 |
Each function is called in different situations while the input is parsed. The |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6665 |
boolean return value informs the parser whether to continue processing the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6666 |
input. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6667 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6668 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6669 |
struct json_sax |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6670 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6671 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6672 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6673 |
using number_float_t = typename BasicJsonType::number_float_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6674 |
using string_t = typename BasicJsonType::string_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6675 |
using binary_t = typename BasicJsonType::binary_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6676 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6677 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6678 |
@brief a null value was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6679 |
@return whether parsing should proceed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6680 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6681 |
virtual bool null() = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6682 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6683 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6684 |
@brief a boolean value was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6685 |
@param[in] val boolean value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6686 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6687 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6688 |
virtual bool boolean(bool val) = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6689 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6690 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6691 |
@brief an integer number was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6692 |
@param[in] val integer value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6693 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6694 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6695 |
virtual bool number_integer(number_integer_t val) = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6696 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6697 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6698 |
@brief an unsigned integer number was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6699 |
@param[in] val unsigned integer value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6700 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6701 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6702 |
virtual bool number_unsigned(number_unsigned_t val) = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6703 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6704 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6705 |
@brief a floating-point number was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6706 |
@param[in] val floating-point value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6707 |
@param[in] s raw token value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6708 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6709 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6710 |
virtual bool number_float(number_float_t val, const string_t& s) = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6711 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6712 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6713 |
@brief a string value was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6714 |
@param[in] val string value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6715 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6716 |
@note It is safe to move the passed string value. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6717 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6718 |
virtual bool string(string_t& val) = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
6719 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6720 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6721 |
@brief a binary value was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6722 |
@param[in] val binary value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6723 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6724 |
@note It is safe to move the passed binary value. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6725 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6726 |
virtual bool binary(binary_t& val) = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6727 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6728 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6729 |
@brief the beginning of an object was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6730 |
@param[in] elements number of object elements or -1 if unknown |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6731 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6732 |
@note binary formats may report the number of elements |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6733 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6734 |
virtual bool start_object(std::size_t elements) = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6735 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6736 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6737 |
@brief an object key was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6738 |
@param[in] val object key |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6739 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6740 |
@note It is safe to move the passed string. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6741 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6742 |
virtual bool key(string_t& val) = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6743 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6744 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6745 |
@brief the end of an object was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6746 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6747 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6748 |
virtual bool end_object() = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6749 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6750 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6751 |
@brief the beginning of an array was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6752 |
@param[in] elements number of array elements or -1 if unknown |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6753 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6754 |
@note binary formats may report the number of elements |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6755 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6756 |
virtual bool start_array(std::size_t elements) = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6757 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6758 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6759 |
@brief the end of an array was read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6760 |
@return whether parsing should proceed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6761 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6762 |
virtual bool end_array() = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6763 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6764 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6765 |
@brief a parse error occurred |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6766 |
@param[in] position the position in the input where the error occurs |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6767 |
@param[in] last_token the last read token |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6768 |
@param[in] ex an exception object describing the error |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6769 |
@return whether parsing should proceed (must return false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6770 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6771 |
virtual bool parse_error(std::size_t position, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6772 |
const std::string& last_token, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6773 |
const detail::exception& ex) = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6774 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6775 |
json_sax() = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6776 |
json_sax(const json_sax&) = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6777 |
json_sax(json_sax&&) noexcept = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6778 |
json_sax& operator=(const json_sax&) = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6779 |
json_sax& operator=(json_sax&&) noexcept = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6780 |
virtual ~json_sax() = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6781 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6782 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6783 |
namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6784 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6785 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6786 |
@brief SAX implementation to create a JSON value from SAX events |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6787 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6788 |
This class implements the @ref json_sax interface and processes the SAX events |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6789 |
to create a JSON value which makes it basically a DOM parser. The structure or |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6790 |
hierarchy of the JSON value is managed by the stack `ref_stack` which contains |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6791 |
a pointer to the respective array or object for each recursion depth. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6792 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6793 |
After successful parsing, the value that is passed by reference to the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6794 |
constructor contains the parsed value. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6795 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6796 |
@tparam BasicJsonType the JSON type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6797 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6798 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6799 |
class json_sax_dom_parser |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6800 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6801 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6802 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6803 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6804 |
using number_float_t = typename BasicJsonType::number_float_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6805 |
using string_t = typename BasicJsonType::string_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6806 |
using binary_t = typename BasicJsonType::binary_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6807 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6808 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6809 |
@param[in,out] r reference to a JSON value that is manipulated while |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6810 |
parsing |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6811 |
@param[in] allow_exceptions_ whether parse errors yield exceptions |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6812 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6813 |
explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6814 |
: root(r), allow_exceptions(allow_exceptions_) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6815 |
{} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6816 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6817 |
// make class move-only |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6818 |
json_sax_dom_parser(const json_sax_dom_parser&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6819 |
json_sax_dom_parser(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6820 |
json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6821 |
json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6822 |
~json_sax_dom_parser() = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6823 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6824 |
bool null() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6825 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6826 |
handle_value(nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6827 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6828 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6829 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6830 |
bool boolean(bool val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6831 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6832 |
handle_value(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6833 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6834 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6835 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6836 |
bool number_integer(number_integer_t val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6837 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6838 |
handle_value(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6839 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6840 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6841 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6842 |
bool number_unsigned(number_unsigned_t val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6843 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6844 |
handle_value(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6845 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6846 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6847 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6848 |
bool number_float(number_float_t val, const string_t& /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6849 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6850 |
handle_value(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6851 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6852 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6853 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6854 |
bool string(string_t& val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6855 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6856 |
handle_value(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6857 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6858 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6859 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6860 |
bool binary(binary_t& val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6861 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6862 |
handle_value(std::move(val)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6863 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6864 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6865 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6866 |
bool start_object(std::size_t len) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6867 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6868 |
ref_stack.push_back(handle_value(BasicJsonType::value_t::object)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6869 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6870 |
if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6871 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6872 |
JSON_THROW(out_of_range::create(408, concat("excessive object size: ", std::to_string(len)), ref_stack.back())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6873 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6874 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6875 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6876 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6877 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6878 |
bool key(string_t& val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6879 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6880 |
JSON_ASSERT(!ref_stack.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6881 |
JSON_ASSERT(ref_stack.back()->is_object()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6882 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6883 |
// add null at given key and store the reference for later |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6884 |
object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6885 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6886 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6887 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6888 |
bool end_object() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6889 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6890 |
JSON_ASSERT(!ref_stack.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6891 |
JSON_ASSERT(ref_stack.back()->is_object()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6892 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6893 |
ref_stack.back()->set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6894 |
ref_stack.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6895 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6896 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6897 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6898 |
bool start_array(std::size_t len) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6899 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6900 |
ref_stack.push_back(handle_value(BasicJsonType::value_t::array)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6901 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6902 |
if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6903 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6904 |
JSON_THROW(out_of_range::create(408, concat("excessive array size: ", std::to_string(len)), ref_stack.back())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6905 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6906 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6907 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6908 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6909 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6910 |
bool end_array() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6911 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6912 |
JSON_ASSERT(!ref_stack.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6913 |
JSON_ASSERT(ref_stack.back()->is_array()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6914 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6915 |
ref_stack.back()->set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6916 |
ref_stack.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6917 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6918 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6919 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6920 |
template<class Exception> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6921 |
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6922 |
const Exception& ex) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6923 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6924 |
errored = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6925 |
static_cast<void>(ex); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6926 |
if (allow_exceptions) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6927 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6928 |
JSON_THROW(ex); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6929 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6930 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6931 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6932 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6933 |
constexpr bool is_errored() const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6934 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6935 |
return errored; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6936 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6937 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6938 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6939 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6940 |
@invariant If the ref stack is empty, then the passed value will be the new |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6941 |
root. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6942 |
@invariant If the ref stack contains a value, then it is an array or an |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6943 |
object to which we can add elements |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6944 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6945 |
template<typename Value> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6946 |
JSON_HEDLEY_RETURNS_NON_NULL |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6947 |
BasicJsonType* handle_value(Value&& v) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6948 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6949 |
if (ref_stack.empty()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6950 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6951 |
root = BasicJsonType(std::forward<Value>(v)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6952 |
return &root; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6953 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6954 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6955 |
JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6956 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6957 |
if (ref_stack.back()->is_array()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6958 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6959 |
ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6960 |
return &(ref_stack.back()->m_data.m_value.array->back()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6961 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6962 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6963 |
JSON_ASSERT(ref_stack.back()->is_object()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6964 |
JSON_ASSERT(object_element); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6965 |
*object_element = BasicJsonType(std::forward<Value>(v)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6966 |
return object_element; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6967 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6968 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6969 |
/// the parsed JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6970 |
BasicJsonType& root; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6971 |
/// stack to model hierarchy of values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6972 |
std::vector<BasicJsonType*> ref_stack {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6973 |
/// helper to hold the reference for the next object element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6974 |
BasicJsonType* object_element = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6975 |
/// whether a syntax error occurred |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6976 |
bool errored = false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6977 |
/// whether to throw exceptions in case of errors |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6978 |
const bool allow_exceptions = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6979 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6980 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6981 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6982 |
class json_sax_dom_callback_parser |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6983 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6984 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6985 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6986 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6987 |
using number_float_t = typename BasicJsonType::number_float_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6988 |
using string_t = typename BasicJsonType::string_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6989 |
using binary_t = typename BasicJsonType::binary_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6990 |
using parser_callback_t = typename BasicJsonType::parser_callback_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6991 |
using parse_event_t = typename BasicJsonType::parse_event_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6992 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6993 |
json_sax_dom_callback_parser(BasicJsonType& r, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6994 |
const parser_callback_t cb, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6995 |
const bool allow_exceptions_ = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6996 |
: root(r), callback(cb), allow_exceptions(allow_exceptions_) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6997 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6998 |
keep_stack.push_back(true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
6999 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7000 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7001 |
// make class move-only |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7002 |
json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7003 |
json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7004 |
json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7005 |
json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7006 |
~json_sax_dom_callback_parser() = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7007 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7008 |
bool null() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7009 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7010 |
handle_value(nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7011 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7012 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7013 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7014 |
bool boolean(bool val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7015 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7016 |
handle_value(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7017 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7018 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7019 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7020 |
bool number_integer(number_integer_t val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7021 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7022 |
handle_value(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7023 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7024 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7025 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7026 |
bool number_unsigned(number_unsigned_t val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7027 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7028 |
handle_value(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7029 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7030 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7031 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7032 |
bool number_float(number_float_t val, const string_t& /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7033 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7034 |
handle_value(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7035 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7036 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7037 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7038 |
bool string(string_t& val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7039 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7040 |
handle_value(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7041 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7042 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7043 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7044 |
bool binary(binary_t& val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7045 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7046 |
handle_value(std::move(val)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7047 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7048 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7049 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7050 |
bool start_object(std::size_t len) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7051 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7052 |
// check callback for object start |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7053 |
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7054 |
keep_stack.push_back(keep); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7055 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7056 |
auto val = handle_value(BasicJsonType::value_t::object, true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7057 |
ref_stack.push_back(val.second); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7058 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7059 |
// check object limit |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7060 |
if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7061 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7062 |
JSON_THROW(out_of_range::create(408, concat("excessive object size: ", std::to_string(len)), ref_stack.back())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7063 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7064 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7065 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7066 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7067 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7068 |
bool key(string_t& val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7069 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7070 |
BasicJsonType k = BasicJsonType(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7071 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7072 |
// check callback for key |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7073 |
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7074 |
key_keep_stack.push_back(keep); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7075 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7076 |
// add discarded value at given key and store the reference for later |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7077 |
if (keep && ref_stack.back()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7078 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7079 |
object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) = discarded); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7080 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7081 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7082 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7083 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7084 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7085 |
bool end_object() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7086 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7087 |
if (ref_stack.back()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7088 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7089 |
if (!callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7090 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7091 |
// discard object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7092 |
*ref_stack.back() = discarded; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7093 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7094 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7095 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7096 |
ref_stack.back()->set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7097 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7098 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7099 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7100 |
JSON_ASSERT(!ref_stack.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7101 |
JSON_ASSERT(!keep_stack.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7102 |
ref_stack.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7103 |
keep_stack.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7104 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7105 |
if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7106 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7107 |
// remove discarded value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7108 |
for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7109 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7110 |
if (it->is_discarded()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7111 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7112 |
ref_stack.back()->erase(it); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7113 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7114 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7115 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7116 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7117 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7118 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7119 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7120 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7121 |
bool start_array(std::size_t len) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7122 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7123 |
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7124 |
keep_stack.push_back(keep); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7125 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7126 |
auto val = handle_value(BasicJsonType::value_t::array, true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7127 |
ref_stack.push_back(val.second); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7128 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7129 |
// check array limit |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7130 |
if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7131 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7132 |
JSON_THROW(out_of_range::create(408, concat("excessive array size: ", std::to_string(len)), ref_stack.back())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7133 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7134 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7135 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7136 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7137 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7138 |
bool end_array() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7139 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7140 |
bool keep = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7141 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7142 |
if (ref_stack.back()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7143 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7144 |
keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7145 |
if (keep) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7146 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7147 |
ref_stack.back()->set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7148 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7149 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7150 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7151 |
// discard array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7152 |
*ref_stack.back() = discarded; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7153 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7154 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7155 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7156 |
JSON_ASSERT(!ref_stack.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7157 |
JSON_ASSERT(!keep_stack.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7158 |
ref_stack.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7159 |
keep_stack.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7160 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7161 |
// remove discarded value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7162 |
if (!keep && !ref_stack.empty() && ref_stack.back()->is_array()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7163 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7164 |
ref_stack.back()->m_data.m_value.array->pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7165 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7166 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7167 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7168 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7169 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7170 |
template<class Exception> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7171 |
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7172 |
const Exception& ex) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7173 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7174 |
errored = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7175 |
static_cast<void>(ex); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7176 |
if (allow_exceptions) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7177 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7178 |
JSON_THROW(ex); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7179 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7180 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7181 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7182 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7183 |
constexpr bool is_errored() const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7184 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7185 |
return errored; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7186 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7187 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7188 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7189 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7190 |
@param[in] v value to add to the JSON value we build during parsing |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7191 |
@param[in] skip_callback whether we should skip calling the callback |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7192 |
function; this is required after start_array() and |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7193 |
start_object() SAX events, because otherwise we would call the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7194 |
callback function with an empty array or object, respectively. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7195 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7196 |
@invariant If the ref stack is empty, then the passed value will be the new |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7197 |
root. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7198 |
@invariant If the ref stack contains a value, then it is an array or an |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7199 |
object to which we can add elements |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7200 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7201 |
@return pair of boolean (whether value should be kept) and pointer (to the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7202 |
passed value in the ref_stack hierarchy; nullptr if not kept) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7203 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7204 |
template<typename Value> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7205 |
std::pair<bool, BasicJsonType*> handle_value(Value&& v, const bool skip_callback = false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7206 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7207 |
JSON_ASSERT(!keep_stack.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7208 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7209 |
// do not handle this value if we know it would be added to a discarded |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7210 |
// container |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7211 |
if (!keep_stack.back()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7212 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7213 |
return {false, nullptr}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7214 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7215 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7216 |
// create value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7217 |
auto value = BasicJsonType(std::forward<Value>(v)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7218 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7219 |
// check callback |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7220 |
const bool keep = skip_callback || callback(static_cast<int>(ref_stack.size()), parse_event_t::value, value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7221 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7222 |
// do not handle this value if we just learnt it shall be discarded |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7223 |
if (!keep) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7224 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7225 |
return {false, nullptr}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7226 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7227 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7228 |
if (ref_stack.empty()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7229 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7230 |
root = std::move(value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7231 |
return {true, & root}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7232 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7233 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7234 |
// skip this value if we already decided to skip the parent |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7235 |
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7236 |
if (!ref_stack.back()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7237 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7238 |
return {false, nullptr}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7239 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7240 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7241 |
// we now only expect arrays and objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7242 |
JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7243 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7244 |
// array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7245 |
if (ref_stack.back()->is_array()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7246 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7247 |
ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7248 |
return {true, & (ref_stack.back()->m_data.m_value.array->back())}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7249 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7250 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7251 |
// object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7252 |
JSON_ASSERT(ref_stack.back()->is_object()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7253 |
// check if we should store an element for the current key |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7254 |
JSON_ASSERT(!key_keep_stack.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7255 |
const bool store_element = key_keep_stack.back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7256 |
key_keep_stack.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7257 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7258 |
if (!store_element) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7259 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7260 |
return {false, nullptr}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7261 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7262 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7263 |
JSON_ASSERT(object_element); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7264 |
*object_element = std::move(value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7265 |
return {true, object_element}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7266 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7267 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7268 |
/// the parsed JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7269 |
BasicJsonType& root; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7270 |
/// stack to model hierarchy of values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7271 |
std::vector<BasicJsonType*> ref_stack {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7272 |
/// stack to manage which values to keep |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7273 |
std::vector<bool> keep_stack {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7274 |
/// stack to manage which object keys to keep |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7275 |
std::vector<bool> key_keep_stack {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7276 |
/// helper to hold the reference for the next object element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7277 |
BasicJsonType* object_element = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7278 |
/// whether a syntax error occurred |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7279 |
bool errored = false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7280 |
/// callback function |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7281 |
const parser_callback_t callback = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7282 |
/// whether to throw exceptions in case of errors |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7283 |
const bool allow_exceptions = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7284 |
/// a discarded value for the callback |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7285 |
BasicJsonType discarded = BasicJsonType::value_t::discarded; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7286 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7287 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7288 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7289 |
class json_sax_acceptor |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7290 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7291 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7292 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7293 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7294 |
using number_float_t = typename BasicJsonType::number_float_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7295 |
using string_t = typename BasicJsonType::string_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7296 |
using binary_t = typename BasicJsonType::binary_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7297 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7298 |
bool null() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7299 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7300 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7301 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7302 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7303 |
bool boolean(bool /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7304 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7305 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7306 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7307 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7308 |
bool number_integer(number_integer_t /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7309 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7310 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7311 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7312 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7313 |
bool number_unsigned(number_unsigned_t /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7314 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7315 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7316 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7317 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7318 |
bool number_float(number_float_t /*unused*/, const string_t& /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7319 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7320 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7321 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7322 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7323 |
bool string(string_t& /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7324 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7325 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7326 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7327 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7328 |
bool binary(binary_t& /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7329 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7330 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7331 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7332 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7333 |
bool start_object(std::size_t /*unused*/ = static_cast<std::size_t>(-1)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7334 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7335 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7336 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7337 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7338 |
bool key(string_t& /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7339 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7340 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7341 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7342 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7343 |
bool end_object() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7344 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7345 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7346 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7347 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7348 |
bool start_array(std::size_t /*unused*/ = static_cast<std::size_t>(-1)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7349 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7350 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7351 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7352 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7353 |
bool end_array() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7354 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7355 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7356 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7357 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7358 |
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7359 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7360 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7361 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7362 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7363 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7364 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7365 |
NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7366 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7367 |
// #include <nlohmann/detail/input/lexer.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7368 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7369 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7370 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7371 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7372 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7373 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7374 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7375 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7376 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7377 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7378 |
#include <array> // array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7379 |
#include <clocale> // localeconv |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7380 |
#include <cstddef> // size_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7381 |
#include <cstdio> // snprintf |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7382 |
#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7383 |
#include <initializer_list> // initializer_list |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7384 |
#include <string> // char_traits, string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7385 |
#include <utility> // move |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7386 |
#include <vector> // vector |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7387 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7388 |
// #include <nlohmann/detail/input/input_adapters.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7389 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7390 |
// #include <nlohmann/detail/input/position_t.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7391 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7392 |
// #include <nlohmann/detail/macro_scope.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7393 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7394 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7395 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7396 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7397 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7398 |
namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7399 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7400 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7401 |
/////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7402 |
// lexer // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7403 |
/////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7404 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7405 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7406 |
class lexer_base |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7407 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7408 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7409 |
/// token types for the parser |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7410 |
enum class token_type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7411 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7412 |
uninitialized, ///< indicating the scanner is uninitialized |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7413 |
literal_true, ///< the `true` literal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7414 |
literal_false, ///< the `false` literal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7415 |
literal_null, ///< the `null` literal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7416 |
value_string, ///< a string -- use get_string() for actual value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7417 |
value_unsigned, ///< an unsigned integer -- use get_number_unsigned() for actual value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7418 |
value_integer, ///< a signed integer -- use get_number_integer() for actual value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7419 |
value_float, ///< an floating point number -- use get_number_float() for actual value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7420 |
begin_array, ///< the character for array begin `[` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7421 |
begin_object, ///< the character for object begin `{` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7422 |
end_array, ///< the character for array end `]` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7423 |
end_object, ///< the character for object end `}` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7424 |
name_separator, ///< the name separator `:` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7425 |
value_separator, ///< the value separator `,` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7426 |
parse_error, ///< indicating a parse error |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7427 |
end_of_input, ///< indicating the end of the input buffer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7428 |
literal_or_value ///< a literal or the begin of a value (only for diagnostics) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7429 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7430 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7431 |
/// return name of values of type token_type (only used for errors) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7432 |
JSON_HEDLEY_RETURNS_NON_NULL |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7433 |
JSON_HEDLEY_CONST |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7434 |
static const char* token_type_name(const token_type t) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7435 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7436 |
switch (t) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7437 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7438 |
case token_type::uninitialized: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7439 |
return "<uninitialized>"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7440 |
case token_type::literal_true: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7441 |
return "true literal"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7442 |
case token_type::literal_false: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7443 |
return "false literal"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7444 |
case token_type::literal_null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7445 |
return "null literal"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7446 |
case token_type::value_string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7447 |
return "string literal"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7448 |
case token_type::value_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7449 |
case token_type::value_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7450 |
case token_type::value_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7451 |
return "number literal"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7452 |
case token_type::begin_array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7453 |
return "'['"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7454 |
case token_type::begin_object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7455 |
return "'{'"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7456 |
case token_type::end_array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7457 |
return "']'"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7458 |
case token_type::end_object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7459 |
return "'}'"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7460 |
case token_type::name_separator: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7461 |
return "':'"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7462 |
case token_type::value_separator: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7463 |
return "','"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7464 |
case token_type::parse_error: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7465 |
return "<parse error>"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7466 |
case token_type::end_of_input: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7467 |
return "end of input"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7468 |
case token_type::literal_or_value: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7469 |
return "'[', '{', or a literal"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7470 |
// LCOV_EXCL_START |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7471 |
default: // catch non-enum values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7472 |
return "unknown token"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7473 |
// LCOV_EXCL_STOP |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7474 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7475 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7476 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7477 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7478 |
@brief lexical analysis |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7479 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7480 |
This class organizes the lexical analysis during JSON deserialization. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7481 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7482 |
template<typename BasicJsonType, typename InputAdapterType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7483 |
class lexer : public lexer_base<BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7484 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7485 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7486 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7487 |
using number_float_t = typename BasicJsonType::number_float_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7488 |
using string_t = typename BasicJsonType::string_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7489 |
using char_type = typename InputAdapterType::char_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7490 |
using char_int_type = typename char_traits<char_type>::int_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7491 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7492 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7493 |
using token_type = typename lexer_base<BasicJsonType>::token_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7494 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7495 |
explicit lexer(InputAdapterType&& adapter, bool ignore_comments_ = false) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7496 |
: ia(std::move(adapter)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7497 |
, ignore_comments(ignore_comments_) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7498 |
, decimal_point_char(static_cast<char_int_type>(get_decimal_point())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7499 |
{} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7500 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7501 |
// delete because of pointer members |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7502 |
lexer(const lexer&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7503 |
lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7504 |
lexer& operator=(lexer&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7505 |
lexer& operator=(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7506 |
~lexer() = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7507 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7508 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7509 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7510 |
// locales |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7511 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7512 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7513 |
/// return the locale-dependent decimal point |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7514 |
JSON_HEDLEY_PURE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7515 |
static char get_decimal_point() noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7516 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7517 |
const auto* loc = localeconv(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7518 |
JSON_ASSERT(loc != nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7519 |
return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7520 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7521 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7522 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7523 |
// scan functions |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7524 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7525 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7526 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7527 |
@brief get codepoint from 4 hex characters following `\u` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7528 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7529 |
For input "\u c1 c2 c3 c4" the codepoint is: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7530 |
(c1 * 0x1000) + (c2 * 0x0100) + (c3 * 0x0010) + c4 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7531 |
= (c1 << 12) + (c2 << 8) + (c3 << 4) + (c4 << 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7532 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7533 |
Furthermore, the possible characters '0'..'9', 'A'..'F', and 'a'..'f' |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7534 |
must be converted to the integers 0x0..0x9, 0xA..0xF, 0xA..0xF, resp. The |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7535 |
conversion is done by subtracting the offset (0x30, 0x37, and 0x57) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7536 |
between the ASCII value of the character and the desired integer value. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7537 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7538 |
@return codepoint (0x0000..0xFFFF) or -1 in case of an error (e.g. EOF or |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7539 |
non-hex character) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7540 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7541 |
int get_codepoint() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7542 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7543 |
// this function only makes sense after reading `\u` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7544 |
JSON_ASSERT(current == 'u'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7545 |
int codepoint = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7546 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7547 |
const auto factors = { 12u, 8u, 4u, 0u }; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7548 |
for (const auto factor : factors) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7549 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7550 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7551 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7552 |
if (current >= '0' && current <= '9') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7553 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7554 |
codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x30u) << factor); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7555 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7556 |
else if (current >= 'A' && current <= 'F') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7557 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7558 |
codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x37u) << factor); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7559 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7560 |
else if (current >= 'a' && current <= 'f') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7561 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7562 |
codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x57u) << factor); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7563 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7564 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7565 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7566 |
return -1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7567 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7568 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7569 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7570 |
JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7571 |
return codepoint; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7572 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7573 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7574 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7575 |
@brief check if the next byte(s) are inside a given range |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7576 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7577 |
Adds the current byte and, for each passed range, reads a new byte and |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7578 |
checks if it is inside the range. If a violation was detected, set up an |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7579 |
error message and return false. Otherwise, return true. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7580 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7581 |
@param[in] ranges list of integers; interpreted as list of pairs of |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7582 |
inclusive lower and upper bound, respectively |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7583 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7584 |
@pre The passed list @a ranges must have 2, 4, or 6 elements; that is, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7585 |
1, 2, or 3 pairs. This precondition is enforced by an assertion. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7586 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7587 |
@return true if and only if no range violation was detected |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7588 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7589 |
bool next_byte_in_range(std::initializer_list<char_int_type> ranges) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7590 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7591 |
JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7592 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7593 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7594 |
for (auto range = ranges.begin(); range != ranges.end(); ++range) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7595 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7596 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7597 |
if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) // NOLINT(bugprone-inc-dec-in-conditions) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7598 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7599 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7600 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7601 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7602 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7603 |
error_message = "invalid string: ill-formed UTF-8 byte"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7604 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7605 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7606 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7607 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7608 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7609 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7610 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7611 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7612 |
@brief scan a string literal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7613 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7614 |
This function scans a string according to Sect. 7 of RFC 8259. While |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7615 |
scanning, bytes are escaped and copied into buffer token_buffer. Then the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7616 |
function returns successfully, token_buffer is *not* null-terminated (as it |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7617 |
may contain \0 bytes), and token_buffer.size() is the number of bytes in the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7618 |
string. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7619 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7620 |
@return token_type::value_string if string could be successfully scanned, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7621 |
token_type::parse_error otherwise |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7622 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7623 |
@note In case of errors, variable error_message contains a textual |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7624 |
description. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7625 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7626 |
token_type scan_string() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7627 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7628 |
// reset token_buffer (ignore opening quote) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7629 |
reset(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7630 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7631 |
// we entered the function by reading an open quote |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7632 |
JSON_ASSERT(current == '\"'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7633 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7634 |
while (true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7635 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7636 |
// get next character |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7637 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7638 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7639 |
// end of file while parsing string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7640 |
case char_traits<char_type>::eof(): |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7641 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7642 |
error_message = "invalid string: missing closing quote"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7643 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7644 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7645 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7646 |
// closing quote |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7647 |
case '\"': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7648 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7649 |
return token_type::value_string; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7650 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7651 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7652 |
// escapes |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7653 |
case '\\': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7654 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7655 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7656 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7657 |
// quotation mark |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7658 |
case '\"': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7659 |
add('\"'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7660 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7661 |
// reverse solidus |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7662 |
case '\\': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7663 |
add('\\'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7664 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7665 |
// solidus |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7666 |
case '/': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7667 |
add('/'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7668 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7669 |
// backspace |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7670 |
case 'b': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7671 |
add('\b'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7672 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7673 |
// form feed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7674 |
case 'f': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7675 |
add('\f'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7676 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7677 |
// line feed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7678 |
case 'n': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7679 |
add('\n'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7680 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7681 |
// carriage return |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7682 |
case 'r': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7683 |
add('\r'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7684 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7685 |
// tab |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7686 |
case 't': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7687 |
add('\t'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7688 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7689 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7690 |
// unicode escapes |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7691 |
case 'u': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7692 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7693 |
const int codepoint1 = get_codepoint(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7694 |
int codepoint = codepoint1; // start with codepoint1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7695 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7696 |
if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7697 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7698 |
error_message = "invalid string: '\\u' must be followed by 4 hex digits"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7699 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7700 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7701 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7702 |
// check if code point is a high surrogate |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7703 |
if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7704 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7705 |
// expect next \uxxxx entry |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7706 |
if (JSON_HEDLEY_LIKELY(get() == '\\' && get() == 'u')) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7707 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7708 |
const int codepoint2 = get_codepoint(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7709 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7710 |
if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7711 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7712 |
error_message = "invalid string: '\\u' must be followed by 4 hex digits"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7713 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7714 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7715 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7716 |
// check if codepoint2 is a low surrogate |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7717 |
if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7718 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7719 |
// overwrite codepoint |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7720 |
codepoint = static_cast<int>( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7721 |
// high surrogate occupies the most significant 22 bits |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7722 |
(static_cast<unsigned int>(codepoint1) << 10u) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7723 |
// low surrogate occupies the least significant 15 bits |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7724 |
+ static_cast<unsigned int>(codepoint2) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7725 |
// there is still the 0xD800, 0xDC00 and 0x10000 noise |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7726 |
// in the result, so we have to subtract with: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7727 |
// (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7728 |
- 0x35FDC00u); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7729 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7730 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7731 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7732 |
error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7733 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7734 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7735 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7736 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7737 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7738 |
error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7739 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7740 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7741 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7742 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7743 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7744 |
if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7745 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7746 |
error_message = "invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7747 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7748 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7749 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7750 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7751 |
// result of the above calculation yields a proper codepoint |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7752 |
JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7753 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7754 |
// translate codepoint into bytes |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7755 |
if (codepoint < 0x80) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7756 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7757 |
// 1-byte characters: 0xxxxxxx (ASCII) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7758 |
add(static_cast<char_int_type>(codepoint)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7759 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7760 |
else if (codepoint <= 0x7FF) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7761 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7762 |
// 2-byte characters: 110xxxxx 10xxxxxx |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7763 |
add(static_cast<char_int_type>(0xC0u | (static_cast<unsigned int>(codepoint) >> 6u))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7764 |
add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7765 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7766 |
else if (codepoint <= 0xFFFF) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7767 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7768 |
// 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7769 |
add(static_cast<char_int_type>(0xE0u | (static_cast<unsigned int>(codepoint) >> 12u))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7770 |
add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7771 |
add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7772 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7773 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7774 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7775 |
// 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7776 |
add(static_cast<char_int_type>(0xF0u | (static_cast<unsigned int>(codepoint) >> 18u))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7777 |
add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7778 |
add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7779 |
add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7780 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7781 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7782 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7783 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7784 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7785 |
// other characters after escape |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7786 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7787 |
error_message = "invalid string: forbidden character after backslash"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7788 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7789 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7790 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7791 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7792 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7793 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7794 |
// invalid control characters |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7795 |
case 0x00: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7796 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7797 |
error_message = "invalid string: control character U+0000 (NUL) must be escaped to \\u0000"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7798 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7799 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7800 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7801 |
case 0x01: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7802 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7803 |
error_message = "invalid string: control character U+0001 (SOH) must be escaped to \\u0001"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7804 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7805 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7806 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7807 |
case 0x02: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7808 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7809 |
error_message = "invalid string: control character U+0002 (STX) must be escaped to \\u0002"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7810 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7811 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7812 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7813 |
case 0x03: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7814 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7815 |
error_message = "invalid string: control character U+0003 (ETX) must be escaped to \\u0003"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7816 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7817 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7818 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7819 |
case 0x04: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7820 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7821 |
error_message = "invalid string: control character U+0004 (EOT) must be escaped to \\u0004"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7822 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7823 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7824 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7825 |
case 0x05: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7826 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7827 |
error_message = "invalid string: control character U+0005 (ENQ) must be escaped to \\u0005"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7828 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7829 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7830 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7831 |
case 0x06: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7832 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7833 |
error_message = "invalid string: control character U+0006 (ACK) must be escaped to \\u0006"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7834 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7835 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7836 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7837 |
case 0x07: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7838 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7839 |
error_message = "invalid string: control character U+0007 (BEL) must be escaped to \\u0007"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7840 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7841 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7842 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7843 |
case 0x08: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7844 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7845 |
error_message = "invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7846 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7847 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7848 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7849 |
case 0x09: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7850 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7851 |
error_message = "invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7852 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7853 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7854 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7855 |
case 0x0A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7856 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7857 |
error_message = "invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7858 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7859 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7860 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7861 |
case 0x0B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7862 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7863 |
error_message = "invalid string: control character U+000B (VT) must be escaped to \\u000B"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7864 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7865 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7866 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7867 |
case 0x0C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7868 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7869 |
error_message = "invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7870 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7871 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7872 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7873 |
case 0x0D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7874 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7875 |
error_message = "invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7876 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7877 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7878 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7879 |
case 0x0E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7880 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7881 |
error_message = "invalid string: control character U+000E (SO) must be escaped to \\u000E"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7882 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7883 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7884 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7885 |
case 0x0F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7886 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7887 |
error_message = "invalid string: control character U+000F (SI) must be escaped to \\u000F"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7888 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7889 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7890 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7891 |
case 0x10: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7892 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7893 |
error_message = "invalid string: control character U+0010 (DLE) must be escaped to \\u0010"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7894 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7895 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7896 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7897 |
case 0x11: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7898 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7899 |
error_message = "invalid string: control character U+0011 (DC1) must be escaped to \\u0011"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7900 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7901 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7902 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7903 |
case 0x12: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7904 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7905 |
error_message = "invalid string: control character U+0012 (DC2) must be escaped to \\u0012"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7906 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7907 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7908 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7909 |
case 0x13: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7910 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7911 |
error_message = "invalid string: control character U+0013 (DC3) must be escaped to \\u0013"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7912 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7913 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7914 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7915 |
case 0x14: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7916 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7917 |
error_message = "invalid string: control character U+0014 (DC4) must be escaped to \\u0014"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7918 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7919 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7920 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7921 |
case 0x15: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7922 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7923 |
error_message = "invalid string: control character U+0015 (NAK) must be escaped to \\u0015"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7924 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7925 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7926 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7927 |
case 0x16: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7928 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7929 |
error_message = "invalid string: control character U+0016 (SYN) must be escaped to \\u0016"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7930 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7931 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7932 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7933 |
case 0x17: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7934 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7935 |
error_message = "invalid string: control character U+0017 (ETB) must be escaped to \\u0017"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7936 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7937 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7938 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7939 |
case 0x18: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7940 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7941 |
error_message = "invalid string: control character U+0018 (CAN) must be escaped to \\u0018"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7942 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7943 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7944 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7945 |
case 0x19: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7946 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7947 |
error_message = "invalid string: control character U+0019 (EM) must be escaped to \\u0019"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7948 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7949 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7950 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7951 |
case 0x1A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7952 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7953 |
error_message = "invalid string: control character U+001A (SUB) must be escaped to \\u001A"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7954 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7955 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7956 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7957 |
case 0x1B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7958 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7959 |
error_message = "invalid string: control character U+001B (ESC) must be escaped to \\u001B"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7960 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7961 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7962 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7963 |
case 0x1C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7964 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7965 |
error_message = "invalid string: control character U+001C (FS) must be escaped to \\u001C"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7966 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7967 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7968 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7969 |
case 0x1D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7970 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7971 |
error_message = "invalid string: control character U+001D (GS) must be escaped to \\u001D"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7972 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7973 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7974 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7975 |
case 0x1E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7976 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7977 |
error_message = "invalid string: control character U+001E (RS) must be escaped to \\u001E"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7978 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7979 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7980 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7981 |
case 0x1F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7982 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7983 |
error_message = "invalid string: control character U+001F (US) must be escaped to \\u001F"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7984 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7985 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7986 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7987 |
// U+0020..U+007F (except U+0022 (quote) and U+005C (backspace)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7988 |
case 0x20: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7989 |
case 0x21: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7990 |
case 0x23: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7991 |
case 0x24: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7992 |
case 0x25: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7993 |
case 0x26: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7994 |
case 0x27: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7995 |
case 0x28: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7996 |
case 0x29: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7997 |
case 0x2A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7998 |
case 0x2B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
7999 |
case 0x2C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8000 |
case 0x2D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8001 |
case 0x2E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8002 |
case 0x2F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8003 |
case 0x30: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8004 |
case 0x31: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8005 |
case 0x32: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8006 |
case 0x33: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8007 |
case 0x34: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8008 |
case 0x35: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8009 |
case 0x36: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8010 |
case 0x37: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8011 |
case 0x38: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8012 |
case 0x39: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8013 |
case 0x3A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8014 |
case 0x3B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8015 |
case 0x3C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8016 |
case 0x3D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8017 |
case 0x3E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8018 |
case 0x3F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8019 |
case 0x40: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8020 |
case 0x41: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8021 |
case 0x42: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8022 |
case 0x43: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8023 |
case 0x44: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8024 |
case 0x45: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8025 |
case 0x46: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8026 |
case 0x47: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8027 |
case 0x48: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8028 |
case 0x49: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8029 |
case 0x4A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8030 |
case 0x4B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8031 |
case 0x4C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8032 |
case 0x4D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8033 |
case 0x4E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8034 |
case 0x4F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8035 |
case 0x50: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8036 |
case 0x51: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8037 |
case 0x52: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8038 |
case 0x53: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8039 |
case 0x54: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8040 |
case 0x55: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8041 |
case 0x56: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8042 |
case 0x57: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8043 |
case 0x58: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8044 |
case 0x59: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8045 |
case 0x5A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8046 |
case 0x5B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8047 |
case 0x5D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8048 |
case 0x5E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8049 |
case 0x5F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8050 |
case 0x60: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8051 |
case 0x61: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8052 |
case 0x62: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8053 |
case 0x63: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8054 |
case 0x64: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8055 |
case 0x65: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8056 |
case 0x66: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8057 |
case 0x67: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8058 |
case 0x68: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8059 |
case 0x69: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8060 |
case 0x6A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8061 |
case 0x6B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8062 |
case 0x6C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8063 |
case 0x6D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8064 |
case 0x6E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8065 |
case 0x6F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8066 |
case 0x70: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8067 |
case 0x71: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8068 |
case 0x72: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8069 |
case 0x73: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8070 |
case 0x74: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8071 |
case 0x75: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8072 |
case 0x76: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8073 |
case 0x77: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8074 |
case 0x78: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8075 |
case 0x79: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8076 |
case 0x7A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8077 |
case 0x7B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8078 |
case 0x7C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8079 |
case 0x7D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8080 |
case 0x7E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8081 |
case 0x7F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8082 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8083 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8084 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8085 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8086 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8087 |
// U+0080..U+07FF: bytes C2..DF 80..BF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8088 |
case 0xC2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8089 |
case 0xC3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8090 |
case 0xC4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8091 |
case 0xC5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8092 |
case 0xC6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8093 |
case 0xC7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8094 |
case 0xC8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8095 |
case 0xC9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8096 |
case 0xCA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8097 |
case 0xCB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8098 |
case 0xCC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8099 |
case 0xCD: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8100 |
case 0xCE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8101 |
case 0xCF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8102 |
case 0xD0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8103 |
case 0xD1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8104 |
case 0xD2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8105 |
case 0xD3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8106 |
case 0xD4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8107 |
case 0xD5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8108 |
case 0xD6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8109 |
case 0xD7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8110 |
case 0xD8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8111 |
case 0xD9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8112 |
case 0xDA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8113 |
case 0xDB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8114 |
case 0xDC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8115 |
case 0xDD: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8116 |
case 0xDE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8117 |
case 0xDF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8118 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8119 |
if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF}))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8120 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8121 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8122 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8123 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8124 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8125 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8126 |
// U+0800..U+0FFF: bytes E0 A0..BF 80..BF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8127 |
case 0xE0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8128 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8129 |
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF})))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8130 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8131 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8132 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8133 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8134 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8135 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8136 |
// U+1000..U+CFFF: bytes E1..EC 80..BF 80..BF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8137 |
// U+E000..U+FFFF: bytes EE..EF 80..BF 80..BF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8138 |
case 0xE1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8139 |
case 0xE2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8140 |
case 0xE3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8141 |
case 0xE4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8142 |
case 0xE5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8143 |
case 0xE6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8144 |
case 0xE7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8145 |
case 0xE8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8146 |
case 0xE9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8147 |
case 0xEA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8148 |
case 0xEB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8149 |
case 0xEC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8150 |
case 0xEE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8151 |
case 0xEF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8152 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8153 |
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF})))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8154 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8155 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8156 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8157 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8158 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8159 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8160 |
// U+D000..U+D7FF: bytes ED 80..9F 80..BF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8161 |
case 0xED: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8162 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8163 |
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF})))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8164 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8165 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8166 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8167 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8168 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8169 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8170 |
// U+10000..U+3FFFF F0 90..BF 80..BF 80..BF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8171 |
case 0xF0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8172 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8173 |
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF})))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8174 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8175 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8176 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8177 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8178 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8179 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8180 |
// U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8181 |
case 0xF1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8182 |
case 0xF2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8183 |
case 0xF3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8184 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8185 |
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF})))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8186 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8187 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8188 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8189 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8190 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8191 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8192 |
// U+100000..U+10FFFF F4 80..8F 80..BF 80..BF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8193 |
case 0xF4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8194 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8195 |
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF})))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8196 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8197 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8198 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8199 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8200 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8201 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8202 |
// remaining bytes (80..C1 and F5..FF) are ill-formed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8203 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8204 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8205 |
error_message = "invalid string: ill-formed UTF-8 byte"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8206 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8207 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8208 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8209 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8210 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8211 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8212 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8213 |
* @brief scan a comment |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8214 |
* @return whether comment could be scanned successfully |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8215 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8216 |
bool scan_comment() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8217 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8218 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8219 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8220 |
// single-line comments skip input until a newline or EOF is read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8221 |
case '/': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8222 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8223 |
while (true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8224 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8225 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8226 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8227 |
case '\n': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8228 |
case '\r': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8229 |
case char_traits<char_type>::eof(): |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8230 |
case '\0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8231 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8232 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8233 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8234 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8235 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8236 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8237 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8238 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8239 |
// multi-line comments skip input until */ is read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8240 |
case '*': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8241 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8242 |
while (true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8243 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8244 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8245 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8246 |
case char_traits<char_type>::eof(): |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8247 |
case '\0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8248 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8249 |
error_message = "invalid comment; missing closing '*/'"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8250 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8251 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8252 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8253 |
case '*': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8254 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8255 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8256 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8257 |
case '/': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8258 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8259 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8260 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8261 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8262 |
unget(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8263 |
continue; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8264 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8265 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8266 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8267 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8268 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8269 |
continue; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8270 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8271 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8272 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8273 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8274 |
// unexpected character after reading '/' |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8275 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8276 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8277 |
error_message = "invalid comment; expecting '/' or '*' after '/'"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8278 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8279 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8280 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8281 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8282 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8283 |
JSON_HEDLEY_NON_NULL(2) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8284 |
static void strtof(float& f, const char* str, char** endptr) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8285 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8286 |
f = std::strtof(str, endptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8287 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8288 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8289 |
JSON_HEDLEY_NON_NULL(2) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8290 |
static void strtof(double& f, const char* str, char** endptr) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8291 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8292 |
f = std::strtod(str, endptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8293 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8294 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8295 |
JSON_HEDLEY_NON_NULL(2) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8296 |
static void strtof(long double& f, const char* str, char** endptr) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8297 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8298 |
f = std::strtold(str, endptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8299 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8300 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8301 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8302 |
@brief scan a number literal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8303 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8304 |
This function scans a string according to Sect. 6 of RFC 8259. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8305 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8306 |
The function is realized with a deterministic finite state machine derived |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8307 |
from the grammar described in RFC 8259. Starting in state "init", the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8308 |
input is read and used to determined the next state. Only state "done" |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8309 |
accepts the number. State "error" is a trap state to model errors. In the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8310 |
table below, "anything" means any character but the ones listed before. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8311 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8312 |
state | 0 | 1-9 | e E | + | - | . | anything |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8313 |
---------|----------|----------|----------|---------|---------|----------|----------- |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8314 |
init | zero | any1 | [error] | [error] | minus | [error] | [error] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8315 |
minus | zero | any1 | [error] | [error] | [error] | [error] | [error] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8316 |
zero | done | done | exponent | done | done | decimal1 | done |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8317 |
any1 | any1 | any1 | exponent | done | done | decimal1 | done |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8318 |
decimal1 | decimal2 | decimal2 | [error] | [error] | [error] | [error] | [error] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8319 |
decimal2 | decimal2 | decimal2 | exponent | done | done | done | done |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8320 |
exponent | any2 | any2 | [error] | sign | sign | [error] | [error] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8321 |
sign | any2 | any2 | [error] | [error] | [error] | [error] | [error] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8322 |
any2 | any2 | any2 | done | done | done | done | done |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8323 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8324 |
The state machine is realized with one label per state (prefixed with |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8325 |
"scan_number_") and `goto` statements between them. The state machine |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8326 |
contains cycles, but any cycle can be left when EOF is read. Therefore, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8327 |
the function is guaranteed to terminate. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8328 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8329 |
During scanning, the read bytes are stored in token_buffer. This string is |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8330 |
then converted to a signed integer, an unsigned integer, or a |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8331 |
floating-point number. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8332 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8333 |
@return token_type::value_unsigned, token_type::value_integer, or |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8334 |
token_type::value_float if number could be successfully scanned, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8335 |
token_type::parse_error otherwise |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8336 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8337 |
@note The scanner is independent of the current locale. Internally, the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8338 |
locale's decimal point is used instead of `.` to work with the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8339 |
locale-dependent converters. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8340 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8341 |
token_type scan_number() // lgtm [cpp/use-of-goto] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8342 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8343 |
// reset token_buffer to store the number's bytes |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8344 |
reset(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8345 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8346 |
// the type of the parsed number; initially set to unsigned; will be |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8347 |
// changed if minus sign, decimal point or exponent is read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8348 |
token_type number_type = token_type::value_unsigned; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8349 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8350 |
// state (init): we just found out we need to scan a number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8351 |
switch (current) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8352 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8353 |
case '-': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8354 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8355 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8356 |
goto scan_number_minus; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8357 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8358 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8359 |
case '0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8360 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8361 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8362 |
goto scan_number_zero; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8363 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8364 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8365 |
case '1': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8366 |
case '2': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8367 |
case '3': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8368 |
case '4': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8369 |
case '5': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8370 |
case '6': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8371 |
case '7': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8372 |
case '8': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8373 |
case '9': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8374 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8375 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8376 |
goto scan_number_any1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8377 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8378 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8379 |
// all other characters are rejected outside scan_number() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8380 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8381 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8382 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8383 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8384 |
scan_number_minus: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8385 |
// state: we just parsed a leading minus sign |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8386 |
number_type = token_type::value_integer; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8387 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8388 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8389 |
case '0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8390 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8391 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8392 |
goto scan_number_zero; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8393 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8394 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8395 |
case '1': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8396 |
case '2': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8397 |
case '3': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8398 |
case '4': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8399 |
case '5': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8400 |
case '6': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8401 |
case '7': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8402 |
case '8': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8403 |
case '9': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8404 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8405 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8406 |
goto scan_number_any1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8407 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8408 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8409 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8410 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8411 |
error_message = "invalid number; expected digit after '-'"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8412 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8413 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8414 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8415 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8416 |
scan_number_zero: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8417 |
// state: we just parse a zero (maybe with a leading minus sign) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8418 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8419 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8420 |
case '.': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8421 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8422 |
add(decimal_point_char); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8423 |
goto scan_number_decimal1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8424 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8425 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8426 |
case 'e': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8427 |
case 'E': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8428 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8429 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8430 |
goto scan_number_exponent; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8431 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8432 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8433 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8434 |
goto scan_number_done; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8435 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8436 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8437 |
scan_number_any1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8438 |
// state: we just parsed a number 0-9 (maybe with a leading minus sign) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8439 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8440 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8441 |
case '0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8442 |
case '1': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8443 |
case '2': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8444 |
case '3': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8445 |
case '4': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8446 |
case '5': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8447 |
case '6': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8448 |
case '7': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8449 |
case '8': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8450 |
case '9': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8451 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8452 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8453 |
goto scan_number_any1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8454 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8455 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8456 |
case '.': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8457 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8458 |
add(decimal_point_char); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8459 |
goto scan_number_decimal1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8460 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8461 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8462 |
case 'e': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8463 |
case 'E': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8464 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8465 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8466 |
goto scan_number_exponent; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8467 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8468 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8469 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8470 |
goto scan_number_done; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8471 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8472 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8473 |
scan_number_decimal1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8474 |
// state: we just parsed a decimal point |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8475 |
number_type = token_type::value_float; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8476 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8477 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8478 |
case '0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8479 |
case '1': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8480 |
case '2': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8481 |
case '3': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8482 |
case '4': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8483 |
case '5': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8484 |
case '6': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8485 |
case '7': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8486 |
case '8': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8487 |
case '9': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8488 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8489 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8490 |
goto scan_number_decimal2; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8491 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8492 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8493 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8494 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8495 |
error_message = "invalid number; expected digit after '.'"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8496 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8497 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8498 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8499 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8500 |
scan_number_decimal2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8501 |
// we just parsed at least one number after a decimal point |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8502 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8503 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8504 |
case '0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8505 |
case '1': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8506 |
case '2': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8507 |
case '3': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8508 |
case '4': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8509 |
case '5': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8510 |
case '6': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8511 |
case '7': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8512 |
case '8': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8513 |
case '9': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8514 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8515 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8516 |
goto scan_number_decimal2; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8517 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8518 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8519 |
case 'e': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8520 |
case 'E': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8521 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8522 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8523 |
goto scan_number_exponent; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8524 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8525 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8526 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8527 |
goto scan_number_done; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8528 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8529 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8530 |
scan_number_exponent: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8531 |
// we just parsed an exponent |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8532 |
number_type = token_type::value_float; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8533 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8534 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8535 |
case '+': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8536 |
case '-': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8537 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8538 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8539 |
goto scan_number_sign; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8540 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8541 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8542 |
case '0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8543 |
case '1': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8544 |
case '2': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8545 |
case '3': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8546 |
case '4': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8547 |
case '5': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8548 |
case '6': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8549 |
case '7': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8550 |
case '8': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8551 |
case '9': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8552 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8553 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8554 |
goto scan_number_any2; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8555 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8556 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8557 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8558 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8559 |
error_message = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8560 |
"invalid number; expected '+', '-', or digit after exponent"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8561 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8562 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8563 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8564 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8565 |
scan_number_sign: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8566 |
// we just parsed an exponent sign |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8567 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8568 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8569 |
case '0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8570 |
case '1': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8571 |
case '2': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8572 |
case '3': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8573 |
case '4': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8574 |
case '5': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8575 |
case '6': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8576 |
case '7': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8577 |
case '8': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8578 |
case '9': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8579 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8580 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8581 |
goto scan_number_any2; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8582 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8583 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8584 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8585 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8586 |
error_message = "invalid number; expected digit after exponent sign"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8587 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8588 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8589 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8590 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8591 |
scan_number_any2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8592 |
// we just parsed a number after the exponent or exponent sign |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8593 |
switch (get()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8594 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8595 |
case '0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8596 |
case '1': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8597 |
case '2': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8598 |
case '3': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8599 |
case '4': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8600 |
case '5': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8601 |
case '6': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8602 |
case '7': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8603 |
case '8': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8604 |
case '9': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8605 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8606 |
add(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8607 |
goto scan_number_any2; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8608 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8609 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8610 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8611 |
goto scan_number_done; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8612 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8613 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8614 |
scan_number_done: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8615 |
// unget the character after the number (we only read it to know that |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8616 |
// we are done scanning a number) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8617 |
unget(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8618 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8619 |
char* endptr = nullptr; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8620 |
errno = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8621 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8622 |
// try to parse integers first and fall back to floats |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8623 |
if (number_type == token_type::value_unsigned) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8624 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8625 |
const auto x = std::strtoull(token_buffer.data(), &endptr, 10); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8626 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8627 |
// we checked the number format before |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8628 |
JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8629 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8630 |
if (errno == 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8631 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8632 |
value_unsigned = static_cast<number_unsigned_t>(x); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8633 |
if (value_unsigned == x) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8634 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8635 |
return token_type::value_unsigned; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8636 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8637 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8638 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8639 |
else if (number_type == token_type::value_integer) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8640 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8641 |
const auto x = std::strtoll(token_buffer.data(), &endptr, 10); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8642 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8643 |
// we checked the number format before |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8644 |
JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8645 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8646 |
if (errno == 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8647 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8648 |
value_integer = static_cast<number_integer_t>(x); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8649 |
if (value_integer == x) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8650 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8651 |
return token_type::value_integer; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8652 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8653 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8654 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8655 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8656 |
// this code is reached if we parse a floating-point number or if an |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8657 |
// integer conversion above failed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8658 |
strtof(value_float, token_buffer.data(), &endptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8659 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8660 |
// we checked the number format before |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8661 |
JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8662 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8663 |
return token_type::value_float; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8664 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8665 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8666 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8667 |
@param[in] literal_text the literal text to expect |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8668 |
@param[in] length the length of the passed literal text |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8669 |
@param[in] return_type the token type to return on success |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8670 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8671 |
JSON_HEDLEY_NON_NULL(2) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8672 |
token_type scan_literal(const char_type* literal_text, const std::size_t length, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8673 |
token_type return_type) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8674 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8675 |
JSON_ASSERT(char_traits<char_type>::to_char_type(current) == literal_text[0]); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8676 |
for (std::size_t i = 1; i < length; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8677 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8678 |
if (JSON_HEDLEY_UNLIKELY(char_traits<char_type>::to_char_type(get()) != literal_text[i])) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8679 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8680 |
error_message = "invalid literal"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8681 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8682 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8683 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8684 |
return return_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8685 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8686 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8687 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8688 |
// input management |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8689 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8690 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8691 |
/// reset token_buffer; current character is beginning of token |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8692 |
void reset() noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8693 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8694 |
token_buffer.clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8695 |
token_string.clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8696 |
token_string.push_back(char_traits<char_type>::to_char_type(current)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8697 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8698 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8699 |
/* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8700 |
@brief get next character from the input |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8701 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8702 |
This function provides the interface to the used input adapter. It does |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8703 |
not throw in case the input reached EOF, but returns a |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8704 |
`char_traits<char>::eof()` in that case. Stores the scanned characters |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8705 |
for use in error messages. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8706 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8707 |
@return character read from the input |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8708 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8709 |
char_int_type get() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8710 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8711 |
++position.chars_read_total; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8712 |
++position.chars_read_current_line; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8713 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8714 |
if (next_unget) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8715 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8716 |
// just reset the next_unget variable and work with current |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8717 |
next_unget = false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8718 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8719 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8720 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8721 |
current = ia.get_character(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8722 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8723 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8724 |
if (JSON_HEDLEY_LIKELY(current != char_traits<char_type>::eof())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8725 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8726 |
token_string.push_back(char_traits<char_type>::to_char_type(current)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8727 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8728 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8729 |
if (current == '\n') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8730 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8731 |
++position.lines_read; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8732 |
position.chars_read_current_line = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8733 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8734 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8735 |
return current; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8736 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8737 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8738 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8739 |
@brief unget current character (read it again on next get) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8740 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8741 |
We implement unget by setting variable next_unget to true. The input is not |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8742 |
changed - we just simulate ungetting by modifying chars_read_total, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8743 |
chars_read_current_line, and token_string. The next call to get() will |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8744 |
behave as if the unget character is read again. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8745 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8746 |
void unget() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8747 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8748 |
next_unget = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8749 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8750 |
--position.chars_read_total; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8751 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8752 |
// in case we "unget" a newline, we have to also decrement the lines_read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8753 |
if (position.chars_read_current_line == 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8754 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8755 |
if (position.lines_read > 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8756 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8757 |
--position.lines_read; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8758 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8759 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8760 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8761 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8762 |
--position.chars_read_current_line; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8763 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8764 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8765 |
if (JSON_HEDLEY_LIKELY(current != char_traits<char_type>::eof())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8766 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8767 |
JSON_ASSERT(!token_string.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8768 |
token_string.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8769 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8770 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8771 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8772 |
/// add a character to token_buffer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8773 |
void add(char_int_type c) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8774 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8775 |
token_buffer.push_back(static_cast<typename string_t::value_type>(c)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8776 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8777 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8778 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8779 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8780 |
// value getters |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8781 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8782 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8783 |
/// return integer value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8784 |
constexpr number_integer_t get_number_integer() const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8785 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8786 |
return value_integer; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8787 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8788 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8789 |
/// return unsigned integer value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8790 |
constexpr number_unsigned_t get_number_unsigned() const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8791 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8792 |
return value_unsigned; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8793 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8794 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8795 |
/// return floating-point value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8796 |
constexpr number_float_t get_number_float() const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8797 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8798 |
return value_float; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8799 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8800 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8801 |
/// return current string value (implicitly resets the token; useful only once) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8802 |
string_t& get_string() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8803 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8804 |
return token_buffer; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8805 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8806 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8807 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8808 |
// diagnostics |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8809 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8810 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8811 |
/// return position of last read token |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8812 |
constexpr position_t get_position() const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8813 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8814 |
return position; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8815 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8816 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8817 |
/// return the last read token (for errors only). Will never contain EOF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8818 |
/// (an arbitrary value that is not a valid char value, often -1), because |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8819 |
/// 255 may legitimately occur. May contain NUL, which should be escaped. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8820 |
std::string get_token_string() const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8821 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8822 |
// escape control characters |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8823 |
std::string result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8824 |
for (const auto c : token_string) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8825 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8826 |
if (static_cast<unsigned char>(c) <= '\x1F') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8827 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8828 |
// escape control characters |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8829 |
std::array<char, 9> cs{{}}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8830 |
static_cast<void>((std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8831 |
result += cs.data(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8832 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8833 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8834 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8835 |
// add character as is |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8836 |
result.push_back(static_cast<std::string::value_type>(c)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8837 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8838 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8839 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8840 |
return result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8841 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8842 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8843 |
/// return syntax error message |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8844 |
JSON_HEDLEY_RETURNS_NON_NULL |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8845 |
constexpr const char* get_error_message() const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8846 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8847 |
return error_message; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8848 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8849 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8850 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8851 |
// actual scanner |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8852 |
///////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8853 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8854 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8855 |
@brief skip the UTF-8 byte order mark |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8856 |
@return true iff there is no BOM or the correct BOM has been skipped |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8857 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8858 |
bool skip_bom() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8859 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8860 |
if (get() == 0xEF) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8861 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8862 |
// check if we completely parse the BOM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8863 |
return get() == 0xBB && get() == 0xBF; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8864 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8865 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8866 |
// the first character is not the beginning of the BOM; unget it to |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8867 |
// process is later |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8868 |
unget(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8869 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8870 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8871 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8872 |
void skip_whitespace() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8873 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8874 |
do |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8875 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8876 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8877 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8878 |
while (current == ' ' || current == '\t' || current == '\n' || current == '\r'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8879 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8880 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8881 |
token_type scan() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8882 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8883 |
// initially, skip the BOM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8884 |
if (position.chars_read_total == 0 && !skip_bom()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8885 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8886 |
error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8887 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8888 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8889 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8890 |
// read next character and ignore whitespace |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8891 |
skip_whitespace(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8892 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8893 |
// ignore comments |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8894 |
while (ignore_comments && current == '/') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8895 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8896 |
if (!scan_comment()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8897 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8898 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8899 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8900 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8901 |
// skip following whitespace |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8902 |
skip_whitespace(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8903 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8904 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8905 |
switch (current) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8906 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8907 |
// structural characters |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8908 |
case '[': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8909 |
return token_type::begin_array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8910 |
case ']': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8911 |
return token_type::end_array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8912 |
case '{': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8913 |
return token_type::begin_object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8914 |
case '}': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8915 |
return token_type::end_object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8916 |
case ':': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8917 |
return token_type::name_separator; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8918 |
case ',': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8919 |
return token_type::value_separator; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8920 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8921 |
// literals |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8922 |
case 't': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8923 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8924 |
std::array<char_type, 4> true_literal = {{static_cast<char_type>('t'), static_cast<char_type>('r'), static_cast<char_type>('u'), static_cast<char_type>('e')}}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8925 |
return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8926 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8927 |
case 'f': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8928 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8929 |
std::array<char_type, 5> false_literal = {{static_cast<char_type>('f'), static_cast<char_type>('a'), static_cast<char_type>('l'), static_cast<char_type>('s'), static_cast<char_type>('e')}}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8930 |
return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8931 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8932 |
case 'n': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8933 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8934 |
std::array<char_type, 4> null_literal = {{static_cast<char_type>('n'), static_cast<char_type>('u'), static_cast<char_type>('l'), static_cast<char_type>('l')}}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8935 |
return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8936 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8937 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8938 |
// string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8939 |
case '\"': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8940 |
return scan_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8941 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8942 |
// number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8943 |
case '-': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8944 |
case '0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8945 |
case '1': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8946 |
case '2': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8947 |
case '3': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8948 |
case '4': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8949 |
case '5': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8950 |
case '6': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8951 |
case '7': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8952 |
case '8': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8953 |
case '9': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8954 |
return scan_number(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8955 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8956 |
// end of input (the null byte is needed when parsing from |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8957 |
// string literals) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8958 |
case '\0': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8959 |
case char_traits<char_type>::eof(): |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8960 |
return token_type::end_of_input; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8961 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8962 |
// error |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8963 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8964 |
error_message = "invalid literal"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8965 |
return token_type::parse_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8966 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8967 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8968 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8969 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8970 |
/// input adapter |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8971 |
InputAdapterType ia; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8972 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8973 |
/// whether comments should be ignored (true) or signaled as errors (false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8974 |
const bool ignore_comments = false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8975 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8976 |
/// the current character |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8977 |
char_int_type current = char_traits<char_type>::eof(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
8978 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8979 |
/// whether the next get() call should just return current |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8980 |
bool next_unget = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
8981 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8982 |
/// the start position of the current token |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8983 |
position_t position {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
8984 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8985 |
/// raw input token string (for error messages) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8986 |
std::vector<char_type> token_string {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8987 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8988 |
/// buffer for variable-length tokens (numbers, strings) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8989 |
string_t token_buffer {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8990 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8991 |
/// a description of occurred lexer errors |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8992 |
const char* error_message = ""; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8993 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8994 |
// number values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8995 |
number_integer_t value_integer = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8996 |
number_unsigned_t value_unsigned = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8997 |
number_float_t value_float = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8998 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
8999 |
/// the decimal point |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9000 |
const char_int_type decimal_point_char = '.'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9001 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9002 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9003 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9004 |
NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9005 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9006 |
// #include <nlohmann/detail/macro_scope.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9007 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9008 |
// #include <nlohmann/detail/meta/is_sax.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9009 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9010 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9011 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9012 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9013 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9014 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9015 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9016 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9017 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9018 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9019 |
#include <cstdint> // size_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9020 |
#include <utility> // declval |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9021 |
#include <string> // string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9022 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9023 |
// #include <nlohmann/detail/abi_macros.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9024 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9025 |
// #include <nlohmann/detail/meta/detected.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9026 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9027 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9028 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9029 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9030 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9031 |
namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9032 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9033 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9034 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9035 |
using null_function_t = decltype(std::declval<T&>().null()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9036 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9037 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9038 |
using boolean_function_t = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9039 |
decltype(std::declval<T&>().boolean(std::declval<bool>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9040 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9041 |
template<typename T, typename Integer> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9042 |
using number_integer_function_t = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9043 |
decltype(std::declval<T&>().number_integer(std::declval<Integer>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9044 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9045 |
template<typename T, typename Unsigned> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9046 |
using number_unsigned_function_t = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9047 |
decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9048 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9049 |
template<typename T, typename Float, typename String> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9050 |
using number_float_function_t = decltype(std::declval<T&>().number_float( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9051 |
std::declval<Float>(), std::declval<const String&>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9052 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9053 |
template<typename T, typename String> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9054 |
using string_function_t = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9055 |
decltype(std::declval<T&>().string(std::declval<String&>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9056 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9057 |
template<typename T, typename Binary> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9058 |
using binary_function_t = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9059 |
decltype(std::declval<T&>().binary(std::declval<Binary&>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9060 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9061 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9062 |
using start_object_function_t = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9063 |
decltype(std::declval<T&>().start_object(std::declval<std::size_t>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9064 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9065 |
template<typename T, typename String> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9066 |
using key_function_t = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9067 |
decltype(std::declval<T&>().key(std::declval<String&>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9068 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9069 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9070 |
using end_object_function_t = decltype(std::declval<T&>().end_object()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9071 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9072 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9073 |
using start_array_function_t = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9074 |
decltype(std::declval<T&>().start_array(std::declval<std::size_t>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9075 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9076 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9077 |
using end_array_function_t = decltype(std::declval<T&>().end_array()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9078 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9079 |
template<typename T, typename Exception> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9080 |
using parse_error_function_t = decltype(std::declval<T&>().parse_error( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9081 |
std::declval<std::size_t>(), std::declval<const std::string&>(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9082 |
std::declval<const Exception&>())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9083 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9084 |
template<typename SAX, typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9085 |
struct is_sax |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9086 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9087 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9088 |
static_assert(is_basic_json<BasicJsonType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9089 |
"BasicJsonType must be of type basic_json<...>"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9090 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9091 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9092 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9093 |
using number_float_t = typename BasicJsonType::number_float_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9094 |
using string_t = typename BasicJsonType::string_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9095 |
using binary_t = typename BasicJsonType::binary_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9096 |
using exception_t = typename BasicJsonType::exception; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9097 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9098 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9099 |
static constexpr bool value = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9100 |
is_detected_exact<bool, null_function_t, SAX>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9101 |
is_detected_exact<bool, boolean_function_t, SAX>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9102 |
is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9103 |
is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9104 |
is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9105 |
is_detected_exact<bool, string_function_t, SAX, string_t>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9106 |
is_detected_exact<bool, binary_function_t, SAX, binary_t>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9107 |
is_detected_exact<bool, start_object_function_t, SAX>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9108 |
is_detected_exact<bool, key_function_t, SAX, string_t>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9109 |
is_detected_exact<bool, end_object_function_t, SAX>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9110 |
is_detected_exact<bool, start_array_function_t, SAX>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9111 |
is_detected_exact<bool, end_array_function_t, SAX>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9112 |
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9113 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9114 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9115 |
template<typename SAX, typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9116 |
struct is_sax_static_asserts |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9117 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9118 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9119 |
static_assert(is_basic_json<BasicJsonType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9120 |
"BasicJsonType must be of type basic_json<...>"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9121 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9122 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9123 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9124 |
using number_float_t = typename BasicJsonType::number_float_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9125 |
using string_t = typename BasicJsonType::string_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9126 |
using binary_t = typename BasicJsonType::binary_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9127 |
using exception_t = typename BasicJsonType::exception; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9128 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9129 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9130 |
static_assert(is_detected_exact<bool, null_function_t, SAX>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9131 |
"Missing/invalid function: bool null()"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9132 |
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9133 |
"Missing/invalid function: bool boolean(bool)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9134 |
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9135 |
"Missing/invalid function: bool boolean(bool)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9136 |
static_assert( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9137 |
is_detected_exact<bool, number_integer_function_t, SAX, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9138 |
number_integer_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9139 |
"Missing/invalid function: bool number_integer(number_integer_t)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9140 |
static_assert( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9141 |
is_detected_exact<bool, number_unsigned_function_t, SAX, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9142 |
number_unsigned_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9143 |
"Missing/invalid function: bool number_unsigned(number_unsigned_t)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9144 |
static_assert(is_detected_exact<bool, number_float_function_t, SAX, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9145 |
number_float_t, string_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9146 |
"Missing/invalid function: bool number_float(number_float_t, const string_t&)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9147 |
static_assert( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9148 |
is_detected_exact<bool, string_function_t, SAX, string_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9149 |
"Missing/invalid function: bool string(string_t&)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9150 |
static_assert( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9151 |
is_detected_exact<bool, binary_function_t, SAX, binary_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9152 |
"Missing/invalid function: bool binary(binary_t&)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9153 |
static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9154 |
"Missing/invalid function: bool start_object(std::size_t)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9155 |
static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9156 |
"Missing/invalid function: bool key(string_t&)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9157 |
static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9158 |
"Missing/invalid function: bool end_object()"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9159 |
static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9160 |
"Missing/invalid function: bool start_array(std::size_t)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9161 |
static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9162 |
"Missing/invalid function: bool end_array()"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9163 |
static_assert( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9164 |
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9165 |
"Missing/invalid function: bool parse_error(std::size_t, const " |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9166 |
"std::string&, const exception&)"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9167 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9168 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9169 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9170 |
NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9171 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9172 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9173 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9174 |
// #include <nlohmann/detail/string_concat.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9175 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9176 |
// #include <nlohmann/detail/value_t.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9177 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9178 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9179 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9180 |
namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9181 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9182 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9183 |
/// how to treat CBOR tags |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9184 |
enum class cbor_tag_handler_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9185 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9186 |
error, ///< throw a parse_error exception in case of a tag |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9187 |
ignore, ///< ignore tags |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9188 |
store ///< store tags as binary type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9189 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9190 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9191 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9192 |
@brief determine system byte order |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9193 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9194 |
@return true if and only if system's byte order is little endian |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9195 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9196 |
@note from https://stackoverflow.com/a/1001328/266378 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9197 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9198 |
static inline bool little_endianness(int num = 1) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9199 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9200 |
return *reinterpret_cast<char*>(&num) == 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9201 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9202 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9203 |
/////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9204 |
// binary reader // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9205 |
/////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9206 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9207 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9208 |
@brief deserialization of CBOR, MessagePack, and UBJSON values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9209 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9210 |
template<typename BasicJsonType, typename InputAdapterType, typename SAX = json_sax_dom_parser<BasicJsonType>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9211 |
class binary_reader |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9212 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9213 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9214 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9215 |
using number_float_t = typename BasicJsonType::number_float_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9216 |
using string_t = typename BasicJsonType::string_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9217 |
using binary_t = typename BasicJsonType::binary_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9218 |
using json_sax_t = SAX; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9219 |
using char_type = typename InputAdapterType::char_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9220 |
using char_int_type = typename char_traits<char_type>::int_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9221 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9222 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9223 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9224 |
@brief create a binary reader |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9225 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9226 |
@param[in] adapter input adapter to read from |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9227 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9228 |
explicit binary_reader(InputAdapterType&& adapter, const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9229 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9230 |
(void)detail::is_sax_static_asserts<SAX, BasicJsonType> {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9231 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9232 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9233 |
// make class move-only |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9234 |
binary_reader(const binary_reader&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9235 |
binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9236 |
binary_reader& operator=(const binary_reader&) = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9237 |
binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9238 |
~binary_reader() = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9239 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9240 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9241 |
@param[in] format the binary format to parse |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9242 |
@param[in] sax_ a SAX event processor |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9243 |
@param[in] strict whether to expect the input to be consumed completed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9244 |
@param[in] tag_handler how to treat CBOR tags |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9245 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9246 |
@return whether parsing was successful |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9247 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9248 |
JSON_HEDLEY_NON_NULL(3) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9249 |
bool sax_parse(const input_format_t format, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9250 |
json_sax_t* sax_, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9251 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9252 |
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9253 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9254 |
sax = sax_; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9255 |
bool result = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9256 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9257 |
switch (format) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9258 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9259 |
case input_format_t::bson: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9260 |
result = parse_bson_internal(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9261 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9262 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9263 |
case input_format_t::cbor: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9264 |
result = parse_cbor_internal(true, tag_handler); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9265 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9266 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9267 |
case input_format_t::msgpack: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9268 |
result = parse_msgpack_internal(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9269 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9270 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9271 |
case input_format_t::ubjson: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9272 |
case input_format_t::bjdata: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9273 |
result = parse_ubjson_internal(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9274 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9275 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9276 |
case input_format_t::json: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9277 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9278 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9279 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9280 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9281 |
// strict mode: next byte must be EOF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9282 |
if (result && strict) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9283 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9284 |
if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9285 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9286 |
get_ignore_noop(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9287 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9288 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9289 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9290 |
get(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9291 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9292 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9293 |
if (JSON_HEDLEY_UNLIKELY(current != char_traits<char_type>::eof())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9294 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9295 |
return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9296 |
exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9297 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9298 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9299 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9300 |
return result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9301 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9302 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9303 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9304 |
////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9305 |
// BSON // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9306 |
////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9307 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9308 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9309 |
@brief Reads in a BSON-object and passes it to the SAX-parser. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9310 |
@return whether a valid BSON-value was passed to the SAX parser |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9311 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9312 |
bool parse_bson_internal() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9313 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9314 |
std::int32_t document_size{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9315 |
get_number<std::int32_t, true>(input_format_t::bson, document_size); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9316 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9317 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1)))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9318 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9319 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9320 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9321 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9322 |
if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/false))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9323 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9324 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9325 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9326 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9327 |
return sax->end_object(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9328 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9329 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9330 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9331 |
@brief Parses a C-style string from the BSON input. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9332 |
@param[in,out] result A reference to the string variable where the read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9333 |
string is to be stored. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9334 |
@return `true` if the \x00-byte indicating the end of the string was |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9335 |
encountered before the EOF; false` indicates an unexpected EOF. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9336 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9337 |
bool get_bson_cstr(string_t& result) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9338 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9339 |
auto out = std::back_inserter(result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9340 |
while (true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9341 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9342 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9343 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "cstring"))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9344 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9345 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9346 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9347 |
if (current == 0x00) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9348 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9349 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9350 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9351 |
*out++ = static_cast<typename string_t::value_type>(current); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9352 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9353 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9354 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9355 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9356 |
@brief Parses a zero-terminated string of length @a len from the BSON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9357 |
input. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9358 |
@param[in] len The length (including the zero-byte at the end) of the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9359 |
string to be read. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9360 |
@param[in,out] result A reference to the string variable where the read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9361 |
string is to be stored. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9362 |
@tparam NumberType The type of the length @a len |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9363 |
@pre len >= 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9364 |
@return `true` if the string was successfully parsed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9365 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9366 |
template<typename NumberType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9367 |
bool get_bson_string(const NumberType len, string_t& result) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9368 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9369 |
if (JSON_HEDLEY_UNLIKELY(len < 1)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9370 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9371 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9372 |
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9373 |
exception_message(input_format_t::bson, concat("string length must be at least 1, is ", std::to_string(len)), "string"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9374 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9375 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9376 |
return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != char_traits<char_type>::eof(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9377 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9378 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9379 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9380 |
@brief Parses a byte array input of length @a len from the BSON input. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9381 |
@param[in] len The length of the byte array to be read. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9382 |
@param[in,out] result A reference to the binary variable where the read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9383 |
array is to be stored. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9384 |
@tparam NumberType The type of the length @a len |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9385 |
@pre len >= 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9386 |
@return `true` if the byte array was successfully parsed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9387 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9388 |
template<typename NumberType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9389 |
bool get_bson_binary(const NumberType len, binary_t& result) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9390 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9391 |
if (JSON_HEDLEY_UNLIKELY(len < 0)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9392 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9393 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9394 |
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9395 |
exception_message(input_format_t::bson, concat("byte array length cannot be negative, is ", std::to_string(len)), "binary"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9396 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9397 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9398 |
// All BSON binary values have a subtype |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9399 |
std::uint8_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9400 |
get_number<std::uint8_t>(input_format_t::bson, subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9401 |
result.set_subtype(subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9402 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9403 |
return get_binary(input_format_t::bson, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9404 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9405 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9406 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9407 |
@brief Read a BSON document element of the given @a element_type. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9408 |
@param[in] element_type The BSON element type, c.f. http://bsonspec.org/spec.html |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9409 |
@param[in] element_type_parse_position The position in the input stream, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9410 |
where the `element_type` was read. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9411 |
@warning Not all BSON element types are supported yet. An unsupported |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9412 |
@a element_type will give rise to a parse_error.114: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9413 |
Unsupported BSON record type 0x... |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9414 |
@return whether a valid BSON-object/array was passed to the SAX parser |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9415 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9416 |
bool parse_bson_element_internal(const char_int_type element_type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9417 |
const std::size_t element_type_parse_position) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9418 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9419 |
switch (element_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9420 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9421 |
case 0x01: // double |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9422 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9423 |
double number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9424 |
return get_number<double, true>(input_format_t::bson, number) && sax->number_float(static_cast<number_float_t>(number), ""); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9425 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9426 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9427 |
case 0x02: // string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9428 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9429 |
std::int32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9430 |
string_t value; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9431 |
return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9432 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9433 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9434 |
case 0x03: // object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9435 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9436 |
return parse_bson_internal(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9437 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9438 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9439 |
case 0x04: // array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9440 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9441 |
return parse_bson_array(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9442 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9443 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9444 |
case 0x05: // binary |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9445 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9446 |
std::int32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9447 |
binary_t value; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9448 |
return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9449 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9450 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9451 |
case 0x08: // boolean |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9452 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9453 |
return sax->boolean(get() != 0); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9454 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9455 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9456 |
case 0x0A: // null |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9457 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9458 |
return sax->null(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9459 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9460 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9461 |
case 0x10: // int32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9462 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9463 |
std::int32_t value{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9464 |
return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9465 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9466 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9467 |
case 0x12: // int64 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9468 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9469 |
std::int64_t value{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9470 |
return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9471 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9472 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9473 |
default: // anything else not supported (yet) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9474 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9475 |
std::array<char, 3> cr{{}}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9476 |
static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9477 |
const std::string cr_str{cr.data()}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9478 |
return sax->parse_error(element_type_parse_position, cr_str, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9479 |
parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9480 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9481 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9482 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9483 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9484 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9485 |
@brief Read a BSON element list (as specified in the BSON-spec) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9486 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9487 |
The same binary layout is used for objects and arrays, hence it must be |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9488 |
indicated with the argument @a is_array which one is expected |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9489 |
(true --> array, false --> object). |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9490 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9491 |
@param[in] is_array Determines if the element list being read is to be |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9492 |
treated as an object (@a is_array == false), or as an |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9493 |
array (@a is_array == true). |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9494 |
@return whether a valid BSON-object/array was passed to the SAX parser |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9495 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9496 |
bool parse_bson_element_list(const bool is_array) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9497 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9498 |
string_t key; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9499 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9500 |
while (auto element_type = get()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9501 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9502 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "element list"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9503 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9504 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9505 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9506 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9507 |
const std::size_t element_type_parse_position = chars_read; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9508 |
if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9509 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9510 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9511 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9512 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9513 |
if (!is_array && !sax->key(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9514 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9515 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9516 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9517 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9518 |
if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9519 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9520 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9521 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9522 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9523 |
// get_bson_cstr only appends |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9524 |
key.clear(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9525 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9526 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9527 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9528 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9529 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9530 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9531 |
@brief Reads an array from the BSON input and passes it to the SAX-parser. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9532 |
@return whether a valid BSON-array was passed to the SAX parser |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9533 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9534 |
bool parse_bson_array() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9535 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9536 |
std::int32_t document_size{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9537 |
get_number<std::int32_t, true>(input_format_t::bson, document_size); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9538 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9539 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1)))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9540 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9541 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9542 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9543 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9544 |
if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/true))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9545 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9546 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9547 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9548 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9549 |
return sax->end_array(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9550 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9551 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9552 |
////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9553 |
// CBOR // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9554 |
////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9555 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9556 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9557 |
@param[in] get_char whether a new character should be retrieved from the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9558 |
input (true) or whether the last read character should |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9559 |
be considered instead (false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9560 |
@param[in] tag_handler how CBOR tags should be treated |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9561 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9562 |
@return whether a valid CBOR value was passed to the SAX parser |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9563 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9564 |
bool parse_cbor_internal(const bool get_char, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9565 |
const cbor_tag_handler_t tag_handler) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9566 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9567 |
switch (get_char ? get() : current) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9568 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9569 |
// EOF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9570 |
case char_traits<char_type>::eof(): |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9571 |
return unexpect_eof(input_format_t::cbor, "value"); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9572 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9573 |
// Integer 0x00..0x17 (0..23) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9574 |
case 0x00: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9575 |
case 0x01: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9576 |
case 0x02: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9577 |
case 0x03: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9578 |
case 0x04: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9579 |
case 0x05: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9580 |
case 0x06: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9581 |
case 0x07: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9582 |
case 0x08: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9583 |
case 0x09: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9584 |
case 0x0A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9585 |
case 0x0B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9586 |
case 0x0C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9587 |
case 0x0D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9588 |
case 0x0E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9589 |
case 0x0F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9590 |
case 0x10: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9591 |
case 0x11: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9592 |
case 0x12: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9593 |
case 0x13: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9594 |
case 0x14: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9595 |
case 0x15: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9596 |
case 0x16: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9597 |
case 0x17: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9598 |
return sax->number_unsigned(static_cast<number_unsigned_t>(current)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9599 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9600 |
case 0x18: // Unsigned integer (one-byte uint8_t follows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9601 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9602 |
std::uint8_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9603 |
return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9604 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9605 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9606 |
case 0x19: // Unsigned integer (two-byte uint16_t follows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9607 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9608 |
std::uint16_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9609 |
return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9610 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9611 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9612 |
case 0x1A: // Unsigned integer (four-byte uint32_t follows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9613 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9614 |
std::uint32_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9615 |
return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9616 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9617 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9618 |
case 0x1B: // Unsigned integer (eight-byte uint64_t follows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9619 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9620 |
std::uint64_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9621 |
return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9622 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9623 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9624 |
// Negative integer -1-0x00..-1-0x17 (-1..-24) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9625 |
case 0x20: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9626 |
case 0x21: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9627 |
case 0x22: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9628 |
case 0x23: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9629 |
case 0x24: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9630 |
case 0x25: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9631 |
case 0x26: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9632 |
case 0x27: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9633 |
case 0x28: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9634 |
case 0x29: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9635 |
case 0x2A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9636 |
case 0x2B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9637 |
case 0x2C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9638 |
case 0x2D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9639 |
case 0x2E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9640 |
case 0x2F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9641 |
case 0x30: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9642 |
case 0x31: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9643 |
case 0x32: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9644 |
case 0x33: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9645 |
case 0x34: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9646 |
case 0x35: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9647 |
case 0x36: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9648 |
case 0x37: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9649 |
return sax->number_integer(static_cast<std::int8_t>(0x20 - 1 - current)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9650 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9651 |
case 0x38: // Negative integer (one-byte uint8_t follows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9652 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9653 |
std::uint8_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9654 |
return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9655 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9656 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9657 |
case 0x39: // Negative integer -1-n (two-byte uint16_t follows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9658 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9659 |
std::uint16_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9660 |
return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9661 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9662 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9663 |
case 0x3A: // Negative integer -1-n (four-byte uint32_t follows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9664 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9665 |
std::uint32_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9666 |
return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9667 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9668 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9669 |
case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9670 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9671 |
std::uint64_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9672 |
return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9673 |
- static_cast<number_integer_t>(number)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9674 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9675 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9676 |
// Binary data (0x00..0x17 bytes follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9677 |
case 0x40: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9678 |
case 0x41: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9679 |
case 0x42: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9680 |
case 0x43: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9681 |
case 0x44: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9682 |
case 0x45: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9683 |
case 0x46: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9684 |
case 0x47: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9685 |
case 0x48: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9686 |
case 0x49: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9687 |
case 0x4A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9688 |
case 0x4B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9689 |
case 0x4C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9690 |
case 0x4D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9691 |
case 0x4E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9692 |
case 0x4F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9693 |
case 0x50: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9694 |
case 0x51: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9695 |
case 0x52: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9696 |
case 0x53: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9697 |
case 0x54: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9698 |
case 0x55: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9699 |
case 0x56: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9700 |
case 0x57: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9701 |
case 0x58: // Binary data (one-byte uint8_t for n follows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9702 |
case 0x59: // Binary data (two-byte uint16_t for n follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9703 |
case 0x5A: // Binary data (four-byte uint32_t for n follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9704 |
case 0x5B: // Binary data (eight-byte uint64_t for n follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9705 |
case 0x5F: // Binary data (indefinite length) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9706 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9707 |
binary_t b; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9708 |
return get_cbor_binary(b) && sax->binary(b); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9709 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9710 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9711 |
// UTF-8 string (0x00..0x17 bytes follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9712 |
case 0x60: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9713 |
case 0x61: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9714 |
case 0x62: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9715 |
case 0x63: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9716 |
case 0x64: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9717 |
case 0x65: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9718 |
case 0x66: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9719 |
case 0x67: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9720 |
case 0x68: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9721 |
case 0x69: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9722 |
case 0x6A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9723 |
case 0x6B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9724 |
case 0x6C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9725 |
case 0x6D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9726 |
case 0x6E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9727 |
case 0x6F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9728 |
case 0x70: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9729 |
case 0x71: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9730 |
case 0x72: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9731 |
case 0x73: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9732 |
case 0x74: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9733 |
case 0x75: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9734 |
case 0x76: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9735 |
case 0x77: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9736 |
case 0x78: // UTF-8 string (one-byte uint8_t for n follows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9737 |
case 0x79: // UTF-8 string (two-byte uint16_t for n follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9738 |
case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9739 |
case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9740 |
case 0x7F: // UTF-8 string (indefinite length) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9741 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9742 |
string_t s; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9743 |
return get_cbor_string(s) && sax->string(s); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9744 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9745 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9746 |
// array (0x00..0x17 data items follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9747 |
case 0x80: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9748 |
case 0x81: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9749 |
case 0x82: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9750 |
case 0x83: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9751 |
case 0x84: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9752 |
case 0x85: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9753 |
case 0x86: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9754 |
case 0x87: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9755 |
case 0x88: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9756 |
case 0x89: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9757 |
case 0x8A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9758 |
case 0x8B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9759 |
case 0x8C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9760 |
case 0x8D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9761 |
case 0x8E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9762 |
case 0x8F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9763 |
case 0x90: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9764 |
case 0x91: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9765 |
case 0x92: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9766 |
case 0x93: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9767 |
case 0x94: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9768 |
case 0x95: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9769 |
case 0x96: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9770 |
case 0x97: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9771 |
return get_cbor_array( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9772 |
conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9773 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9774 |
case 0x98: // array (one-byte uint8_t for n follows) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9775 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9776 |
std::uint8_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9777 |
return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9778 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9779 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9780 |
case 0x99: // array (two-byte uint16_t for n follow) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9781 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9782 |
std::uint16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9783 |
return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9784 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9785 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9786 |
case 0x9A: // array (four-byte uint32_t for n follow) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9787 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9788 |
std::uint32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9789 |
return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9790 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9791 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9792 |
case 0x9B: // array (eight-byte uint64_t for n follow) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9793 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9794 |
std::uint64_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9795 |
return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9796 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9797 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9798 |
case 0x9F: // array (indefinite length) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9799 |
return get_cbor_array(static_cast<std::size_t>(-1), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9800 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9801 |
// map (0x00..0x17 pairs of data items follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9802 |
case 0xA0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9803 |
case 0xA1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9804 |
case 0xA2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9805 |
case 0xA3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9806 |
case 0xA4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9807 |
case 0xA5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9808 |
case 0xA6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9809 |
case 0xA7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9810 |
case 0xA8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9811 |
case 0xA9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9812 |
case 0xAA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9813 |
case 0xAB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9814 |
case 0xAC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9815 |
case 0xAD: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9816 |
case 0xAE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9817 |
case 0xAF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9818 |
case 0xB0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9819 |
case 0xB1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9820 |
case 0xB2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9821 |
case 0xB3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9822 |
case 0xB4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9823 |
case 0xB5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9824 |
case 0xB6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9825 |
case 0xB7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9826 |
return get_cbor_object(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9827 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9828 |
case 0xB8: // map (one-byte uint8_t for n follows) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9829 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9830 |
std::uint8_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9831 |
return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9832 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9833 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9834 |
case 0xB9: // map (two-byte uint16_t for n follow) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9835 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9836 |
std::uint16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9837 |
return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9838 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9839 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9840 |
case 0xBA: // map (four-byte uint32_t for n follow) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9841 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9842 |
std::uint32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9843 |
return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9844 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9845 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9846 |
case 0xBB: // map (eight-byte uint64_t for n follow) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9847 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9848 |
std::uint64_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9849 |
return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9850 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9851 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9852 |
case 0xBF: // map (indefinite length) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9853 |
return get_cbor_object(static_cast<std::size_t>(-1), tag_handler); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9854 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9855 |
case 0xC6: // tagged item |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9856 |
case 0xC7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9857 |
case 0xC8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9858 |
case 0xC9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9859 |
case 0xCA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9860 |
case 0xCB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9861 |
case 0xCC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9862 |
case 0xCD: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9863 |
case 0xCE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9864 |
case 0xCF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9865 |
case 0xD0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9866 |
case 0xD1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9867 |
case 0xD2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9868 |
case 0xD3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9869 |
case 0xD4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9870 |
case 0xD8: // tagged item (1 bytes follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9871 |
case 0xD9: // tagged item (2 bytes follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9872 |
case 0xDA: // tagged item (4 bytes follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9873 |
case 0xDB: // tagged item (8 bytes follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9874 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9875 |
switch (tag_handler) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9876 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9877 |
case cbor_tag_handler_t::error: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9878 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9879 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9880 |
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9881 |
exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9882 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9883 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9884 |
case cbor_tag_handler_t::ignore: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9885 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9886 |
// ignore binary subtype |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9887 |
switch (current) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9888 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9889 |
case 0xD8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9890 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9891 |
std::uint8_t subtype_to_ignore{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9892 |
get_number(input_format_t::cbor, subtype_to_ignore); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9893 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9894 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9895 |
case 0xD9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9896 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9897 |
std::uint16_t subtype_to_ignore{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9898 |
get_number(input_format_t::cbor, subtype_to_ignore); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9899 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9900 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9901 |
case 0xDA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9902 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9903 |
std::uint32_t subtype_to_ignore{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9904 |
get_number(input_format_t::cbor, subtype_to_ignore); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9905 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9906 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9907 |
case 0xDB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9908 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9909 |
std::uint64_t subtype_to_ignore{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9910 |
get_number(input_format_t::cbor, subtype_to_ignore); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9911 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9912 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9913 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9914 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9915 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9916 |
return parse_cbor_internal(true, tag_handler); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9917 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9918 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9919 |
case cbor_tag_handler_t::store: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9920 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9921 |
binary_t b; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9922 |
// use binary subtype and store in binary container |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9923 |
switch (current) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9924 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9925 |
case 0xD8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9926 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9927 |
std::uint8_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9928 |
get_number(input_format_t::cbor, subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9929 |
b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9930 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9931 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9932 |
case 0xD9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9933 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9934 |
std::uint16_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9935 |
get_number(input_format_t::cbor, subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9936 |
b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9937 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9938 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9939 |
case 0xDA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9940 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9941 |
std::uint32_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9942 |
get_number(input_format_t::cbor, subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9943 |
b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9944 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9945 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9946 |
case 0xDB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9947 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9948 |
std::uint64_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9949 |
get_number(input_format_t::cbor, subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9950 |
b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9951 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9952 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9953 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9954 |
return parse_cbor_internal(true, tag_handler); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9955 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9956 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9957 |
return get_cbor_binary(b) && sax->binary(b); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9958 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9959 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9960 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9961 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9962 |
return false; // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9963 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9964 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9965 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9966 |
case 0xF4: // false |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9967 |
return sax->boolean(false); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9968 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9969 |
case 0xF5: // true |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9970 |
return sax->boolean(true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9971 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9972 |
case 0xF6: // null |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9973 |
return sax->null(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9974 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9975 |
case 0xF9: // Half-Precision Float (two-byte IEEE 754) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9976 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9977 |
const auto byte1_raw = get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9978 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9979 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9980 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9981 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9982 |
const auto byte2_raw = get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9983 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9984 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9985 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9986 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9987 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9988 |
const auto byte1 = static_cast<unsigned char>(byte1_raw); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9989 |
const auto byte2 = static_cast<unsigned char>(byte2_raw); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
9990 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9991 |
// code from RFC 7049, Appendix D, Figure 3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9992 |
// As half-precision floating-point numbers were only added |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9993 |
// to IEEE 754 in 2008, today's programming platforms often |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9994 |
// still only have limited support for them. It is very |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9995 |
// easy to include at least decoding support for them even |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9996 |
// without such support. An example of a small decoder for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9997 |
// half-precision floating-point numbers in the C language |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9998 |
// is shown in Fig. 3. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
9999 |
const auto half = static_cast<unsigned int>((byte1 << 8u) + byte2); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10000 |
const double val = [&half] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10001 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10002 |
const int exp = (half >> 10u) & 0x1Fu; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10003 |
const unsigned int mant = half & 0x3FFu; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10004 |
JSON_ASSERT(0 <= exp&& exp <= 32); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10005 |
JSON_ASSERT(mant <= 1024); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10006 |
switch (exp) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10007 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10008 |
case 0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10009 |
return std::ldexp(mant, -24); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10010 |
case 31: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10011 |
return (mant == 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10012 |
? std::numeric_limits<double>::infinity() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10013 |
: std::numeric_limits<double>::quiet_NaN(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10014 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10015 |
return std::ldexp(mant + 1024, exp - 25); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10016 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10017 |
}(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10018 |
return sax->number_float((half & 0x8000u) != 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10019 |
? static_cast<number_float_t>(-val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10020 |
: static_cast<number_float_t>(val), ""); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10021 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10022 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10023 |
case 0xFA: // Single-Precision Float (four-byte IEEE 754) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10024 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10025 |
float number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10026 |
return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), ""); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10027 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10028 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10029 |
case 0xFB: // Double-Precision Float (eight-byte IEEE 754) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10030 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10031 |
double number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10032 |
return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), ""); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10033 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10034 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10035 |
default: // anything else (0xFF is handled inside the other types) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10036 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10037 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10038 |
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10039 |
exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10040 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10041 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10042 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10043 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10044 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10045 |
@brief reads a CBOR string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10046 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10047 |
This function first reads starting bytes to determine the expected |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10048 |
string length and then copies this number of bytes into a string. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10049 |
Additionally, CBOR's strings with indefinite lengths are supported. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10050 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10051 |
@param[out] result created string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10052 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10053 |
@return whether string creation completed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10054 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10055 |
bool get_cbor_string(string_t& result) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10056 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10057 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string"))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10058 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10059 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10060 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10061 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10062 |
switch (current) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10063 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10064 |
// UTF-8 string (0x00..0x17 bytes follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10065 |
case 0x60: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10066 |
case 0x61: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10067 |
case 0x62: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10068 |
case 0x63: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10069 |
case 0x64: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10070 |
case 0x65: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10071 |
case 0x66: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10072 |
case 0x67: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10073 |
case 0x68: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10074 |
case 0x69: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10075 |
case 0x6A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10076 |
case 0x6B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10077 |
case 0x6C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10078 |
case 0x6D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10079 |
case 0x6E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10080 |
case 0x6F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10081 |
case 0x70: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10082 |
case 0x71: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10083 |
case 0x72: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10084 |
case 0x73: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10085 |
case 0x74: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10086 |
case 0x75: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10087 |
case 0x76: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10088 |
case 0x77: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10089 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10090 |
return get_string(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10091 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10092 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10093 |
case 0x78: // UTF-8 string (one-byte uint8_t for n follows) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10094 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10095 |
std::uint8_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10096 |
return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10097 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10098 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10099 |
case 0x79: // UTF-8 string (two-byte uint16_t for n follow) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10100 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10101 |
std::uint16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10102 |
return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10103 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10104 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10105 |
case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10106 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10107 |
std::uint32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10108 |
return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10109 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10110 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10111 |
case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10112 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10113 |
std::uint64_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10114 |
return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10115 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10116 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10117 |
case 0x7F: // UTF-8 string (indefinite length) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10118 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10119 |
while (get() != 0xFF) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10120 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10121 |
string_t chunk; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10122 |
if (!get_cbor_string(chunk)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10123 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10124 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10125 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10126 |
result.append(chunk); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10127 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10128 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10129 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10130 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10131 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10132 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10133 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10134 |
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10135 |
exception_message(input_format_t::cbor, concat("expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token), "string"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10136 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10137 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10138 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10139 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10140 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10141 |
@brief reads a CBOR byte array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10142 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10143 |
This function first reads starting bytes to determine the expected |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10144 |
byte array length and then copies this number of bytes into the byte array. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10145 |
Additionally, CBOR's byte arrays with indefinite lengths are supported. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10146 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10147 |
@param[out] result created byte array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10148 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10149 |
@return whether byte array creation completed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10150 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10151 |
bool get_cbor_binary(binary_t& result) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10152 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10153 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "binary"))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10154 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10155 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10156 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10157 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10158 |
switch (current) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10159 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10160 |
// Binary data (0x00..0x17 bytes follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10161 |
case 0x40: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10162 |
case 0x41: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10163 |
case 0x42: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10164 |
case 0x43: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10165 |
case 0x44: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10166 |
case 0x45: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10167 |
case 0x46: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10168 |
case 0x47: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10169 |
case 0x48: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10170 |
case 0x49: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10171 |
case 0x4A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10172 |
case 0x4B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10173 |
case 0x4C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10174 |
case 0x4D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10175 |
case 0x4E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10176 |
case 0x4F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10177 |
case 0x50: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10178 |
case 0x51: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10179 |
case 0x52: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10180 |
case 0x53: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10181 |
case 0x54: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10182 |
case 0x55: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10183 |
case 0x56: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10184 |
case 0x57: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10185 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10186 |
return get_binary(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10187 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10188 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10189 |
case 0x58: // Binary data (one-byte uint8_t for n follows) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10190 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10191 |
std::uint8_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10192 |
return get_number(input_format_t::cbor, len) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10193 |
get_binary(input_format_t::cbor, len, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10194 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10195 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10196 |
case 0x59: // Binary data (two-byte uint16_t for n follow) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10197 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10198 |
std::uint16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10199 |
return get_number(input_format_t::cbor, len) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10200 |
get_binary(input_format_t::cbor, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10201 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10202 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10203 |
case 0x5A: // Binary data (four-byte uint32_t for n follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10204 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10205 |
std::uint32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10206 |
return get_number(input_format_t::cbor, len) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10207 |
get_binary(input_format_t::cbor, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10208 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10209 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10210 |
case 0x5B: // Binary data (eight-byte uint64_t for n follow) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10211 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10212 |
std::uint64_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10213 |
return get_number(input_format_t::cbor, len) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10214 |
get_binary(input_format_t::cbor, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10215 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10216 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10217 |
case 0x5F: // Binary data (indefinite length) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10218 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10219 |
while (get() != 0xFF) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10220 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10221 |
binary_t chunk; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10222 |
if (!get_cbor_binary(chunk)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10223 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10224 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10225 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10226 |
result.insert(result.end(), chunk.begin(), chunk.end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10227 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10228 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10229 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10230 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10231 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10232 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10233 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10234 |
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10235 |
exception_message(input_format_t::cbor, concat("expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token), "binary"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10236 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10237 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10238 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10239 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10240 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10241 |
@param[in] len the length of the array or static_cast<std::size_t>(-1) for an |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10242 |
array of indefinite size |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10243 |
@param[in] tag_handler how CBOR tags should be treated |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10244 |
@return whether array creation completed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10245 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10246 |
bool get_cbor_array(const std::size_t len, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10247 |
const cbor_tag_handler_t tag_handler) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10248 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10249 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10250 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10251 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10252 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10253 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10254 |
if (len != static_cast<std::size_t>(-1)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10255 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10256 |
for (std::size_t i = 0; i < len; ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10257 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10258 |
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10259 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10260 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10261 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10262 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10263 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10264 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10265 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10266 |
while (get() != 0xFF) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10267 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10268 |
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(false, tag_handler))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10269 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10270 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10271 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10272 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10273 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10274 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10275 |
return sax->end_array(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10276 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10277 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10278 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10279 |
@param[in] len the length of the object or static_cast<std::size_t>(-1) for an |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10280 |
object of indefinite size |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10281 |
@param[in] tag_handler how CBOR tags should be treated |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10282 |
@return whether object creation completed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10283 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10284 |
bool get_cbor_object(const std::size_t len, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10285 |
const cbor_tag_handler_t tag_handler) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10286 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10287 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10288 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10289 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10290 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10291 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10292 |
if (len != 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10293 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10294 |
string_t key; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10295 |
if (len != static_cast<std::size_t>(-1)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10296 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10297 |
for (std::size_t i = 0; i < len; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10298 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10299 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10300 |
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10301 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10302 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10303 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10304 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10305 |
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10306 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10307 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10308 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10309 |
key.clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10310 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10311 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10312 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10313 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10314 |
while (get() != 0xFF) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10315 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10316 |
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10317 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10318 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10319 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10320 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10321 |
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10322 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10323 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10324 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10325 |
key.clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10326 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10327 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10328 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10329 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10330 |
return sax->end_object(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10331 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10332 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10333 |
///////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10334 |
// MsgPack // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10335 |
///////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10336 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10337 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10338 |
@return whether a valid MessagePack value was passed to the SAX parser |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10339 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10340 |
bool parse_msgpack_internal() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10341 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10342 |
switch (get()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10343 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10344 |
// EOF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10345 |
case char_traits<char_type>::eof(): |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10346 |
return unexpect_eof(input_format_t::msgpack, "value"); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10347 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10348 |
// positive fixint |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10349 |
case 0x00: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10350 |
case 0x01: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10351 |
case 0x02: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10352 |
case 0x03: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10353 |
case 0x04: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10354 |
case 0x05: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10355 |
case 0x06: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10356 |
case 0x07: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10357 |
case 0x08: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10358 |
case 0x09: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10359 |
case 0x0A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10360 |
case 0x0B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10361 |
case 0x0C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10362 |
case 0x0D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10363 |
case 0x0E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10364 |
case 0x0F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10365 |
case 0x10: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10366 |
case 0x11: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10367 |
case 0x12: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10368 |
case 0x13: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10369 |
case 0x14: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10370 |
case 0x15: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10371 |
case 0x16: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10372 |
case 0x17: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10373 |
case 0x18: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10374 |
case 0x19: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10375 |
case 0x1A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10376 |
case 0x1B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10377 |
case 0x1C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10378 |
case 0x1D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10379 |
case 0x1E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10380 |
case 0x1F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10381 |
case 0x20: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10382 |
case 0x21: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10383 |
case 0x22: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10384 |
case 0x23: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10385 |
case 0x24: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10386 |
case 0x25: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10387 |
case 0x26: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10388 |
case 0x27: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10389 |
case 0x28: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10390 |
case 0x29: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10391 |
case 0x2A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10392 |
case 0x2B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10393 |
case 0x2C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10394 |
case 0x2D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10395 |
case 0x2E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10396 |
case 0x2F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10397 |
case 0x30: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10398 |
case 0x31: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10399 |
case 0x32: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10400 |
case 0x33: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10401 |
case 0x34: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10402 |
case 0x35: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10403 |
case 0x36: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10404 |
case 0x37: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10405 |
case 0x38: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10406 |
case 0x39: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10407 |
case 0x3A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10408 |
case 0x3B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10409 |
case 0x3C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10410 |
case 0x3D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10411 |
case 0x3E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10412 |
case 0x3F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10413 |
case 0x40: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10414 |
case 0x41: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10415 |
case 0x42: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10416 |
case 0x43: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10417 |
case 0x44: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10418 |
case 0x45: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10419 |
case 0x46: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10420 |
case 0x47: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10421 |
case 0x48: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10422 |
case 0x49: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10423 |
case 0x4A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10424 |
case 0x4B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10425 |
case 0x4C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10426 |
case 0x4D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10427 |
case 0x4E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10428 |
case 0x4F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10429 |
case 0x50: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10430 |
case 0x51: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10431 |
case 0x52: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10432 |
case 0x53: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10433 |
case 0x54: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10434 |
case 0x55: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10435 |
case 0x56: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10436 |
case 0x57: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10437 |
case 0x58: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10438 |
case 0x59: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10439 |
case 0x5A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10440 |
case 0x5B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10441 |
case 0x5C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10442 |
case 0x5D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10443 |
case 0x5E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10444 |
case 0x5F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10445 |
case 0x60: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10446 |
case 0x61: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10447 |
case 0x62: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10448 |
case 0x63: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10449 |
case 0x64: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10450 |
case 0x65: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10451 |
case 0x66: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10452 |
case 0x67: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10453 |
case 0x68: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10454 |
case 0x69: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10455 |
case 0x6A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10456 |
case 0x6B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10457 |
case 0x6C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10458 |
case 0x6D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10459 |
case 0x6E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10460 |
case 0x6F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10461 |
case 0x70: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10462 |
case 0x71: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10463 |
case 0x72: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10464 |
case 0x73: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10465 |
case 0x74: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10466 |
case 0x75: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10467 |
case 0x76: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10468 |
case 0x77: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10469 |
case 0x78: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10470 |
case 0x79: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10471 |
case 0x7A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10472 |
case 0x7B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10473 |
case 0x7C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10474 |
case 0x7D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10475 |
case 0x7E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10476 |
case 0x7F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10477 |
return sax->number_unsigned(static_cast<number_unsigned_t>(current)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10478 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10479 |
// fixmap |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10480 |
case 0x80: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10481 |
case 0x81: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10482 |
case 0x82: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10483 |
case 0x83: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10484 |
case 0x84: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10485 |
case 0x85: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10486 |
case 0x86: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10487 |
case 0x87: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10488 |
case 0x88: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10489 |
case 0x89: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10490 |
case 0x8A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10491 |
case 0x8B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10492 |
case 0x8C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10493 |
case 0x8D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10494 |
case 0x8E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10495 |
case 0x8F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10496 |
return get_msgpack_object(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10497 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10498 |
// fixarray |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10499 |
case 0x90: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10500 |
case 0x91: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10501 |
case 0x92: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10502 |
case 0x93: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10503 |
case 0x94: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10504 |
case 0x95: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10505 |
case 0x96: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10506 |
case 0x97: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10507 |
case 0x98: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10508 |
case 0x99: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10509 |
case 0x9A: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10510 |
case 0x9B: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10511 |
case 0x9C: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10512 |
case 0x9D: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10513 |
case 0x9E: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10514 |
case 0x9F: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10515 |
return get_msgpack_array(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10516 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10517 |
// fixstr |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10518 |
case 0xA0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10519 |
case 0xA1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10520 |
case 0xA2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10521 |
case 0xA3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10522 |
case 0xA4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10523 |
case 0xA5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10524 |
case 0xA6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10525 |
case 0xA7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10526 |
case 0xA8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10527 |
case 0xA9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10528 |
case 0xAA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10529 |
case 0xAB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10530 |
case 0xAC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10531 |
case 0xAD: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10532 |
case 0xAE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10533 |
case 0xAF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10534 |
case 0xB0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10535 |
case 0xB1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10536 |
case 0xB2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10537 |
case 0xB3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10538 |
case 0xB4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10539 |
case 0xB5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10540 |
case 0xB6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10541 |
case 0xB7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10542 |
case 0xB8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10543 |
case 0xB9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10544 |
case 0xBA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10545 |
case 0xBB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10546 |
case 0xBC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10547 |
case 0xBD: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10548 |
case 0xBE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10549 |
case 0xBF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10550 |
case 0xD9: // str 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10551 |
case 0xDA: // str 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10552 |
case 0xDB: // str 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10553 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10554 |
string_t s; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10555 |
return get_msgpack_string(s) && sax->string(s); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10556 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10557 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10558 |
case 0xC0: // nil |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10559 |
return sax->null(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10560 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10561 |
case 0xC2: // false |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10562 |
return sax->boolean(false); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10563 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10564 |
case 0xC3: // true |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10565 |
return sax->boolean(true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10566 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10567 |
case 0xC4: // bin 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10568 |
case 0xC5: // bin 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10569 |
case 0xC6: // bin 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10570 |
case 0xC7: // ext 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10571 |
case 0xC8: // ext 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10572 |
case 0xC9: // ext 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10573 |
case 0xD4: // fixext 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10574 |
case 0xD5: // fixext 2 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10575 |
case 0xD6: // fixext 4 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10576 |
case 0xD7: // fixext 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10577 |
case 0xD8: // fixext 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10578 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10579 |
binary_t b; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10580 |
return get_msgpack_binary(b) && sax->binary(b); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10581 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10582 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10583 |
case 0xCA: // float 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10584 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10585 |
float number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10586 |
return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), ""); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10587 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10588 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10589 |
case 0xCB: // float 64 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10590 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10591 |
double number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10592 |
return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), ""); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10593 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10594 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10595 |
case 0xCC: // uint 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10596 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10597 |
std::uint8_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10598 |
return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10599 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10600 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10601 |
case 0xCD: // uint 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10602 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10603 |
std::uint16_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10604 |
return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10605 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10606 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10607 |
case 0xCE: // uint 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10608 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10609 |
std::uint32_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10610 |
return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10611 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10612 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10613 |
case 0xCF: // uint 64 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10614 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10615 |
std::uint64_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10616 |
return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10617 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10618 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10619 |
case 0xD0: // int 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10620 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10621 |
std::int8_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10622 |
return get_number(input_format_t::msgpack, number) && sax->number_integer(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10623 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10624 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10625 |
case 0xD1: // int 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10626 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10627 |
std::int16_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10628 |
return get_number(input_format_t::msgpack, number) && sax->number_integer(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10629 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10630 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10631 |
case 0xD2: // int 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10632 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10633 |
std::int32_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10634 |
return get_number(input_format_t::msgpack, number) && sax->number_integer(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10635 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10636 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10637 |
case 0xD3: // int 64 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10638 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10639 |
std::int64_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10640 |
return get_number(input_format_t::msgpack, number) && sax->number_integer(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10641 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10642 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10643 |
case 0xDC: // array 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10644 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10645 |
std::uint16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10646 |
return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10647 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10648 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10649 |
case 0xDD: // array 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10650 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10651 |
std::uint32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10652 |
return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10653 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10654 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10655 |
case 0xDE: // map 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10656 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10657 |
std::uint16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10658 |
return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10659 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10660 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10661 |
case 0xDF: // map 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10662 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10663 |
std::uint32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10664 |
return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10665 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10666 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10667 |
// negative fixint |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10668 |
case 0xE0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10669 |
case 0xE1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10670 |
case 0xE2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10671 |
case 0xE3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10672 |
case 0xE4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10673 |
case 0xE5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10674 |
case 0xE6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10675 |
case 0xE7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10676 |
case 0xE8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10677 |
case 0xE9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10678 |
case 0xEA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10679 |
case 0xEB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10680 |
case 0xEC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10681 |
case 0xED: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10682 |
case 0xEE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10683 |
case 0xEF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10684 |
case 0xF0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10685 |
case 0xF1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10686 |
case 0xF2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10687 |
case 0xF3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10688 |
case 0xF4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10689 |
case 0xF5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10690 |
case 0xF6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10691 |
case 0xF7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10692 |
case 0xF8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10693 |
case 0xF9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10694 |
case 0xFA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10695 |
case 0xFB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10696 |
case 0xFC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10697 |
case 0xFD: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10698 |
case 0xFE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10699 |
case 0xFF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10700 |
return sax->number_integer(static_cast<std::int8_t>(current)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10701 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10702 |
default: // anything else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10703 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10704 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10705 |
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10706 |
exception_message(input_format_t::msgpack, concat("invalid byte: 0x", last_token), "value"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10707 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10708 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10709 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10710 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10711 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10712 |
@brief reads a MessagePack string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10713 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10714 |
This function first reads starting bytes to determine the expected |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10715 |
string length and then copies this number of bytes into a string. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10716 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10717 |
@param[out] result created string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10718 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10719 |
@return whether string creation completed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10720 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10721 |
bool get_msgpack_string(string_t& result) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10722 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10723 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack, "string"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10724 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10725 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10726 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10727 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10728 |
switch (current) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10729 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10730 |
// fixstr |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10731 |
case 0xA0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10732 |
case 0xA1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10733 |
case 0xA2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10734 |
case 0xA3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10735 |
case 0xA4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10736 |
case 0xA5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10737 |
case 0xA6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10738 |
case 0xA7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10739 |
case 0xA8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10740 |
case 0xA9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10741 |
case 0xAA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10742 |
case 0xAB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10743 |
case 0xAC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10744 |
case 0xAD: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10745 |
case 0xAE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10746 |
case 0xAF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10747 |
case 0xB0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10748 |
case 0xB1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10749 |
case 0xB2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10750 |
case 0xB3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10751 |
case 0xB4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10752 |
case 0xB5: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10753 |
case 0xB6: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10754 |
case 0xB7: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10755 |
case 0xB8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10756 |
case 0xB9: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10757 |
case 0xBA: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10758 |
case 0xBB: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10759 |
case 0xBC: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10760 |
case 0xBD: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10761 |
case 0xBE: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10762 |
case 0xBF: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10763 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10764 |
return get_string(input_format_t::msgpack, static_cast<unsigned int>(current) & 0x1Fu, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10765 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10766 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10767 |
case 0xD9: // str 8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10768 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10769 |
std::uint8_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10770 |
return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10771 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10772 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10773 |
case 0xDA: // str 16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10774 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10775 |
std::uint16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10776 |
return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10777 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10778 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10779 |
case 0xDB: // str 32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10780 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10781 |
std::uint32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10782 |
return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10783 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10784 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10785 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10786 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10787 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10788 |
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10789 |
exception_message(input_format_t::msgpack, concat("expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token), "string"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10790 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10791 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10792 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10793 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10794 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10795 |
@brief reads a MessagePack byte array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10796 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10797 |
This function first reads starting bytes to determine the expected |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10798 |
byte array length and then copies this number of bytes into a byte array. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10799 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10800 |
@param[out] result created byte array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10801 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10802 |
@return whether byte array creation completed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10803 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10804 |
bool get_msgpack_binary(binary_t& result) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10805 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10806 |
// helper function to set the subtype |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10807 |
auto assign_and_return_true = [&result](std::int8_t subtype) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10808 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10809 |
result.set_subtype(static_cast<std::uint8_t>(subtype)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10810 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10811 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10812 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10813 |
switch (current) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10814 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10815 |
case 0xC4: // bin 8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10816 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10817 |
std::uint8_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10818 |
return get_number(input_format_t::msgpack, len) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10819 |
get_binary(input_format_t::msgpack, len, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10820 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10821 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10822 |
case 0xC5: // bin 16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10823 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10824 |
std::uint16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10825 |
return get_number(input_format_t::msgpack, len) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10826 |
get_binary(input_format_t::msgpack, len, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10827 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10828 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10829 |
case 0xC6: // bin 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10830 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10831 |
std::uint32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10832 |
return get_number(input_format_t::msgpack, len) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10833 |
get_binary(input_format_t::msgpack, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10834 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10835 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10836 |
case 0xC7: // ext 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10837 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10838 |
std::uint8_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10839 |
std::int8_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10840 |
return get_number(input_format_t::msgpack, len) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10841 |
get_number(input_format_t::msgpack, subtype) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10842 |
get_binary(input_format_t::msgpack, len, result) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10843 |
assign_and_return_true(subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10844 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10845 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10846 |
case 0xC8: // ext 16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10847 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10848 |
std::uint16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10849 |
std::int8_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10850 |
return get_number(input_format_t::msgpack, len) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10851 |
get_number(input_format_t::msgpack, subtype) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10852 |
get_binary(input_format_t::msgpack, len, result) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10853 |
assign_and_return_true(subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10854 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10855 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10856 |
case 0xC9: // ext 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10857 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10858 |
std::uint32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10859 |
std::int8_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10860 |
return get_number(input_format_t::msgpack, len) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10861 |
get_number(input_format_t::msgpack, subtype) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10862 |
get_binary(input_format_t::msgpack, len, result) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10863 |
assign_and_return_true(subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10864 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10865 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10866 |
case 0xD4: // fixext 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10867 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10868 |
std::int8_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10869 |
return get_number(input_format_t::msgpack, subtype) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10870 |
get_binary(input_format_t::msgpack, 1, result) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10871 |
assign_and_return_true(subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10872 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10873 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10874 |
case 0xD5: // fixext 2 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10875 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10876 |
std::int8_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10877 |
return get_number(input_format_t::msgpack, subtype) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10878 |
get_binary(input_format_t::msgpack, 2, result) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10879 |
assign_and_return_true(subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10880 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10881 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10882 |
case 0xD6: // fixext 4 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10883 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10884 |
std::int8_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10885 |
return get_number(input_format_t::msgpack, subtype) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10886 |
get_binary(input_format_t::msgpack, 4, result) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10887 |
assign_and_return_true(subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10888 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10889 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10890 |
case 0xD7: // fixext 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10891 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10892 |
std::int8_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10893 |
return get_number(input_format_t::msgpack, subtype) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10894 |
get_binary(input_format_t::msgpack, 8, result) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10895 |
assign_and_return_true(subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10896 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10897 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10898 |
case 0xD8: // fixext 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10899 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10900 |
std::int8_t subtype{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10901 |
return get_number(input_format_t::msgpack, subtype) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10902 |
get_binary(input_format_t::msgpack, 16, result) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10903 |
assign_and_return_true(subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10904 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10905 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10906 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10907 |
return false; // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10908 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10909 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10910 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10911 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10912 |
@param[in] len the length of the array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10913 |
@return whether array creation completed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10914 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10915 |
bool get_msgpack_array(const std::size_t len) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10916 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10917 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10918 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10919 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10920 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10921 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10922 |
for (std::size_t i = 0; i < len; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10923 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10924 |
if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10925 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10926 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10927 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10928 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10929 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10930 |
return sax->end_array(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10931 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10932 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10933 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10934 |
@param[in] len the length of the object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10935 |
@return whether object creation completed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10936 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10937 |
bool get_msgpack_object(const std::size_t len) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10938 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10939 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10940 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10941 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10942 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10943 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10944 |
string_t key; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10945 |
for (std::size_t i = 0; i < len; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10946 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10947 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10948 |
if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10949 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10950 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10951 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10952 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10953 |
if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10954 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10955 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10956 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10957 |
key.clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10958 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10959 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10960 |
return sax->end_object(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10961 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10962 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10963 |
//////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10964 |
// UBJSON // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10965 |
//////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10966 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10967 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10968 |
@param[in] get_char whether a new character should be retrieved from the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10969 |
input (true, default) or whether the last read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10970 |
character should be considered instead |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10971 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10972 |
@return whether a valid UBJSON value was passed to the SAX parser |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10973 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10974 |
bool parse_ubjson_internal(const bool get_char = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10975 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10976 |
return get_ubjson_value(get_char ? get_ignore_noop() : current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10977 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10978 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10979 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10980 |
@brief reads a UBJSON string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10981 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10982 |
This function is either called after reading the 'S' byte explicitly |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10983 |
indicating a string, or in case of an object key where the 'S' byte can be |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10984 |
left out. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10985 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10986 |
@param[out] result created string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10987 |
@param[in] get_char whether a new character should be retrieved from the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10988 |
input (true, default) or whether the last read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10989 |
character should be considered instead |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10990 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10991 |
@return whether string creation completed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10992 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10993 |
bool get_ubjson_string(string_t& result, const bool get_char = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10994 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10995 |
if (get_char) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10996 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10997 |
get(); // TODO(niels): may we ignore N here? |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
10998 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
10999 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11000 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "value"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11001 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11002 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11003 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11004 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11005 |
switch (current) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11006 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11007 |
case 'U': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11008 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11009 |
std::uint8_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11010 |
return get_number(input_format, len) && get_string(input_format, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11011 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11012 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11013 |
case 'i': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11014 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11015 |
std::int8_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11016 |
return get_number(input_format, len) && get_string(input_format, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11017 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11018 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11019 |
case 'I': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11020 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11021 |
std::int16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11022 |
return get_number(input_format, len) && get_string(input_format, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11023 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11024 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11025 |
case 'l': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11026 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11027 |
std::int32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11028 |
return get_number(input_format, len) && get_string(input_format, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11029 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11030 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11031 |
case 'L': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11032 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11033 |
std::int64_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11034 |
return get_number(input_format, len) && get_string(input_format, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11035 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11036 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11037 |
case 'u': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11038 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11039 |
if (input_format != input_format_t::bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11040 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11041 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11042 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11043 |
std::uint16_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11044 |
return get_number(input_format, len) && get_string(input_format, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11045 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11046 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11047 |
case 'm': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11048 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11049 |
if (input_format != input_format_t::bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11050 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11051 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11052 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11053 |
std::uint32_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11054 |
return get_number(input_format, len) && get_string(input_format, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11055 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11056 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11057 |
case 'M': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11058 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11059 |
if (input_format != input_format_t::bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11060 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11061 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11062 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11063 |
std::uint64_t len{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11064 |
return get_number(input_format, len) && get_string(input_format, len, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11065 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11066 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11067 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11068 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11069 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11070 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11071 |
std::string message; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11072 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11073 |
if (input_format != input_format_t::bjdata) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11074 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11075 |
message = "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11076 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11077 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11078 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11079 |
message = "expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11080 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11081 |
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, "string"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11082 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11083 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11084 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11085 |
@param[out] dim an integer vector storing the ND array dimensions |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11086 |
@return whether reading ND array size vector is successful |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11087 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11088 |
bool get_ubjson_ndarray_size(std::vector<size_t>& dim) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11089 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11090 |
std::pair<std::size_t, char_int_type> size_and_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11091 |
size_t dimlen = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11092 |
bool no_ndarray = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11093 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11094 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11095 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11096 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11097 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11098 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11099 |
if (size_and_type.first != npos) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11100 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11101 |
if (size_and_type.second != 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11102 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11103 |
if (size_and_type.second != 'N') |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11104 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11105 |
for (std::size_t i = 0; i < size_and_type.first; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11106 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11107 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11108 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11109 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11110 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11111 |
dim.push_back(dimlen); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11112 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11113 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11114 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11115 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11116 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11117 |
for (std::size_t i = 0; i < size_and_type.first; ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11118 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11119 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11120 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11121 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11122 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11123 |
dim.push_back(dimlen); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11124 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11125 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11126 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11127 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11128 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11129 |
while (current != ']') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11130 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11131 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11132 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11133 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11134 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11135 |
dim.push_back(dimlen); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11136 |
get_ignore_noop(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11137 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11138 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11139 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11140 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11141 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11142 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11143 |
@param[out] result determined size |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11144 |
@param[in,out] is_ndarray for input, `true` means already inside an ndarray vector |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11145 |
or ndarray dimension is not allowed; `false` means ndarray |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11146 |
is allowed; for output, `true` means an ndarray is found; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11147 |
is_ndarray can only return `true` when its initial value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11148 |
is `false` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11149 |
@param[in] prefix type marker if already read, otherwise set to 0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11150 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11151 |
@return whether size determination completed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11152 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11153 |
bool get_ubjson_size_value(std::size_t& result, bool& is_ndarray, char_int_type prefix = 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11154 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11155 |
if (prefix == 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11156 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11157 |
prefix = get_ignore_noop(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11158 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11159 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11160 |
switch (prefix) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11161 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11162 |
case 'U': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11163 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11164 |
std::uint8_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11165 |
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11166 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11167 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11168 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11169 |
result = static_cast<std::size_t>(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11170 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11171 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11172 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11173 |
case 'i': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11174 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11175 |
std::int8_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11176 |
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11177 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11178 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11179 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11180 |
if (number < 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11181 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11182 |
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11183 |
exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11184 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11185 |
result = static_cast<std::size_t>(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11186 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11187 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11188 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11189 |
case 'I': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11190 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11191 |
std::int16_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11192 |
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11193 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11194 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11195 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11196 |
if (number < 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11197 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11198 |
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11199 |
exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11200 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11201 |
result = static_cast<std::size_t>(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11202 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11203 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11204 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11205 |
case 'l': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11206 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11207 |
std::int32_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11208 |
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11209 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11210 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11211 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11212 |
if (number < 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11213 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11214 |
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11215 |
exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11216 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11217 |
result = static_cast<std::size_t>(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11218 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11219 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11220 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11221 |
case 'L': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11222 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11223 |
std::int64_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11224 |
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11225 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11226 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11227 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11228 |
if (number < 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11229 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11230 |
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11231 |
exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11232 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11233 |
if (!value_in_range_of<std::size_t>(number)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11234 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11235 |
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11236 |
exception_message(input_format, "integer value overflow", "size"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11237 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11238 |
result = static_cast<std::size_t>(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11239 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11240 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11241 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11242 |
case 'u': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11243 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11244 |
if (input_format != input_format_t::bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11245 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11246 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11247 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11248 |
std::uint16_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11249 |
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11250 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11251 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11252 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11253 |
result = static_cast<std::size_t>(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11254 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11255 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11256 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11257 |
case 'm': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11258 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11259 |
if (input_format != input_format_t::bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11260 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11261 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11262 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11263 |
std::uint32_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11264 |
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11265 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11266 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11267 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11268 |
result = conditional_static_cast<std::size_t>(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11269 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11270 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11271 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11272 |
case 'M': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11273 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11274 |
if (input_format != input_format_t::bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11275 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11276 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11277 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11278 |
std::uint64_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11279 |
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11280 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11281 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11282 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11283 |
if (!value_in_range_of<std::size_t>(number)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11284 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11285 |
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11286 |
exception_message(input_format, "integer value overflow", "size"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11287 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11288 |
result = detail::conditional_static_cast<std::size_t>(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11289 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11290 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11291 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11292 |
case '[': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11293 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11294 |
if (input_format != input_format_t::bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11295 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11296 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11297 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11298 |
if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11299 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11300 |
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11301 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11302 |
std::vector<size_t> dim; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11303 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11304 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11305 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11306 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11307 |
if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1)) // return normal array size if 1D row vector |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11308 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11309 |
result = dim.at(dim.size() - 1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11310 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11311 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11312 |
if (!dim.empty()) // if ndarray, convert to an object in JData annotated array format |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11313 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11314 |
for (auto i : dim) // test if any dimension in an ndarray is 0, if so, return a 1D empty container |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11315 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11316 |
if ( i == 0 ) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11317 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11318 |
result = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11319 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11320 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11321 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11322 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11323 |
string_t key = "_ArraySize_"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11324 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11325 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11326 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11327 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11328 |
result = 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11329 |
for (auto i : dim) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11330 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11331 |
result *= i; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11332 |
if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11333 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11334 |
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11335 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11336 |
if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(static_cast<number_unsigned_t>(i)))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11337 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11338 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11339 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11340 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11341 |
is_ndarray = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11342 |
return sax->end_array(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11343 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11344 |
result = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11345 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11346 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11347 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11348 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11349 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11350 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11351 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11352 |
std::string message; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11353 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11354 |
if (input_format != input_format_t::bjdata) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11355 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11356 |
message = "expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11357 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11358 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11359 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11360 |
message = "expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11361 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11362 |
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, "size"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11363 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11364 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11365 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11366 |
@brief determine the type and size for a container |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11367 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11368 |
In the optimized UBJSON format, a type and a size can be provided to allow |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11369 |
for a more compact representation. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11370 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11371 |
@param[out] result pair of the size and the type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11372 |
@param[in] inside_ndarray whether the parser is parsing an ND array dimensional vector |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11373 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11374 |
@return whether pair creation completed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11375 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11376 |
bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result, bool inside_ndarray = false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11377 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11378 |
result.first = npos; // size |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11379 |
result.second = 0; // type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11380 |
bool is_ndarray = false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11381 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11382 |
get_ignore_noop(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11383 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11384 |
if (current == '$') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11385 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11386 |
result.second = get(); // must not ignore 'N', because 'N' maybe the type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11387 |
if (input_format == input_format_t::bjdata |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11388 |
&& JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11389 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11390 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11391 |
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11392 |
exception_message(input_format, concat("marker 0x", last_token, " is not a permitted optimized array type"), "type"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11393 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11394 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11395 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "type"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11396 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11397 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11398 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11399 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11400 |
get_ignore_noop(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11401 |
if (JSON_HEDLEY_UNLIKELY(current != '#')) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11402 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11403 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "value"))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11404 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11405 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11406 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11407 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11408 |
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11409 |
exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11410 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11411 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11412 |
const bool is_error = get_ubjson_size_value(result.first, is_ndarray); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11413 |
if (input_format == input_format_t::bjdata && is_ndarray) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11414 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11415 |
if (inside_ndarray) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11416 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11417 |
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11418 |
exception_message(input_format, "ndarray can not be recursive", "size"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11419 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11420 |
result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11421 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11422 |
return is_error; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11423 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11424 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11425 |
if (current == '#') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11426 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11427 |
const bool is_error = get_ubjson_size_value(result.first, is_ndarray); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11428 |
if (input_format == input_format_t::bjdata && is_ndarray) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11429 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11430 |
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11431 |
exception_message(input_format, "ndarray requires both type and size", "size"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11432 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11433 |
return is_error; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11434 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11435 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11436 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11437 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11438 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11439 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11440 |
@param prefix the previously read or set type prefix |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11441 |
@return whether value creation completed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11442 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11443 |
bool get_ubjson_value(const char_int_type prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11444 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11445 |
switch (prefix) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11446 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11447 |
case char_traits<char_type>::eof(): // EOF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11448 |
return unexpect_eof(input_format, "value"); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11449 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11450 |
case 'T': // true |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11451 |
return sax->boolean(true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11452 |
case 'F': // false |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11453 |
return sax->boolean(false); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11454 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11455 |
case 'Z': // null |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11456 |
return sax->null(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11457 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11458 |
case 'U': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11459 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11460 |
std::uint8_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11461 |
return get_number(input_format, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11462 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11463 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11464 |
case 'i': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11465 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11466 |
std::int8_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11467 |
return get_number(input_format, number) && sax->number_integer(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11468 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11469 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11470 |
case 'I': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11471 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11472 |
std::int16_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11473 |
return get_number(input_format, number) && sax->number_integer(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11474 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11475 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11476 |
case 'l': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11477 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11478 |
std::int32_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11479 |
return get_number(input_format, number) && sax->number_integer(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11480 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11481 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11482 |
case 'L': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11483 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11484 |
std::int64_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11485 |
return get_number(input_format, number) && sax->number_integer(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11486 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11487 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11488 |
case 'u': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11489 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11490 |
if (input_format != input_format_t::bjdata) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11491 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11492 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11493 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11494 |
std::uint16_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11495 |
return get_number(input_format, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11496 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11497 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11498 |
case 'm': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11499 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11500 |
if (input_format != input_format_t::bjdata) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11501 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11502 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11503 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11504 |
std::uint32_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11505 |
return get_number(input_format, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11506 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11507 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11508 |
case 'M': |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11509 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11510 |
if (input_format != input_format_t::bjdata) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11511 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11512 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11513 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11514 |
std::uint64_t number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11515 |
return get_number(input_format, number) && sax->number_unsigned(number); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11516 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11517 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11518 |
case 'h': |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11519 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11520 |
if (input_format != input_format_t::bjdata) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11521 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11522 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11523 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11524 |
const auto byte1_raw = get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11525 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "number"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11526 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11527 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11528 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11529 |
const auto byte2_raw = get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11530 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "number"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11531 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11532 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11533 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11534 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11535 |
const auto byte1 = static_cast<unsigned char>(byte1_raw); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11536 |
const auto byte2 = static_cast<unsigned char>(byte2_raw); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11537 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11538 |
// code from RFC 7049, Appendix D, Figure 3: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11539 |
// As half-precision floating-point numbers were only added |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11540 |
// to IEEE 754 in 2008, today's programming platforms often |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11541 |
// still only have limited support for them. It is very |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11542 |
// easy to include at least decoding support for them even |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11543 |
// without such support. An example of a small decoder for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11544 |
// half-precision floating-point numbers in the C language |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11545 |
// is shown in Fig. 3. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11546 |
const auto half = static_cast<unsigned int>((byte2 << 8u) + byte1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11547 |
const double val = [&half] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11548 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11549 |
const int exp = (half >> 10u) & 0x1Fu; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11550 |
const unsigned int mant = half & 0x3FFu; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11551 |
JSON_ASSERT(0 <= exp&& exp <= 32); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11552 |
JSON_ASSERT(mant <= 1024); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11553 |
switch (exp) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11554 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11555 |
case 0: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11556 |
return std::ldexp(mant, -24); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11557 |
case 31: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11558 |
return (mant == 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11559 |
? std::numeric_limits<double>::infinity() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11560 |
: std::numeric_limits<double>::quiet_NaN(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11561 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11562 |
return std::ldexp(mant + 1024, exp - 25); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11563 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11564 |
}(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11565 |
return sax->number_float((half & 0x8000u) != 0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11566 |
? static_cast<number_float_t>(-val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11567 |
: static_cast<number_float_t>(val), ""); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11568 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11569 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11570 |
case 'd': |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11571 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11572 |
float number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11573 |
return get_number(input_format, number) && sax->number_float(static_cast<number_float_t>(number), ""); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11574 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11575 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11576 |
case 'D': |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11577 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11578 |
double number{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11579 |
return get_number(input_format, number) && sax->number_float(static_cast<number_float_t>(number), ""); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11580 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11581 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11582 |
case 'H': |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11583 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11584 |
return get_ubjson_high_precision_number(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11585 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11586 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11587 |
case 'C': // char |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11588 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11589 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11590 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "char"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11591 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11592 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11593 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11594 |
if (JSON_HEDLEY_UNLIKELY(current > 127)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11595 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11596 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11597 |
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11598 |
exception_message(input_format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11599 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11600 |
string_t s(1, static_cast<typename string_t::value_type>(current)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11601 |
return sax->string(s); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11602 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11603 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11604 |
case 'S': // string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11605 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11606 |
string_t s; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11607 |
return get_ubjson_string(s) && sax->string(s); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11608 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11609 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11610 |
case '[': // array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11611 |
return get_ubjson_array(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11612 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11613 |
case '{': // object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11614 |
return get_ubjson_object(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11615 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11616 |
default: // anything else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11617 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11618 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11619 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11620 |
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "invalid byte: 0x" + last_token, "value"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11621 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11622 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11623 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11624 |
@return whether array creation completed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11625 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11626 |
bool get_ubjson_array() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11627 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11628 |
std::pair<std::size_t, char_int_type> size_and_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11629 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11630 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11631 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11632 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11633 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11634 |
// if bit-8 of size_and_type.second is set to 1, encode bjdata ndarray as an object in JData annotated array format (https://github.com/NeuroJSON/jdata): |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11635 |
// {"_ArrayType_" : "typeid", "_ArraySize_" : [n1, n2, ...], "_ArrayData_" : [v1, v2, ...]} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11636 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11637 |
if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11638 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11639 |
size_and_type.second &= ~(static_cast<char_int_type>(1) << 8); // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11640 |
auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type & p, char_int_type t) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11641 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11642 |
return p.first < t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11643 |
}); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11644 |
string_t key = "_ArrayType_"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11645 |
if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11646 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11647 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11648 |
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11649 |
exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11650 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11651 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11652 |
string_t type = it->second; // sax->string() takes a reference |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11653 |
if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11654 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11655 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11656 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11657 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11658 |
if (size_and_type.second == 'C') |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11659 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11660 |
size_and_type.second = 'U'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11661 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11662 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11663 |
key = "_ArrayData_"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11664 |
if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) )) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11665 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11666 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11667 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11668 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11669 |
for (std::size_t i = 0; i < size_and_type.first; ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11670 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11671 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11672 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11673 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11674 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11675 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11676 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11677 |
return (sax->end_array() && sax->end_object()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11678 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11679 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11680 |
if (size_and_type.first != npos) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11681 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11682 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11683 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11684 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11685 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11686 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11687 |
if (size_and_type.second != 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11688 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11689 |
if (size_and_type.second != 'N') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11690 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11691 |
for (std::size_t i = 0; i < size_and_type.first; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11692 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11693 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11694 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11695 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11696 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11697 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11698 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11699 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11700 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11701 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11702 |
for (std::size_t i = 0; i < size_and_type.first; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11703 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11704 |
if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11705 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11706 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11707 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11708 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11709 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11710 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11711 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11712 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11713 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1)))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11714 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11715 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11716 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11717 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11718 |
while (current != ']') |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11719 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11720 |
if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(false))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11721 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11722 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11723 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11724 |
get_ignore_noop(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11725 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11726 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11727 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11728 |
return sax->end_array(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11729 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11730 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11731 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11732 |
@return whether object creation completed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11733 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11734 |
bool get_ubjson_object() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11735 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11736 |
std::pair<std::size_t, char_int_type> size_and_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11737 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11738 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11739 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11740 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11741 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11742 |
// do not accept ND-array size in objects in BJData |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11743 |
if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11744 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11745 |
auto last_token = get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11746 |
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11747 |
exception_message(input_format, "BJData object does not support ND-array size in optimized format", "object"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11748 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11749 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11750 |
string_t key; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11751 |
if (size_and_type.first != npos) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11752 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11753 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11754 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11755 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11756 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11757 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11758 |
if (size_and_type.second != 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11759 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11760 |
for (std::size_t i = 0; i < size_and_type.first; ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11761 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11762 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11763 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11764 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11765 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11766 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11767 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11768 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11769 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11770 |
key.clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11771 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11772 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11773 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11774 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11775 |
for (std::size_t i = 0; i < size_and_type.first; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11776 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11777 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11778 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11779 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11780 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11781 |
if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11782 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11783 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11784 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11785 |
key.clear(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11786 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11787 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11788 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11789 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11790 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11791 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1)))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11792 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11793 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11794 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11795 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11796 |
while (current != '}') |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11797 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11798 |
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key, false) || !sax->key(key))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11799 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11800 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11801 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11802 |
if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11803 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11804 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11805 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11806 |
get_ignore_noop(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11807 |
key.clear(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11808 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11809 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11810 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11811 |
return sax->end_object(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11812 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11813 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11814 |
// Note, no reader for UBJSON binary types is implemented because they do |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11815 |
// not exist |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11816 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11817 |
bool get_ubjson_high_precision_number() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11818 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11819 |
// get size of following number string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11820 |
std::size_t size{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11821 |
bool no_ndarray = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11822 |
auto res = get_ubjson_size_value(size, no_ndarray); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11823 |
if (JSON_HEDLEY_UNLIKELY(!res)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11824 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11825 |
return res; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11826 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11827 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11828 |
// get number string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11829 |
std::vector<char> number_vector; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11830 |
for (std::size_t i = 0; i < size; ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11831 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11832 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11833 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "number"))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11834 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11835 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11836 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11837 |
number_vector.push_back(static_cast<char>(current)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11838 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11839 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11840 |
// parse number string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11841 |
using ia_type = decltype(detail::input_adapter(number_vector)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11842 |
auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector), false); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11843 |
const auto result_number = number_lexer.scan(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11844 |
const auto number_string = number_lexer.get_token_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11845 |
const auto result_remainder = number_lexer.scan(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11846 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11847 |
using token_type = typename detail::lexer_base<BasicJsonType>::token_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11848 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11849 |
if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11850 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11851 |
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11852 |
exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11853 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11854 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11855 |
switch (result_number) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11856 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11857 |
case token_type::value_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11858 |
return sax->number_integer(number_lexer.get_number_integer()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11859 |
case token_type::value_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11860 |
return sax->number_unsigned(number_lexer.get_number_unsigned()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11861 |
case token_type::value_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11862 |
return sax->number_float(number_lexer.get_number_float(), std::move(number_string)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11863 |
case token_type::uninitialized: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11864 |
case token_type::literal_true: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11865 |
case token_type::literal_false: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11866 |
case token_type::literal_null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11867 |
case token_type::value_string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11868 |
case token_type::begin_array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11869 |
case token_type::begin_object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11870 |
case token_type::end_array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11871 |
case token_type::end_object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11872 |
case token_type::name_separator: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11873 |
case token_type::value_separator: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11874 |
case token_type::parse_error: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11875 |
case token_type::end_of_input: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11876 |
case token_type::literal_or_value: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11877 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11878 |
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11879 |
exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11880 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11881 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11882 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11883 |
/////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11884 |
// Utility functions // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11885 |
/////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11886 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11887 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11888 |
@brief get next character from the input |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11889 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11890 |
This function provides the interface to the used input adapter. It does |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11891 |
not throw in case the input reached EOF, but returns a -'ve valued |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11892 |
`char_traits<char_type>::eof()` in that case. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11893 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11894 |
@return character read from the input |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11895 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11896 |
char_int_type get() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11897 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11898 |
++chars_read; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11899 |
return current = ia.get_character(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11900 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11901 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11902 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11903 |
@return character read from the input after ignoring all 'N' entries |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11904 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11905 |
char_int_type get_ignore_noop() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11906 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11907 |
do |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11908 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11909 |
get(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11910 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11911 |
while (current == 'N'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11912 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11913 |
return current; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11914 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11915 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11916 |
/* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11917 |
@brief read a number from the input |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11918 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11919 |
@tparam NumberType the type of the number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11920 |
@param[in] format the current format (for diagnostics) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11921 |
@param[out] result number of type @a NumberType |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11922 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11923 |
@return whether conversion completed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11924 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11925 |
@note This function needs to respect the system's endianness, because |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11926 |
bytes in CBOR, MessagePack, and UBJSON are stored in network order |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11927 |
(big endian) and therefore need reordering on little endian systems. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11928 |
On the other hand, BSON and BJData use little endian and should reorder |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11929 |
on big endian systems. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11930 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11931 |
template<typename NumberType, bool InputIsLittleEndian = false> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11932 |
bool get_number(const input_format_t format, NumberType& result) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11933 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11934 |
// step 1: read input into array with system's byte order |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11935 |
std::array<std::uint8_t, sizeof(NumberType)> vec{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11936 |
for (std::size_t i = 0; i < sizeof(NumberType); ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11937 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11938 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11939 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "number"))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11940 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11941 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11942 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11943 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11944 |
// reverse byte order prior to conversion if necessary |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11945 |
if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11946 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11947 |
vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11948 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11949 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11950 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11951 |
vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11952 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11953 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11954 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11955 |
// step 2: convert array into number of type T and return |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11956 |
std::memcpy(&result, vec.data(), sizeof(NumberType)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11957 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11958 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11959 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11960 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11961 |
@brief create a string by reading characters from the input |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11962 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11963 |
@tparam NumberType the type of the number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11964 |
@param[in] format the current format (for diagnostics) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11965 |
@param[in] len number of characters to read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11966 |
@param[out] result string created by reading @a len bytes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11967 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11968 |
@return whether string creation completed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11969 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11970 |
@note We can not reserve @a len bytes for the result, because @a len |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11971 |
may be too large. Usually, @ref unexpect_eof() detects the end of |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11972 |
the input before we run out of string memory. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11973 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11974 |
template<typename NumberType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11975 |
bool get_string(const input_format_t format, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11976 |
const NumberType len, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11977 |
string_t& result) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11978 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11979 |
bool success = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11980 |
for (NumberType i = 0; i < len; i++) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11981 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11982 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11983 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "string"))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11984 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11985 |
success = false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11986 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11987 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11988 |
result.push_back(static_cast<typename string_t::value_type>(current)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11989 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11990 |
return success; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11991 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11992 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11993 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11994 |
@brief create a byte array by reading bytes from the input |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
11995 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11996 |
@tparam NumberType the type of the number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11997 |
@param[in] format the current format (for diagnostics) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11998 |
@param[in] len number of bytes to read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
11999 |
@param[out] result byte array created by reading @a len bytes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12000 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12001 |
@return whether byte array creation completed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12002 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12003 |
@note We can not reserve @a len bytes for the result, because @a len |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12004 |
may be too large. Usually, @ref unexpect_eof() detects the end of |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12005 |
the input before we run out of memory. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12006 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12007 |
template<typename NumberType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12008 |
bool get_binary(const input_format_t format, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12009 |
const NumberType len, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12010 |
binary_t& result) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12011 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12012 |
bool success = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12013 |
for (NumberType i = 0; i < len; i++) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12014 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12015 |
get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12016 |
if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "binary"))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12017 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12018 |
success = false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12019 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12020 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12021 |
result.push_back(static_cast<std::uint8_t>(current)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12022 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12023 |
return success; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12024 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12025 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12026 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12027 |
@param[in] format the current format (for diagnostics) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12028 |
@param[in] context further context information (for diagnostics) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12029 |
@return whether the last read character is not EOF |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12030 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12031 |
JSON_HEDLEY_NON_NULL(3) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12032 |
bool unexpect_eof(const input_format_t format, const char* context) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12033 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12034 |
if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12035 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12036 |
return sax->parse_error(chars_read, "<end of file>", |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12037 |
parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12038 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12039 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12040 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12041 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12042 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12043 |
@return a string representation of the last read byte |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12044 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12045 |
std::string get_token_string() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12046 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12047 |
std::array<char, 3> cr{{}}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12048 |
static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12049 |
return std::string{cr.data()}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12050 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12051 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12052 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12053 |
@param[in] format the current format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12054 |
@param[in] detail a detailed error message |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12055 |
@param[in] context further context information |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12056 |
@return a message string to use in the parse_error exceptions |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12057 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12058 |
std::string exception_message(const input_format_t format, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12059 |
const std::string& detail, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12060 |
const std::string& context) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12061 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12062 |
std::string error_msg = "syntax error while parsing "; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12063 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12064 |
switch (format) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12065 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12066 |
case input_format_t::cbor: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12067 |
error_msg += "CBOR"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12068 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12069 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12070 |
case input_format_t::msgpack: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12071 |
error_msg += "MessagePack"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12072 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12073 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12074 |
case input_format_t::ubjson: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12075 |
error_msg += "UBJSON"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12076 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12077 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12078 |
case input_format_t::bson: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12079 |
error_msg += "BSON"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12080 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12081 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12082 |
case input_format_t::bjdata: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12083 |
error_msg += "BJData"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12084 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12085 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12086 |
case input_format_t::json: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12087 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12088 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12089 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12090 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12091 |
return concat(error_msg, ' ', context, ": ", detail); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12092 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12093 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12094 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12095 |
static JSON_INLINE_VARIABLE constexpr std::size_t npos = static_cast<std::size_t>(-1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12096 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12097 |
/// input adapter |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12098 |
InputAdapterType ia; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12099 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12100 |
/// the current character |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12101 |
char_int_type current = char_traits<char_type>::eof(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12102 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12103 |
/// the number of characters read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12104 |
std::size_t chars_read = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12105 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12106 |
/// whether we can assume little endianness |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12107 |
const bool is_little_endian = little_endianness(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12108 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12109 |
/// input format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12110 |
const input_format_t input_format = input_format_t::json; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12111 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12112 |
/// the SAX parser |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12113 |
json_sax_t* sax = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12114 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12115 |
// excluded markers in bjdata optimized type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12116 |
#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12117 |
make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12118 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12119 |
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12120 |
make_array<bjd_type>( \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12121 |
bjd_type{'C', "char"}, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12122 |
bjd_type{'D', "double"}, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12123 |
bjd_type{'I', "int16"}, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12124 |
bjd_type{'L', "int64"}, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12125 |
bjd_type{'M', "uint64"}, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12126 |
bjd_type{'U', "uint8"}, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12127 |
bjd_type{'d', "single"}, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12128 |
bjd_type{'i', "int8"}, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12129 |
bjd_type{'l', "int32"}, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12130 |
bjd_type{'m', "uint32"}, \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12131 |
bjd_type{'u', "uint16"}) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12132 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12133 |
JSON_PRIVATE_UNLESS_TESTED: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12134 |
// lookup tables |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12135 |
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12136 |
const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12137 |
JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12138 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12139 |
using bjd_type = std::pair<char_int_type, string_t>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12140 |
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12141 |
const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12142 |
JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12143 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12144 |
#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12145 |
#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12146 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12147 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12148 |
#ifndef JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12149 |
template<typename BasicJsonType, typename InputAdapterType, typename SAX> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12150 |
constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12151 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12152 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12153 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12154 |
NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12155 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12156 |
// #include <nlohmann/detail/input/input_adapters.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12157 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12158 |
// #include <nlohmann/detail/input/lexer.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12159 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12160 |
// #include <nlohmann/detail/input/parser.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12161 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12162 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12163 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12164 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12165 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12166 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12167 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12168 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12169 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12170 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12171 |
#include <cmath> // isfinite |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12172 |
#include <cstdint> // uint8_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12173 |
#include <functional> // function |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12174 |
#include <string> // string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12175 |
#include <utility> // move |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12176 |
#include <vector> // vector |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12177 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12178 |
// #include <nlohmann/detail/exceptions.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12179 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12180 |
// #include <nlohmann/detail/input/input_adapters.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12181 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12182 |
// #include <nlohmann/detail/input/json_sax.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12183 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12184 |
// #include <nlohmann/detail/input/lexer.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12185 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12186 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12187 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12188 |
// #include <nlohmann/detail/meta/is_sax.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12189 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12190 |
// #include <nlohmann/detail/string_concat.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12191 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12192 |
// #include <nlohmann/detail/value_t.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12193 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12194 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12195 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12196 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12197 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12198 |
//////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12199 |
// parser // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12200 |
//////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12201 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12202 |
enum class parse_event_t : std::uint8_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12203 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12204 |
/// the parser read `{` and started to process a JSON object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12205 |
object_start, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12206 |
/// the parser read `}` and finished processing a JSON object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12207 |
object_end, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12208 |
/// the parser read `[` and started to process a JSON array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12209 |
array_start, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12210 |
/// the parser read `]` and finished processing a JSON array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12211 |
array_end, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12212 |
/// the parser read a key of a value in an object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12213 |
key, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12214 |
/// the parser finished reading a JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12215 |
value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12216 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12217 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12218 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12219 |
using parser_callback_t = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12220 |
std::function<bool(int /*depth*/, parse_event_t /*event*/, BasicJsonType& /*parsed*/)>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12221 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12222 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12223 |
@brief syntax analysis |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12224 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12225 |
This class implements a recursive descent parser. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12226 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12227 |
template<typename BasicJsonType, typename InputAdapterType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12228 |
class parser |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12229 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12230 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12231 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12232 |
using number_float_t = typename BasicJsonType::number_float_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12233 |
using string_t = typename BasicJsonType::string_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12234 |
using lexer_t = lexer<BasicJsonType, InputAdapterType>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12235 |
using token_type = typename lexer_t::token_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12236 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12237 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12238 |
/// a parser reading from an input adapter |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12239 |
explicit parser(InputAdapterType&& adapter, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12240 |
const parser_callback_t<BasicJsonType> cb = nullptr, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12241 |
const bool allow_exceptions_ = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12242 |
const bool skip_comments = false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12243 |
: callback(cb) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12244 |
, m_lexer(std::move(adapter), skip_comments) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12245 |
, allow_exceptions(allow_exceptions_) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12246 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12247 |
// read first token |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12248 |
get_token(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12249 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12250 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12251 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12252 |
@brief public parser interface |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12253 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12254 |
@param[in] strict whether to expect the last token to be EOF |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12255 |
@param[in,out] result parsed JSON value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12256 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12257 |
@throw parse_error.101 in case of an unexpected token |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12258 |
@throw parse_error.102 if to_unicode fails or surrogate error |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12259 |
@throw parse_error.103 if to_unicode fails |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12260 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12261 |
void parse(const bool strict, BasicJsonType& result) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12262 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12263 |
if (callback) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12264 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12265 |
json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12266 |
sax_parse_internal(&sdp); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12267 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12268 |
// in strict mode, input must be completely read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12269 |
if (strict && (get_token() != token_type::end_of_input)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12270 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12271 |
sdp.parse_error(m_lexer.get_position(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12272 |
m_lexer.get_token_string(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12273 |
parse_error::create(101, m_lexer.get_position(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12274 |
exception_message(token_type::end_of_input, "value"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12275 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12276 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12277 |
// in case of an error, return discarded value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12278 |
if (sdp.is_errored()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12279 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12280 |
result = value_t::discarded; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12281 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12282 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12283 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12284 |
// set top-level value to null if it was discarded by the callback |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12285 |
// function |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12286 |
if (result.is_discarded()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12287 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12288 |
result = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12289 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12290 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12291 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12292 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12293 |
json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12294 |
sax_parse_internal(&sdp); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12295 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12296 |
// in strict mode, input must be completely read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12297 |
if (strict && (get_token() != token_type::end_of_input)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12298 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12299 |
sdp.parse_error(m_lexer.get_position(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12300 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12301 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12302 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12303 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12304 |
// in case of an error, return discarded value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12305 |
if (sdp.is_errored()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12306 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12307 |
result = value_t::discarded; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12308 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12309 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12310 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12311 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12312 |
result.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12313 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12314 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12315 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12316 |
@brief public accept interface |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12317 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12318 |
@param[in] strict whether to expect the last token to be EOF |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12319 |
@return whether the input is a proper JSON text |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12320 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12321 |
bool accept(const bool strict = true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12322 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12323 |
json_sax_acceptor<BasicJsonType> sax_acceptor; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12324 |
return sax_parse(&sax_acceptor, strict); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12325 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12326 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12327 |
template<typename SAX> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12328 |
JSON_HEDLEY_NON_NULL(2) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12329 |
bool sax_parse(SAX* sax, const bool strict = true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12330 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12331 |
(void)detail::is_sax_static_asserts<SAX, BasicJsonType> {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12332 |
const bool result = sax_parse_internal(sax); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12333 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12334 |
// strict mode: next byte must be EOF |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12335 |
if (result && strict && (get_token() != token_type::end_of_input)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12336 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12337 |
return sax->parse_error(m_lexer.get_position(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12338 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12339 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12340 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12341 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12342 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12343 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12344 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12345 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12346 |
template<typename SAX> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12347 |
JSON_HEDLEY_NON_NULL(2) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12348 |
bool sax_parse_internal(SAX* sax) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12349 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12350 |
// stack to remember the hierarchy of structured values we are parsing |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12351 |
// true = array; false = object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12352 |
std::vector<bool> states; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12353 |
// value to avoid a goto (see comment where set to true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12354 |
bool skip_to_state_evaluation = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12355 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12356 |
while (true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12357 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12358 |
if (!skip_to_state_evaluation) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12359 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12360 |
// invariant: get_token() was called before each iteration |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12361 |
switch (last_token) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12362 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12363 |
case token_type::begin_object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12364 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12365 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1)))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12366 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12367 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12368 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12369 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12370 |
// closing } -> we are done |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12371 |
if (get_token() == token_type::end_object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12372 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12373 |
if (JSON_HEDLEY_UNLIKELY(!sax->end_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12374 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12375 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12376 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12377 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12378 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12379 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12380 |
// parse key |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12381 |
if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12382 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12383 |
return sax->parse_error(m_lexer.get_position(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12384 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12385 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12386 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12387 |
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12388 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12389 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12390 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12391 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12392 |
// parse separator (:) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12393 |
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12394 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12395 |
return sax->parse_error(m_lexer.get_position(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12396 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12397 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12398 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12399 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12400 |
// remember we are now inside an object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12401 |
states.push_back(false); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12402 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12403 |
// parse values |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12404 |
get_token(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12405 |
continue; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12406 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12407 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12408 |
case token_type::begin_array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12409 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12410 |
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1)))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12411 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12412 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12413 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12414 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12415 |
// closing ] -> we are done |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12416 |
if (get_token() == token_type::end_array) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12417 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12418 |
if (JSON_HEDLEY_UNLIKELY(!sax->end_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12419 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12420 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12421 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12422 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12423 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12424 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12425 |
// remember we are now inside an array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12426 |
states.push_back(true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12427 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12428 |
// parse values (no need to call get_token) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12429 |
continue; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12430 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12431 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12432 |
case token_type::value_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12433 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12434 |
const auto res = m_lexer.get_number_float(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12435 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12436 |
if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12437 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12438 |
return sax->parse_error(m_lexer.get_position(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12439 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12440 |
out_of_range::create(406, concat("number overflow parsing '", m_lexer.get_token_string(), '\''), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12441 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12442 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12443 |
if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12444 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12445 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12446 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12447 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12448 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12449 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12450 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12451 |
case token_type::literal_false: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12452 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12453 |
if (JSON_HEDLEY_UNLIKELY(!sax->boolean(false))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12454 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12455 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12456 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12457 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12458 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12459 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12460 |
case token_type::literal_null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12461 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12462 |
if (JSON_HEDLEY_UNLIKELY(!sax->null())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12463 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12464 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12465 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12466 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12467 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12468 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12469 |
case token_type::literal_true: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12470 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12471 |
if (JSON_HEDLEY_UNLIKELY(!sax->boolean(true))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12472 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12473 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12474 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12475 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12476 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12477 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12478 |
case token_type::value_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12479 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12480 |
if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12481 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12482 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12483 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12484 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12485 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12486 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12487 |
case token_type::value_string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12488 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12489 |
if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12490 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12491 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12492 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12493 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12494 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12495 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12496 |
case token_type::value_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12497 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12498 |
if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12499 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12500 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12501 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12502 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12503 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12504 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12505 |
case token_type::parse_error: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12506 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12507 |
// using "uninitialized" to avoid "expected" message |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12508 |
return sax->parse_error(m_lexer.get_position(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12509 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12510 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12511 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12512 |
case token_type::end_of_input: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12513 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12514 |
if (JSON_HEDLEY_UNLIKELY(m_lexer.get_position().chars_read_total == 1)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12515 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12516 |
return sax->parse_error(m_lexer.get_position(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12517 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12518 |
parse_error::create(101, m_lexer.get_position(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12519 |
"attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12520 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12521 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12522 |
return sax->parse_error(m_lexer.get_position(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12523 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12524 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12525 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12526 |
case token_type::uninitialized: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12527 |
case token_type::end_array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12528 |
case token_type::end_object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12529 |
case token_type::name_separator: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12530 |
case token_type::value_separator: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12531 |
case token_type::literal_or_value: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12532 |
default: // the last token was unexpected |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12533 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12534 |
return sax->parse_error(m_lexer.get_position(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12535 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12536 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12537 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12538 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12539 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12540 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12541 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12542 |
skip_to_state_evaluation = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12543 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12544 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12545 |
// we reached this line after we successfully parsed a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12546 |
if (states.empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12547 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12548 |
// empty stack: we reached the end of the hierarchy: done |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12549 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12550 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12551 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12552 |
if (states.back()) // array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12553 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12554 |
// comma -> next value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12555 |
if (get_token() == token_type::value_separator) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12556 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12557 |
// parse a new value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12558 |
get_token(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12559 |
continue; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12560 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12561 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12562 |
// closing ] |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12563 |
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12564 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12565 |
if (JSON_HEDLEY_UNLIKELY(!sax->end_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12566 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12567 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12568 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12569 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12570 |
// We are done with this array. Before we can parse a |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12571 |
// new value, we need to evaluate the new state first. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12572 |
// By setting skip_to_state_evaluation to false, we |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12573 |
// are effectively jumping to the beginning of this if. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12574 |
JSON_ASSERT(!states.empty()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12575 |
states.pop_back(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12576 |
skip_to_state_evaluation = true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12577 |
continue; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12578 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12579 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12580 |
return sax->parse_error(m_lexer.get_position(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12581 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12582 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array, "array"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12583 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12584 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12585 |
// states.back() is false -> object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12586 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12587 |
// comma -> next value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12588 |
if (get_token() == token_type::value_separator) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12589 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12590 |
// parse key |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12591 |
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12592 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12593 |
return sax->parse_error(m_lexer.get_position(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12594 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12595 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12596 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12597 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12598 |
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12599 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12600 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12601 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12602 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12603 |
// parse separator (:) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12604 |
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12605 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12606 |
return sax->parse_error(m_lexer.get_position(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12607 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12608 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12609 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12610 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12611 |
// parse values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12612 |
get_token(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12613 |
continue; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12614 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12615 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12616 |
// closing } |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12617 |
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12618 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12619 |
if (JSON_HEDLEY_UNLIKELY(!sax->end_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12620 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12621 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12622 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12623 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12624 |
// We are done with this object. Before we can parse a |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12625 |
// new value, we need to evaluate the new state first. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12626 |
// By setting skip_to_state_evaluation to false, we |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12627 |
// are effectively jumping to the beginning of this if. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12628 |
JSON_ASSERT(!states.empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12629 |
states.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12630 |
skip_to_state_evaluation = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12631 |
continue; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12632 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12633 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12634 |
return sax->parse_error(m_lexer.get_position(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12635 |
m_lexer.get_token_string(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12636 |
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object, "object"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12637 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12638 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12639 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12640 |
/// get next token from lexer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12641 |
token_type get_token() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12642 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12643 |
return last_token = m_lexer.scan(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12644 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12645 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12646 |
std::string exception_message(const token_type expected, const std::string& context) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12647 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12648 |
std::string error_msg = "syntax error "; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12649 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12650 |
if (!context.empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12651 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12652 |
error_msg += concat("while parsing ", context, ' '); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12653 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12654 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12655 |
error_msg += "- "; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12656 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12657 |
if (last_token == token_type::parse_error) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12658 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12659 |
error_msg += concat(m_lexer.get_error_message(), "; last read: '", |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12660 |
m_lexer.get_token_string(), '\''); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12661 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12662 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12663 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12664 |
error_msg += concat("unexpected ", lexer_t::token_type_name(last_token)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12665 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12666 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12667 |
if (expected != token_type::uninitialized) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12668 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12669 |
error_msg += concat("; expected ", lexer_t::token_type_name(expected)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12670 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12671 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12672 |
return error_msg; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12673 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12674 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12675 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12676 |
/// callback function |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12677 |
const parser_callback_t<BasicJsonType> callback = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12678 |
/// the type of the last read token |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12679 |
token_type last_token = token_type::uninitialized; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12680 |
/// the lexer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12681 |
lexer_t m_lexer; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12682 |
/// whether to throw exceptions in case of errors |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12683 |
const bool allow_exceptions = true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12684 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12685 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12686 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12687 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12688 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12689 |
// #include <nlohmann/detail/iterators/internal_iterator.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12690 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12691 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12692 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12693 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12694 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12695 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12696 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12697 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12698 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12699 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12700 |
// #include <nlohmann/detail/abi_macros.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12701 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12702 |
// #include <nlohmann/detail/iterators/primitive_iterator.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12703 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12704 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12705 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12706 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12707 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12708 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12709 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12710 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12711 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12712 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12713 |
#include <cstddef> // ptrdiff_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12714 |
#include <limits> // numeric_limits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12715 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12716 |
// #include <nlohmann/detail/macro_scope.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12717 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12718 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12719 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12720 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12721 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12722 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12723 |
/* |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12724 |
@brief an iterator for primitive JSON types |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12725 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12726 |
This class models an iterator for primitive JSON types (boolean, number, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12727 |
string). It's only purpose is to allow the iterator/const_iterator classes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12728 |
to "iterate" over primitive values. Internally, the iterator is modeled by |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12729 |
a `difference_type` variable. Value begin_value (`0`) models the begin, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12730 |
end_value (`1`) models past the end. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12731 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12732 |
class primitive_iterator_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12733 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12734 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12735 |
using difference_type = std::ptrdiff_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12736 |
static constexpr difference_type begin_value = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12737 |
static constexpr difference_type end_value = begin_value + 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12738 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12739 |
JSON_PRIVATE_UNLESS_TESTED: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12740 |
/// iterator as signed integer type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12741 |
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12742 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12743 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12744 |
constexpr difference_type get_value() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12745 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12746 |
return m_it; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12747 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12748 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12749 |
/// set iterator to a defined beginning |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12750 |
void set_begin() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12751 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12752 |
m_it = begin_value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12753 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12754 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12755 |
/// set iterator to a defined past the end |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12756 |
void set_end() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12757 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12758 |
m_it = end_value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12759 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12760 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12761 |
/// return whether the iterator can be dereferenced |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12762 |
constexpr bool is_begin() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12763 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12764 |
return m_it == begin_value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12765 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12766 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12767 |
/// return whether the iterator is at end |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12768 |
constexpr bool is_end() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12769 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12770 |
return m_it == end_value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12771 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12772 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12773 |
friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12774 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12775 |
return lhs.m_it == rhs.m_it; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12776 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12777 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12778 |
friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12779 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12780 |
return lhs.m_it < rhs.m_it; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12781 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12782 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12783 |
primitive_iterator_t operator+(difference_type n) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12784 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12785 |
auto result = *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12786 |
result += n; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12787 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12788 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12789 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12790 |
friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12791 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12792 |
return lhs.m_it - rhs.m_it; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12793 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12794 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12795 |
primitive_iterator_t& operator++() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12796 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12797 |
++m_it; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12798 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12799 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12800 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12801 |
primitive_iterator_t operator++(int)& noexcept // NOLINT(cert-dcl21-cpp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12802 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12803 |
auto result = *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12804 |
++m_it; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12805 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12806 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12807 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12808 |
primitive_iterator_t& operator--() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12809 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12810 |
--m_it; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12811 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12812 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12813 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12814 |
primitive_iterator_t operator--(int)& noexcept // NOLINT(cert-dcl21-cpp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12815 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12816 |
auto result = *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12817 |
--m_it; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12818 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12819 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12820 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12821 |
primitive_iterator_t& operator+=(difference_type n) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12822 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12823 |
m_it += n; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12824 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12825 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12826 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12827 |
primitive_iterator_t& operator-=(difference_type n) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12828 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12829 |
m_it -= n; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12830 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12831 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12832 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12833 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12834 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12835 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12836 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12837 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12838 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12839 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12840 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12841 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12842 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12843 |
@brief an iterator value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12844 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12845 |
@note This structure could easily be a union, but MSVC currently does not allow |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12846 |
unions members with complex constructors, see https://github.com/nlohmann/json/pull/105. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12847 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12848 |
template<typename BasicJsonType> struct internal_iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12849 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12850 |
/// iterator for JSON objects |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12851 |
typename BasicJsonType::object_t::iterator object_iterator {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12852 |
/// iterator for JSON arrays |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12853 |
typename BasicJsonType::array_t::iterator array_iterator {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12854 |
/// generic iterator for all other types |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12855 |
primitive_iterator_t primitive_iterator {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12856 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12857 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12858 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12859 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12860 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12861 |
// #include <nlohmann/detail/iterators/iter_impl.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12862 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12863 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12864 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12865 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12866 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12867 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12868 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12869 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12870 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12871 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12872 |
#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12873 |
#include <type_traits> // conditional, is_const, remove_const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12874 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12875 |
// #include <nlohmann/detail/exceptions.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12876 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12877 |
// #include <nlohmann/detail/iterators/internal_iterator.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12878 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12879 |
// #include <nlohmann/detail/iterators/primitive_iterator.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12880 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12881 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12882 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12883 |
// #include <nlohmann/detail/meta/cpp_future.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12884 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12885 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12886 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12887 |
// #include <nlohmann/detail/value_t.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12888 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12889 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12890 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12891 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12892 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12893 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12894 |
// forward declare, to be able to friend it later on |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12895 |
template<typename IteratorType> class iteration_proxy; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12896 |
template<typename IteratorType> class iteration_proxy_value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12897 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12898 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12899 |
@brief a template for a bidirectional iterator for the @ref basic_json class |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12900 |
This class implements a both iterators (iterator and const_iterator) for the |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12901 |
@ref basic_json class. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12902 |
@note An iterator is called *initialized* when a pointer to a JSON value has |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12903 |
been set (e.g., by a constructor or a copy assignment). If the iterator is |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12904 |
default-constructed, it is *uninitialized* and most methods are undefined. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12905 |
**The library uses assertions to detect calls on uninitialized iterators.** |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12906 |
@requirement The class satisfies the following concept requirements: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12907 |
- |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12908 |
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator): |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12909 |
The iterator that can be moved can be moved in both directions (i.e. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12910 |
incremented and decremented). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12911 |
@since version 1.0.0, simplified in version 2.0.9, change to bidirectional |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12912 |
iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12913 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12914 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12915 |
class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12916 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12917 |
/// the iterator with BasicJsonType of different const-ness |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12918 |
using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12919 |
/// allow basic_json to access private members |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12920 |
friend other_iter_impl; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12921 |
friend BasicJsonType; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12922 |
friend iteration_proxy<iter_impl>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12923 |
friend iteration_proxy_value<iter_impl>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12924 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12925 |
using object_t = typename BasicJsonType::object_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12926 |
using array_t = typename BasicJsonType::array_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12927 |
// make sure BasicJsonType is basic_json or const basic_json |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12928 |
static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12929 |
"iter_impl only accepts (const) basic_json"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12930 |
// superficial check for the LegacyBidirectionalIterator named requirement |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12931 |
static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12932 |
&& std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12933 |
"basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement."); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12934 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12935 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12936 |
/// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12937 |
/// The C++ Standard has never required user-defined iterators to derive from std::iterator. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12938 |
/// A user-defined iterator should provide publicly accessible typedefs named |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12939 |
/// iterator_category, value_type, difference_type, pointer, and reference. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12940 |
/// Note that value_type is required to be non-const, even for constant iterators. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12941 |
using iterator_category = std::bidirectional_iterator_tag; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12942 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12943 |
/// the type of the values when the iterator is dereferenced |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12944 |
using value_type = typename BasicJsonType::value_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12945 |
/// a type to represent differences between iterators |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12946 |
using difference_type = typename BasicJsonType::difference_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12947 |
/// defines a pointer to the type iterated over (value_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12948 |
using pointer = typename std::conditional<std::is_const<BasicJsonType>::value, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12949 |
typename BasicJsonType::const_pointer, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12950 |
typename BasicJsonType::pointer>::type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12951 |
/// defines a reference to the type iterated over (value_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12952 |
using reference = |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12953 |
typename std::conditional<std::is_const<BasicJsonType>::value, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12954 |
typename BasicJsonType::const_reference, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12955 |
typename BasicJsonType::reference>::type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12956 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12957 |
iter_impl() = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12958 |
~iter_impl() = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12959 |
iter_impl(iter_impl&&) noexcept = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12960 |
iter_impl& operator=(iter_impl&&) noexcept = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12961 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12962 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12963 |
@brief constructor for a given JSON instance |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12964 |
@param[in] object pointer to a JSON object for this iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12965 |
@pre object != nullptr |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12966 |
@post The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12967 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12968 |
explicit iter_impl(pointer object) noexcept : m_object(object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12969 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12970 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12971 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12972 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12973 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12974 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12975 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12976 |
m_it.object_iterator = typename object_t::iterator(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12977 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12978 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12979 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12980 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12981 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12982 |
m_it.array_iterator = typename array_t::iterator(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12983 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12984 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12985 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12986 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12987 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12988 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12989 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12990 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12991 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12992 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
12993 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12994 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12995 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12996 |
m_it.primitive_iterator = primitive_iterator_t(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12997 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12998 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
12999 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13000 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13001 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13002 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13003 |
@note The conventional copy constructor and copy assignment are implicitly |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13004 |
defined. Combined with the following converting constructor and |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13005 |
assignment, they support: (1) copy from iterator to iterator, (2) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13006 |
copy from const iterator to const iterator, and (3) conversion from |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13007 |
iterator to const iterator. However conversion from const iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13008 |
to iterator is not defined. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13009 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13010 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13011 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13012 |
@brief const copy constructor |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13013 |
@param[in] other const iterator to copy from |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13014 |
@note This copy constructor had to be defined explicitly to circumvent a bug |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13015 |
occurring on msvc v19.0 compiler (VS 2015) debug build. For more |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13016 |
information refer to: https://github.com/nlohmann/json/issues/1608 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13017 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13018 |
iter_impl(const iter_impl<const BasicJsonType>& other) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13019 |
: m_object(other.m_object), m_it(other.m_it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13020 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13021 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13022 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13023 |
@brief converting assignment |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13024 |
@param[in] other const iterator to copy from |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13025 |
@return const/non-const iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13026 |
@note It is not checked whether @a other is initialized. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13027 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13028 |
iter_impl& operator=(const iter_impl<const BasicJsonType>& other) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13029 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13030 |
if (&other != this) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13031 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13032 |
m_object = other.m_object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13033 |
m_it = other.m_it; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13034 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13035 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13036 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13037 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13038 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13039 |
@brief converting constructor |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13040 |
@param[in] other non-const iterator to copy from |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13041 |
@note It is not checked whether @a other is initialized. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13042 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13043 |
iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13044 |
: m_object(other.m_object), m_it(other.m_it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13045 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13046 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13047 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13048 |
@brief converting assignment |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13049 |
@param[in] other non-const iterator to copy from |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13050 |
@return const/non-const iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13051 |
@note It is not checked whether @a other is initialized. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13052 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13053 |
iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept // NOLINT(cert-oop54-cpp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13054 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13055 |
m_object = other.m_object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13056 |
m_it = other.m_it; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13057 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13058 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13059 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13060 |
JSON_PRIVATE_UNLESS_TESTED: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13061 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13062 |
@brief set the iterator to the first value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13063 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13064 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13065 |
void set_begin() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13066 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13067 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13068 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13069 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13070 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13071 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13072 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13073 |
m_it.object_iterator = m_object->m_data.m_value.object->begin(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13074 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13075 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13076 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13077 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13078 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13079 |
m_it.array_iterator = m_object->m_data.m_value.array->begin(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13080 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13081 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13082 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13083 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13084 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13085 |
// set to end so begin()==end() is true: null is empty |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13086 |
m_it.primitive_iterator.set_end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13087 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13088 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13089 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13090 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13091 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13092 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13093 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13094 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13095 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13096 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13097 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13098 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13099 |
m_it.primitive_iterator.set_begin(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13100 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13101 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13102 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13103 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13104 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13105 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13106 |
@brief set the iterator past the last value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13107 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13108 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13109 |
void set_end() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13110 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13111 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13112 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13113 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13114 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13115 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13116 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13117 |
m_it.object_iterator = m_object->m_data.m_value.object->end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13118 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13119 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13120 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13121 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13122 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13123 |
m_it.array_iterator = m_object->m_data.m_value.array->end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13124 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13125 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13126 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13127 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13128 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13129 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13130 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13131 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13132 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13133 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13134 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13135 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13136 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13137 |
m_it.primitive_iterator.set_end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13138 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13139 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13140 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13141 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13142 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13143 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13144 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13145 |
@brief return a reference to the value pointed to by the iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13146 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13147 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13148 |
reference operator*() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13149 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13150 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13151 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13152 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13153 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13154 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13155 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13156 |
JSON_ASSERT(m_it.object_iterator != m_object->m_data.m_value.object->end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13157 |
return m_it.object_iterator->second; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13158 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13159 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13160 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13161 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13162 |
JSON_ASSERT(m_it.array_iterator != m_object->m_data.m_value.array->end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13163 |
return *m_it.array_iterator; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13164 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13165 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13166 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13167 |
JSON_THROW(invalid_iterator::create(214, "cannot get value", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13168 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13169 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13170 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13171 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13172 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13173 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13174 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13175 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13176 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13177 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13178 |
if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13179 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13180 |
return *m_object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13181 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13182 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13183 |
JSON_THROW(invalid_iterator::create(214, "cannot get value", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13184 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13185 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13186 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13187 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13188 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13189 |
@brief dereference the iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13190 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13191 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13192 |
pointer operator->() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13193 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13194 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13195 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13196 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13197 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13198 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13199 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13200 |
JSON_ASSERT(m_it.object_iterator != m_object->m_data.m_value.object->end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13201 |
return &(m_it.object_iterator->second); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13202 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13203 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13204 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13205 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13206 |
JSON_ASSERT(m_it.array_iterator != m_object->m_data.m_value.array->end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13207 |
return &*m_it.array_iterator; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13208 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13209 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13210 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13211 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13212 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13213 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13214 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13215 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13216 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13217 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13218 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13219 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13220 |
if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13221 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13222 |
return m_object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13223 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13224 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13225 |
JSON_THROW(invalid_iterator::create(214, "cannot get value", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13226 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13227 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13228 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13229 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13230 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13231 |
@brief post-increment (it++) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13232 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13233 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13234 |
iter_impl operator++(int)& // NOLINT(cert-dcl21-cpp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13235 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13236 |
auto result = *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13237 |
++(*this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13238 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13239 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13240 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13241 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13242 |
@brief pre-increment (++it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13243 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13244 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13245 |
iter_impl& operator++() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13246 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13247 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13248 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13249 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13250 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13251 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13252 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13253 |
std::advance(m_it.object_iterator, 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13254 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13255 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13256 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13257 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13258 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13259 |
std::advance(m_it.array_iterator, 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13260 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13261 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13262 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13263 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13264 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13265 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13266 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13267 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13268 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13269 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13270 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13271 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13272 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13273 |
++m_it.primitive_iterator; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13274 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13275 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13276 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13277 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13278 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13279 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13280 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13281 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13282 |
@brief post-decrement (it--) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13283 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13284 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13285 |
iter_impl operator--(int)& // NOLINT(cert-dcl21-cpp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13286 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13287 |
auto result = *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13288 |
--(*this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13289 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13290 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13291 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13292 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13293 |
@brief pre-decrement (--it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13294 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13295 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13296 |
iter_impl& operator--() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13297 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13298 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13299 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13300 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13301 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13302 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13303 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13304 |
std::advance(m_it.object_iterator, -1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13305 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13306 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13307 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13308 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13309 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13310 |
std::advance(m_it.array_iterator, -1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13311 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13312 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13313 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13314 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13315 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13316 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13317 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13318 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13319 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13320 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13321 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13322 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13323 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13324 |
--m_it.primitive_iterator; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13325 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13326 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13327 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13328 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13329 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13330 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13331 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13332 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13333 |
@brief comparison: equal |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13334 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13335 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13336 |
template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13337 |
bool operator==(const IterImpl& other) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13338 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13339 |
// if objects are not the same, the comparison is undefined |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13340 |
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13341 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13342 |
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13343 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13344 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13345 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13346 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13347 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13348 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13349 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13350 |
return (m_it.object_iterator == other.m_it.object_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13351 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13352 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13353 |
return (m_it.array_iterator == other.m_it.array_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13354 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13355 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13356 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13357 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13358 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13359 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13360 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13361 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13362 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13363 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13364 |
return (m_it.primitive_iterator == other.m_it.primitive_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13365 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13366 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13367 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13368 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13369 |
@brief comparison: not equal |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13370 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13371 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13372 |
template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13373 |
bool operator!=(const IterImpl& other) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13374 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13375 |
return !operator==(other); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13376 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13377 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13378 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13379 |
@brief comparison: smaller |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13380 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13381 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13382 |
bool operator<(const iter_impl& other) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13383 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13384 |
// if objects are not the same, the comparison is undefined |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13385 |
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13386 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13387 |
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13388 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13389 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13390 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13391 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13392 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13393 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13394 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13395 |
JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13396 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13397 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13398 |
return (m_it.array_iterator < other.m_it.array_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13399 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13400 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13401 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13402 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13403 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13404 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13405 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13406 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13407 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13408 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13409 |
return (m_it.primitive_iterator < other.m_it.primitive_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13410 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13411 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13412 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13413 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13414 |
@brief comparison: less than or equal |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13415 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13416 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13417 |
bool operator<=(const iter_impl& other) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13418 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13419 |
return !other.operator < (*this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13420 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13421 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13422 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13423 |
@brief comparison: greater than |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13424 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13425 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13426 |
bool operator>(const iter_impl& other) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13427 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13428 |
return !operator<=(other); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13429 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13430 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13431 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13432 |
@brief comparison: greater than or equal |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13433 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13434 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13435 |
bool operator>=(const iter_impl& other) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13436 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13437 |
return !operator<(other); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13438 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13439 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13440 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13441 |
@brief add to iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13442 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13443 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13444 |
iter_impl& operator+=(difference_type i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13445 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13446 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13447 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13448 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13449 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13450 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13451 |
JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13452 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13453 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13454 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13455 |
std::advance(m_it.array_iterator, i); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13456 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13457 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13458 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13459 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13460 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13461 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13462 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13463 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13464 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13465 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13466 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13467 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13468 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13469 |
m_it.primitive_iterator += i; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13470 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13471 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13472 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13473 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13474 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13475 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13476 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13477 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13478 |
@brief subtract from iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13479 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13480 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13481 |
iter_impl& operator-=(difference_type i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13482 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13483 |
return operator+=(-i); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13484 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13485 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13486 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13487 |
@brief add to iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13488 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13489 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13490 |
iter_impl operator+(difference_type i) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13491 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13492 |
auto result = *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13493 |
result += i; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13494 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13495 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13496 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13497 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13498 |
@brief addition of distance and iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13499 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13500 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13501 |
friend iter_impl operator+(difference_type i, const iter_impl& it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13502 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13503 |
auto result = it; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13504 |
result += i; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13505 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13506 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13507 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13508 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13509 |
@brief subtract from iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13510 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13511 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13512 |
iter_impl operator-(difference_type i) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13513 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13514 |
auto result = *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13515 |
result -= i; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13516 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13517 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13518 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13519 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13520 |
@brief return difference |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13521 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13522 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13523 |
difference_type operator-(const iter_impl& other) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13524 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13525 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13526 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13527 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13528 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13529 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13530 |
JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13531 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13532 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13533 |
return m_it.array_iterator - other.m_it.array_iterator; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13534 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13535 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13536 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13537 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13538 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13539 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13540 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13541 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13542 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13543 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13544 |
return m_it.primitive_iterator - other.m_it.primitive_iterator; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13545 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13546 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13547 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13548 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13549 |
@brief access to successor |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13550 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13551 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13552 |
reference operator[](difference_type n) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13553 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13554 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13555 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13556 |
switch (m_object->m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13557 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13558 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13559 |
JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13560 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13561 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13562 |
return *std::next(m_it.array_iterator, n); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13563 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13564 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13565 |
JSON_THROW(invalid_iterator::create(214, "cannot get value", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13566 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13567 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13568 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13569 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13570 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13571 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13572 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13573 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13574 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13575 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13576 |
if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13577 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13578 |
return *m_object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13579 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13580 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13581 |
JSON_THROW(invalid_iterator::create(214, "cannot get value", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13582 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13583 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13584 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13585 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13586 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13587 |
@brief return the key of an object iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13588 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13589 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13590 |
const typename object_t::key_type& key() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13591 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13592 |
JSON_ASSERT(m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13593 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13594 |
if (JSON_HEDLEY_LIKELY(m_object->is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13595 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13596 |
return m_it.object_iterator->first; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13597 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13598 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13599 |
JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators", m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13600 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13601 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13602 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13603 |
@brief return the value of an iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13604 |
@pre The iterator is initialized; i.e. `m_object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13605 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13606 |
reference value() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13607 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13608 |
return operator*(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13609 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13610 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13611 |
JSON_PRIVATE_UNLESS_TESTED: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13612 |
/// associated JSON instance |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13613 |
pointer m_object = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13614 |
/// the actual iterator of the associated instance |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13615 |
internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13616 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13617 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13618 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13619 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13620 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13621 |
// #include <nlohmann/detail/iterators/iteration_proxy.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13622 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13623 |
// #include <nlohmann/detail/iterators/json_reverse_iterator.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13624 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13625 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13626 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13627 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13628 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13629 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13630 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13631 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13632 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13633 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13634 |
#include <cstddef> // ptrdiff_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13635 |
#include <iterator> // reverse_iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13636 |
#include <utility> // declval |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13637 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13638 |
// #include <nlohmann/detail/abi_macros.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13639 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13640 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13641 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13642 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13643 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13644 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13645 |
////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13646 |
// reverse_iterator // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13647 |
////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13648 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13649 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13650 |
@brief a template for a reverse iterator class |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13651 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13652 |
@tparam Base the base iterator type to reverse. Valid types are @ref |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13653 |
iterator (to create @ref reverse_iterator) and @ref const_iterator (to |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13654 |
create @ref const_reverse_iterator). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13655 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13656 |
@requirement The class satisfies the following concept requirements: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13657 |
- |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13658 |
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator): |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13659 |
The iterator that can be moved can be moved in both directions (i.e. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13660 |
incremented and decremented). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13661 |
- [OutputIterator](https://en.cppreference.com/w/cpp/named_req/OutputIterator): |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13662 |
It is possible to write to the pointed-to element (only if @a Base is |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13663 |
@ref iterator). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13664 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13665 |
@since version 1.0.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13666 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13667 |
template<typename Base> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13668 |
class json_reverse_iterator : public std::reverse_iterator<Base> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13669 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13670 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13671 |
using difference_type = std::ptrdiff_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13672 |
/// shortcut to the reverse iterator adapter |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13673 |
using base_iterator = std::reverse_iterator<Base>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13674 |
/// the reference type for the pointed-to element |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13675 |
using reference = typename Base::reference; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13676 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13677 |
/// create reverse iterator from iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13678 |
explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13679 |
: base_iterator(it) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13680 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13681 |
/// create reverse iterator from base class |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13682 |
explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13683 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13684 |
/// post-increment (it++) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13685 |
json_reverse_iterator operator++(int)& // NOLINT(cert-dcl21-cpp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13686 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13687 |
return static_cast<json_reverse_iterator>(base_iterator::operator++(1)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13688 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13689 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13690 |
/// pre-increment (++it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13691 |
json_reverse_iterator& operator++() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13692 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13693 |
return static_cast<json_reverse_iterator&>(base_iterator::operator++()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13694 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13695 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13696 |
/// post-decrement (it--) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13697 |
json_reverse_iterator operator--(int)& // NOLINT(cert-dcl21-cpp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13698 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13699 |
return static_cast<json_reverse_iterator>(base_iterator::operator--(1)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13700 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13701 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13702 |
/// pre-decrement (--it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13703 |
json_reverse_iterator& operator--() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13704 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13705 |
return static_cast<json_reverse_iterator&>(base_iterator::operator--()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13706 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13707 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13708 |
/// add to iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13709 |
json_reverse_iterator& operator+=(difference_type i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13710 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13711 |
return static_cast<json_reverse_iterator&>(base_iterator::operator+=(i)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13712 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13713 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13714 |
/// add to iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13715 |
json_reverse_iterator operator+(difference_type i) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13716 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13717 |
return static_cast<json_reverse_iterator>(base_iterator::operator+(i)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13718 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13719 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13720 |
/// subtract from iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13721 |
json_reverse_iterator operator-(difference_type i) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13722 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13723 |
return static_cast<json_reverse_iterator>(base_iterator::operator-(i)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13724 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13725 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13726 |
/// return difference |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13727 |
difference_type operator-(const json_reverse_iterator& other) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13728 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13729 |
return base_iterator(*this) - base_iterator(other); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13730 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13731 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13732 |
/// access to successor |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13733 |
reference operator[](difference_type n) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13734 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13735 |
return *(this->operator+(n)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13736 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13737 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13738 |
/// return the key of an object iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13739 |
auto key() const -> decltype(std::declval<Base>().key()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13740 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13741 |
auto it = --this->base(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13742 |
return it.key(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13743 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13744 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13745 |
/// return the value of an iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13746 |
reference value() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13747 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13748 |
auto it = --this->base(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13749 |
return it.operator * (); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13750 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13751 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13752 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13753 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13754 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13755 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13756 |
// #include <nlohmann/detail/iterators/primitive_iterator.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13757 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13758 |
// #include <nlohmann/detail/json_custom_base_class.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13759 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13760 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13761 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13762 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13763 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13764 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13765 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13766 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13767 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13768 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13769 |
#include <type_traits> // conditional, is_same |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13770 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13771 |
// #include <nlohmann/detail/abi_macros.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13772 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13773 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13774 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13775 |
namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13776 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13777 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13778 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13779 |
@brief Default base class of the @ref basic_json class. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13780 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13781 |
So that the correct implementations of the copy / move ctors / assign operators |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13782 |
of @ref basic_json do not require complex case distinctions |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13783 |
(no base class / custom base class used as customization point), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13784 |
@ref basic_json always has a base class. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13785 |
By default, this class is used because it is empty and thus has no effect |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13786 |
on the behavior of @ref basic_json. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13787 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13788 |
struct json_default_base {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13789 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13790 |
template<class T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13791 |
using json_base_class = typename std::conditional < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13792 |
std::is_same<T, void>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13793 |
json_default_base, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13794 |
T |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13795 |
>::type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13796 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13797 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13798 |
NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13799 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13800 |
// #include <nlohmann/detail/json_pointer.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13801 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13802 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13803 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13804 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13805 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13806 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13807 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13808 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13809 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13810 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13811 |
#include <algorithm> // all_of |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13812 |
#include <cctype> // isdigit |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13813 |
#include <cerrno> // errno, ERANGE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13814 |
#include <cstdlib> // strtoull |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13815 |
#ifndef JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13816 |
#include <iosfwd> // ostream |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13817 |
#endif // JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13818 |
#include <limits> // max |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13819 |
#include <numeric> // accumulate |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13820 |
#include <string> // string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13821 |
#include <utility> // move |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13822 |
#include <vector> // vector |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13823 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13824 |
// #include <nlohmann/detail/exceptions.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13825 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13826 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13827 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13828 |
// #include <nlohmann/detail/string_concat.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13829 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13830 |
// #include <nlohmann/detail/string_escape.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13831 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13832 |
// #include <nlohmann/detail/value_t.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13833 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13834 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13835 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13836 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13837 |
/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13838 |
/// @sa https://json.nlohmann.me/api/json_pointer/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13839 |
template<typename RefStringType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13840 |
class json_pointer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13841 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13842 |
// allow basic_json to access private members |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13843 |
NLOHMANN_BASIC_JSON_TPL_DECLARATION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13844 |
friend class basic_json; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13845 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13846 |
template<typename> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13847 |
friend class json_pointer; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13848 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13849 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13850 |
struct string_t_helper |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13851 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13852 |
using type = T; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13853 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13854 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13855 |
NLOHMANN_BASIC_JSON_TPL_DECLARATION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13856 |
struct string_t_helper<NLOHMANN_BASIC_JSON_TPL> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13857 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13858 |
using type = StringType; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13859 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13860 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13861 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13862 |
// for backwards compatibility accept BasicJsonType |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13863 |
using string_t = typename string_t_helper<RefStringType>::type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13864 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13865 |
/// @brief create JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13866 |
/// @sa https://json.nlohmann.me/api/json_pointer/json_pointer/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13867 |
explicit json_pointer(const string_t& s = "") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13868 |
: reference_tokens(split(s)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13869 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13870 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13871 |
/// @brief return a string representation of the JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13872 |
/// @sa https://json.nlohmann.me/api/json_pointer/to_string/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13873 |
string_t to_string() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13874 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13875 |
return std::accumulate(reference_tokens.begin(), reference_tokens.end(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13876 |
string_t{}, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13877 |
[](const string_t& a, const string_t& b) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13878 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13879 |
return detail::concat(a, '/', detail::escape(b)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13880 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13881 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13882 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13883 |
/// @brief return a string representation of the JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13884 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_string/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13885 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, to_string()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13886 |
operator string_t() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13887 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13888 |
return to_string(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13889 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13890 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13891 |
#ifndef JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13892 |
/// @brief write string representation of the JSON pointer to stream |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13893 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13894 |
friend std::ostream& operator<<(std::ostream& o, const json_pointer& ptr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13895 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13896 |
o << ptr.to_string(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13897 |
return o; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13898 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13899 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13900 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13901 |
/// @brief append another JSON pointer at the end of this JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13902 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13903 |
json_pointer& operator/=(const json_pointer& ptr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13904 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13905 |
reference_tokens.insert(reference_tokens.end(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13906 |
ptr.reference_tokens.begin(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13907 |
ptr.reference_tokens.end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13908 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13909 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13910 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13911 |
/// @brief append an unescaped reference token at the end of this JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13912 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13913 |
json_pointer& operator/=(string_t token) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13914 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13915 |
push_back(std::move(token)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13916 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13917 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13918 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13919 |
/// @brief append an array index at the end of this JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13920 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13921 |
json_pointer& operator/=(std::size_t array_idx) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13922 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13923 |
return *this /= std::to_string(array_idx); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13924 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13925 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13926 |
/// @brief create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13927 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13928 |
friend json_pointer operator/(const json_pointer& lhs, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13929 |
const json_pointer& rhs) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13930 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13931 |
return json_pointer(lhs) /= rhs; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13932 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13933 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13934 |
/// @brief create a new JSON pointer by appending the unescaped token at the end of the JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13935 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13936 |
friend json_pointer operator/(const json_pointer& lhs, string_t token) // NOLINT(performance-unnecessary-value-param) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13937 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13938 |
return json_pointer(lhs) /= std::move(token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13939 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13940 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13941 |
/// @brief create a new JSON pointer by appending the array-index-token at the end of the JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13942 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13943 |
friend json_pointer operator/(const json_pointer& lhs, std::size_t array_idx) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13944 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13945 |
return json_pointer(lhs) /= array_idx; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13946 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13947 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13948 |
/// @brief returns the parent of this JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13949 |
/// @sa https://json.nlohmann.me/api/json_pointer/parent_pointer/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13950 |
json_pointer parent_pointer() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13951 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13952 |
if (empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13953 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13954 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13955 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13956 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13957 |
json_pointer res = *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13958 |
res.pop_back(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13959 |
return res; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13960 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13961 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13962 |
/// @brief remove last reference token |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13963 |
/// @sa https://json.nlohmann.me/api/json_pointer/pop_back/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13964 |
void pop_back() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13965 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13966 |
if (JSON_HEDLEY_UNLIKELY(empty())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13967 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13968 |
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13969 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13970 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13971 |
reference_tokens.pop_back(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13972 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13973 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13974 |
/// @brief return last reference token |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13975 |
/// @sa https://json.nlohmann.me/api/json_pointer/back/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13976 |
const string_t& back() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13977 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13978 |
if (JSON_HEDLEY_UNLIKELY(empty())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13979 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13980 |
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13981 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13982 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13983 |
return reference_tokens.back(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13984 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13985 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13986 |
/// @brief append an unescaped token at the end of the reference pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13987 |
/// @sa https://json.nlohmann.me/api/json_pointer/push_back/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13988 |
void push_back(const string_t& token) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13989 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13990 |
reference_tokens.push_back(token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13991 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13992 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13993 |
/// @brief append an unescaped token at the end of the reference pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13994 |
/// @sa https://json.nlohmann.me/api/json_pointer/push_back/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
13995 |
void push_back(string_t&& token) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13996 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13997 |
reference_tokens.push_back(std::move(token)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13998 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
13999 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14000 |
/// @brief return whether pointer points to the root document |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14001 |
/// @sa https://json.nlohmann.me/api/json_pointer/empty/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14002 |
bool empty() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14003 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14004 |
return reference_tokens.empty(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14005 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14006 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14007 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14008 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14009 |
@param[in] s reference token to be converted into an array index |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14010 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14011 |
@return integer representation of @a s |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14012 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14013 |
@throw parse_error.106 if an array index begins with '0' |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14014 |
@throw parse_error.109 if an array index begins not with a digit |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14015 |
@throw out_of_range.404 if string @a s could not be converted to an integer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14016 |
@throw out_of_range.410 if an array index exceeds size_type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14017 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14018 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14019 |
static typename BasicJsonType::size_type array_index(const string_t& s) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14020 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14021 |
using size_type = typename BasicJsonType::size_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14022 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14023 |
// error condition (cf. RFC 6901, Sect. 4) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14024 |
if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0')) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14025 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14026 |
JSON_THROW(detail::parse_error::create(106, 0, detail::concat("array index '", s, "' must not begin with '0'"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14027 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14028 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14029 |
// error condition (cf. RFC 6901, Sect. 4) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14030 |
if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9'))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14031 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14032 |
JSON_THROW(detail::parse_error::create(109, 0, detail::concat("array index '", s, "' is not a number"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14033 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14034 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14035 |
const char* p = s.c_str(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14036 |
char* p_end = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14037 |
errno = 0; // strtoull doesn't reset errno |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14038 |
const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14039 |
if (p == p_end // invalid input or empty string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14040 |
|| errno == ERANGE // out of range |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14041 |
|| JSON_HEDLEY_UNLIKELY(static_cast<std::size_t>(p_end - p) != s.size())) // incomplete read |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14042 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14043 |
JSON_THROW(detail::out_of_range::create(404, detail::concat("unresolved reference token '", s, "'"), nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14044 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14045 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14046 |
// only triggered on special platforms (like 32bit), see also |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14047 |
// https://github.com/nlohmann/json/pull/2203 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14048 |
if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)())) // NOLINT(runtime/int) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14049 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14050 |
JSON_THROW(detail::out_of_range::create(410, detail::concat("array index ", s, " exceeds size_type"), nullptr)); // LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14051 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14052 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14053 |
return static_cast<size_type>(res); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14054 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14055 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14056 |
JSON_PRIVATE_UNLESS_TESTED: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14057 |
json_pointer top() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14058 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14059 |
if (JSON_HEDLEY_UNLIKELY(empty())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14060 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14061 |
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14062 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14063 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14064 |
json_pointer result = *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14065 |
result.reference_tokens = {reference_tokens[0]}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14066 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14067 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14068 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14069 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14070 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14071 |
@brief create and return a reference to the pointed to value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14072 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14073 |
@complexity Linear in the number of reference tokens. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14074 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14075 |
@throw parse_error.109 if array index is not a number |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14076 |
@throw type_error.313 if value cannot be unflattened |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14077 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14078 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14079 |
BasicJsonType& get_and_create(BasicJsonType& j) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14080 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14081 |
auto* result = &j; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14082 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14083 |
// in case no reference tokens exist, return a reference to the JSON value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14084 |
// j which will be overwritten by a primitive value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14085 |
for (const auto& reference_token : reference_tokens) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14086 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14087 |
switch (result->type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14088 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14089 |
case detail::value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14090 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14091 |
if (reference_token == "0") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14092 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14093 |
// start a new array if reference token is 0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14094 |
result = &result->operator[](0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14095 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14096 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14097 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14098 |
// start a new object otherwise |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14099 |
result = &result->operator[](reference_token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14100 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14101 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14102 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14103 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14104 |
case detail::value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14105 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14106 |
// create an entry in the object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14107 |
result = &result->operator[](reference_token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14108 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14109 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14110 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14111 |
case detail::value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14112 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14113 |
// create an entry in the array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14114 |
result = &result->operator[](array_index<BasicJsonType>(reference_token)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14115 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14116 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14117 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14118 |
/* |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14119 |
The following code is only reached if there exists a reference |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14120 |
token _and_ the current value is primitive. In this case, we have |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14121 |
an error situation, because primitive values may only occur as |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14122 |
single value; that is, with an empty list of reference tokens. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14123 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14124 |
case detail::value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14125 |
case detail::value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14126 |
case detail::value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14127 |
case detail::value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14128 |
case detail::value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14129 |
case detail::value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14130 |
case detail::value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14131 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14132 |
JSON_THROW(detail::type_error::create(313, "invalid value to unflatten", &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14133 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14134 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14135 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14136 |
return *result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14137 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14138 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14139 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14140 |
@brief return a reference to the pointed to value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14141 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14142 |
@note This version does not throw if a value is not present, but tries to |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14143 |
create nested values instead. For instance, calling this function |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14144 |
with pointer `"/this/that"` on a null value is equivalent to calling |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14145 |
`operator[]("this").operator[]("that")` on that value, effectively |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14146 |
changing the null value to an object. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14147 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14148 |
@param[in] ptr a JSON value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14149 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14150 |
@return reference to the JSON value pointed to by the JSON pointer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14151 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14152 |
@complexity Linear in the length of the JSON pointer. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14153 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14154 |
@throw parse_error.106 if an array index begins with '0' |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14155 |
@throw parse_error.109 if an array index was not a number |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14156 |
@throw out_of_range.404 if the JSON pointer can not be resolved |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14157 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14158 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14159 |
BasicJsonType& get_unchecked(BasicJsonType* ptr) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14160 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14161 |
for (const auto& reference_token : reference_tokens) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14162 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14163 |
// convert null values to arrays or objects before continuing |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14164 |
if (ptr->is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14165 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14166 |
// check if reference token is a number |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14167 |
const bool nums = |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14168 |
std::all_of(reference_token.begin(), reference_token.end(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14169 |
[](const unsigned char x) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14170 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14171 |
return std::isdigit(x); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14172 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14173 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14174 |
// change value to array for numbers or "-" or to object otherwise |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14175 |
*ptr = (nums || reference_token == "-") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14176 |
? detail::value_t::array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14177 |
: detail::value_t::object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14178 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14179 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14180 |
switch (ptr->type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14181 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14182 |
case detail::value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14183 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14184 |
// use unchecked object access |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14185 |
ptr = &ptr->operator[](reference_token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14186 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14187 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14188 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14189 |
case detail::value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14190 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14191 |
if (reference_token == "-") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14192 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14193 |
// explicitly treat "-" as index beyond the end |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14194 |
ptr = &ptr->operator[](ptr->m_data.m_value.array->size()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14195 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14196 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14197 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14198 |
// convert array index to number; unchecked access |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14199 |
ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14200 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14201 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14202 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14203 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14204 |
case detail::value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14205 |
case detail::value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14206 |
case detail::value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14207 |
case detail::value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14208 |
case detail::value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14209 |
case detail::value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14210 |
case detail::value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14211 |
case detail::value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14212 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14213 |
JSON_THROW(detail::out_of_range::create(404, detail::concat("unresolved reference token '", reference_token, "'"), ptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14214 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14215 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14216 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14217 |
return *ptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14218 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14219 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14220 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14221 |
@throw parse_error.106 if an array index begins with '0' |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14222 |
@throw parse_error.109 if an array index was not a number |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14223 |
@throw out_of_range.402 if the array index '-' is used |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14224 |
@throw out_of_range.404 if the JSON pointer can not be resolved |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14225 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14226 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14227 |
BasicJsonType& get_checked(BasicJsonType* ptr) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14228 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14229 |
for (const auto& reference_token : reference_tokens) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14230 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14231 |
switch (ptr->type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14232 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14233 |
case detail::value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14234 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14235 |
// note: at performs range check |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14236 |
ptr = &ptr->at(reference_token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14237 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14238 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14239 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14240 |
case detail::value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14241 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14242 |
if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14243 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14244 |
// "-" always fails the range check |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14245 |
JSON_THROW(detail::out_of_range::create(402, detail::concat( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14246 |
"array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14247 |
") is out of range"), ptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14248 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14249 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14250 |
// note: at performs range check |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14251 |
ptr = &ptr->at(array_index<BasicJsonType>(reference_token)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14252 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14253 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14254 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14255 |
case detail::value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14256 |
case detail::value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14257 |
case detail::value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14258 |
case detail::value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14259 |
case detail::value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14260 |
case detail::value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14261 |
case detail::value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14262 |
case detail::value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14263 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14264 |
JSON_THROW(detail::out_of_range::create(404, detail::concat("unresolved reference token '", reference_token, "'"), ptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14265 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14266 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14267 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14268 |
return *ptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14269 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14270 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14271 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14272 |
@brief return a const reference to the pointed to value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14273 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14274 |
@param[in] ptr a JSON value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14275 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14276 |
@return const reference to the JSON value pointed to by the JSON |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14277 |
pointer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14278 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14279 |
@throw parse_error.106 if an array index begins with '0' |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14280 |
@throw parse_error.109 if an array index was not a number |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14281 |
@throw out_of_range.402 if the array index '-' is used |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14282 |
@throw out_of_range.404 if the JSON pointer can not be resolved |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14283 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14284 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14285 |
const BasicJsonType& get_unchecked(const BasicJsonType* ptr) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14286 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14287 |
for (const auto& reference_token : reference_tokens) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14288 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14289 |
switch (ptr->type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14290 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14291 |
case detail::value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14292 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14293 |
// use unchecked object access |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14294 |
ptr = &ptr->operator[](reference_token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14295 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14296 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14297 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14298 |
case detail::value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14299 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14300 |
if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14301 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14302 |
// "-" cannot be used for const access |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14303 |
JSON_THROW(detail::out_of_range::create(402, detail::concat("array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), ") is out of range"), ptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14304 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14305 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14306 |
// use unchecked array access |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14307 |
ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14308 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14309 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14310 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14311 |
case detail::value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14312 |
case detail::value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14313 |
case detail::value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14314 |
case detail::value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14315 |
case detail::value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14316 |
case detail::value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14317 |
case detail::value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14318 |
case detail::value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14319 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14320 |
JSON_THROW(detail::out_of_range::create(404, detail::concat("unresolved reference token '", reference_token, "'"), ptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14321 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14322 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14323 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14324 |
return *ptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14325 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14326 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14327 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14328 |
@throw parse_error.106 if an array index begins with '0' |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14329 |
@throw parse_error.109 if an array index was not a number |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14330 |
@throw out_of_range.402 if the array index '-' is used |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14331 |
@throw out_of_range.404 if the JSON pointer can not be resolved |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14332 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14333 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14334 |
const BasicJsonType& get_checked(const BasicJsonType* ptr) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14335 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14336 |
for (const auto& reference_token : reference_tokens) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14337 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14338 |
switch (ptr->type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14339 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14340 |
case detail::value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14341 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14342 |
// note: at performs range check |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14343 |
ptr = &ptr->at(reference_token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14344 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14345 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14346 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14347 |
case detail::value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14348 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14349 |
if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14350 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14351 |
// "-" always fails the range check |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14352 |
JSON_THROW(detail::out_of_range::create(402, detail::concat( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14353 |
"array index '-' (", std::to_string(ptr->m_data.m_value.array->size()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14354 |
") is out of range"), ptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14355 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14356 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14357 |
// note: at performs range check |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14358 |
ptr = &ptr->at(array_index<BasicJsonType>(reference_token)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14359 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14360 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14361 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14362 |
case detail::value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14363 |
case detail::value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14364 |
case detail::value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14365 |
case detail::value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14366 |
case detail::value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14367 |
case detail::value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14368 |
case detail::value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14369 |
case detail::value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14370 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14371 |
JSON_THROW(detail::out_of_range::create(404, detail::concat("unresolved reference token '", reference_token, "'"), ptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14372 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14373 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14374 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14375 |
return *ptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14376 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14377 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14378 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14379 |
@throw parse_error.106 if an array index begins with '0' |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14380 |
@throw parse_error.109 if an array index was not a number |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14381 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14382 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14383 |
bool contains(const BasicJsonType* ptr) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14384 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14385 |
for (const auto& reference_token : reference_tokens) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14386 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14387 |
switch (ptr->type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14388 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14389 |
case detail::value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14390 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14391 |
if (!ptr->contains(reference_token)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14392 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14393 |
// we did not find the key in the object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14394 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14395 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14396 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14397 |
ptr = &ptr->operator[](reference_token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14398 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14399 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14400 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14401 |
case detail::value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14402 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14403 |
if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14404 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14405 |
// "-" always fails the range check |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14406 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14407 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14408 |
if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !("0" <= reference_token && reference_token <= "9"))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14409 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14410 |
// invalid char |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14411 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14412 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14413 |
if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14414 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14415 |
if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9'))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14416 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14417 |
// first char should be between '1' and '9' |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14418 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14419 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14420 |
for (std::size_t i = 1; i < reference_token.size(); i++) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14421 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14422 |
if (JSON_HEDLEY_UNLIKELY(!('0' <= reference_token[i] && reference_token[i] <= '9'))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14423 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14424 |
// other char should be between '0' and '9' |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14425 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14426 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14427 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14428 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14429 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14430 |
const auto idx = array_index<BasicJsonType>(reference_token); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14431 |
if (idx >= ptr->size()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14432 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14433 |
// index out of range |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14434 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14435 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14436 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14437 |
ptr = &ptr->operator[](idx); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14438 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14439 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14440 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14441 |
case detail::value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14442 |
case detail::value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14443 |
case detail::value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14444 |
case detail::value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14445 |
case detail::value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14446 |
case detail::value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14447 |
case detail::value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14448 |
case detail::value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14449 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14450 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14451 |
// we do not expect primitive values if there is still a |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14452 |
// reference token to process |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14453 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14454 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14455 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14456 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14457 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14458 |
// no reference token left means we found a primitive value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14459 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14460 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14461 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14462 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14463 |
@brief split the string input to reference tokens |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14464 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14465 |
@note This function is only called by the json_pointer constructor. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14466 |
All exceptions below are documented there. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14467 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14468 |
@throw parse_error.107 if the pointer is not empty or begins with '/' |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14469 |
@throw parse_error.108 if character '~' is not followed by '0' or '1' |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14470 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14471 |
static std::vector<string_t> split(const string_t& reference_string) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14472 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14473 |
std::vector<string_t> result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14474 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14475 |
// special case: empty reference string -> no reference tokens |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14476 |
if (reference_string.empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14477 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14478 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14479 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14480 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14481 |
// check if nonempty reference string begins with slash |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14482 |
if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/')) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14483 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14484 |
JSON_THROW(detail::parse_error::create(107, 1, detail::concat("JSON pointer must be empty or begin with '/' - was: '", reference_string, "'"), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14485 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14486 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14487 |
// extract the reference tokens: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14488 |
// - slash: position of the last read slash (or end of string) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14489 |
// - start: position after the previous slash |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14490 |
for ( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14491 |
// search for the first slash after the first character |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14492 |
std::size_t slash = reference_string.find_first_of('/', 1), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14493 |
// set the beginning of the first reference token |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14494 |
start = 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14495 |
// we can stop if start == 0 (if slash == string_t::npos) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14496 |
start != 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14497 |
// set the beginning of the next reference token |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14498 |
// (will eventually be 0 if slash == string_t::npos) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14499 |
start = (slash == string_t::npos) ? 0 : slash + 1, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14500 |
// find next slash |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14501 |
slash = reference_string.find_first_of('/', start)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14502 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14503 |
// use the text between the beginning of the reference token |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14504 |
// (start) and the last slash (slash). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14505 |
auto reference_token = reference_string.substr(start, slash - start); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14506 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14507 |
// check reference tokens are properly escaped |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14508 |
for (std::size_t pos = reference_token.find_first_of('~'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14509 |
pos != string_t::npos; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14510 |
pos = reference_token.find_first_of('~', pos + 1)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14511 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14512 |
JSON_ASSERT(reference_token[pos] == '~'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14513 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14514 |
// ~ must be followed by 0 or 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14515 |
if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14516 |
(reference_token[pos + 1] != '0' && |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14517 |
reference_token[pos + 1] != '1'))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14518 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14519 |
JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14520 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14521 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14522 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14523 |
// finally, store the reference token |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14524 |
detail::unescape(reference_token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14525 |
result.push_back(reference_token); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14526 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14527 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14528 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14529 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14530 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14531 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14532 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14533 |
@param[in] reference_string the reference string to the current value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14534 |
@param[in] value the value to consider |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14535 |
@param[in,out] result the result object to insert values to |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14536 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14537 |
@note Empty objects or arrays are flattened to `null`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14538 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14539 |
template<typename BasicJsonType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14540 |
static void flatten(const string_t& reference_string, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14541 |
const BasicJsonType& value, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14542 |
BasicJsonType& result) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14543 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14544 |
switch (value.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14545 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14546 |
case detail::value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14547 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14548 |
if (value.m_data.m_value.array->empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14549 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14550 |
// flatten empty array as null |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14551 |
result[reference_string] = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14552 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14553 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14554 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14555 |
// iterate array and use index as reference string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14556 |
for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14557 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14558 |
flatten(detail::concat(reference_string, '/', std::to_string(i)), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14559 |
value.m_data.m_value.array->operator[](i), result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14560 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14561 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14562 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14563 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14564 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14565 |
case detail::value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14566 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14567 |
if (value.m_data.m_value.object->empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14568 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14569 |
// flatten empty object as null |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14570 |
result[reference_string] = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14571 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14572 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14573 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14574 |
// iterate object and use keys as reference string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14575 |
for (const auto& element : *value.m_data.m_value.object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14576 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14577 |
flatten(detail::concat(reference_string, '/', detail::escape(element.first)), element.second, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14578 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14579 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14580 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14581 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14582 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14583 |
case detail::value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14584 |
case detail::value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14585 |
case detail::value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14586 |
case detail::value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14587 |
case detail::value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14588 |
case detail::value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14589 |
case detail::value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14590 |
case detail::value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14591 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14592 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14593 |
// add primitive value with its reference string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14594 |
result[reference_string] = value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14595 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14596 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14597 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14598 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14599 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14600 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14601 |
@param[in] value flattened JSON |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14602 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14603 |
@return unflattened JSON |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14604 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14605 |
@throw parse_error.109 if array index is not a number |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14606 |
@throw type_error.314 if value is not an object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14607 |
@throw type_error.315 if object values are not primitive |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14608 |
@throw type_error.313 if value cannot be unflattened |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14609 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14610 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14611 |
static BasicJsonType |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14612 |
unflatten(const BasicJsonType& value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14613 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14614 |
if (JSON_HEDLEY_UNLIKELY(!value.is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14615 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14616 |
JSON_THROW(detail::type_error::create(314, "only objects can be unflattened", &value)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14617 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14618 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14619 |
BasicJsonType result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14620 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14621 |
// iterate the JSON object values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14622 |
for (const auto& element : *value.m_data.m_value.object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14623 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14624 |
if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14625 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14626 |
JSON_THROW(detail::type_error::create(315, "values in object must be primitive", &element.second)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14627 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14628 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14629 |
// assign value to reference pointed to by JSON pointer; Note that if |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14630 |
// the JSON pointer is "" (i.e., points to the whole value), function |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14631 |
// get_and_create returns a reference to result itself. An assignment |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14632 |
// will then create a primitive value. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14633 |
json_pointer(element.first).get_and_create(result) = element.second; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14634 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14635 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14636 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14637 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14638 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14639 |
// can't use conversion operator because of ambiguity |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14640 |
json_pointer<string_t> convert() const& |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14641 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14642 |
json_pointer<string_t> result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14643 |
result.reference_tokens = reference_tokens; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14644 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14645 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14646 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14647 |
json_pointer<string_t> convert()&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14648 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14649 |
json_pointer<string_t> result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14650 |
result.reference_tokens = std::move(reference_tokens); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14651 |
return result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14652 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14653 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14654 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14655 |
#if JSON_HAS_THREE_WAY_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14656 |
/// @brief compares two JSON pointers for equality |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14657 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14658 |
template<typename RefStringTypeRhs> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14659 |
bool operator==(const json_pointer<RefStringTypeRhs>& rhs) const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14660 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14661 |
return reference_tokens == rhs.reference_tokens; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14662 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14663 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14664 |
/// @brief compares JSON pointer and string for equality |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14665 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14666 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14667 |
bool operator==(const string_t& rhs) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14668 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14669 |
return *this == json_pointer(rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14670 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14671 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14672 |
/// @brief 3-way compares two JSON pointers |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14673 |
template<typename RefStringTypeRhs> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14674 |
std::strong_ordering operator<=>(const json_pointer<RefStringTypeRhs>& rhs) const noexcept // *NOPAD* |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14675 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14676 |
return reference_tokens <=> rhs.reference_tokens; // *NOPAD* |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14677 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14678 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14679 |
/// @brief compares two JSON pointers for equality |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14680 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14681 |
template<typename RefStringTypeLhs, typename RefStringTypeRhs> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14682 |
// NOLINTNEXTLINE(readability-redundant-declaration) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14683 |
friend bool operator==(const json_pointer<RefStringTypeLhs>& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14684 |
const json_pointer<RefStringTypeRhs>& rhs) noexcept; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14685 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14686 |
/// @brief compares JSON pointer and string for equality |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14687 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14688 |
template<typename RefStringTypeLhs, typename StringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14689 |
// NOLINTNEXTLINE(readability-redundant-declaration) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14690 |
friend bool operator==(const json_pointer<RefStringTypeLhs>& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14691 |
const StringType& rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14692 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14693 |
/// @brief compares string and JSON pointer for equality |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14694 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14695 |
template<typename RefStringTypeRhs, typename StringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14696 |
// NOLINTNEXTLINE(readability-redundant-declaration) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14697 |
friend bool operator==(const StringType& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14698 |
const json_pointer<RefStringTypeRhs>& rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14699 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14700 |
/// @brief compares two JSON pointers for inequality |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14701 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14702 |
template<typename RefStringTypeLhs, typename RefStringTypeRhs> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14703 |
// NOLINTNEXTLINE(readability-redundant-declaration) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14704 |
friend bool operator!=(const json_pointer<RefStringTypeLhs>& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14705 |
const json_pointer<RefStringTypeRhs>& rhs) noexcept; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14706 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14707 |
/// @brief compares JSON pointer and string for inequality |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14708 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14709 |
template<typename RefStringTypeLhs, typename StringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14710 |
// NOLINTNEXTLINE(readability-redundant-declaration) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14711 |
friend bool operator!=(const json_pointer<RefStringTypeLhs>& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14712 |
const StringType& rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14713 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14714 |
/// @brief compares string and JSON pointer for inequality |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14715 |
/// @sa https://json.nlohmann.me/api/json_pointer/operator_ne/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14716 |
template<typename RefStringTypeRhs, typename StringType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14717 |
// NOLINTNEXTLINE(readability-redundant-declaration) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14718 |
friend bool operator!=(const StringType& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14719 |
const json_pointer<RefStringTypeRhs>& rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14720 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14721 |
/// @brief compares two JSON pointer for less-than |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14722 |
template<typename RefStringTypeLhs, typename RefStringTypeRhs> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14723 |
// NOLINTNEXTLINE(readability-redundant-declaration) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14724 |
friend bool operator<(const json_pointer<RefStringTypeLhs>& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14725 |
const json_pointer<RefStringTypeRhs>& rhs) noexcept; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14726 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14727 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14728 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14729 |
/// the reference tokens |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14730 |
std::vector<string_t> reference_tokens; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14731 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14732 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14733 |
#if !JSON_HAS_THREE_WAY_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14734 |
// functions cannot be defined inside class due to ODR violations |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14735 |
template<typename RefStringTypeLhs, typename RefStringTypeRhs> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14736 |
inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14737 |
const json_pointer<RefStringTypeRhs>& rhs) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14738 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14739 |
return lhs.reference_tokens == rhs.reference_tokens; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14740 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14741 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14742 |
template<typename RefStringTypeLhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14743 |
typename StringType = typename json_pointer<RefStringTypeLhs>::string_t> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14744 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14745 |
inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14746 |
const StringType& rhs) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14747 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14748 |
return lhs == json_pointer<RefStringTypeLhs>(rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14749 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14750 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14751 |
template<typename RefStringTypeRhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14752 |
typename StringType = typename json_pointer<RefStringTypeRhs>::string_t> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14753 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator==(json_pointer, json_pointer)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14754 |
inline bool operator==(const StringType& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14755 |
const json_pointer<RefStringTypeRhs>& rhs) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14756 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14757 |
return json_pointer<RefStringTypeRhs>(lhs) == rhs; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14758 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14759 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14760 |
template<typename RefStringTypeLhs, typename RefStringTypeRhs> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14761 |
inline bool operator!=(const json_pointer<RefStringTypeLhs>& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14762 |
const json_pointer<RefStringTypeRhs>& rhs) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14763 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14764 |
return !(lhs == rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14765 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14766 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14767 |
template<typename RefStringTypeLhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14768 |
typename StringType = typename json_pointer<RefStringTypeLhs>::string_t> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14769 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14770 |
inline bool operator!=(const json_pointer<RefStringTypeLhs>& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14771 |
const StringType& rhs) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14772 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14773 |
return !(lhs == rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14774 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14775 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14776 |
template<typename RefStringTypeRhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14777 |
typename StringType = typename json_pointer<RefStringTypeRhs>::string_t> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14778 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.2, operator!=(json_pointer, json_pointer)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14779 |
inline bool operator!=(const StringType& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14780 |
const json_pointer<RefStringTypeRhs>& rhs) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14781 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14782 |
return !(lhs == rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14783 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14784 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14785 |
template<typename RefStringTypeLhs, typename RefStringTypeRhs> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14786 |
inline bool operator<(const json_pointer<RefStringTypeLhs>& lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14787 |
const json_pointer<RefStringTypeRhs>& rhs) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14788 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14789 |
return lhs.reference_tokens < rhs.reference_tokens; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14790 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14791 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14792 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14793 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14794 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14795 |
// #include <nlohmann/detail/json_ref.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14796 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14797 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14798 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14799 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14800 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14801 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14802 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14803 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14804 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14805 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14806 |
#include <initializer_list> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14807 |
#include <utility> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14808 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14809 |
// #include <nlohmann/detail/abi_macros.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14810 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14811 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14812 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14813 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14814 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14815 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14816 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14817 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14818 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14819 |
class json_ref |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14820 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14821 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14822 |
using value_type = BasicJsonType; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14823 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14824 |
json_ref(value_type&& value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14825 |
: owned_value(std::move(value)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14826 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14827 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14828 |
json_ref(const value_type& value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14829 |
: value_ref(&value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14830 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14831 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14832 |
json_ref(std::initializer_list<json_ref> init) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14833 |
: owned_value(init) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14834 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14835 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14836 |
template < |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14837 |
class... Args, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14838 |
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14839 |
json_ref(Args && ... args) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14840 |
: owned_value(std::forward<Args>(args)...) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14841 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14842 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14843 |
// class should be movable only |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14844 |
json_ref(json_ref&&) noexcept = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14845 |
json_ref(const json_ref&) = delete; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14846 |
json_ref& operator=(const json_ref&) = delete; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14847 |
json_ref& operator=(json_ref&&) = delete; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14848 |
~json_ref() = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14849 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14850 |
value_type moved_or_copied() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14851 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14852 |
if (value_ref == nullptr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14853 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14854 |
return std::move(owned_value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14855 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14856 |
return *value_ref; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14857 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14858 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14859 |
value_type const& operator*() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14860 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14861 |
return value_ref ? *value_ref : owned_value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14862 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14863 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14864 |
value_type const* operator->() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14865 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14866 |
return &** this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14867 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14868 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14869 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14870 |
mutable value_type owned_value = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14871 |
value_type const* value_ref = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14872 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14873 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14874 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14875 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14876 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14877 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14878 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14879 |
// #include <nlohmann/detail/string_concat.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14880 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14881 |
// #include <nlohmann/detail/string_escape.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14882 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14883 |
// #include <nlohmann/detail/meta/cpp_future.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14884 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14885 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14886 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14887 |
// #include <nlohmann/detail/output/binary_writer.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14888 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14889 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14890 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14891 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14892 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14893 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14894 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14895 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14896 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14897 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14898 |
#include <algorithm> // reverse |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14899 |
#include <array> // array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14900 |
#include <map> // map |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14901 |
#include <cmath> // isnan, isinf |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14902 |
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14903 |
#include <cstring> // memcpy |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14904 |
#include <limits> // numeric_limits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14905 |
#include <string> // string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14906 |
#include <utility> // move |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14907 |
#include <vector> // vector |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14908 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14909 |
// #include <nlohmann/detail/input/binary_reader.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14910 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14911 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14912 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14913 |
// #include <nlohmann/detail/output/output_adapters.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14914 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14915 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14916 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14917 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14918 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14919 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14920 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14921 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14922 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14923 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14924 |
#include <algorithm> // copy |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14925 |
#include <cstddef> // size_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14926 |
#include <iterator> // back_inserter |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14927 |
#include <memory> // shared_ptr, make_shared |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14928 |
#include <string> // basic_string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14929 |
#include <vector> // vector |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14930 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14931 |
#ifndef JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14932 |
#include <ios> // streamsize |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14933 |
#include <ostream> // basic_ostream |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14934 |
#endif // JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14935 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14936 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14937 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14938 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14939 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14940 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14941 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14942 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14943 |
/// abstract output adapter interface |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14944 |
template<typename CharType> struct output_adapter_protocol |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14945 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14946 |
virtual void write_character(CharType c) = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14947 |
virtual void write_characters(const CharType* s, std::size_t length) = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14948 |
virtual ~output_adapter_protocol() = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14949 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14950 |
output_adapter_protocol() = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14951 |
output_adapter_protocol(const output_adapter_protocol&) = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14952 |
output_adapter_protocol(output_adapter_protocol&&) noexcept = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14953 |
output_adapter_protocol& operator=(const output_adapter_protocol&) = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14954 |
output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14955 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14956 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14957 |
/// a type to simplify interfaces |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14958 |
template<typename CharType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14959 |
using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14960 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14961 |
/// output adapter for byte vectors |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14962 |
template<typename CharType, typename AllocatorType = std::allocator<CharType>> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14963 |
class output_vector_adapter : public output_adapter_protocol<CharType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14964 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14965 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14966 |
explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14967 |
: v(vec) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14968 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14969 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14970 |
void write_character(CharType c) override |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14971 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14972 |
v.push_back(c); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14973 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14974 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14975 |
JSON_HEDLEY_NON_NULL(2) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14976 |
void write_characters(const CharType* s, std::size_t length) override |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14977 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14978 |
v.insert(v.end(), s, s + length); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14979 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14980 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14981 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14982 |
std::vector<CharType, AllocatorType>& v; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14983 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14984 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
14985 |
#ifndef JSON_NO_IO |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14986 |
/// output adapter for output streams |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14987 |
template<typename CharType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14988 |
class output_stream_adapter : public output_adapter_protocol<CharType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14989 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14990 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14991 |
explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14992 |
: stream(s) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14993 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14994 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14995 |
void write_character(CharType c) override |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14996 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14997 |
stream.put(c); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14998 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
14999 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15000 |
JSON_HEDLEY_NON_NULL(2) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15001 |
void write_characters(const CharType* s, std::size_t length) override |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15002 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15003 |
stream.write(s, static_cast<std::streamsize>(length)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15004 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15005 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15006 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15007 |
std::basic_ostream<CharType>& stream; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15008 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15009 |
#endif // JSON_NO_IO |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15010 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15011 |
/// output adapter for basic_string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15012 |
template<typename CharType, typename StringType = std::basic_string<CharType>> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15013 |
class output_string_adapter : public output_adapter_protocol<CharType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15014 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15015 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15016 |
explicit output_string_adapter(StringType& s) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15017 |
: str(s) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15018 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15019 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15020 |
void write_character(CharType c) override |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15021 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15022 |
str.push_back(c); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15023 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15024 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15025 |
JSON_HEDLEY_NON_NULL(2) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15026 |
void write_characters(const CharType* s, std::size_t length) override |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15027 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15028 |
str.append(s, length); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15029 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15030 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15031 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15032 |
StringType& str; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15033 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15034 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15035 |
template<typename CharType, typename StringType = std::basic_string<CharType>> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15036 |
class output_adapter |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15037 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15038 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15039 |
template<typename AllocatorType = std::allocator<CharType>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15040 |
output_adapter(std::vector<CharType, AllocatorType>& vec) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15041 |
: oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15042 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15043 |
#ifndef JSON_NO_IO |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15044 |
output_adapter(std::basic_ostream<CharType>& s) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15045 |
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15046 |
#endif // JSON_NO_IO |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15047 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15048 |
output_adapter(StringType& s) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15049 |
: oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15050 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15051 |
operator output_adapter_t<CharType>() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15052 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15053 |
return oa; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15054 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15055 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15056 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15057 |
output_adapter_t<CharType> oa = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15058 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15059 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15060 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15061 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15062 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15063 |
// #include <nlohmann/detail/string_concat.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15064 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15065 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15066 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15067 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15068 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15069 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15070 |
/////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15071 |
// binary writer // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15072 |
/////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15073 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15074 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15075 |
@brief serialization to CBOR and MessagePack values |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15076 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15077 |
template<typename BasicJsonType, typename CharType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15078 |
class binary_writer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15079 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15080 |
using string_t = typename BasicJsonType::string_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15081 |
using binary_t = typename BasicJsonType::binary_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15082 |
using number_float_t = typename BasicJsonType::number_float_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15083 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15084 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15085 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15086 |
@brief create a binary writer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15087 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15088 |
@param[in] adapter output adapter to write to |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15089 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15090 |
explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15091 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15092 |
JSON_ASSERT(oa); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15093 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15094 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15095 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15096 |
@param[in] j JSON value to serialize |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15097 |
@pre j.type() == value_t::object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15098 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15099 |
void write_bson(const BasicJsonType& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15100 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15101 |
switch (j.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15102 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15103 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15104 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15105 |
write_bson_object(*j.m_data.m_value.object); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15106 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15107 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15108 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15109 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15110 |
case value_t::array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15111 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15112 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15113 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15114 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15115 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15116 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15117 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15118 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15119 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15120 |
JSON_THROW(type_error::create(317, concat("to serialize to BSON, top-level type must be object, but is ", j.type_name()), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15121 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15122 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15123 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15124 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15125 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15126 |
@param[in] j JSON value to serialize |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15127 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15128 |
void write_cbor(const BasicJsonType& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15129 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15130 |
switch (j.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15131 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15132 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15133 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15134 |
oa->write_character(to_char_type(0xF6)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15135 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15136 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15137 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15138 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15139 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15140 |
oa->write_character(j.m_data.m_value.boolean |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15141 |
? to_char_type(0xF5) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15142 |
: to_char_type(0xF4)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15143 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15144 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15145 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15146 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15147 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15148 |
if (j.m_data.m_value.number_integer >= 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15149 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15150 |
// CBOR does not differentiate between positive signed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15151 |
// integers and unsigned integers. Therefore, we used the |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15152 |
// code from the value_t::number_unsigned case here. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15153 |
if (j.m_data.m_value.number_integer <= 0x17) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15154 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15155 |
write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15156 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15157 |
else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15158 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15159 |
oa->write_character(to_char_type(0x18)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15160 |
write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15161 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15162 |
else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15163 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15164 |
oa->write_character(to_char_type(0x19)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15165 |
write_number(static_cast<std::uint16_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15166 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15167 |
else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15168 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15169 |
oa->write_character(to_char_type(0x1A)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15170 |
write_number(static_cast<std::uint32_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15171 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15172 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15173 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15174 |
oa->write_character(to_char_type(0x1B)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15175 |
write_number(static_cast<std::uint64_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15176 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15177 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15178 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15179 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15180 |
// The conversions below encode the sign in the first |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15181 |
// byte, and the value is converted to a positive number. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15182 |
const auto positive_number = -1 - j.m_data.m_value.number_integer; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15183 |
if (j.m_data.m_value.number_integer >= -24) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15184 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15185 |
write_number(static_cast<std::uint8_t>(0x20 + positive_number)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15186 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15187 |
else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15188 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15189 |
oa->write_character(to_char_type(0x38)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15190 |
write_number(static_cast<std::uint8_t>(positive_number)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15191 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15192 |
else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15193 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15194 |
oa->write_character(to_char_type(0x39)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15195 |
write_number(static_cast<std::uint16_t>(positive_number)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15196 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15197 |
else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15198 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15199 |
oa->write_character(to_char_type(0x3A)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15200 |
write_number(static_cast<std::uint32_t>(positive_number)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15201 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15202 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15203 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15204 |
oa->write_character(to_char_type(0x3B)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15205 |
write_number(static_cast<std::uint64_t>(positive_number)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15206 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15207 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15208 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15209 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15210 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15211 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15212 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15213 |
if (j.m_data.m_value.number_unsigned <= 0x17) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15214 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15215 |
write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_unsigned)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15216 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15217 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15218 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15219 |
oa->write_character(to_char_type(0x18)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15220 |
write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_unsigned)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15221 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15222 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15223 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15224 |
oa->write_character(to_char_type(0x19)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15225 |
write_number(static_cast<std::uint16_t>(j.m_data.m_value.number_unsigned)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15226 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15227 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15228 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15229 |
oa->write_character(to_char_type(0x1A)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15230 |
write_number(static_cast<std::uint32_t>(j.m_data.m_value.number_unsigned)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15231 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15232 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15233 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15234 |
oa->write_character(to_char_type(0x1B)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15235 |
write_number(static_cast<std::uint64_t>(j.m_data.m_value.number_unsigned)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15236 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15237 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15238 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15239 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15240 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15241 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15242 |
if (std::isnan(j.m_data.m_value.number_float)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15243 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15244 |
// NaN is 0xf97e00 in CBOR |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15245 |
oa->write_character(to_char_type(0xF9)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15246 |
oa->write_character(to_char_type(0x7E)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15247 |
oa->write_character(to_char_type(0x00)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15248 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15249 |
else if (std::isinf(j.m_data.m_value.number_float)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15250 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15251 |
// Infinity is 0xf97c00, -Infinity is 0xf9fc00 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15252 |
oa->write_character(to_char_type(0xf9)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15253 |
oa->write_character(j.m_data.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15254 |
oa->write_character(to_char_type(0x00)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15255 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15256 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15257 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15258 |
write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::cbor); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15259 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15260 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15261 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15262 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15263 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15264 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15265 |
// step 1: write control byte and the string length |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15266 |
const auto N = j.m_data.m_value.string->size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15267 |
if (N <= 0x17) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15268 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15269 |
write_number(static_cast<std::uint8_t>(0x60 + N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15270 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15271 |
else if (N <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15272 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15273 |
oa->write_character(to_char_type(0x78)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15274 |
write_number(static_cast<std::uint8_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15275 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15276 |
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15277 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15278 |
oa->write_character(to_char_type(0x79)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15279 |
write_number(static_cast<std::uint16_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15280 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15281 |
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15282 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15283 |
oa->write_character(to_char_type(0x7A)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15284 |
write_number(static_cast<std::uint32_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15285 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15286 |
// LCOV_EXCL_START |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15287 |
else if (N <= (std::numeric_limits<std::uint64_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15288 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15289 |
oa->write_character(to_char_type(0x7B)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15290 |
write_number(static_cast<std::uint64_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15291 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15292 |
// LCOV_EXCL_STOP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15293 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15294 |
// step 2: write the string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15295 |
oa->write_characters( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15296 |
reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15297 |
j.m_data.m_value.string->size()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15298 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15299 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15300 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15301 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15302 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15303 |
// step 1: write control byte and the array size |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15304 |
const auto N = j.m_data.m_value.array->size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15305 |
if (N <= 0x17) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15306 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15307 |
write_number(static_cast<std::uint8_t>(0x80 + N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15308 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15309 |
else if (N <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15310 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15311 |
oa->write_character(to_char_type(0x98)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15312 |
write_number(static_cast<std::uint8_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15313 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15314 |
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15315 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15316 |
oa->write_character(to_char_type(0x99)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15317 |
write_number(static_cast<std::uint16_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15318 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15319 |
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15320 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15321 |
oa->write_character(to_char_type(0x9A)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15322 |
write_number(static_cast<std::uint32_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15323 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15324 |
// LCOV_EXCL_START |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15325 |
else if (N <= (std::numeric_limits<std::uint64_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15326 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15327 |
oa->write_character(to_char_type(0x9B)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15328 |
write_number(static_cast<std::uint64_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15329 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15330 |
// LCOV_EXCL_STOP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15331 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15332 |
// step 2: write each element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15333 |
for (const auto& el : *j.m_data.m_value.array) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15334 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15335 |
write_cbor(el); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15336 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15337 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15338 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15339 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15340 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15341 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15342 |
if (j.m_data.m_value.binary->has_subtype()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15343 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15344 |
if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15345 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15346 |
write_number(static_cast<std::uint8_t>(0xd8)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15347 |
write_number(static_cast<std::uint8_t>(j.m_data.m_value.binary->subtype())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15348 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15349 |
else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15350 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15351 |
write_number(static_cast<std::uint8_t>(0xd9)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15352 |
write_number(static_cast<std::uint16_t>(j.m_data.m_value.binary->subtype())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15353 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15354 |
else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15355 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15356 |
write_number(static_cast<std::uint8_t>(0xda)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15357 |
write_number(static_cast<std::uint32_t>(j.m_data.m_value.binary->subtype())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15358 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15359 |
else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15360 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15361 |
write_number(static_cast<std::uint8_t>(0xdb)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15362 |
write_number(static_cast<std::uint64_t>(j.m_data.m_value.binary->subtype())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15363 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15364 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15365 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15366 |
// step 1: write control byte and the binary array size |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15367 |
const auto N = j.m_data.m_value.binary->size(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15368 |
if (N <= 0x17) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15369 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15370 |
write_number(static_cast<std::uint8_t>(0x40 + N)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15371 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15372 |
else if (N <= (std::numeric_limits<std::uint8_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15373 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15374 |
oa->write_character(to_char_type(0x58)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15375 |
write_number(static_cast<std::uint8_t>(N)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15376 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15377 |
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15378 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15379 |
oa->write_character(to_char_type(0x59)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15380 |
write_number(static_cast<std::uint16_t>(N)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15381 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15382 |
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15383 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15384 |
oa->write_character(to_char_type(0x5A)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15385 |
write_number(static_cast<std::uint32_t>(N)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15386 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15387 |
// LCOV_EXCL_START |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15388 |
else if (N <= (std::numeric_limits<std::uint64_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15389 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15390 |
oa->write_character(to_char_type(0x5B)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15391 |
write_number(static_cast<std::uint64_t>(N)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15392 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15393 |
// LCOV_EXCL_STOP |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15394 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15395 |
// step 2: write each element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15396 |
oa->write_characters( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15397 |
reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15398 |
N); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15399 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15400 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15401 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15402 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15403 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15404 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15405 |
// step 1: write control byte and the object size |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15406 |
const auto N = j.m_data.m_value.object->size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15407 |
if (N <= 0x17) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15408 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15409 |
write_number(static_cast<std::uint8_t>(0xA0 + N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15410 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15411 |
else if (N <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15412 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15413 |
oa->write_character(to_char_type(0xB8)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15414 |
write_number(static_cast<std::uint8_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15415 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15416 |
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15417 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15418 |
oa->write_character(to_char_type(0xB9)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15419 |
write_number(static_cast<std::uint16_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15420 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15421 |
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15422 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15423 |
oa->write_character(to_char_type(0xBA)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15424 |
write_number(static_cast<std::uint32_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15425 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15426 |
// LCOV_EXCL_START |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15427 |
else if (N <= (std::numeric_limits<std::uint64_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15428 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15429 |
oa->write_character(to_char_type(0xBB)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15430 |
write_number(static_cast<std::uint64_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15431 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15432 |
// LCOV_EXCL_STOP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15433 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15434 |
// step 2: write each element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15435 |
for (const auto& el : *j.m_data.m_value.object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15436 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15437 |
write_cbor(el.first); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15438 |
write_cbor(el.second); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15439 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15440 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15441 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15442 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15443 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15444 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15445 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15446 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15447 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15448 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15449 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15450 |
@param[in] j JSON value to serialize |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15451 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15452 |
void write_msgpack(const BasicJsonType& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15453 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15454 |
switch (j.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15455 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15456 |
case value_t::null: // nil |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15457 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15458 |
oa->write_character(to_char_type(0xC0)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15459 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15460 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15461 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15462 |
case value_t::boolean: // true and false |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15463 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15464 |
oa->write_character(j.m_data.m_value.boolean |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15465 |
? to_char_type(0xC3) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15466 |
: to_char_type(0xC2)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15467 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15468 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15469 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15470 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15471 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15472 |
if (j.m_data.m_value.number_integer >= 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15473 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15474 |
// MessagePack does not differentiate between positive |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15475 |
// signed integers and unsigned integers. Therefore, we used |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15476 |
// the code from the value_t::number_unsigned case here. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15477 |
if (j.m_data.m_value.number_unsigned < 128) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15478 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15479 |
// positive fixnum |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15480 |
write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15481 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15482 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15483 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15484 |
// uint 8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15485 |
oa->write_character(to_char_type(0xCC)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15486 |
write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15487 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15488 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15489 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15490 |
// uint 16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15491 |
oa->write_character(to_char_type(0xCD)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15492 |
write_number(static_cast<std::uint16_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15493 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15494 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15495 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15496 |
// uint 32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15497 |
oa->write_character(to_char_type(0xCE)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15498 |
write_number(static_cast<std::uint32_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15499 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15500 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15501 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15502 |
// uint 64 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15503 |
oa->write_character(to_char_type(0xCF)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15504 |
write_number(static_cast<std::uint64_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15505 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15506 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15507 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15508 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15509 |
if (j.m_data.m_value.number_integer >= -32) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15510 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15511 |
// negative fixnum |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15512 |
write_number(static_cast<std::int8_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15513 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15514 |
else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15515 |
j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15516 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15517 |
// int 8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15518 |
oa->write_character(to_char_type(0xD0)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15519 |
write_number(static_cast<std::int8_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15520 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15521 |
else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15522 |
j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15523 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15524 |
// int 16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15525 |
oa->write_character(to_char_type(0xD1)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15526 |
write_number(static_cast<std::int16_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15527 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15528 |
else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15529 |
j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15530 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15531 |
// int 32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15532 |
oa->write_character(to_char_type(0xD2)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15533 |
write_number(static_cast<std::int32_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15534 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15535 |
else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15536 |
j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15537 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15538 |
// int 64 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15539 |
oa->write_character(to_char_type(0xD3)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15540 |
write_number(static_cast<std::int64_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15541 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15542 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15543 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15544 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15545 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15546 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15547 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15548 |
if (j.m_data.m_value.number_unsigned < 128) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15549 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15550 |
// positive fixnum |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15551 |
write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15552 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15553 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15554 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15555 |
// uint 8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15556 |
oa->write_character(to_char_type(0xCC)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15557 |
write_number(static_cast<std::uint8_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15558 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15559 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15560 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15561 |
// uint 16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15562 |
oa->write_character(to_char_type(0xCD)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15563 |
write_number(static_cast<std::uint16_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15564 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15565 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15566 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15567 |
// uint 32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15568 |
oa->write_character(to_char_type(0xCE)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15569 |
write_number(static_cast<std::uint32_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15570 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15571 |
else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15572 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15573 |
// uint 64 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15574 |
oa->write_character(to_char_type(0xCF)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15575 |
write_number(static_cast<std::uint64_t>(j.m_data.m_value.number_integer)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15576 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15577 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15578 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15579 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15580 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15581 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15582 |
write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::msgpack); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15583 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15584 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15585 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15586 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15587 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15588 |
// step 1: write control byte and the string length |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15589 |
const auto N = j.m_data.m_value.string->size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15590 |
if (N <= 31) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15591 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15592 |
// fixstr |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15593 |
write_number(static_cast<std::uint8_t>(0xA0 | N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15594 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15595 |
else if (N <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15596 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15597 |
// str 8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15598 |
oa->write_character(to_char_type(0xD9)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15599 |
write_number(static_cast<std::uint8_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15600 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15601 |
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15602 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15603 |
// str 16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15604 |
oa->write_character(to_char_type(0xDA)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15605 |
write_number(static_cast<std::uint16_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15606 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15607 |
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15608 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15609 |
// str 32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15610 |
oa->write_character(to_char_type(0xDB)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15611 |
write_number(static_cast<std::uint32_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15612 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15613 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15614 |
// step 2: write the string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15615 |
oa->write_characters( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15616 |
reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15617 |
j.m_data.m_value.string->size()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15618 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15619 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15620 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15621 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15622 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15623 |
// step 1: write control byte and the array size |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15624 |
const auto N = j.m_data.m_value.array->size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15625 |
if (N <= 15) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15626 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15627 |
// fixarray |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15628 |
write_number(static_cast<std::uint8_t>(0x90 | N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15629 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15630 |
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15631 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15632 |
// array 16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15633 |
oa->write_character(to_char_type(0xDC)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15634 |
write_number(static_cast<std::uint16_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15635 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15636 |
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15637 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15638 |
// array 32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15639 |
oa->write_character(to_char_type(0xDD)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15640 |
write_number(static_cast<std::uint32_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15641 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15642 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15643 |
// step 2: write each element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15644 |
for (const auto& el : *j.m_data.m_value.array) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15645 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15646 |
write_msgpack(el); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15647 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15648 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15649 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15650 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15651 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15652 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15653 |
// step 0: determine if the binary type has a set subtype to |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15654 |
// determine whether or not to use the ext or fixext types |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15655 |
const bool use_ext = j.m_data.m_value.binary->has_subtype(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15656 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15657 |
// step 1: write control byte and the byte string length |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15658 |
const auto N = j.m_data.m_value.binary->size(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15659 |
if (N <= (std::numeric_limits<std::uint8_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15660 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15661 |
std::uint8_t output_type{}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15662 |
bool fixed = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15663 |
if (use_ext) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15664 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15665 |
switch (N) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15666 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15667 |
case 1: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15668 |
output_type = 0xD4; // fixext 1 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15669 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15670 |
case 2: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15671 |
output_type = 0xD5; // fixext 2 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15672 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15673 |
case 4: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15674 |
output_type = 0xD6; // fixext 4 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15675 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15676 |
case 8: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15677 |
output_type = 0xD7; // fixext 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15678 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15679 |
case 16: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15680 |
output_type = 0xD8; // fixext 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15681 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15682 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15683 |
output_type = 0xC7; // ext 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15684 |
fixed = false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15685 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15686 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15687 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15688 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15689 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15690 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15691 |
output_type = 0xC4; // bin 8 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15692 |
fixed = false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15693 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15694 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15695 |
oa->write_character(to_char_type(output_type)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15696 |
if (!fixed) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15697 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15698 |
write_number(static_cast<std::uint8_t>(N)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15699 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15700 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15701 |
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15702 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15703 |
const std::uint8_t output_type = use_ext |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15704 |
? 0xC8 // ext 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15705 |
: 0xC5; // bin 16 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15706 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15707 |
oa->write_character(to_char_type(output_type)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15708 |
write_number(static_cast<std::uint16_t>(N)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15709 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15710 |
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15711 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15712 |
const std::uint8_t output_type = use_ext |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15713 |
? 0xC9 // ext 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15714 |
: 0xC6; // bin 32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15715 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15716 |
oa->write_character(to_char_type(output_type)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15717 |
write_number(static_cast<std::uint32_t>(N)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15718 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15719 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15720 |
// step 1.5: if this is an ext type, write the subtype |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15721 |
if (use_ext) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15722 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15723 |
write_number(static_cast<std::int8_t>(j.m_data.m_value.binary->subtype())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15724 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15725 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15726 |
// step 2: write the byte string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15727 |
oa->write_characters( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15728 |
reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15729 |
N); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15730 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15731 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15732 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15733 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15734 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15735 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15736 |
// step 1: write control byte and the object size |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15737 |
const auto N = j.m_data.m_value.object->size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15738 |
if (N <= 15) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15739 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15740 |
// fixmap |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15741 |
write_number(static_cast<std::uint8_t>(0x80 | (N & 0xF))); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15742 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15743 |
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15744 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15745 |
// map 16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15746 |
oa->write_character(to_char_type(0xDE)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15747 |
write_number(static_cast<std::uint16_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15748 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15749 |
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15750 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15751 |
// map 32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15752 |
oa->write_character(to_char_type(0xDF)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15753 |
write_number(static_cast<std::uint32_t>(N)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15754 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15755 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15756 |
// step 2: write each element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15757 |
for (const auto& el : *j.m_data.m_value.object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15758 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15759 |
write_msgpack(el.first); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15760 |
write_msgpack(el.second); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15761 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15762 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15763 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15764 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15765 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15766 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15767 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15768 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15769 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15770 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15771 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15772 |
@param[in] j JSON value to serialize |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15773 |
@param[in] use_count whether to use '#' prefixes (optimized format) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15774 |
@param[in] use_type whether to use '$' prefixes (optimized format) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15775 |
@param[in] add_prefix whether prefixes need to be used for this value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15776 |
@param[in] use_bjdata whether write in BJData format, default is false |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15777 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15778 |
void write_ubjson(const BasicJsonType& j, const bool use_count, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15779 |
const bool use_type, const bool add_prefix = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15780 |
const bool use_bjdata = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15781 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15782 |
switch (j.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15783 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15784 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15785 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15786 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15787 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15788 |
oa->write_character(to_char_type('Z')); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15789 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15790 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15791 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15792 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15793 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15794 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15795 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15796 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15797 |
oa->write_character(j.m_data.m_value.boolean |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15798 |
? to_char_type('T') |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15799 |
: to_char_type('F')); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15800 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15801 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15802 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15803 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15804 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15805 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15806 |
write_number_with_ubjson_prefix(j.m_data.m_value.number_integer, add_prefix, use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15807 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15808 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15809 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15810 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15811 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15812 |
write_number_with_ubjson_prefix(j.m_data.m_value.number_unsigned, add_prefix, use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15813 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15814 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15815 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15816 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15817 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15818 |
write_number_with_ubjson_prefix(j.m_data.m_value.number_float, add_prefix, use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15819 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15820 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15821 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15822 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15823 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15824 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15825 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15826 |
oa->write_character(to_char_type('S')); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15827 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15828 |
write_number_with_ubjson_prefix(j.m_data.m_value.string->size(), true, use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15829 |
oa->write_characters( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15830 |
reinterpret_cast<const CharType*>(j.m_data.m_value.string->c_str()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15831 |
j.m_data.m_value.string->size()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15832 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15833 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15834 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15835 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15836 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15837 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15838 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15839 |
oa->write_character(to_char_type('[')); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15840 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15841 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15842 |
bool prefix_required = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15843 |
if (use_type && !j.m_data.m_value.array->empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15844 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15845 |
JSON_ASSERT(use_count); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15846 |
const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15847 |
const bool same_prefix = std::all_of(j.begin() + 1, j.end(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15848 |
[this, first_prefix, use_bjdata](const BasicJsonType & v) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15849 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15850 |
return ubjson_prefix(v, use_bjdata) == first_prefix; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15851 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15852 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15853 |
std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15854 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15855 |
if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15856 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15857 |
prefix_required = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15858 |
oa->write_character(to_char_type('$')); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15859 |
oa->write_character(first_prefix); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15860 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15861 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15862 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15863 |
if (use_count) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15864 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15865 |
oa->write_character(to_char_type('#')); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15866 |
write_number_with_ubjson_prefix(j.m_data.m_value.array->size(), true, use_bjdata); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15867 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15868 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15869 |
for (const auto& el : *j.m_data.m_value.array) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15870 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15871 |
write_ubjson(el, use_count, use_type, prefix_required, use_bjdata); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15872 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15873 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15874 |
if (!use_count) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15875 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15876 |
oa->write_character(to_char_type(']')); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15877 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15878 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15879 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15880 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15881 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15882 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15883 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15884 |
if (add_prefix) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15885 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15886 |
oa->write_character(to_char_type('[')); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15887 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15888 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15889 |
if (use_type && !j.m_data.m_value.binary->empty()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15890 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15891 |
JSON_ASSERT(use_count); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15892 |
oa->write_character(to_char_type('$')); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15893 |
oa->write_character('U'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15894 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15895 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15896 |
if (use_count) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15897 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15898 |
oa->write_character(to_char_type('#')); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15899 |
write_number_with_ubjson_prefix(j.m_data.m_value.binary->size(), true, use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15900 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15901 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15902 |
if (use_type) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15903 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15904 |
oa->write_characters( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15905 |
reinterpret_cast<const CharType*>(j.m_data.m_value.binary->data()), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15906 |
j.m_data.m_value.binary->size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15907 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15908 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15909 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15910 |
for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15911 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15912 |
oa->write_character(to_char_type('U')); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15913 |
oa->write_character(j.m_data.m_value.binary->data()[i]); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15914 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15915 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15916 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15917 |
if (!use_count) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15918 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15919 |
oa->write_character(to_char_type(']')); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15920 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15921 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15922 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15923 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15924 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15925 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15926 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15927 |
if (use_bjdata && j.m_data.m_value.object->size() == 3 && j.m_data.m_value.object->find("_ArrayType_") != j.m_data.m_value.object->end() && j.m_data.m_value.object->find("_ArraySize_") != j.m_data.m_value.object->end() && j.m_data.m_value.object->find("_ArrayData_") != j.m_data.m_value.object->end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15928 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15929 |
if (!write_bjdata_ndarray(*j.m_data.m_value.object, use_count, use_type)) // decode bjdata ndarray in the JData format (https://github.com/NeuroJSON/jdata) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15930 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15931 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15932 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15933 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15934 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15935 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15936 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15937 |
oa->write_character(to_char_type('{')); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15938 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15939 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15940 |
bool prefix_required = true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15941 |
if (use_type && !j.m_data.m_value.object->empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15942 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15943 |
JSON_ASSERT(use_count); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15944 |
const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15945 |
const bool same_prefix = std::all_of(j.begin(), j.end(), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15946 |
[this, first_prefix, use_bjdata](const BasicJsonType & v) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15947 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15948 |
return ubjson_prefix(v, use_bjdata) == first_prefix; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15949 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15950 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15951 |
std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15952 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15953 |
if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15954 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15955 |
prefix_required = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15956 |
oa->write_character(to_char_type('$')); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15957 |
oa->write_character(first_prefix); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15958 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15959 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15960 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15961 |
if (use_count) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15962 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15963 |
oa->write_character(to_char_type('#')); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15964 |
write_number_with_ubjson_prefix(j.m_data.m_value.object->size(), true, use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15965 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15966 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15967 |
for (const auto& el : *j.m_data.m_value.object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15968 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15969 |
write_number_with_ubjson_prefix(el.first.size(), true, use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15970 |
oa->write_characters( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15971 |
reinterpret_cast<const CharType*>(el.first.c_str()), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15972 |
el.first.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15973 |
write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15974 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15975 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15976 |
if (!use_count) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15977 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15978 |
oa->write_character(to_char_type('}')); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15979 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15980 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15981 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15982 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15983 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15984 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15985 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15986 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15987 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15988 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15989 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15990 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15991 |
////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15992 |
// BSON // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15993 |
////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15994 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15995 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15996 |
@return The size of a BSON document entry header, including the id marker |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15997 |
and the entry name size (and its null-terminator). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
15998 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
15999 |
static std::size_t calc_bson_entry_header_size(const string_t& name, const BasicJsonType& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16000 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16001 |
const auto it = name.find(static_cast<typename string_t::value_type>(0)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16002 |
if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16003 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16004 |
JSON_THROW(out_of_range::create(409, concat("BSON key cannot contain code point U+0000 (at byte ", std::to_string(it), ")"), &j)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16005 |
static_cast<void>(j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16006 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16007 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16008 |
return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16009 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16010 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16011 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16012 |
@brief Writes the given @a element_type and @a name to the output adapter |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16013 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16014 |
void write_bson_entry_header(const string_t& name, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16015 |
const std::uint8_t element_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16016 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16017 |
oa->write_character(to_char_type(element_type)); // boolean |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16018 |
oa->write_characters( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16019 |
reinterpret_cast<const CharType*>(name.c_str()), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16020 |
name.size() + 1u); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16021 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16022 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16023 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16024 |
@brief Writes a BSON element with key @a name and boolean value @a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16025 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16026 |
void write_bson_boolean(const string_t& name, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16027 |
const bool value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16028 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16029 |
write_bson_entry_header(name, 0x08); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16030 |
oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16031 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16032 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16033 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16034 |
@brief Writes a BSON element with key @a name and double value @a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16035 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16036 |
void write_bson_double(const string_t& name, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16037 |
const double value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16038 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16039 |
write_bson_entry_header(name, 0x01); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16040 |
write_number<double>(value, true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16041 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16042 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16043 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16044 |
@return The size of the BSON-encoded string in @a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16045 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16046 |
static std::size_t calc_bson_string_size(const string_t& value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16047 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16048 |
return sizeof(std::int32_t) + value.size() + 1ul; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16049 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16050 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16051 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16052 |
@brief Writes a BSON element with key @a name and string value @a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16053 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16054 |
void write_bson_string(const string_t& name, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16055 |
const string_t& value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16056 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16057 |
write_bson_entry_header(name, 0x02); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16058 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16059 |
write_number<std::int32_t>(static_cast<std::int32_t>(value.size() + 1ul), true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16060 |
oa->write_characters( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16061 |
reinterpret_cast<const CharType*>(value.c_str()), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16062 |
value.size() + 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16063 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16064 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16065 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16066 |
@brief Writes a BSON element with key @a name and null value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16067 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16068 |
void write_bson_null(const string_t& name) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16069 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16070 |
write_bson_entry_header(name, 0x0A); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16071 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16072 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16073 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16074 |
@return The size of the BSON-encoded integer @a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16075 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16076 |
static std::size_t calc_bson_integer_size(const std::int64_t value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16077 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16078 |
return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16079 |
? sizeof(std::int32_t) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16080 |
: sizeof(std::int64_t); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16081 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16082 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16083 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16084 |
@brief Writes a BSON element with key @a name and integer @a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16085 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16086 |
void write_bson_integer(const string_t& name, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16087 |
const std::int64_t value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16088 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16089 |
if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16090 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16091 |
write_bson_entry_header(name, 0x10); // int32 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16092 |
write_number<std::int32_t>(static_cast<std::int32_t>(value), true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16093 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16094 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16095 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16096 |
write_bson_entry_header(name, 0x12); // int64 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16097 |
write_number<std::int64_t>(static_cast<std::int64_t>(value), true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16098 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16099 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16100 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16101 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16102 |
@return The size of the BSON-encoded unsigned integer in @a j |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16103 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16104 |
static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16105 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16106 |
return (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16107 |
? sizeof(std::int32_t) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16108 |
: sizeof(std::int64_t); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16109 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16110 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16111 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16112 |
@brief Writes a BSON element with key @a name and unsigned @a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16113 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16114 |
void write_bson_unsigned(const string_t& name, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16115 |
const BasicJsonType& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16116 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16117 |
if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16118 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16119 |
write_bson_entry_header(name, 0x10 /* int32 */); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16120 |
write_number<std::int32_t>(static_cast<std::int32_t>(j.m_data.m_value.number_unsigned), true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16121 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16122 |
else if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16123 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16124 |
write_bson_entry_header(name, 0x12 /* int64 */); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16125 |
write_number<std::int64_t>(static_cast<std::int64_t>(j.m_data.m_value.number_unsigned), true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16126 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16127 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16128 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16129 |
JSON_THROW(out_of_range::create(407, concat("integer number ", std::to_string(j.m_data.m_value.number_unsigned), " cannot be represented by BSON as it does not fit int64"), &j)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16130 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16131 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16132 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16133 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16134 |
@brief Writes a BSON element with key @a name and object @a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16135 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16136 |
void write_bson_object_entry(const string_t& name, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16137 |
const typename BasicJsonType::object_t& value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16138 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16139 |
write_bson_entry_header(name, 0x03); // object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16140 |
write_bson_object(value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16141 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16142 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16143 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16144 |
@return The size of the BSON-encoded array @a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16145 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16146 |
static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16147 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16148 |
std::size_t array_index = 0ul; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16149 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16150 |
const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast<std::size_t>(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16151 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16152 |
return result + calc_bson_element_size(std::to_string(array_index++), el); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16153 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16154 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16155 |
return sizeof(std::int32_t) + embedded_document_size + 1ul; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16156 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16157 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16158 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16159 |
@return The size of the BSON-encoded binary array @a value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16160 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16161 |
static std::size_t calc_bson_binary_size(const typename BasicJsonType::binary_t& value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16162 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16163 |
return sizeof(std::int32_t) + value.size() + 1ul; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16164 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16165 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16166 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16167 |
@brief Writes a BSON element with key @a name and array @a value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16168 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16169 |
void write_bson_array(const string_t& name, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16170 |
const typename BasicJsonType::array_t& value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16171 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16172 |
write_bson_entry_header(name, 0x04); // array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16173 |
write_number<std::int32_t>(static_cast<std::int32_t>(calc_bson_array_size(value)), true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16174 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16175 |
std::size_t array_index = 0ul; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16176 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16177 |
for (const auto& el : value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16178 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16179 |
write_bson_element(std::to_string(array_index++), el); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16180 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16181 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16182 |
oa->write_character(to_char_type(0x00)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16183 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16184 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16185 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16186 |
@brief Writes a BSON element with key @a name and binary value @a value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16187 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16188 |
void write_bson_binary(const string_t& name, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16189 |
const binary_t& value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16190 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16191 |
write_bson_entry_header(name, 0x05); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16192 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16193 |
write_number<std::int32_t>(static_cast<std::int32_t>(value.size()), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16194 |
write_number(value.has_subtype() ? static_cast<std::uint8_t>(value.subtype()) : static_cast<std::uint8_t>(0x00)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16195 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16196 |
oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16197 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16198 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16199 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16200 |
@brief Calculates the size necessary to serialize the JSON value @a j with its @a name |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16201 |
@return The calculated size for the BSON document entry for @a j with the given @a name. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16202 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16203 |
static std::size_t calc_bson_element_size(const string_t& name, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16204 |
const BasicJsonType& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16205 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16206 |
const auto header_size = calc_bson_entry_header_size(name, j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16207 |
switch (j.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16208 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16209 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16210 |
return header_size + calc_bson_object_size(*j.m_data.m_value.object); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16211 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16212 |
case value_t::array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16213 |
return header_size + calc_bson_array_size(*j.m_data.m_value.array); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16214 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16215 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16216 |
return header_size + calc_bson_binary_size(*j.m_data.m_value.binary); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16217 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16218 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16219 |
return header_size + 1ul; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16220 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16221 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16222 |
return header_size + 8ul; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16223 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16224 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16225 |
return header_size + calc_bson_integer_size(j.m_data.m_value.number_integer); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16226 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16227 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16228 |
return header_size + calc_bson_unsigned_size(j.m_data.m_value.number_unsigned); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16229 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16230 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16231 |
return header_size + calc_bson_string_size(*j.m_data.m_value.string); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16232 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16233 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16234 |
return header_size + 0ul; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16235 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16236 |
// LCOV_EXCL_START |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16237 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16238 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16239 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16240 |
return 0ul; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16241 |
// LCOV_EXCL_STOP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16242 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16243 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16244 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16245 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16246 |
@brief Serializes the JSON value @a j to BSON and associates it with the |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16247 |
key @a name. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16248 |
@param name The name to associate with the JSON entity @a j within the |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16249 |
current BSON document |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16250 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16251 |
void write_bson_element(const string_t& name, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16252 |
const BasicJsonType& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16253 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16254 |
switch (j.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16255 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16256 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16257 |
return write_bson_object_entry(name, *j.m_data.m_value.object); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16258 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16259 |
case value_t::array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16260 |
return write_bson_array(name, *j.m_data.m_value.array); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16261 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16262 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16263 |
return write_bson_binary(name, *j.m_data.m_value.binary); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16264 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16265 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16266 |
return write_bson_boolean(name, j.m_data.m_value.boolean); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16267 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16268 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16269 |
return write_bson_double(name, j.m_data.m_value.number_float); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16270 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16271 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16272 |
return write_bson_integer(name, j.m_data.m_value.number_integer); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16273 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16274 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16275 |
return write_bson_unsigned(name, j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16276 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16277 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16278 |
return write_bson_string(name, *j.m_data.m_value.string); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16279 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16280 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16281 |
return write_bson_null(name); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16282 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16283 |
// LCOV_EXCL_START |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16284 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16285 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16286 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16287 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16288 |
// LCOV_EXCL_STOP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16289 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16290 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16291 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16292 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16293 |
@brief Calculates the size of the BSON serialization of the given |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16294 |
JSON-object @a j. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16295 |
@param[in] value JSON value to serialize |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16296 |
@pre value.type() == value_t::object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16297 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16298 |
static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16299 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16300 |
const std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16301 |
[](size_t result, const typename BasicJsonType::object_t::value_type & el) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16302 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16303 |
return result += calc_bson_element_size(el.first, el.second); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16304 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16305 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16306 |
return sizeof(std::int32_t) + document_size + 1ul; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16307 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16308 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16309 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16310 |
@param[in] value JSON value to serialize |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16311 |
@pre value.type() == value_t::object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16312 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16313 |
void write_bson_object(const typename BasicJsonType::object_t& value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16314 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16315 |
write_number<std::int32_t>(static_cast<std::int32_t>(calc_bson_object_size(value)), true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16316 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16317 |
for (const auto& el : value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16318 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16319 |
write_bson_element(el.first, el.second); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16320 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16321 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16322 |
oa->write_character(to_char_type(0x00)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16323 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16324 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16325 |
////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16326 |
// CBOR // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16327 |
////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16328 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16329 |
static constexpr CharType get_cbor_float_prefix(float /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16330 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16331 |
return to_char_type(0xFA); // Single-Precision Float |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16332 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16333 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16334 |
static constexpr CharType get_cbor_float_prefix(double /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16335 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16336 |
return to_char_type(0xFB); // Double-Precision Float |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16337 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16338 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16339 |
///////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16340 |
// MsgPack // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16341 |
///////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16342 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16343 |
static constexpr CharType get_msgpack_float_prefix(float /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16344 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16345 |
return to_char_type(0xCA); // float 32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16346 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16347 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16348 |
static constexpr CharType get_msgpack_float_prefix(double /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16349 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16350 |
return to_char_type(0xCB); // float 64 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16351 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16352 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16353 |
//////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16354 |
// UBJSON // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16355 |
//////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16356 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16357 |
// UBJSON: write number (floating point) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16358 |
template<typename NumberType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16359 |
std::is_floating_point<NumberType>::value, int>::type = 0> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16360 |
void write_number_with_ubjson_prefix(const NumberType n, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16361 |
const bool add_prefix, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16362 |
const bool use_bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16363 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16364 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16365 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16366 |
oa->write_character(get_ubjson_float_prefix(n)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16367 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16368 |
write_number(n, use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16369 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16370 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16371 |
// UBJSON: write number (unsigned integer) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16372 |
template<typename NumberType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16373 |
std::is_unsigned<NumberType>::value, int>::type = 0> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16374 |
void write_number_with_ubjson_prefix(const NumberType n, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16375 |
const bool add_prefix, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16376 |
const bool use_bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16377 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16378 |
if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16379 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16380 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16381 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16382 |
oa->write_character(to_char_type('i')); // int8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16383 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16384 |
write_number(static_cast<std::uint8_t>(n), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16385 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16386 |
else if (n <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16387 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16388 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16389 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16390 |
oa->write_character(to_char_type('U')); // uint8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16391 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16392 |
write_number(static_cast<std::uint8_t>(n), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16393 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16394 |
else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16395 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16396 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16397 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16398 |
oa->write_character(to_char_type('I')); // int16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16399 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16400 |
write_number(static_cast<std::int16_t>(n), use_bjdata); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16401 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16402 |
else if (use_bjdata && n <= static_cast<uint64_t>((std::numeric_limits<uint16_t>::max)())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16403 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16404 |
if (add_prefix) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16405 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16406 |
oa->write_character(to_char_type('u')); // uint16 - bjdata only |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16407 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16408 |
write_number(static_cast<std::uint16_t>(n), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16409 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16410 |
else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16411 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16412 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16413 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16414 |
oa->write_character(to_char_type('l')); // int32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16415 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16416 |
write_number(static_cast<std::int32_t>(n), use_bjdata); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16417 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16418 |
else if (use_bjdata && n <= static_cast<uint64_t>((std::numeric_limits<uint32_t>::max)())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16419 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16420 |
if (add_prefix) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16421 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16422 |
oa->write_character(to_char_type('m')); // uint32 - bjdata only |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16423 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16424 |
write_number(static_cast<std::uint32_t>(n), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16425 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16426 |
else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16427 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16428 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16429 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16430 |
oa->write_character(to_char_type('L')); // int64 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16431 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16432 |
write_number(static_cast<std::int64_t>(n), use_bjdata); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16433 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16434 |
else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16435 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16436 |
if (add_prefix) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16437 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16438 |
oa->write_character(to_char_type('M')); // uint64 - bjdata only |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16439 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16440 |
write_number(static_cast<std::uint64_t>(n), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16441 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16442 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16443 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16444 |
if (add_prefix) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16445 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16446 |
oa->write_character(to_char_type('H')); // high-precision number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16447 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16448 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16449 |
const auto number = BasicJsonType(n).dump(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16450 |
write_number_with_ubjson_prefix(number.size(), true, use_bjdata); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16451 |
for (std::size_t i = 0; i < number.size(); ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16452 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16453 |
oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i]))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16454 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16455 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16456 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16457 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16458 |
// UBJSON: write number (signed integer) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16459 |
template < typename NumberType, typename std::enable_if < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16460 |
std::is_signed<NumberType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16461 |
!std::is_floating_point<NumberType>::value, int >::type = 0 > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16462 |
void write_number_with_ubjson_prefix(const NumberType n, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16463 |
const bool add_prefix, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16464 |
const bool use_bjdata) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16465 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16466 |
if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16467 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16468 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16469 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16470 |
oa->write_character(to_char_type('i')); // int8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16471 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16472 |
write_number(static_cast<std::int8_t>(n), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16473 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16474 |
else if (static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16475 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16476 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16477 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16478 |
oa->write_character(to_char_type('U')); // uint8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16479 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16480 |
write_number(static_cast<std::uint8_t>(n), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16481 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16482 |
else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16483 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16484 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16485 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16486 |
oa->write_character(to_char_type('I')); // int16 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16487 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16488 |
write_number(static_cast<std::int16_t>(n), use_bjdata); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16489 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16490 |
else if (use_bjdata && (static_cast<std::int64_t>((std::numeric_limits<std::uint16_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint16_t>::max)()))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16491 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16492 |
if (add_prefix) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16493 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16494 |
oa->write_character(to_char_type('u')); // uint16 - bjdata only |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16495 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16496 |
write_number(static_cast<uint16_t>(n), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16497 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16498 |
else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16499 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16500 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16501 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16502 |
oa->write_character(to_char_type('l')); // int32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16503 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16504 |
write_number(static_cast<std::int32_t>(n), use_bjdata); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16505 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16506 |
else if (use_bjdata && (static_cast<std::int64_t>((std::numeric_limits<std::uint32_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint32_t>::max)()))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16507 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16508 |
if (add_prefix) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16509 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16510 |
oa->write_character(to_char_type('m')); // uint32 - bjdata only |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16511 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16512 |
write_number(static_cast<uint32_t>(n), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16513 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16514 |
else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16515 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16516 |
if (add_prefix) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16517 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16518 |
oa->write_character(to_char_type('L')); // int64 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16519 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16520 |
write_number(static_cast<std::int64_t>(n), use_bjdata); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16521 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16522 |
// LCOV_EXCL_START |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16523 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16524 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16525 |
if (add_prefix) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16526 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16527 |
oa->write_character(to_char_type('H')); // high-precision number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16528 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16529 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16530 |
const auto number = BasicJsonType(n).dump(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16531 |
write_number_with_ubjson_prefix(number.size(), true, use_bjdata); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16532 |
for (std::size_t i = 0; i < number.size(); ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16533 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16534 |
oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i]))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16535 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16536 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16537 |
// LCOV_EXCL_STOP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16538 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16539 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16540 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16541 |
@brief determine the type prefix of container values |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16542 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16543 |
CharType ubjson_prefix(const BasicJsonType& j, const bool use_bjdata) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16544 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16545 |
switch (j.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16546 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16547 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16548 |
return 'Z'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16549 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16550 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16551 |
return j.m_data.m_value.boolean ? 'T' : 'F'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16552 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16553 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16554 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16555 |
if ((std::numeric_limits<std::int8_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16556 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16557 |
return 'i'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16558 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16559 |
if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16560 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16561 |
return 'U'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16562 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16563 |
if ((std::numeric_limits<std::int16_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16564 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16565 |
return 'I'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16566 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16567 |
if (use_bjdata && ((std::numeric_limits<std::uint16_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16568 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16569 |
return 'u'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16570 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16571 |
if ((std::numeric_limits<std::int32_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16572 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16573 |
return 'l'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16574 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16575 |
if (use_bjdata && ((std::numeric_limits<std::uint32_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16576 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16577 |
return 'm'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16578 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16579 |
if ((std::numeric_limits<std::int64_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16580 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16581 |
return 'L'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16582 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16583 |
// anything else is treated as high-precision number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16584 |
return 'H'; // LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16585 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16586 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16587 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16588 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16589 |
if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16590 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16591 |
return 'i'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16592 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16593 |
if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint8_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16594 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16595 |
return 'U'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16596 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16597 |
if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16598 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16599 |
return 'I'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16600 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16601 |
if (use_bjdata && j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint16_t>::max)())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16602 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16603 |
return 'u'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16604 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16605 |
if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16606 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16607 |
return 'l'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16608 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16609 |
if (use_bjdata && j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint32_t>::max)())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16610 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16611 |
return 'm'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16612 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16613 |
if (j.m_data.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16614 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16615 |
return 'L'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16616 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16617 |
if (use_bjdata && j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16618 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16619 |
return 'M'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16620 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16621 |
// anything else is treated as high-precision number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16622 |
return 'H'; // LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16623 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16624 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16625 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16626 |
return get_ubjson_float_prefix(j.m_data.m_value.number_float); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16627 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16628 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16629 |
return 'S'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16630 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16631 |
case value_t::array: // fallthrough |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16632 |
case value_t::binary: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16633 |
return '['; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16634 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16635 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16636 |
return '{'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16637 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16638 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16639 |
default: // discarded values |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16640 |
return 'N'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16641 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16642 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16643 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16644 |
static constexpr CharType get_ubjson_float_prefix(float /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16645 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16646 |
return 'd'; // float 32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16647 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16648 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16649 |
static constexpr CharType get_ubjson_float_prefix(double /*unused*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16650 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16651 |
return 'D'; // float 64 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16652 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16653 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16654 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16655 |
@return false if the object is successfully converted to a bjdata ndarray, true if the type or size is invalid |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16656 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16657 |
bool write_bjdata_ndarray(const typename BasicJsonType::object_t& value, const bool use_count, const bool use_type) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16658 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16659 |
std::map<string_t, CharType> bjdtype = {{"uint8", 'U'}, {"int8", 'i'}, {"uint16", 'u'}, {"int16", 'I'}, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16660 |
{"uint32", 'm'}, {"int32", 'l'}, {"uint64", 'M'}, {"int64", 'L'}, {"single", 'd'}, {"double", 'D'}, {"char", 'C'} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16661 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16662 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16663 |
string_t key = "_ArrayType_"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16664 |
auto it = bjdtype.find(static_cast<string_t>(value.at(key))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16665 |
if (it == bjdtype.end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16666 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16667 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16668 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16669 |
CharType dtype = it->second; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16670 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16671 |
key = "_ArraySize_"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16672 |
std::size_t len = (value.at(key).empty() ? 0 : 1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16673 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16674 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16675 |
len *= static_cast<std::size_t>(el.m_data.m_value.number_unsigned); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16676 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16677 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16678 |
key = "_ArrayData_"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16679 |
if (value.at(key).size() != len) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16680 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16681 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16682 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16683 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16684 |
oa->write_character('['); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16685 |
oa->write_character('$'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16686 |
oa->write_character(dtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16687 |
oa->write_character('#'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16688 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16689 |
key = "_ArraySize_"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16690 |
write_ubjson(value.at(key), use_count, use_type, true, true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16691 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16692 |
key = "_ArrayData_"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16693 |
if (dtype == 'U' || dtype == 'C') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16694 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16695 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16696 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16697 |
write_number(static_cast<std::uint8_t>(el.m_data.m_value.number_unsigned), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16698 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16699 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16700 |
else if (dtype == 'i') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16701 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16702 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16703 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16704 |
write_number(static_cast<std::int8_t>(el.m_data.m_value.number_integer), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16705 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16706 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16707 |
else if (dtype == 'u') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16708 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16709 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16710 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16711 |
write_number(static_cast<std::uint16_t>(el.m_data.m_value.number_unsigned), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16712 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16713 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16714 |
else if (dtype == 'I') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16715 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16716 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16717 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16718 |
write_number(static_cast<std::int16_t>(el.m_data.m_value.number_integer), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16719 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16720 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16721 |
else if (dtype == 'm') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16722 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16723 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16724 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16725 |
write_number(static_cast<std::uint32_t>(el.m_data.m_value.number_unsigned), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16726 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16727 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16728 |
else if (dtype == 'l') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16729 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16730 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16731 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16732 |
write_number(static_cast<std::int32_t>(el.m_data.m_value.number_integer), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16733 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16734 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16735 |
else if (dtype == 'M') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16736 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16737 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16738 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16739 |
write_number(static_cast<std::uint64_t>(el.m_data.m_value.number_unsigned), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16740 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16741 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16742 |
else if (dtype == 'L') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16743 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16744 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16745 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16746 |
write_number(static_cast<std::int64_t>(el.m_data.m_value.number_integer), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16747 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16748 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16749 |
else if (dtype == 'd') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16750 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16751 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16752 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16753 |
write_number(static_cast<float>(el.m_data.m_value.number_float), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16754 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16755 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16756 |
else if (dtype == 'D') |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16757 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16758 |
for (const auto& el : value.at(key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16759 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16760 |
write_number(static_cast<double>(el.m_data.m_value.number_float), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16761 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16762 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16763 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16764 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16765 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16766 |
/////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16767 |
// Utility functions // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16768 |
/////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16769 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16770 |
/* |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16771 |
@brief write a number to output input |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16772 |
@param[in] n number of type @a NumberType |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16773 |
@param[in] OutputIsLittleEndian Set to true if output data is |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16774 |
required to be little endian |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16775 |
@tparam NumberType the type of the number |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16776 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16777 |
@note This function needs to respect the system's endianness, because bytes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16778 |
in CBOR, MessagePack, and UBJSON are stored in network order (big |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16779 |
endian) and therefore need reordering on little endian systems. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16780 |
On the other hand, BSON and BJData use little endian and should reorder |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16781 |
on big endian systems. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16782 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16783 |
template<typename NumberType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16784 |
void write_number(const NumberType n, const bool OutputIsLittleEndian = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16785 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16786 |
// step 1: write number to array of length NumberType |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16787 |
std::array<CharType, sizeof(NumberType)> vec{}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16788 |
std::memcpy(vec.data(), &n, sizeof(NumberType)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16789 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16790 |
// step 2: write array to output (with possible reordering) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16791 |
if (is_little_endian != OutputIsLittleEndian) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16792 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16793 |
// reverse byte order prior to conversion if necessary |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16794 |
std::reverse(vec.begin(), vec.end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16795 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16796 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16797 |
oa->write_characters(vec.data(), sizeof(NumberType)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16798 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16799 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16800 |
void write_compact_float(const number_float_t n, detail::input_format_t format) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16801 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16802 |
#ifdef __GNUC__ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16803 |
#pragma GCC diagnostic push |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16804 |
#pragma GCC diagnostic ignored "-Wfloat-equal" |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16805 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16806 |
if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16807 |
static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16808 |
static_cast<double>(static_cast<float>(n)) == static_cast<double>(n)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16809 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16810 |
oa->write_character(format == detail::input_format_t::cbor |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16811 |
? get_cbor_float_prefix(static_cast<float>(n)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16812 |
: get_msgpack_float_prefix(static_cast<float>(n))); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16813 |
write_number(static_cast<float>(n)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16814 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16815 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16816 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16817 |
oa->write_character(format == detail::input_format_t::cbor |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16818 |
? get_cbor_float_prefix(n) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16819 |
: get_msgpack_float_prefix(n)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16820 |
write_number(n); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16821 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16822 |
#ifdef __GNUC__ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16823 |
#pragma GCC diagnostic pop |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16824 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16825 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16826 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16827 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16828 |
// The following to_char_type functions are implement the conversion |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16829 |
// between uint8_t and CharType. In case CharType is not unsigned, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16830 |
// such a conversion is required to allow values greater than 128. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16831 |
// See <https://github.com/nlohmann/json/issues/1286> for a discussion. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16832 |
template < typename C = CharType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16833 |
enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * = nullptr > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16834 |
static constexpr CharType to_char_type(std::uint8_t x) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16835 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16836 |
return *reinterpret_cast<char*>(&x); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16837 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16838 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16839 |
template < typename C = CharType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16840 |
enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * = nullptr > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16841 |
static CharType to_char_type(std::uint8_t x) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16842 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16843 |
static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16844 |
static_assert(std::is_trivial<CharType>::value, "CharType must be trivial"); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16845 |
CharType result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16846 |
std::memcpy(&result, &x, sizeof(x)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16847 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16848 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16849 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16850 |
template<typename C = CharType, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16851 |
enable_if_t<std::is_unsigned<C>::value>* = nullptr> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16852 |
static constexpr CharType to_char_type(std::uint8_t x) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16853 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16854 |
return x; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16855 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16856 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16857 |
template < typename InputCharType, typename C = CharType, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16858 |
enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16859 |
std::is_signed<C>::value && |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16860 |
std::is_signed<char>::value && |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16861 |
std::is_same<char, typename std::remove_cv<InputCharType>::type>::value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16862 |
> * = nullptr > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16863 |
static constexpr CharType to_char_type(InputCharType x) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16864 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16865 |
return x; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16866 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16867 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16868 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16869 |
/// whether we can assume little endianness |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16870 |
const bool is_little_endian = little_endianness(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16871 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16872 |
/// the output |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16873 |
output_adapter_t<CharType> oa = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16874 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16875 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16876 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16877 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16878 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16879 |
// #include <nlohmann/detail/output/output_adapters.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16880 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16881 |
// #include <nlohmann/detail/output/serializer.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16882 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16883 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16884 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16885 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16886 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16887 |
// SPDX-FileCopyrightText: 2008-2009 Björn Hoehrmann <bjoern@hoehrmann.de> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16888 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16889 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16890 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16891 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16892 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16893 |
#include <algorithm> // reverse, remove, fill, find, none_of |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16894 |
#include <array> // array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16895 |
#include <clocale> // localeconv, lconv |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16896 |
#include <cmath> // labs, isfinite, isnan, signbit |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16897 |
#include <cstddef> // size_t, ptrdiff_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16898 |
#include <cstdint> // uint8_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16899 |
#include <cstdio> // snprintf |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16900 |
#include <limits> // numeric_limits |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16901 |
#include <string> // string, char_traits |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16902 |
#include <iomanip> // setfill, setw |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16903 |
#include <type_traits> // is_same |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16904 |
#include <utility> // move |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16905 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16906 |
// #include <nlohmann/detail/conversions/to_chars.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16907 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16908 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16909 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16910 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16911 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16912 |
// SPDX-FileCopyrightText: 2009 Florian Loitsch <https://florian.loitsch.com/> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16913 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16914 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16915 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16916 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16917 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16918 |
#include <array> // array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16919 |
#include <cmath> // signbit, isfinite |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16920 |
#include <cstdint> // intN_t, uintN_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16921 |
#include <cstring> // memcpy, memmove |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16922 |
#include <limits> // numeric_limits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16923 |
#include <type_traits> // conditional |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16924 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16925 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16926 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16927 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16928 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16929 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16930 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16931 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16932 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16933 |
@brief implements the Grisu2 algorithm for binary to decimal floating-point |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16934 |
conversion. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16935 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16936 |
This implementation is a slightly modified version of the reference |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16937 |
implementation which may be obtained from |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16938 |
http://florian.loitsch.com/publications (bench.tar.gz). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16939 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16940 |
The code is distributed under the MIT license, Copyright (c) 2009 Florian Loitsch. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16941 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16942 |
For a detailed description of the algorithm see: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16943 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16944 |
[1] Loitsch, "Printing Floating-Point Numbers Quickly and Accurately with |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16945 |
Integers", Proceedings of the ACM SIGPLAN 2010 Conference on Programming |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16946 |
Language Design and Implementation, PLDI 2010 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16947 |
[2] Burger, Dybvig, "Printing Floating-Point Numbers Quickly and Accurately", |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16948 |
Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16949 |
Design and Implementation, PLDI 1996 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16950 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16951 |
namespace dtoa_impl |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16952 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16953 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16954 |
template<typename Target, typename Source> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16955 |
Target reinterpret_bits(const Source source) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16956 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16957 |
static_assert(sizeof(Target) == sizeof(Source), "size mismatch"); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16958 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16959 |
Target target; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16960 |
std::memcpy(&target, &source, sizeof(Source)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16961 |
return target; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16962 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16963 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16964 |
struct diyfp // f * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16965 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16966 |
static constexpr int kPrecision = 64; // = q |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16967 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16968 |
std::uint64_t f = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16969 |
int e = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16970 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16971 |
constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16972 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16973 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16974 |
@brief returns x - y |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16975 |
@pre x.e == y.e and x.f >= y.f |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16976 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16977 |
static diyfp sub(const diyfp& x, const diyfp& y) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16978 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16979 |
JSON_ASSERT(x.e == y.e); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
16980 |
JSON_ASSERT(x.f >= y.f); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16981 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16982 |
return {x.f - y.f, x.e}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16983 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16984 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16985 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16986 |
@brief returns x * y |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16987 |
@note The result is rounded. (Only the upper q bits are returned.) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16988 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16989 |
static diyfp mul(const diyfp& x, const diyfp& y) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16990 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16991 |
static_assert(kPrecision == 64, "internal error"); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16992 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16993 |
// Computes: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16994 |
// f = round((x.f * y.f) / 2^q) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16995 |
// e = x.e + y.e + q |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16996 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16997 |
// Emulate the 64-bit * 64-bit multiplication: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16998 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
16999 |
// p = u * v |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17000 |
// = (u_lo + 2^32 u_hi) (v_lo + 2^32 v_hi) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17001 |
// = (u_lo v_lo ) + 2^32 ((u_lo v_hi ) + (u_hi v_lo )) + 2^64 (u_hi v_hi ) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17002 |
// = (p0 ) + 2^32 ((p1 ) + (p2 )) + 2^64 (p3 ) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17003 |
// = (p0_lo + 2^32 p0_hi) + 2^32 ((p1_lo + 2^32 p1_hi) + (p2_lo + 2^32 p2_hi)) + 2^64 (p3 ) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17004 |
// = (p0_lo ) + 2^32 (p0_hi + p1_lo + p2_lo ) + 2^64 (p1_hi + p2_hi + p3) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17005 |
// = (p0_lo ) + 2^32 (Q ) + 2^64 (H ) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17006 |
// = (p0_lo ) + 2^32 (Q_lo + 2^32 Q_hi ) + 2^64 (H ) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17007 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17008 |
// (Since Q might be larger than 2^32 - 1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17009 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17010 |
// = (p0_lo + 2^32 Q_lo) + 2^64 (Q_hi + H) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17011 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17012 |
// (Q_hi + H does not overflow a 64-bit int) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17013 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17014 |
// = p_lo + 2^64 p_hi |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17015 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17016 |
const std::uint64_t u_lo = x.f & 0xFFFFFFFFu; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17017 |
const std::uint64_t u_hi = x.f >> 32u; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17018 |
const std::uint64_t v_lo = y.f & 0xFFFFFFFFu; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17019 |
const std::uint64_t v_hi = y.f >> 32u; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17020 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17021 |
const std::uint64_t p0 = u_lo * v_lo; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17022 |
const std::uint64_t p1 = u_lo * v_hi; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17023 |
const std::uint64_t p2 = u_hi * v_lo; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17024 |
const std::uint64_t p3 = u_hi * v_hi; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17025 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17026 |
const std::uint64_t p0_hi = p0 >> 32u; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17027 |
const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17028 |
const std::uint64_t p1_hi = p1 >> 32u; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17029 |
const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17030 |
const std::uint64_t p2_hi = p2 >> 32u; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17031 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17032 |
std::uint64_t Q = p0_hi + p1_lo + p2_lo; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17033 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17034 |
// The full product might now be computed as |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17035 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17036 |
// p_hi = p3 + p2_hi + p1_hi + (Q >> 32) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17037 |
// p_lo = p0_lo + (Q << 32) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17038 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17039 |
// But in this particular case here, the full p_lo is not required. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17040 |
// Effectively we only need to add the highest bit in p_lo to p_hi (and |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17041 |
// Q_hi + 1 does not overflow). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17042 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17043 |
Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17044 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17045 |
const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17046 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17047 |
return {h, x.e + y.e + 64}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17048 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17049 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17050 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17051 |
@brief normalize x such that the significand is >= 2^(q-1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17052 |
@pre x.f != 0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17053 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17054 |
static diyfp normalize(diyfp x) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17055 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17056 |
JSON_ASSERT(x.f != 0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17057 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17058 |
while ((x.f >> 63u) == 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17059 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17060 |
x.f <<= 1u; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17061 |
x.e--; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17062 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17063 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17064 |
return x; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17065 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17066 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17067 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17068 |
@brief normalize x such that the result has the exponent E |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17069 |
@pre e >= x.e and the upper e - x.e bits of x.f must be zero. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17070 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17071 |
static diyfp normalize_to(const diyfp& x, const int target_exponent) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17072 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17073 |
const int delta = x.e - target_exponent; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17074 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17075 |
JSON_ASSERT(delta >= 0); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17076 |
JSON_ASSERT(((x.f << delta) >> delta) == x.f); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17077 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17078 |
return {x.f << delta, target_exponent}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17079 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17080 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17081 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17082 |
struct boundaries |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17083 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17084 |
diyfp w; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17085 |
diyfp minus; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17086 |
diyfp plus; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17087 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17088 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17089 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17090 |
Compute the (normalized) diyfp representing the input number 'value' and its |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17091 |
boundaries. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17092 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17093 |
@pre value must be finite and positive |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17094 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17095 |
template<typename FloatType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17096 |
boundaries compute_boundaries(FloatType value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17097 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17098 |
JSON_ASSERT(std::isfinite(value)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17099 |
JSON_ASSERT(value > 0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17100 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17101 |
// Convert the IEEE representation into a diyfp. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17102 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17103 |
// If v is denormal: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17104 |
// value = 0.F * 2^(1 - bias) = ( F) * 2^(1 - bias - (p-1)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17105 |
// If v is normalized: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17106 |
// value = 1.F * 2^(E - bias) = (2^(p-1) + F) * 2^(E - bias - (p-1)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17107 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17108 |
static_assert(std::numeric_limits<FloatType>::is_iec559, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17109 |
"internal error: dtoa_short requires an IEEE-754 floating-point implementation"); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17110 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17111 |
constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17112 |
constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17113 |
constexpr int kMinExp = 1 - kBias; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17114 |
constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17115 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17116 |
using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17117 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17118 |
const auto bits = static_cast<std::uint64_t>(reinterpret_bits<bits_type>(value)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17119 |
const std::uint64_t E = bits >> (kPrecision - 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17120 |
const std::uint64_t F = bits & (kHiddenBit - 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17121 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17122 |
const bool is_denormal = E == 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17123 |
const diyfp v = is_denormal |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17124 |
? diyfp(F, kMinExp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17125 |
: diyfp(F + kHiddenBit, static_cast<int>(E) - kBias); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17126 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17127 |
// Compute the boundaries m- and m+ of the floating-point value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17128 |
// v = f * 2^e. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17129 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17130 |
// Determine v- and v+, the floating-point predecessor and successor if v, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17131 |
// respectively. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17132 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17133 |
// v- = v - 2^e if f != 2^(p-1) or e == e_min (A) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17134 |
// = v - 2^(e-1) if f == 2^(p-1) and e > e_min (B) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17135 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17136 |
// v+ = v + 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17137 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17138 |
// Let m- = (v- + v) / 2 and m+ = (v + v+) / 2. All real numbers _strictly_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17139 |
// between m- and m+ round to v, regardless of how the input rounding |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17140 |
// algorithm breaks ties. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17141 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17142 |
// ---+-------------+-------------+-------------+-------------+--- (A) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17143 |
// v- m- v m+ v+ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17144 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17145 |
// -----------------+------+------+-------------+-------------+--- (B) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17146 |
// v- m- v m+ v+ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17147 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17148 |
const bool lower_boundary_is_closer = F == 0 && E > 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17149 |
const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17150 |
const diyfp m_minus = lower_boundary_is_closer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17151 |
? diyfp(4 * v.f - 1, v.e - 2) // (B) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17152 |
: diyfp(2 * v.f - 1, v.e - 1); // (A) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17153 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17154 |
// Determine the normalized w+ = m+. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17155 |
const diyfp w_plus = diyfp::normalize(m_plus); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17156 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17157 |
// Determine w- = m- such that e_(w-) = e_(w+). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17158 |
const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17159 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17160 |
return {diyfp::normalize(v), w_minus, w_plus}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17161 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17162 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17163 |
// Given normalized diyfp w, Grisu needs to find a (normalized) cached |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17164 |
// power-of-ten c, such that the exponent of the product c * w = f * 2^e lies |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17165 |
// within a certain range [alpha, gamma] (Definition 3.2 from [1]) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17166 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17167 |
// alpha <= e = e_c + e_w + q <= gamma |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17168 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17169 |
// or |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17170 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17171 |
// f_c * f_w * 2^alpha <= f_c 2^(e_c) * f_w 2^(e_w) * 2^q |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17172 |
// <= f_c * f_w * 2^gamma |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17173 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17174 |
// Since c and w are normalized, i.e. 2^(q-1) <= f < 2^q, this implies |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17175 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17176 |
// 2^(q-1) * 2^(q-1) * 2^alpha <= c * w * 2^q < 2^q * 2^q * 2^gamma |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17177 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17178 |
// or |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17179 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17180 |
// 2^(q - 2 + alpha) <= c * w < 2^(q + gamma) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17181 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17182 |
// The choice of (alpha,gamma) determines the size of the table and the form of |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17183 |
// the digit generation procedure. Using (alpha,gamma)=(-60,-32) works out well |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17184 |
// in practice: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17185 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17186 |
// The idea is to cut the number c * w = f * 2^e into two parts, which can be |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17187 |
// processed independently: An integral part p1, and a fractional part p2: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17188 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17189 |
// f * 2^e = ( (f div 2^-e) * 2^-e + (f mod 2^-e) ) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17190 |
// = (f div 2^-e) + (f mod 2^-e) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17191 |
// = p1 + p2 * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17192 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17193 |
// The conversion of p1 into decimal form requires a series of divisions and |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17194 |
// modulos by (a power of) 10. These operations are faster for 32-bit than for |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17195 |
// 64-bit integers, so p1 should ideally fit into a 32-bit integer. This can be |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17196 |
// achieved by choosing |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17197 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17198 |
// -e >= 32 or e <= -32 := gamma |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17199 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17200 |
// In order to convert the fractional part |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17201 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17202 |
// p2 * 2^e = p2 / 2^-e = d[-1] / 10^1 + d[-2] / 10^2 + ... |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17203 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17204 |
// into decimal form, the fraction is repeatedly multiplied by 10 and the digits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17205 |
// d[-i] are extracted in order: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17206 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17207 |
// (10 * p2) div 2^-e = d[-1] |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17208 |
// (10 * p2) mod 2^-e = d[-2] / 10^1 + ... |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17209 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17210 |
// The multiplication by 10 must not overflow. It is sufficient to choose |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17211 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17212 |
// 10 * p2 < 16 * p2 = 2^4 * p2 <= 2^64. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17213 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17214 |
// Since p2 = f mod 2^-e < 2^-e, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17215 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17216 |
// -e <= 60 or e >= -60 := alpha |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17217 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17218 |
constexpr int kAlpha = -60; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17219 |
constexpr int kGamma = -32; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17220 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17221 |
struct cached_power // c = f * 2^e ~= 10^k |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17222 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17223 |
std::uint64_t f; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17224 |
int e; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17225 |
int k; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17226 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17227 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17228 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17229 |
For a normalized diyfp w = f * 2^e, this function returns a (normalized) cached |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17230 |
power-of-ten c = f_c * 2^e_c, such that the exponent of the product w * c |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17231 |
satisfies (Definition 3.2 from [1]) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17232 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17233 |
alpha <= e_c + e + q <= gamma. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17234 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17235 |
inline cached_power get_cached_power_for_binary_exponent(int e) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17236 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17237 |
// Now |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17238 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17239 |
// alpha <= e_c + e + q <= gamma (1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17240 |
// ==> f_c * 2^alpha <= c * 2^e * 2^q |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17241 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17242 |
// and since the c's are normalized, 2^(q-1) <= f_c, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17243 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17244 |
// ==> 2^(q - 1 + alpha) <= c * 2^(e + q) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17245 |
// ==> 2^(alpha - e - 1) <= c |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17246 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17247 |
// If c were an exact power of ten, i.e. c = 10^k, one may determine k as |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17248 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17249 |
// k = ceil( log_10( 2^(alpha - e - 1) ) ) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17250 |
// = ceil( (alpha - e - 1) * log_10(2) ) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17251 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17252 |
// From the paper: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17253 |
// "In theory the result of the procedure could be wrong since c is rounded, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17254 |
// and the computation itself is approximated [...]. In practice, however, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17255 |
// this simple function is sufficient." |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17256 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17257 |
// For IEEE double precision floating-point numbers converted into |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17258 |
// normalized diyfp's w = f * 2^e, with q = 64, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17259 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17260 |
// e >= -1022 (min IEEE exponent) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17261 |
// -52 (p - 1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17262 |
// -52 (p - 1, possibly normalize denormal IEEE numbers) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17263 |
// -11 (normalize the diyfp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17264 |
// = -1137 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17265 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17266 |
// and |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17267 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17268 |
// e <= +1023 (max IEEE exponent) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17269 |
// -52 (p - 1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17270 |
// -11 (normalize the diyfp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17271 |
// = 960 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17272 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17273 |
// This binary exponent range [-1137,960] results in a decimal exponent |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17274 |
// range [-307,324]. One does not need to store a cached power for each |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17275 |
// k in this range. For each such k it suffices to find a cached power |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17276 |
// such that the exponent of the product lies in [alpha,gamma]. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17277 |
// This implies that the difference of the decimal exponents of adjacent |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17278 |
// table entries must be less than or equal to |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17279 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17280 |
// floor( (gamma - alpha) * log_10(2) ) = 8. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17281 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17282 |
// (A smaller distance gamma-alpha would require a larger table.) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17283 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17284 |
// NB: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17285 |
// Actually this function returns c, such that -60 <= e_c + e + 64 <= -34. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17286 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17287 |
constexpr int kCachedPowersMinDecExp = -300; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17288 |
constexpr int kCachedPowersDecStep = 8; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17289 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17290 |
static constexpr std::array<cached_power, 79> kCachedPowers = |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17291 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17292 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17293 |
{ 0xAB70FE17C79AC6CA, -1060, -300 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17294 |
{ 0xFF77B1FCBEBCDC4F, -1034, -292 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17295 |
{ 0xBE5691EF416BD60C, -1007, -284 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17296 |
{ 0x8DD01FAD907FFC3C, -980, -276 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17297 |
{ 0xD3515C2831559A83, -954, -268 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17298 |
{ 0x9D71AC8FADA6C9B5, -927, -260 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17299 |
{ 0xEA9C227723EE8BCB, -901, -252 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17300 |
{ 0xAECC49914078536D, -874, -244 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17301 |
{ 0x823C12795DB6CE57, -847, -236 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17302 |
{ 0xC21094364DFB5637, -821, -228 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17303 |
{ 0x9096EA6F3848984F, -794, -220 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17304 |
{ 0xD77485CB25823AC7, -768, -212 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17305 |
{ 0xA086CFCD97BF97F4, -741, -204 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17306 |
{ 0xEF340A98172AACE5, -715, -196 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17307 |
{ 0xB23867FB2A35B28E, -688, -188 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17308 |
{ 0x84C8D4DFD2C63F3B, -661, -180 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17309 |
{ 0xC5DD44271AD3CDBA, -635, -172 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17310 |
{ 0x936B9FCEBB25C996, -608, -164 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17311 |
{ 0xDBAC6C247D62A584, -582, -156 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17312 |
{ 0xA3AB66580D5FDAF6, -555, -148 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17313 |
{ 0xF3E2F893DEC3F126, -529, -140 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17314 |
{ 0xB5B5ADA8AAFF80B8, -502, -132 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17315 |
{ 0x87625F056C7C4A8B, -475, -124 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17316 |
{ 0xC9BCFF6034C13053, -449, -116 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17317 |
{ 0x964E858C91BA2655, -422, -108 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17318 |
{ 0xDFF9772470297EBD, -396, -100 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17319 |
{ 0xA6DFBD9FB8E5B88F, -369, -92 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17320 |
{ 0xF8A95FCF88747D94, -343, -84 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17321 |
{ 0xB94470938FA89BCF, -316, -76 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17322 |
{ 0x8A08F0F8BF0F156B, -289, -68 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17323 |
{ 0xCDB02555653131B6, -263, -60 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17324 |
{ 0x993FE2C6D07B7FAC, -236, -52 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17325 |
{ 0xE45C10C42A2B3B06, -210, -44 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17326 |
{ 0xAA242499697392D3, -183, -36 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17327 |
{ 0xFD87B5F28300CA0E, -157, -28 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17328 |
{ 0xBCE5086492111AEB, -130, -20 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17329 |
{ 0x8CBCCC096F5088CC, -103, -12 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17330 |
{ 0xD1B71758E219652C, -77, -4 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17331 |
{ 0x9C40000000000000, -50, 4 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17332 |
{ 0xE8D4A51000000000, -24, 12 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17333 |
{ 0xAD78EBC5AC620000, 3, 20 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17334 |
{ 0x813F3978F8940984, 30, 28 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17335 |
{ 0xC097CE7BC90715B3, 56, 36 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17336 |
{ 0x8F7E32CE7BEA5C70, 83, 44 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17337 |
{ 0xD5D238A4ABE98068, 109, 52 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17338 |
{ 0x9F4F2726179A2245, 136, 60 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17339 |
{ 0xED63A231D4C4FB27, 162, 68 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17340 |
{ 0xB0DE65388CC8ADA8, 189, 76 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17341 |
{ 0x83C7088E1AAB65DB, 216, 84 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17342 |
{ 0xC45D1DF942711D9A, 242, 92 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17343 |
{ 0x924D692CA61BE758, 269, 100 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17344 |
{ 0xDA01EE641A708DEA, 295, 108 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17345 |
{ 0xA26DA3999AEF774A, 322, 116 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17346 |
{ 0xF209787BB47D6B85, 348, 124 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17347 |
{ 0xB454E4A179DD1877, 375, 132 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17348 |
{ 0x865B86925B9BC5C2, 402, 140 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17349 |
{ 0xC83553C5C8965D3D, 428, 148 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17350 |
{ 0x952AB45CFA97A0B3, 455, 156 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17351 |
{ 0xDE469FBD99A05FE3, 481, 164 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17352 |
{ 0xA59BC234DB398C25, 508, 172 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17353 |
{ 0xF6C69A72A3989F5C, 534, 180 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17354 |
{ 0xB7DCBF5354E9BECE, 561, 188 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17355 |
{ 0x88FCF317F22241E2, 588, 196 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17356 |
{ 0xCC20CE9BD35C78A5, 614, 204 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17357 |
{ 0x98165AF37B2153DF, 641, 212 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17358 |
{ 0xE2A0B5DC971F303A, 667, 220 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17359 |
{ 0xA8D9D1535CE3B396, 694, 228 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17360 |
{ 0xFB9B7CD9A4A7443C, 720, 236 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17361 |
{ 0xBB764C4CA7A44410, 747, 244 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17362 |
{ 0x8BAB8EEFB6409C1A, 774, 252 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17363 |
{ 0xD01FEF10A657842C, 800, 260 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17364 |
{ 0x9B10A4E5E9913129, 827, 268 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17365 |
{ 0xE7109BFBA19C0C9D, 853, 276 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17366 |
{ 0xAC2820D9623BF429, 880, 284 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17367 |
{ 0x80444B5E7AA7CF85, 907, 292 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17368 |
{ 0xBF21E44003ACDD2D, 933, 300 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17369 |
{ 0x8E679C2F5E44FF8F, 960, 308 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17370 |
{ 0xD433179D9C8CB841, 986, 316 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17371 |
{ 0x9E19DB92B4E31BA9, 1013, 324 }, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17372 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17373 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17374 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17375 |
// This computation gives exactly the same results for k as |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17376 |
// k = ceil((kAlpha - e - 1) * 0.30102999566398114) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17377 |
// for |e| <= 1500, but doesn't require floating-point operations. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17378 |
// NB: log_10(2) ~= 78913 / 2^18 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17379 |
JSON_ASSERT(e >= -1500); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17380 |
JSON_ASSERT(e <= 1500); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17381 |
const int f = kAlpha - e - 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17382 |
const int k = (f * 78913) / (1 << 18) + static_cast<int>(f > 0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17383 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17384 |
const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17385 |
JSON_ASSERT(index >= 0); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17386 |
JSON_ASSERT(static_cast<std::size_t>(index) < kCachedPowers.size()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17387 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17388 |
const cached_power cached = kCachedPowers[static_cast<std::size_t>(index)]; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17389 |
JSON_ASSERT(kAlpha <= cached.e + e + 64); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17390 |
JSON_ASSERT(kGamma >= cached.e + e + 64); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17391 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17392 |
return cached; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17393 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17394 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17395 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17396 |
For n != 0, returns k, such that pow10 := 10^(k-1) <= n < 10^k. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17397 |
For n == 0, returns 1 and sets pow10 := 1. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17398 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17399 |
inline int find_largest_pow10(const std::uint32_t n, std::uint32_t& pow10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17400 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17401 |
// LCOV_EXCL_START |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17402 |
if (n >= 1000000000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17403 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17404 |
pow10 = 1000000000; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17405 |
return 10; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17406 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17407 |
// LCOV_EXCL_STOP |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17408 |
if (n >= 100000000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17409 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17410 |
pow10 = 100000000; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17411 |
return 9; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17412 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17413 |
if (n >= 10000000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17414 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17415 |
pow10 = 10000000; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17416 |
return 8; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17417 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17418 |
if (n >= 1000000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17419 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17420 |
pow10 = 1000000; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17421 |
return 7; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17422 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17423 |
if (n >= 100000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17424 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17425 |
pow10 = 100000; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17426 |
return 6; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17427 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17428 |
if (n >= 10000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17429 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17430 |
pow10 = 10000; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17431 |
return 5; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17432 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17433 |
if (n >= 1000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17434 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17435 |
pow10 = 1000; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17436 |
return 4; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17437 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17438 |
if (n >= 100) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17439 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17440 |
pow10 = 100; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17441 |
return 3; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17442 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17443 |
if (n >= 10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17444 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17445 |
pow10 = 10; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17446 |
return 2; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17447 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17448 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17449 |
pow10 = 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17450 |
return 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17451 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17452 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17453 |
inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17454 |
std::uint64_t rest, std::uint64_t ten_k) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17455 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17456 |
JSON_ASSERT(len >= 1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17457 |
JSON_ASSERT(dist <= delta); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17458 |
JSON_ASSERT(rest <= delta); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17459 |
JSON_ASSERT(ten_k > 0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17460 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17461 |
// <--------------------------- delta ----> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17462 |
// <---- dist ---------> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17463 |
// --------------[------------------+-------------------]-------------- |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17464 |
// M- w M+ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17465 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17466 |
// ten_k |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17467 |
// <------> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17468 |
// <---- rest ----> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17469 |
// --------------[------------------+----+--------------]-------------- |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17470 |
// w V |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17471 |
// = buf * 10^k |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17472 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17473 |
// ten_k represents a unit-in-the-last-place in the decimal representation |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17474 |
// stored in buf. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17475 |
// Decrement buf by ten_k while this takes buf closer to w. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17476 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17477 |
// The tests are written in this order to avoid overflow in unsigned |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17478 |
// integer arithmetic. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17479 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17480 |
while (rest < dist |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17481 |
&& delta - rest >= ten_k |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17482 |
&& (rest + ten_k < dist || dist - rest > rest + ten_k - dist)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17483 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17484 |
JSON_ASSERT(buf[len - 1] != '0'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17485 |
buf[len - 1]--; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17486 |
rest += ten_k; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17487 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17488 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17489 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17490 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17491 |
Generates V = buffer * 10^decimal_exponent, such that M- <= V <= M+. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17492 |
M- and M+ must be normalized and share the same exponent -60 <= e <= -32. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17493 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17494 |
inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17495 |
diyfp M_minus, diyfp w, diyfp M_plus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17496 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17497 |
static_assert(kAlpha >= -60, "internal error"); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17498 |
static_assert(kGamma <= -32, "internal error"); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17499 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17500 |
// Generates the digits (and the exponent) of a decimal floating-point |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17501 |
// number V = buffer * 10^decimal_exponent in the range [M-, M+]. The diyfp's |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17502 |
// w, M- and M+ share the same exponent e, which satisfies alpha <= e <= gamma. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17503 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17504 |
// <--------------------------- delta ----> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17505 |
// <---- dist ---------> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17506 |
// --------------[------------------+-------------------]-------------- |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17507 |
// M- w M+ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17508 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17509 |
// Grisu2 generates the digits of M+ from left to right and stops as soon as |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17510 |
// V is in [M-,M+]. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17511 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17512 |
JSON_ASSERT(M_plus.e >= kAlpha); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17513 |
JSON_ASSERT(M_plus.e <= kGamma); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17514 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17515 |
std::uint64_t delta = diyfp::sub(M_plus, M_minus).f; // (significand of (M+ - M-), implicit exponent is e) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17516 |
std::uint64_t dist = diyfp::sub(M_plus, w ).f; // (significand of (M+ - w ), implicit exponent is e) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17517 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17518 |
// Split M+ = f * 2^e into two parts p1 and p2 (note: e < 0): |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17519 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17520 |
// M+ = f * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17521 |
// = ((f div 2^-e) * 2^-e + (f mod 2^-e)) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17522 |
// = ((p1 ) * 2^-e + (p2 )) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17523 |
// = p1 + p2 * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17524 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17525 |
const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17526 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17527 |
auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17528 |
std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17529 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17530 |
// 1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17531 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17532 |
// Generate the digits of the integral part p1 = d[n-1]...d[1]d[0] |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17533 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17534 |
JSON_ASSERT(p1 > 0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17535 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17536 |
std::uint32_t pow10{}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17537 |
const int k = find_largest_pow10(p1, pow10); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17538 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17539 |
// 10^(k-1) <= p1 < 10^k, pow10 = 10^(k-1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17540 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17541 |
// p1 = (p1 div 10^(k-1)) * 10^(k-1) + (p1 mod 10^(k-1)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17542 |
// = (d[k-1] ) * 10^(k-1) + (p1 mod 10^(k-1)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17543 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17544 |
// M+ = p1 + p2 * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17545 |
// = d[k-1] * 10^(k-1) + (p1 mod 10^(k-1)) + p2 * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17546 |
// = d[k-1] * 10^(k-1) + ((p1 mod 10^(k-1)) * 2^-e + p2) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17547 |
// = d[k-1] * 10^(k-1) + ( rest) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17548 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17549 |
// Now generate the digits d[n] of p1 from left to right (n = k-1,...,0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17550 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17551 |
// p1 = d[k-1]...d[n] * 10^n + d[n-1]...d[0] |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17552 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17553 |
// but stop as soon as |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17554 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17555 |
// rest * 2^e = (d[n-1]...d[0] * 2^-e + p2) * 2^e <= delta * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17556 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17557 |
int n = k; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17558 |
while (n > 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17559 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17560 |
// Invariants: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17561 |
// M+ = buffer * 10^n + (p1 + p2 * 2^e) (buffer = 0 for n = k) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17562 |
// pow10 = 10^(n-1) <= p1 < 10^n |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17563 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17564 |
const std::uint32_t d = p1 / pow10; // d = p1 div 10^(n-1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17565 |
const std::uint32_t r = p1 % pow10; // r = p1 mod 10^(n-1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17566 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17567 |
// M+ = buffer * 10^n + (d * 10^(n-1) + r) + p2 * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17568 |
// = (buffer * 10 + d) * 10^(n-1) + (r + p2 * 2^e) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17569 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17570 |
JSON_ASSERT(d <= 9); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17571 |
buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17572 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17573 |
// M+ = buffer * 10^(n-1) + (r + p2 * 2^e) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17574 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17575 |
p1 = r; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17576 |
n--; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17577 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17578 |
// M+ = buffer * 10^n + (p1 + p2 * 2^e) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17579 |
// pow10 = 10^n |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17580 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17581 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17582 |
// Now check if enough digits have been generated. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17583 |
// Compute |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17584 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17585 |
// p1 + p2 * 2^e = (p1 * 2^-e + p2) * 2^e = rest * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17586 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17587 |
// Note: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17588 |
// Since rest and delta share the same exponent e, it suffices to |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17589 |
// compare the significands. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17590 |
const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17591 |
if (rest <= delta) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17592 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17593 |
// V = buffer * 10^n, with M- <= V <= M+. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17594 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17595 |
decimal_exponent += n; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17596 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17597 |
// We may now just stop. But instead look if the buffer could be |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17598 |
// decremented to bring V closer to w. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17599 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17600 |
// pow10 = 10^n is now 1 ulp in the decimal representation V. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17601 |
// The rounding procedure works with diyfp's with an implicit |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17602 |
// exponent of e. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17603 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17604 |
// 10^n = (10^n * 2^-e) * 2^e = ulp * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17605 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17606 |
const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17607 |
grisu2_round(buffer, length, dist, delta, rest, ten_n); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17608 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17609 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17610 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17611 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17612 |
pow10 /= 10; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17613 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17614 |
// pow10 = 10^(n-1) <= p1 < 10^n |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17615 |
// Invariants restored. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17616 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17617 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17618 |
// 2) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17619 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17620 |
// The digits of the integral part have been generated: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17621 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17622 |
// M+ = d[k-1]...d[1]d[0] + p2 * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17623 |
// = buffer + p2 * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17624 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17625 |
// Now generate the digits of the fractional part p2 * 2^e. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17626 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17627 |
// Note: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17628 |
// No decimal point is generated: the exponent is adjusted instead. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17629 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17630 |
// p2 actually represents the fraction |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17631 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17632 |
// p2 * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17633 |
// = p2 / 2^-e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17634 |
// = d[-1] / 10^1 + d[-2] / 10^2 + ... |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17635 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17636 |
// Now generate the digits d[-m] of p1 from left to right (m = 1,2,...) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17637 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17638 |
// p2 * 2^e = d[-1]d[-2]...d[-m] * 10^-m |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17639 |
// + 10^-m * (d[-m-1] / 10^1 + d[-m-2] / 10^2 + ...) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17640 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17641 |
// using |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17642 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17643 |
// 10^m * p2 = ((10^m * p2) div 2^-e) * 2^-e + ((10^m * p2) mod 2^-e) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17644 |
// = ( d) * 2^-e + ( r) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17645 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17646 |
// or |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17647 |
// 10^m * p2 * 2^e = d + r * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17648 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17649 |
// i.e. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17650 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17651 |
// M+ = buffer + p2 * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17652 |
// = buffer + 10^-m * (d + r * 2^e) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17653 |
// = (buffer * 10^m + d) * 10^-m + 10^-m * r * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17654 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17655 |
// and stop as soon as 10^-m * r * 2^e <= delta * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17656 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17657 |
JSON_ASSERT(p2 > delta); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17658 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17659 |
int m = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17660 |
for (;;) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17661 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17662 |
// Invariant: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17663 |
// M+ = buffer * 10^-m + 10^-m * (d[-m-1] / 10 + d[-m-2] / 10^2 + ...) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17664 |
// = buffer * 10^-m + 10^-m * (p2 ) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17665 |
// = buffer * 10^-m + 10^-m * (1/10 * (10 * p2) ) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17666 |
// = buffer * 10^-m + 10^-m * (1/10 * ((10*p2 div 2^-e) * 2^-e + (10*p2 mod 2^-e)) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17667 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17668 |
JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17669 |
p2 *= 10; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17670 |
const std::uint64_t d = p2 >> -one.e; // d = (10 * p2) div 2^-e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17671 |
const std::uint64_t r = p2 & (one.f - 1); // r = (10 * p2) mod 2^-e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17672 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17673 |
// M+ = buffer * 10^-m + 10^-m * (1/10 * (d * 2^-e + r) * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17674 |
// = buffer * 10^-m + 10^-m * (1/10 * (d + r * 2^e)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17675 |
// = (buffer * 10 + d) * 10^(-m-1) + 10^(-m-1) * r * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17676 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17677 |
JSON_ASSERT(d <= 9); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17678 |
buffer[length++] = static_cast<char>('0' + d); // buffer := buffer * 10 + d |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17679 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17680 |
// M+ = buffer * 10^(-m-1) + 10^(-m-1) * r * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17681 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17682 |
p2 = r; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17683 |
m++; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17684 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17685 |
// M+ = buffer * 10^-m + 10^-m * p2 * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17686 |
// Invariant restored. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17687 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17688 |
// Check if enough digits have been generated. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17689 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17690 |
// 10^-m * p2 * 2^e <= delta * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17691 |
// p2 * 2^e <= 10^m * delta * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17692 |
// p2 <= 10^m * delta |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17693 |
delta *= 10; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17694 |
dist *= 10; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17695 |
if (p2 <= delta) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17696 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17697 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17698 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17699 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17700 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17701 |
// V = buffer * 10^-m, with M- <= V <= M+. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17702 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17703 |
decimal_exponent -= m; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17704 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17705 |
// 1 ulp in the decimal representation is now 10^-m. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17706 |
// Since delta and dist are now scaled by 10^m, we need to do the |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17707 |
// same with ulp in order to keep the units in sync. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17708 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17709 |
// 10^m * 10^-m = 1 = 2^-e * 2^e = ten_m * 2^e |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17710 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17711 |
const std::uint64_t ten_m = one.f; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17712 |
grisu2_round(buffer, length, dist, delta, p2, ten_m); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17713 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17714 |
// By construction this algorithm generates the shortest possible decimal |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17715 |
// number (Loitsch, Theorem 6.2) which rounds back to w. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17716 |
// For an input number of precision p, at least |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17717 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17718 |
// N = 1 + ceil(p * log_10(2)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17719 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17720 |
// decimal digits are sufficient to identify all binary floating-point |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17721 |
// numbers (Matula, "In-and-Out conversions"). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17722 |
// This implies that the algorithm does not produce more than N decimal |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17723 |
// digits. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17724 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17725 |
// N = 17 for p = 53 (IEEE double precision) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17726 |
// N = 9 for p = 24 (IEEE single precision) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17727 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17728 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17729 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17730 |
v = buf * 10^decimal_exponent |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17731 |
len is the length of the buffer (number of decimal digits) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17732 |
The buffer must be large enough, i.e. >= max_digits10. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17733 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17734 |
JSON_HEDLEY_NON_NULL(1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17735 |
inline void grisu2(char* buf, int& len, int& decimal_exponent, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17736 |
diyfp m_minus, diyfp v, diyfp m_plus) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17737 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17738 |
JSON_ASSERT(m_plus.e == m_minus.e); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17739 |
JSON_ASSERT(m_plus.e == v.e); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17740 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17741 |
// --------(-----------------------+-----------------------)-------- (A) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17742 |
// m- v m+ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17743 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17744 |
// --------------------(-----------+-----------------------)-------- (B) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17745 |
// m- v m+ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17746 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17747 |
// First scale v (and m- and m+) such that the exponent is in the range |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17748 |
// [alpha, gamma]. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17749 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17750 |
const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17751 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17752 |
const diyfp c_minus_k(cached.f, cached.e); // = c ~= 10^-k |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17753 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17754 |
// The exponent of the products is = v.e + c_minus_k.e + q and is in the range [alpha,gamma] |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17755 |
const diyfp w = diyfp::mul(v, c_minus_k); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17756 |
const diyfp w_minus = diyfp::mul(m_minus, c_minus_k); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17757 |
const diyfp w_plus = diyfp::mul(m_plus, c_minus_k); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17758 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17759 |
// ----(---+---)---------------(---+---)---------------(---+---)---- |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17760 |
// w- w w+ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17761 |
// = c*m- = c*v = c*m+ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17762 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17763 |
// diyfp::mul rounds its result and c_minus_k is approximated too. w, w- and |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17764 |
// w+ are now off by a small amount. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17765 |
// In fact: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17766 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17767 |
// w - v * 10^k < 1 ulp |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17768 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17769 |
// To account for this inaccuracy, add resp. subtract 1 ulp. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17770 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17771 |
// --------+---[---------------(---+---)---------------]---+-------- |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17772 |
// w- M- w M+ w+ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17773 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17774 |
// Now any number in [M-, M+] (bounds included) will round to w when input, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17775 |
// regardless of how the input rounding algorithm breaks ties. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17776 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17777 |
// And digit_gen generates the shortest possible such number in [M-, M+]. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17778 |
// Note that this does not mean that Grisu2 always generates the shortest |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17779 |
// possible number in the interval (m-, m+). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17780 |
const diyfp M_minus(w_minus.f + 1, w_minus.e); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17781 |
const diyfp M_plus (w_plus.f - 1, w_plus.e ); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17782 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17783 |
decimal_exponent = -cached.k; // = -(-k) = k |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17784 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17785 |
grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17786 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17787 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17788 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17789 |
v = buf * 10^decimal_exponent |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17790 |
len is the length of the buffer (number of decimal digits) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17791 |
The buffer must be large enough, i.e. >= max_digits10. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17792 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17793 |
template<typename FloatType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17794 |
JSON_HEDLEY_NON_NULL(1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17795 |
void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17796 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17797 |
static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17798 |
"internal error: not enough precision"); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17799 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17800 |
JSON_ASSERT(std::isfinite(value)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17801 |
JSON_ASSERT(value > 0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17802 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17803 |
// If the neighbors (and boundaries) of 'value' are always computed for double-precision |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17804 |
// numbers, all float's can be recovered using strtod (and strtof). However, the resulting |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17805 |
// decimal representations are not exactly "short". |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17806 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17807 |
// The documentation for 'std::to_chars' (https://en.cppreference.com/w/cpp/utility/to_chars) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17808 |
// says "value is converted to a string as if by std::sprintf in the default ("C") locale" |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17809 |
// and since sprintf promotes floats to doubles, I think this is exactly what 'std::to_chars' |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17810 |
// does. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17811 |
// On the other hand, the documentation for 'std::to_chars' requires that "parsing the |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17812 |
// representation using the corresponding std::from_chars function recovers value exactly". That |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17813 |
// indicates that single precision floating-point numbers should be recovered using |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17814 |
// 'std::strtof'. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17815 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17816 |
// NB: If the neighbors are computed for single-precision numbers, there is a single float |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17817 |
// (7.0385307e-26f) which can't be recovered using strtod. The resulting double precision |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17818 |
// value is off by 1 ulp. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17819 |
#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17820 |
const boundaries w = compute_boundaries(static_cast<double>(value)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17821 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17822 |
const boundaries w = compute_boundaries(value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17823 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17824 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17825 |
grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17826 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17827 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17828 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17829 |
@brief appends a decimal representation of e to buf |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17830 |
@return a pointer to the element following the exponent. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17831 |
@pre -1000 < e < 1000 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17832 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17833 |
JSON_HEDLEY_NON_NULL(1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17834 |
JSON_HEDLEY_RETURNS_NON_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17835 |
inline char* append_exponent(char* buf, int e) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17836 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17837 |
JSON_ASSERT(e > -1000); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17838 |
JSON_ASSERT(e < 1000); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17839 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17840 |
if (e < 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17841 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17842 |
e = -e; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17843 |
*buf++ = '-'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17844 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17845 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17846 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17847 |
*buf++ = '+'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17848 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17849 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17850 |
auto k = static_cast<std::uint32_t>(e); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17851 |
if (k < 10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17852 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17853 |
// Always print at least two digits in the exponent. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17854 |
// This is for compatibility with printf("%g"). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17855 |
*buf++ = '0'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17856 |
*buf++ = static_cast<char>('0' + k); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17857 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17858 |
else if (k < 100) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17859 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17860 |
*buf++ = static_cast<char>('0' + k / 10); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17861 |
k %= 10; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17862 |
*buf++ = static_cast<char>('0' + k); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17863 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17864 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17865 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17866 |
*buf++ = static_cast<char>('0' + k / 100); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17867 |
k %= 100; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17868 |
*buf++ = static_cast<char>('0' + k / 10); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17869 |
k %= 10; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17870 |
*buf++ = static_cast<char>('0' + k); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17871 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17872 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17873 |
return buf; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17874 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17875 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17876 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17877 |
@brief prettify v = buf * 10^decimal_exponent |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17878 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17879 |
If v is in the range [10^min_exp, 10^max_exp) it will be printed in fixed-point |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17880 |
notation. Otherwise it will be printed in exponential notation. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17881 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17882 |
@pre min_exp < 0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17883 |
@pre max_exp > 0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17884 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17885 |
JSON_HEDLEY_NON_NULL(1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17886 |
JSON_HEDLEY_RETURNS_NON_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17887 |
inline char* format_buffer(char* buf, int len, int decimal_exponent, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17888 |
int min_exp, int max_exp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17889 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17890 |
JSON_ASSERT(min_exp < 0); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17891 |
JSON_ASSERT(max_exp > 0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17892 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17893 |
const int k = len; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17894 |
const int n = len + decimal_exponent; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17895 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17896 |
// v = buf * 10^(n-k) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17897 |
// k is the length of the buffer (number of decimal digits) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17898 |
// n is the position of the decimal point relative to the start of the buffer. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17899 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17900 |
if (k <= n && n <= max_exp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17901 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17902 |
// digits[000] |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17903 |
// len <= max_exp + 2 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17904 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17905 |
std::memset(buf + k, '0', static_cast<size_t>(n) - static_cast<size_t>(k)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17906 |
// Make it look like a floating-point number (#362, #378) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17907 |
buf[n + 0] = '.'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17908 |
buf[n + 1] = '0'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17909 |
return buf + (static_cast<size_t>(n) + 2); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17910 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17911 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17912 |
if (0 < n && n <= max_exp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17913 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17914 |
// dig.its |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17915 |
// len <= max_digits10 + 1 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17916 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17917 |
JSON_ASSERT(k > n); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17918 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17919 |
std::memmove(buf + (static_cast<size_t>(n) + 1), buf + n, static_cast<size_t>(k) - static_cast<size_t>(n)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17920 |
buf[n] = '.'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17921 |
return buf + (static_cast<size_t>(k) + 1U); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17922 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17923 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17924 |
if (min_exp < n && n <= 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17925 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17926 |
// 0.[000]digits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17927 |
// len <= 2 + (-min_exp - 1) + max_digits10 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17928 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17929 |
std::memmove(buf + (2 + static_cast<size_t>(-n)), buf, static_cast<size_t>(k)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17930 |
buf[0] = '0'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17931 |
buf[1] = '.'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17932 |
std::memset(buf + 2, '0', static_cast<size_t>(-n)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17933 |
return buf + (2U + static_cast<size_t>(-n) + static_cast<size_t>(k)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17934 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17935 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17936 |
if (k == 1) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17937 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17938 |
// dE+123 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17939 |
// len <= 1 + 5 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17940 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17941 |
buf += 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17942 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17943 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17944 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17945 |
// d.igitsE+123 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17946 |
// len <= max_digits10 + 1 + 5 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17947 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17948 |
std::memmove(buf + 2, buf + 1, static_cast<size_t>(k) - 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17949 |
buf[1] = '.'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17950 |
buf += 1 + static_cast<size_t>(k); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17951 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17952 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17953 |
*buf++ = 'e'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17954 |
return append_exponent(buf, n - 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17955 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17956 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17957 |
} // namespace dtoa_impl |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17958 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17959 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17960 |
@brief generates a decimal representation of the floating-point number value in [first, last). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17961 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17962 |
The format of the resulting decimal representation is similar to printf's %g |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17963 |
format. Returns an iterator pointing past-the-end of the decimal representation. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17964 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17965 |
@note The input number must be finite, i.e. NaN's and Inf's are not supported. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17966 |
@note The buffer must be large enough. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17967 |
@note The result is NOT null-terminated. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17968 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17969 |
template<typename FloatType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17970 |
JSON_HEDLEY_NON_NULL(1, 2) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17971 |
JSON_HEDLEY_RETURNS_NON_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17972 |
char* to_chars(char* first, const char* last, FloatType value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17973 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17974 |
static_cast<void>(last); // maybe unused - fix warning |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17975 |
JSON_ASSERT(std::isfinite(value)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17976 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17977 |
// Use signbit(value) instead of (value < 0) since signbit works for -0. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17978 |
if (std::signbit(value)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17979 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17980 |
value = -value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17981 |
*first++ = '-'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17982 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17983 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17984 |
#ifdef __GNUC__ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17985 |
#pragma GCC diagnostic push |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17986 |
#pragma GCC diagnostic ignored "-Wfloat-equal" |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17987 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17988 |
if (value == 0) // +-0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17989 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17990 |
*first++ = '0'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17991 |
// Make it look like a floating-point number (#362, #378) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17992 |
*first++ = '.'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17993 |
*first++ = '0'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17994 |
return first; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17995 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17996 |
#ifdef __GNUC__ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17997 |
#pragma GCC diagnostic pop |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
17998 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
17999 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18000 |
JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18001 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18002 |
// Compute v = buffer * 10^decimal_exponent. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18003 |
// The decimal digits are stored in the buffer, which needs to be interpreted |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18004 |
// as an unsigned decimal integer. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18005 |
// len is the length of the buffer, i.e. the number of decimal digits. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18006 |
int len = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18007 |
int decimal_exponent = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18008 |
dtoa_impl::grisu2(first, len, decimal_exponent, value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18009 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18010 |
JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18011 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18012 |
// Format the buffer like printf("%.*g", prec, value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18013 |
constexpr int kMinExp = -4; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18014 |
// Use digits10 here to increase compatibility with version 2. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18015 |
constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18016 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18017 |
JSON_ASSERT(last - first >= kMaxExp + 2); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18018 |
JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18019 |
JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18020 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18021 |
return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18022 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18023 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18024 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18025 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18026 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18027 |
// #include <nlohmann/detail/exceptions.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18028 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18029 |
// #include <nlohmann/detail/macro_scope.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18030 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18031 |
// #include <nlohmann/detail/meta/cpp_future.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18032 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18033 |
// #include <nlohmann/detail/output/binary_writer.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18034 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18035 |
// #include <nlohmann/detail/output/output_adapters.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18036 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18037 |
// #include <nlohmann/detail/string_concat.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18038 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18039 |
// #include <nlohmann/detail/value_t.hpp> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18040 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18041 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18042 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18043 |
namespace detail |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18044 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18045 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18046 |
/////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18047 |
// serialization // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18048 |
/////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18049 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18050 |
/// how to treat decoding errors |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18051 |
enum class error_handler_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18052 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18053 |
strict, ///< throw a type_error exception in case of invalid UTF-8 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18054 |
replace, ///< replace invalid UTF-8 sequences with U+FFFD |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18055 |
ignore ///< ignore invalid UTF-8 sequences |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18056 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18057 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18058 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18059 |
class serializer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18060 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18061 |
using string_t = typename BasicJsonType::string_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18062 |
using number_float_t = typename BasicJsonType::number_float_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18063 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18064 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18065 |
using binary_char_t = typename BasicJsonType::binary_t::value_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18066 |
static constexpr std::uint8_t UTF8_ACCEPT = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18067 |
static constexpr std::uint8_t UTF8_REJECT = 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18068 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18069 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18070 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18071 |
@param[in] s output stream to serialize to |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18072 |
@param[in] ichar indentation character to use |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18073 |
@param[in] error_handler_ how to react on decoding errors |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18074 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18075 |
serializer(output_adapter_t<char> s, const char ichar, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18076 |
error_handler_t error_handler_ = error_handler_t::strict) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18077 |
: o(std::move(s)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18078 |
, loc(std::localeconv()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18079 |
, thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18080 |
, decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18081 |
, indent_char(ichar) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18082 |
, indent_string(512, indent_char) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18083 |
, error_handler(error_handler_) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18084 |
{} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18085 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18086 |
// delete because of pointer members |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18087 |
serializer(const serializer&) = delete; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18088 |
serializer& operator=(const serializer&) = delete; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18089 |
serializer(serializer&&) = delete; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18090 |
serializer& operator=(serializer&&) = delete; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18091 |
~serializer() = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18092 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18093 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18094 |
@brief internal implementation of the serialization function |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18095 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18096 |
This function is called by the public member function dump and organizes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18097 |
the serialization internally. The indentation level is propagated as |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18098 |
additional parameter. In case of arrays and objects, the function is |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18099 |
called recursively. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18100 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18101 |
- strings and object keys are escaped using `escape_string()` |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18102 |
- integer numbers are converted implicitly via `operator<<` |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18103 |
- floating-point numbers are converted to a string using `"%g"` format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18104 |
- binary values are serialized as objects containing the subtype and the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18105 |
byte array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18106 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18107 |
@param[in] val value to serialize |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18108 |
@param[in] pretty_print whether the output shall be pretty-printed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18109 |
@param[in] ensure_ascii If @a ensure_ascii is true, all non-ASCII characters |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18110 |
in the output are escaped with `\uXXXX` sequences, and the result consists |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18111 |
of ASCII characters only. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18112 |
@param[in] indent_step the indent level |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18113 |
@param[in] current_indent the current indent level (only used internally) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18114 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18115 |
void dump(const BasicJsonType& val, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18116 |
const bool pretty_print, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18117 |
const bool ensure_ascii, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18118 |
const unsigned int indent_step, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18119 |
const unsigned int current_indent = 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18120 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18121 |
switch (val.m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18122 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18123 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18124 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18125 |
if (val.m_data.m_value.object->empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18126 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18127 |
o->write_characters("{}", 2); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18128 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18129 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18130 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18131 |
if (pretty_print) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18132 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18133 |
o->write_characters("{\n", 2); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18134 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18135 |
// variable to hold indentation for recursive calls |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18136 |
const auto new_indent = current_indent + indent_step; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18137 |
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18138 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18139 |
indent_string.resize(indent_string.size() * 2, ' '); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18140 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18141 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18142 |
// first n-1 elements |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18143 |
auto i = val.m_data.m_value.object->cbegin(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18144 |
for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18145 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18146 |
o->write_characters(indent_string.c_str(), new_indent); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18147 |
o->write_character('\"'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18148 |
dump_escaped(i->first, ensure_ascii); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18149 |
o->write_characters("\": ", 3); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18150 |
dump(i->second, true, ensure_ascii, indent_step, new_indent); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18151 |
o->write_characters(",\n", 2); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18152 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18153 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18154 |
// last element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18155 |
JSON_ASSERT(i != val.m_data.m_value.object->cend()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18156 |
JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18157 |
o->write_characters(indent_string.c_str(), new_indent); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18158 |
o->write_character('\"'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18159 |
dump_escaped(i->first, ensure_ascii); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18160 |
o->write_characters("\": ", 3); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18161 |
dump(i->second, true, ensure_ascii, indent_step, new_indent); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18162 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18163 |
o->write_character('\n'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18164 |
o->write_characters(indent_string.c_str(), current_indent); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18165 |
o->write_character('}'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18166 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18167 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18168 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18169 |
o->write_character('{'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18170 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18171 |
// first n-1 elements |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18172 |
auto i = val.m_data.m_value.object->cbegin(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18173 |
for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18174 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18175 |
o->write_character('\"'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18176 |
dump_escaped(i->first, ensure_ascii); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18177 |
o->write_characters("\":", 2); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18178 |
dump(i->second, false, ensure_ascii, indent_step, current_indent); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18179 |
o->write_character(','); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18180 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18181 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18182 |
// last element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18183 |
JSON_ASSERT(i != val.m_data.m_value.object->cend()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18184 |
JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18185 |
o->write_character('\"'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18186 |
dump_escaped(i->first, ensure_ascii); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18187 |
o->write_characters("\":", 2); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18188 |
dump(i->second, false, ensure_ascii, indent_step, current_indent); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18189 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18190 |
o->write_character('}'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18191 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18192 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18193 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18194 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18195 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18196 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18197 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18198 |
if (val.m_data.m_value.array->empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18199 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18200 |
o->write_characters("[]", 2); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18201 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18202 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18203 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18204 |
if (pretty_print) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18205 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18206 |
o->write_characters("[\n", 2); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18207 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18208 |
// variable to hold indentation for recursive calls |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18209 |
const auto new_indent = current_indent + indent_step; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18210 |
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18211 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18212 |
indent_string.resize(indent_string.size() * 2, ' '); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18213 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18214 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18215 |
// first n-1 elements |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18216 |
for (auto i = val.m_data.m_value.array->cbegin(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18217 |
i != val.m_data.m_value.array->cend() - 1; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18218 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18219 |
o->write_characters(indent_string.c_str(), new_indent); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18220 |
dump(*i, true, ensure_ascii, indent_step, new_indent); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18221 |
o->write_characters(",\n", 2); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18222 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18223 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18224 |
// last element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18225 |
JSON_ASSERT(!val.m_data.m_value.array->empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18226 |
o->write_characters(indent_string.c_str(), new_indent); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18227 |
dump(val.m_data.m_value.array->back(), true, ensure_ascii, indent_step, new_indent); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18228 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18229 |
o->write_character('\n'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18230 |
o->write_characters(indent_string.c_str(), current_indent); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18231 |
o->write_character(']'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18232 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18233 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18234 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18235 |
o->write_character('['); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18236 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18237 |
// first n-1 elements |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18238 |
for (auto i = val.m_data.m_value.array->cbegin(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18239 |
i != val.m_data.m_value.array->cend() - 1; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18240 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18241 |
dump(*i, false, ensure_ascii, indent_step, current_indent); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18242 |
o->write_character(','); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18243 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18244 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18245 |
// last element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18246 |
JSON_ASSERT(!val.m_data.m_value.array->empty()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18247 |
dump(val.m_data.m_value.array->back(), false, ensure_ascii, indent_step, current_indent); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18248 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18249 |
o->write_character(']'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18250 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18251 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18252 |
return; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18253 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18254 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18255 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18256 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18257 |
o->write_character('\"'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18258 |
dump_escaped(*val.m_data.m_value.string, ensure_ascii); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18259 |
o->write_character('\"'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18260 |
return; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18261 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18262 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18263 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18264 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18265 |
if (pretty_print) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18266 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18267 |
o->write_characters("{\n", 2); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18268 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18269 |
// variable to hold indentation for recursive calls |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18270 |
const auto new_indent = current_indent + indent_step; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18271 |
if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18272 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18273 |
indent_string.resize(indent_string.size() * 2, ' '); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18274 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18275 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18276 |
o->write_characters(indent_string.c_str(), new_indent); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18277 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18278 |
o->write_characters("\"bytes\": [", 10); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18279 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18280 |
if (!val.m_data.m_value.binary->empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18281 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18282 |
for (auto i = val.m_data.m_value.binary->cbegin(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18283 |
i != val.m_data.m_value.binary->cend() - 1; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18284 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18285 |
dump_integer(*i); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18286 |
o->write_characters(", ", 2); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18287 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18288 |
dump_integer(val.m_data.m_value.binary->back()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18289 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18290 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18291 |
o->write_characters("],\n", 3); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18292 |
o->write_characters(indent_string.c_str(), new_indent); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18293 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18294 |
o->write_characters("\"subtype\": ", 11); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18295 |
if (val.m_data.m_value.binary->has_subtype()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18296 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18297 |
dump_integer(val.m_data.m_value.binary->subtype()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18298 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18299 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18300 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18301 |
o->write_characters("null", 4); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18302 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18303 |
o->write_character('\n'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18304 |
o->write_characters(indent_string.c_str(), current_indent); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18305 |
o->write_character('}'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18306 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18307 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18308 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18309 |
o->write_characters("{\"bytes\":[", 10); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18310 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18311 |
if (!val.m_data.m_value.binary->empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18312 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18313 |
for (auto i = val.m_data.m_value.binary->cbegin(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18314 |
i != val.m_data.m_value.binary->cend() - 1; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18315 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18316 |
dump_integer(*i); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18317 |
o->write_character(','); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18318 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18319 |
dump_integer(val.m_data.m_value.binary->back()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18320 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18321 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18322 |
o->write_characters("],\"subtype\":", 12); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18323 |
if (val.m_data.m_value.binary->has_subtype()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18324 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18325 |
dump_integer(val.m_data.m_value.binary->subtype()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18326 |
o->write_character('}'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18327 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18328 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18329 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18330 |
o->write_characters("null}", 5); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18331 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18332 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18333 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18334 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18335 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18336 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18337 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18338 |
if (val.m_data.m_value.boolean) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18339 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18340 |
o->write_characters("true", 4); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18341 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18342 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18343 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18344 |
o->write_characters("false", 5); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18345 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18346 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18347 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18348 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18349 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18350 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18351 |
dump_integer(val.m_data.m_value.number_integer); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18352 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18353 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18354 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18355 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18356 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18357 |
dump_integer(val.m_data.m_value.number_unsigned); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18358 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18359 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18360 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18361 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18362 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18363 |
dump_float(val.m_data.m_value.number_float); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18364 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18365 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18366 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18367 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18368 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18369 |
o->write_characters("<discarded>", 11); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18370 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18371 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18372 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18373 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18374 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18375 |
o->write_characters("null", 4); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18376 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18377 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18378 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18379 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18380 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18381 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18382 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18383 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18384 |
JSON_PRIVATE_UNLESS_TESTED: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18385 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18386 |
@brief dump escaped string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18387 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18388 |
Escape a string by replacing certain special characters by a sequence of an |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18389 |
escape character (backslash) and another character and other control |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18390 |
characters by a sequence of "\u" followed by a four-digit hex |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18391 |
representation. The escaped string is written to output stream @a o. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18392 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18393 |
@param[in] s the string to escape |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18394 |
@param[in] ensure_ascii whether to escape non-ASCII characters with |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18395 |
\uXXXX sequences |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18396 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18397 |
@complexity Linear in the length of string @a s. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18398 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18399 |
void dump_escaped(const string_t& s, const bool ensure_ascii) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18400 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18401 |
std::uint32_t codepoint{}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18402 |
std::uint8_t state = UTF8_ACCEPT; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18403 |
std::size_t bytes = 0; // number of bytes written to string_buffer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18404 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18405 |
// number of bytes written at the point of the last valid byte |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18406 |
std::size_t bytes_after_last_accept = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18407 |
std::size_t undumped_chars = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18408 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18409 |
for (std::size_t i = 0; i < s.size(); ++i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18410 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18411 |
const auto byte = static_cast<std::uint8_t>(s[i]); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18412 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18413 |
switch (decode(state, codepoint, byte)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18414 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18415 |
case UTF8_ACCEPT: // decode found a new code point |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18416 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18417 |
switch (codepoint) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18418 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18419 |
case 0x08: // backspace |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18420 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18421 |
string_buffer[bytes++] = '\\'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18422 |
string_buffer[bytes++] = 'b'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18423 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18424 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18425 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18426 |
case 0x09: // horizontal tab |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18427 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18428 |
string_buffer[bytes++] = '\\'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18429 |
string_buffer[bytes++] = 't'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18430 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18431 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18432 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18433 |
case 0x0A: // newline |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18434 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18435 |
string_buffer[bytes++] = '\\'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18436 |
string_buffer[bytes++] = 'n'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18437 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18438 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18439 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18440 |
case 0x0C: // formfeed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18441 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18442 |
string_buffer[bytes++] = '\\'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18443 |
string_buffer[bytes++] = 'f'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18444 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18445 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18446 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18447 |
case 0x0D: // carriage return |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18448 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18449 |
string_buffer[bytes++] = '\\'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18450 |
string_buffer[bytes++] = 'r'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18451 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18452 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18453 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18454 |
case 0x22: // quotation mark |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18455 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18456 |
string_buffer[bytes++] = '\\'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18457 |
string_buffer[bytes++] = '\"'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18458 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18459 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18460 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18461 |
case 0x5C: // reverse solidus |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18462 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18463 |
string_buffer[bytes++] = '\\'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18464 |
string_buffer[bytes++] = '\\'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18465 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18466 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18467 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18468 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18469 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18470 |
// escape control characters (0x00..0x1F) or, if |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18471 |
// ensure_ascii parameter is used, non-ASCII characters |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18472 |
if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18473 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18474 |
if (codepoint <= 0xFFFF) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18475 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18476 |
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18477 |
static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18478 |
static_cast<std::uint16_t>(codepoint))); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18479 |
bytes += 6; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18480 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18481 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18482 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18483 |
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18484 |
static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18485 |
static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18486 |
static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu)))); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18487 |
bytes += 12; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18488 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18489 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18490 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18491 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18492 |
// copy byte to buffer (all previous bytes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18493 |
// been copied have in default case above) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18494 |
string_buffer[bytes++] = s[i]; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18495 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18496 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18497 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18498 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18499 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18500 |
// write buffer and reset index; there must be 13 bytes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18501 |
// left, as this is the maximal number of bytes to be |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18502 |
// written ("\uxxxx\uxxxx\0") for one code point |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18503 |
if (string_buffer.size() - bytes < 13) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18504 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18505 |
o->write_characters(string_buffer.data(), bytes); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18506 |
bytes = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18507 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18508 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18509 |
// remember the byte position of this accept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18510 |
bytes_after_last_accept = bytes; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18511 |
undumped_chars = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18512 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18513 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18514 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18515 |
case UTF8_REJECT: // decode found invalid UTF-8 byte |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18516 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18517 |
switch (error_handler) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18518 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18519 |
case error_handler_t::strict: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18520 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18521 |
JSON_THROW(type_error::create(316, concat("invalid UTF-8 byte at index ", std::to_string(i), ": 0x", hex_bytes(byte | 0)), nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18522 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18523 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18524 |
case error_handler_t::ignore: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18525 |
case error_handler_t::replace: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18526 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18527 |
// in case we saw this character the first time, we |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18528 |
// would like to read it again, because the byte |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18529 |
// may be OK for itself, but just not OK for the |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18530 |
// previous sequence |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18531 |
if (undumped_chars > 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18532 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18533 |
--i; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18534 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18535 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18536 |
// reset length buffer to the last accepted index; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18537 |
// thus removing/ignoring the invalid characters |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18538 |
bytes = bytes_after_last_accept; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18539 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18540 |
if (error_handler == error_handler_t::replace) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18541 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18542 |
// add a replacement character |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18543 |
if (ensure_ascii) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18544 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18545 |
string_buffer[bytes++] = '\\'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18546 |
string_buffer[bytes++] = 'u'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18547 |
string_buffer[bytes++] = 'f'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18548 |
string_buffer[bytes++] = 'f'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18549 |
string_buffer[bytes++] = 'f'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18550 |
string_buffer[bytes++] = 'd'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18551 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18552 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18553 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18554 |
string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xEF'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18555 |
string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xBF'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18556 |
string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xBD'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18557 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18558 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18559 |
// write buffer and reset index; there must be 13 bytes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18560 |
// left, as this is the maximal number of bytes to be |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18561 |
// written ("\uxxxx\uxxxx\0") for one code point |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18562 |
if (string_buffer.size() - bytes < 13) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18563 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18564 |
o->write_characters(string_buffer.data(), bytes); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18565 |
bytes = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18566 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18567 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18568 |
bytes_after_last_accept = bytes; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18569 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18570 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18571 |
undumped_chars = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18572 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18573 |
// continue processing the string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18574 |
state = UTF8_ACCEPT; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18575 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18576 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18577 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18578 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18579 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18580 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18581 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18582 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18583 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18584 |
default: // decode found yet incomplete multi-byte code point |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18585 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18586 |
if (!ensure_ascii) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18587 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18588 |
// code point will not be escaped - copy byte to buffer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18589 |
string_buffer[bytes++] = s[i]; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18590 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18591 |
++undumped_chars; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18592 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18593 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18594 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18595 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18596 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18597 |
// we finished processing the string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18598 |
if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18599 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18600 |
// write buffer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18601 |
if (bytes > 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18602 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18603 |
o->write_characters(string_buffer.data(), bytes); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18604 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18605 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18606 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18607 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18608 |
// we finish reading, but do not accept: string was incomplete |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18609 |
switch (error_handler) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18610 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18611 |
case error_handler_t::strict: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18612 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18613 |
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)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18614 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18615 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18616 |
case error_handler_t::ignore: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18617 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18618 |
// write all accepted bytes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18619 |
o->write_characters(string_buffer.data(), bytes_after_last_accept); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18620 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18621 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18622 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18623 |
case error_handler_t::replace: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18624 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18625 |
// write all accepted bytes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18626 |
o->write_characters(string_buffer.data(), bytes_after_last_accept); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18627 |
// add a replacement character |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18628 |
if (ensure_ascii) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18629 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18630 |
o->write_characters("\\ufffd", 6); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18631 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18632 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18633 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18634 |
o->write_characters("\xEF\xBF\xBD", 3); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18635 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18636 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18637 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18638 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18639 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18640 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18641 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18642 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18643 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18644 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18645 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18646 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18647 |
@brief count digits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18648 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18649 |
Count the number of decimal (base 10) digits for an input unsigned integer. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18650 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18651 |
@param[in] x unsigned integer number to count its digits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18652 |
@return number of decimal digits |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18653 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18654 |
inline unsigned int count_digits(number_unsigned_t x) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18655 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18656 |
unsigned int n_digits = 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18657 |
for (;;) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18658 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18659 |
if (x < 10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18660 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18661 |
return n_digits; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18662 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18663 |
if (x < 100) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18664 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18665 |
return n_digits + 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18666 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18667 |
if (x < 1000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18668 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18669 |
return n_digits + 2; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18670 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18671 |
if (x < 10000) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18672 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18673 |
return n_digits + 3; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18674 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18675 |
x = x / 10000u; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18676 |
n_digits += 4; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18677 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18678 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18679 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18680 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18681 |
* @brief convert a byte to a uppercase hex representation |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18682 |
* @param[in] byte byte to represent |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18683 |
* @return representation ("00".."FF") |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18684 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18685 |
static std::string hex_bytes(std::uint8_t byte) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18686 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18687 |
std::string result = "FF"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18688 |
constexpr const char* nibble_to_hex = "0123456789ABCDEF"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18689 |
result[0] = nibble_to_hex[byte / 16]; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18690 |
result[1] = nibble_to_hex[byte % 16]; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18691 |
return result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18692 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18693 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18694 |
// templates to avoid warnings about useless casts |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18695 |
template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18696 |
bool is_negative_number(NumberType x) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18697 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18698 |
return x < 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18699 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18700 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18701 |
template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18702 |
bool is_negative_number(NumberType /*unused*/) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18703 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18704 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18705 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18706 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18707 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18708 |
@brief dump an integer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18709 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18710 |
Dump a given integer to output stream @a o. Works internally with |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18711 |
@a number_buffer. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18712 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18713 |
@param[in] x integer number (signed or unsigned) to dump |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18714 |
@tparam NumberType either @a number_integer_t or @a number_unsigned_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18715 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18716 |
template < typename NumberType, detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18717 |
std::is_integral<NumberType>::value || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18718 |
std::is_same<NumberType, number_unsigned_t>::value || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18719 |
std::is_same<NumberType, number_integer_t>::value || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18720 |
std::is_same<NumberType, binary_char_t>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18721 |
int > = 0 > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18722 |
void dump_integer(NumberType x) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18723 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18724 |
static constexpr std::array<std::array<char, 2>, 100> digits_to_99 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18725 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18726 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18727 |
{{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18728 |
{{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18729 |
{{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18730 |
{{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18731 |
{{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18732 |
{{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18733 |
{{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18734 |
{{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18735 |
{{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18736 |
{{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18737 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18738 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18739 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18740 |
// special case for "0" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18741 |
if (x == 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18742 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18743 |
o->write_character('0'); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18744 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18745 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18746 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18747 |
// use a pointer to fill the buffer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18748 |
auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18749 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18750 |
number_unsigned_t abs_value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18751 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18752 |
unsigned int n_chars{}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18753 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18754 |
if (is_negative_number(x)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18755 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18756 |
*buffer_ptr = '-'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18757 |
abs_value = remove_sign(static_cast<number_integer_t>(x)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18758 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18759 |
// account one more byte for the minus sign |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18760 |
n_chars = 1 + count_digits(abs_value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18761 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18762 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18763 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18764 |
abs_value = static_cast<number_unsigned_t>(x); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18765 |
n_chars = count_digits(abs_value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18766 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18767 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18768 |
// spare 1 byte for '\0' |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18769 |
JSON_ASSERT(n_chars < number_buffer.size() - 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18770 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18771 |
// jump to the end to generate the string from backward, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18772 |
// so we later avoid reversing the result |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18773 |
buffer_ptr += n_chars; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18774 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18775 |
// Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18776 |
// See: https://www.youtube.com/watch?v=o4-CwDo2zpg |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18777 |
while (abs_value >= 100) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18778 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18779 |
const auto digits_index = static_cast<unsigned>((abs_value % 100)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18780 |
abs_value /= 100; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18781 |
*(--buffer_ptr) = digits_to_99[digits_index][1]; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18782 |
*(--buffer_ptr) = digits_to_99[digits_index][0]; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18783 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18784 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18785 |
if (abs_value >= 10) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18786 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18787 |
const auto digits_index = static_cast<unsigned>(abs_value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18788 |
*(--buffer_ptr) = digits_to_99[digits_index][1]; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18789 |
*(--buffer_ptr) = digits_to_99[digits_index][0]; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18790 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18791 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18792 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18793 |
*(--buffer_ptr) = static_cast<char>('0' + abs_value); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18794 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18795 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18796 |
o->write_characters(number_buffer.data(), n_chars); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18797 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18798 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18799 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18800 |
@brief dump a floating-point number |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18801 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18802 |
Dump a given floating-point number to output stream @a o. Works internally |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18803 |
with @a number_buffer. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18804 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18805 |
@param[in] x floating-point number to dump |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18806 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18807 |
void dump_float(number_float_t x) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18808 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18809 |
// NaN / inf |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18810 |
if (!std::isfinite(x)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18811 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18812 |
o->write_characters("null", 4); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18813 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18814 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18815 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18816 |
// If number_float_t is an IEEE-754 single or double precision number, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18817 |
// use the Grisu2 algorithm to produce short numbers which are |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18818 |
// guaranteed to round-trip, using strtof and strtod, resp. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18819 |
// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18820 |
// NB: The test below works if <long double> == <double>. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18821 |
static constexpr bool is_ieee_single_or_double |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18822 |
= (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) || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18823 |
(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); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18824 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18825 |
dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18826 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18827 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18828 |
void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18829 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18830 |
auto* begin = number_buffer.data(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18831 |
auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18832 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18833 |
o->write_characters(begin, static_cast<size_t>(end - begin)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18834 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18835 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18836 |
void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18837 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18838 |
// get number of digits for a float -> text -> float round-trip |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18839 |
static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18840 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18841 |
// the actual conversion |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18842 |
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18843 |
std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18844 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18845 |
// negative value indicates an error |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18846 |
JSON_ASSERT(len > 0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18847 |
// check if buffer was large enough |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18848 |
JSON_ASSERT(static_cast<std::size_t>(len) < number_buffer.size()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18849 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18850 |
// erase thousands separator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18851 |
if (thousands_sep != '\0') |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18852 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18853 |
// NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::remove returns an iterator, see https://github.com/nlohmann/json/issues/3081 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18854 |
const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18855 |
std::fill(end, number_buffer.end(), '\0'); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18856 |
JSON_ASSERT((end - number_buffer.begin()) <= len); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18857 |
len = (end - number_buffer.begin()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18858 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18859 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18860 |
// convert decimal point to '.' |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18861 |
if (decimal_point != '\0' && decimal_point != '.') |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18862 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18863 |
// NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::find returns an iterator, see https://github.com/nlohmann/json/issues/3081 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18864 |
const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18865 |
if (dec_pos != number_buffer.end()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18866 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18867 |
*dec_pos = '.'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18868 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18869 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18870 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18871 |
o->write_characters(number_buffer.data(), static_cast<std::size_t>(len)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18872 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18873 |
// determine if we need to append ".0" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18874 |
const bool value_is_int_like = |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18875 |
std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18876 |
[](char c) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18877 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18878 |
return c == '.' || c == 'e'; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18879 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18880 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18881 |
if (value_is_int_like) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18882 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18883 |
o->write_characters(".0", 2); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18884 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18885 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18886 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18887 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18888 |
@brief check whether a string is UTF-8 encoded |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18889 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18890 |
The function checks each byte of a string whether it is UTF-8 encoded. The |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18891 |
result of the check is stored in the @a state parameter. The function must |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18892 |
be called initially with state 0 (accept). State 1 means the string must |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18893 |
be rejected, because the current byte is not allowed. If the string is |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18894 |
completely processed, but the state is non-zero, the string ended |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18895 |
prematurely; that is, the last byte indicated more bytes should have |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18896 |
followed. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18897 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18898 |
@param[in,out] state the state of the decoding |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18899 |
@param[in,out] codep codepoint (valid only if resulting state is UTF8_ACCEPT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18900 |
@param[in] byte next byte to decode |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18901 |
@return new state |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18902 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18903 |
@note The function has been edited: a std::array is used. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18904 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18905 |
@copyright Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18906 |
@sa http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18907 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18908 |
static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18909 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18910 |
static const std::array<std::uint8_t, 400> utf8d = |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18911 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18912 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18913 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18914 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18915 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18916 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18917 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18918 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18919 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18920 |
0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18921 |
0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18922 |
0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18923 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18924 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18925 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18926 |
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 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18927 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18928 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18929 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18930 |
JSON_ASSERT(byte < utf8d.size()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18931 |
const std::uint8_t type = utf8d[byte]; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18932 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18933 |
codep = (state != UTF8_ACCEPT) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18934 |
? (byte & 0x3fu) | (codep << 6u) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18935 |
: (0xFFu >> type) & (byte); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18936 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18937 |
const std::size_t index = 256u + static_cast<size_t>(state) * 16u + static_cast<size_t>(type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18938 |
JSON_ASSERT(index < utf8d.size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18939 |
state = utf8d[index]; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18940 |
return state; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18941 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
18942 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18943 |
/* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18944 |
* Overload to make the compiler happy while it is instantiating |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18945 |
* dump_integer for number_unsigned_t. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18946 |
* Must never be called. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18947 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18948 |
number_unsigned_t remove_sign(number_unsigned_t x) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18949 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18950 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18951 |
return x; // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18952 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18953 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18954 |
/* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18955 |
* Helper function for dump_integer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18956 |
* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18957 |
* This function takes a negative signed integer and returns its absolute |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18958 |
* value as unsigned integer. The plus/minus shuffling is necessary as we can |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18959 |
* not directly remove the sign of an arbitrary signed integer as the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18960 |
* absolute values of INT_MIN and INT_MAX are usually not the same. See |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18961 |
* #1708 for details. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18962 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18963 |
inline number_unsigned_t remove_sign(number_integer_t x) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18964 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18965 |
JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18966 |
return static_cast<number_unsigned_t>(-(x + 1)) + 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18967 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18968 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18969 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18970 |
/// the output of the serializer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18971 |
output_adapter_t<char> o = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18972 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18973 |
/// a (hopefully) large enough character buffer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18974 |
std::array<char, 64> number_buffer{{}}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18975 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18976 |
/// the locale |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18977 |
const std::lconv* loc = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18978 |
/// the locale's thousand separator character |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18979 |
const char thousands_sep = '\0'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18980 |
/// the locale's decimal point character |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18981 |
const char decimal_point = '\0'; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18982 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18983 |
/// string buffer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18984 |
std::array<char, 512> string_buffer{{}}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18985 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18986 |
/// the indentation character |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18987 |
const char indent_char; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18988 |
/// the indentation string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18989 |
string_t indent_string; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18990 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18991 |
/// error_handler how to react on decoding errors |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18992 |
const error_handler_t error_handler; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18993 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18994 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18995 |
} // namespace detail |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18996 |
NLOHMANN_JSON_NAMESPACE_END |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18997 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18998 |
// #include <nlohmann/detail/value_t.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
18999 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19000 |
// #include <nlohmann/json_fwd.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19001 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19002 |
// #include <nlohmann/ordered_map.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19003 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19004 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19005 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19006 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19007 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19008 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19009 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19010 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19011 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19012 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19013 |
#include <functional> // equal_to, less |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19014 |
#include <initializer_list> // initializer_list |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19015 |
#include <iterator> // input_iterator_tag, iterator_traits |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19016 |
#include <memory> // allocator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19017 |
#include <stdexcept> // for out_of_range |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19018 |
#include <type_traits> // enable_if, is_convertible |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19019 |
#include <utility> // pair |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19020 |
#include <vector> // vector |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19021 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19022 |
// #include <nlohmann/detail/macro_scope.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19023 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19024 |
// #include <nlohmann/detail/meta/type_traits.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19025 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19026 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19027 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19028 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19029 |
/// ordered_map: a minimal map-like container that preserves insertion order |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19030 |
/// for use within nlohmann::basic_json<ordered_map> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19031 |
template <class Key, class T, class IgnoredLess = std::less<Key>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19032 |
class Allocator = std::allocator<std::pair<const Key, T>>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19033 |
struct ordered_map : std::vector<std::pair<const Key, T>, Allocator> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19034 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19035 |
using key_type = Key; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19036 |
using mapped_type = T; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19037 |
using Container = std::vector<std::pair<const Key, T>, Allocator>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19038 |
using iterator = typename Container::iterator; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19039 |
using const_iterator = typename Container::const_iterator; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19040 |
using size_type = typename Container::size_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19041 |
using value_type = typename Container::value_type; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19042 |
#ifdef JSON_HAS_CPP_14 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19043 |
using key_compare = std::equal_to<>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19044 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19045 |
using key_compare = std::equal_to<Key>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19046 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19047 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19048 |
// Explicit constructors instead of `using Container::Container` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19049 |
// otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19050 |
ordered_map() noexcept(noexcept(Container())) : Container{} {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19051 |
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{alloc} {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19052 |
template <class It> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19053 |
ordered_map(It first, It last, const Allocator& alloc = Allocator()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19054 |
: Container{first, last, alloc} {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19055 |
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator() ) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19056 |
: Container{init, alloc} {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19057 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19058 |
std::pair<iterator, bool> emplace(const key_type& key, T&& t) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19059 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19060 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19061 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19062 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19063 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19064 |
return {it, false}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19065 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19066 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19067 |
Container::emplace_back(key, std::forward<T>(t)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19068 |
return {std::prev(this->end()), true}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19069 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19070 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19071 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19072 |
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19073 |
std::pair<iterator, bool> emplace(KeyType && key, T && t) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19074 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19075 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19076 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19077 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19078 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19079 |
return {it, false}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19080 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19081 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19082 |
Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19083 |
return {std::prev(this->end()), true}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19084 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19085 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19086 |
T& operator[](const key_type& key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19087 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19088 |
return emplace(key, T{}).first->second; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19089 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19090 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19091 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19092 |
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19093 |
T & operator[](KeyType && key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19094 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19095 |
return emplace(std::forward<KeyType>(key), T{}).first->second; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19096 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19097 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19098 |
const T& operator[](const key_type& key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19099 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19100 |
return at(key); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19101 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19102 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19103 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19104 |
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19105 |
const T & operator[](KeyType && key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19106 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19107 |
return at(std::forward<KeyType>(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19108 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19109 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19110 |
T& at(const key_type& key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19111 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19112 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19113 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19114 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19115 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19116 |
return it->second; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19117 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19118 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19119 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19120 |
JSON_THROW(std::out_of_range("key not found")); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19121 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19122 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19123 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19124 |
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19125 |
T & at(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19126 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19127 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19128 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19129 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19130 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19131 |
return it->second; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19132 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19133 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19134 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19135 |
JSON_THROW(std::out_of_range("key not found")); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19136 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19137 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19138 |
const T& at(const key_type& key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19139 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19140 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19141 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19142 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19143 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19144 |
return it->second; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19145 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19146 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19147 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19148 |
JSON_THROW(std::out_of_range("key not found")); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19149 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19150 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19151 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19152 |
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19153 |
const T & at(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19154 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19155 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19156 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19157 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19158 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19159 |
return it->second; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19160 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19161 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19162 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19163 |
JSON_THROW(std::out_of_range("key not found")); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19164 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19165 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19166 |
size_type erase(const key_type& key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19167 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19168 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19169 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19170 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19171 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19172 |
// Since we cannot move const Keys, re-construct them in place |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19173 |
for (auto next = it; ++next != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19174 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19175 |
it->~value_type(); // Destroy but keep allocation |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19176 |
new (&*it) value_type{std::move(*next)}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19177 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19178 |
Container::pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19179 |
return 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19180 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19181 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19182 |
return 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19183 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19184 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19185 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19186 |
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19187 |
size_type erase(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19188 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19189 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19190 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19191 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19192 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19193 |
// Since we cannot move const Keys, re-construct them in place |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19194 |
for (auto next = it; ++next != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19195 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19196 |
it->~value_type(); // Destroy but keep allocation |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19197 |
new (&*it) value_type{std::move(*next)}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19198 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19199 |
Container::pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19200 |
return 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19201 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19202 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19203 |
return 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19204 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19205 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19206 |
iterator erase(iterator pos) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19207 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19208 |
return erase(pos, std::next(pos)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19209 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19210 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19211 |
iterator erase(iterator first, iterator last) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19212 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19213 |
if (first == last) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19214 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19215 |
return first; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19216 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19217 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19218 |
const auto elements_affected = std::distance(first, last); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19219 |
const auto offset = std::distance(Container::begin(), first); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19220 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19221 |
// This is the start situation. We need to delete elements_affected |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19222 |
// elements (3 in this example: e, f, g), and need to return an |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19223 |
// iterator past the last deleted element (h in this example). |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19224 |
// Note that offset is the distance from the start of the vector |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19225 |
// to first. We will need this later. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19226 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19227 |
// [ a, b, c, d, e, f, g, h, i, j ] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19228 |
// ^ ^ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19229 |
// first last |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19230 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19231 |
// Since we cannot move const Keys, we re-construct them in place. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19232 |
// We start at first and re-construct (viz. copy) the elements from |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19233 |
// the back of the vector. Example for first iteration: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19234 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19235 |
// ,--------. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19236 |
// v | destroy e and re-construct with h |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19237 |
// [ a, b, c, d, e, f, g, h, i, j ] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19238 |
// ^ ^ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19239 |
// it it + elements_affected |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19240 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19241 |
for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19242 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19243 |
it->~value_type(); // destroy but keep allocation |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19244 |
new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19245 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19246 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19247 |
// [ a, b, c, d, h, i, j, h, i, j ] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19248 |
// ^ ^ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19249 |
// first last |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19250 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19251 |
// remove the unneeded elements at the end of the vector |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19252 |
Container::resize(this->size() - static_cast<size_type>(elements_affected)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19253 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19254 |
// [ a, b, c, d, h, i, j ] |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19255 |
// ^ ^ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19256 |
// first last |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19257 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19258 |
// first is now pointing past the last deleted element, but we cannot |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19259 |
// use this iterator, because it may have been invalidated by the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19260 |
// resize call. Instead, we can return begin() + offset. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19261 |
return Container::begin() + offset; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19262 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19263 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19264 |
size_type count(const key_type& key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19265 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19266 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19267 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19268 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19269 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19270 |
return 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19271 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19272 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19273 |
return 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19274 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19275 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19276 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19277 |
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19278 |
size_type count(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19279 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19280 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19281 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19282 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19283 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19284 |
return 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19285 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19286 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19287 |
return 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19288 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19289 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19290 |
iterator find(const key_type& key) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19291 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19292 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19293 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19294 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19295 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19296 |
return it; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19297 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19298 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19299 |
return Container::end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19300 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19301 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19302 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19303 |
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19304 |
iterator find(KeyType && key) // NOLINT(cppcoreguidelines-missing-std-forward) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19305 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19306 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19307 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19308 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19309 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19310 |
return it; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19311 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19312 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19313 |
return Container::end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19314 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19315 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19316 |
const_iterator find(const key_type& key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19317 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19318 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19319 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19320 |
if (m_compare(it->first, key)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19321 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19322 |
return it; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19323 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19324 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19325 |
return Container::end(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19326 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19327 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19328 |
std::pair<iterator, bool> insert( value_type&& value ) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19329 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19330 |
return emplace(value.first, std::move(value.second)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19331 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19332 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19333 |
std::pair<iterator, bool> insert( const value_type& value ) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19334 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19335 |
for (auto it = this->begin(); it != this->end(); ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19336 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19337 |
if (m_compare(it->first, value.first)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19338 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19339 |
return {it, false}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19340 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19341 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19342 |
Container::push_back(value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19343 |
return {--this->end(), true}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19344 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19345 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19346 |
template<typename InputIt> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19347 |
using require_input_iter = typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19348 |
std::input_iterator_tag>::value>::type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19349 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19350 |
template<typename InputIt, typename = require_input_iter<InputIt>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19351 |
void insert(InputIt first, InputIt last) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19352 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19353 |
for (auto it = first; it != last; ++it) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19354 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19355 |
insert(*it); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19356 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19357 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19358 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19359 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19360 |
JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19361 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19362 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19363 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19364 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19365 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19366 |
#if defined(JSON_HAS_CPP_17) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19367 |
#if JSON_HAS_STATIC_RTTI |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19368 |
#include <any> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19369 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19370 |
#include <string_view> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19371 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19372 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19373 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19374 |
@brief namespace for Niels Lohmann |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19375 |
@see https://github.com/nlohmann |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19376 |
@since version 1.0.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19377 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19378 |
NLOHMANN_JSON_NAMESPACE_BEGIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19379 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19380 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19381 |
@brief a class to store JSON values |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19382 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19383 |
@internal |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19384 |
@invariant The member variables @a m_value and @a m_type have the following |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19385 |
relationship: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19386 |
- If `m_type == value_t::object`, then `m_value.object != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19387 |
- If `m_type == value_t::array`, then `m_value.array != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19388 |
- If `m_type == value_t::string`, then `m_value.string != nullptr`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19389 |
The invariants are checked by member function assert_invariant(). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19390 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19391 |
@note ObjectType trick from https://stackoverflow.com/a/9860911 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19392 |
@endinternal |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19393 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19394 |
@since version 1.0.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19395 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19396 |
@nosubgrouping |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19397 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19398 |
NLOHMANN_BASIC_JSON_TPL_DECLARATION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19399 |
class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19400 |
: public ::nlohmann::detail::json_base_class<CustomBaseClass> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19401 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19402 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19403 |
template<detail::value_t> friend struct detail::external_constructor; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19404 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19405 |
template<typename> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19406 |
friend class ::nlohmann::json_pointer; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19407 |
// can be restored when json_pointer backwards compatibility is removed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19408 |
// friend ::nlohmann::json_pointer<StringType>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19409 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19410 |
template<typename BasicJsonType, typename InputType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19411 |
friend class ::nlohmann::detail::parser; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19412 |
friend ::nlohmann::detail::serializer<basic_json>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19413 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19414 |
friend class ::nlohmann::detail::iter_impl; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19415 |
template<typename BasicJsonType, typename CharType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19416 |
friend class ::nlohmann::detail::binary_writer; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19417 |
template<typename BasicJsonType, typename InputType, typename SAX> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19418 |
friend class ::nlohmann::detail::binary_reader; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19419 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19420 |
friend class ::nlohmann::detail::json_sax_dom_parser; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19421 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19422 |
friend class ::nlohmann::detail::json_sax_dom_callback_parser; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19423 |
friend class ::nlohmann::detail::exception; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19424 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19425 |
/// workaround type for MSVC |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19426 |
using basic_json_t = NLOHMANN_BASIC_JSON_TPL; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19427 |
using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19428 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19429 |
JSON_PRIVATE_UNLESS_TESTED: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19430 |
// convenience aliases for types residing in namespace detail; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19431 |
using lexer = ::nlohmann::detail::lexer_base<basic_json>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19432 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19433 |
template<typename InputAdapterType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19434 |
static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19435 |
InputAdapterType adapter, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19436 |
detail::parser_callback_t<basic_json>cb = nullptr, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19437 |
const bool allow_exceptions = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19438 |
const bool ignore_comments = false |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19439 |
) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19440 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19441 |
return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19442 |
std::move(cb), allow_exceptions, ignore_comments); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19443 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19444 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19445 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19446 |
using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19447 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19448 |
using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19449 |
template<typename BasicJsonType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19450 |
using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19451 |
template<typename Iterator> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19452 |
using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19453 |
template<typename Base> using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19454 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19455 |
template<typename CharType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19456 |
using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19457 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19458 |
template<typename InputType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19459 |
using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19460 |
template<typename CharType> using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19461 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19462 |
JSON_PRIVATE_UNLESS_TESTED: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19463 |
using serializer = ::nlohmann::detail::serializer<basic_json>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19464 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19465 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19466 |
using value_t = detail::value_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19467 |
/// JSON Pointer, see @ref nlohmann::json_pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19468 |
using json_pointer = ::nlohmann::json_pointer<StringType>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19469 |
template<typename T, typename SFINAE> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19470 |
using json_serializer = JSONSerializer<T, SFINAE>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19471 |
/// how to treat decoding errors |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19472 |
using error_handler_t = detail::error_handler_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19473 |
/// how to treat CBOR tags |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19474 |
using cbor_tag_handler_t = detail::cbor_tag_handler_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19475 |
/// helper type for initializer lists of basic_json values |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19476 |
using initializer_list_t = std::initializer_list<detail::json_ref<basic_json>>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19477 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19478 |
using input_format_t = detail::input_format_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19479 |
/// SAX interface type, see @ref nlohmann::json_sax |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19480 |
using json_sax_t = json_sax<basic_json>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19481 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19482 |
//////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19483 |
// exceptions // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19484 |
//////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19485 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19486 |
/// @name exceptions |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19487 |
/// Classes to implement user-defined exceptions. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19488 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19489 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19490 |
using exception = detail::exception; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19491 |
using parse_error = detail::parse_error; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19492 |
using invalid_iterator = detail::invalid_iterator; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19493 |
using type_error = detail::type_error; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19494 |
using out_of_range = detail::out_of_range; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19495 |
using other_error = detail::other_error; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19496 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19497 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19498 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19499 |
///////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19500 |
// container types // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19501 |
///////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19502 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19503 |
/// @name container types |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19504 |
/// The canonic container types to use @ref basic_json like any other STL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19505 |
/// container. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19506 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19507 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19508 |
/// the type of elements in a basic_json container |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19509 |
using value_type = basic_json; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19510 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19511 |
/// the type of an element reference |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19512 |
using reference = value_type&; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19513 |
/// the type of an element const reference |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19514 |
using const_reference = const value_type&; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19515 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19516 |
/// a type to represent differences between iterators |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19517 |
using difference_type = std::ptrdiff_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19518 |
/// a type to represent container sizes |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19519 |
using size_type = std::size_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19520 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19521 |
/// the allocator type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19522 |
using allocator_type = AllocatorType<basic_json>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19523 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19524 |
/// the type of an element pointer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19525 |
using pointer = typename std::allocator_traits<allocator_type>::pointer; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19526 |
/// the type of an element const pointer |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19527 |
using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19528 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19529 |
/// an iterator for a basic_json container |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19530 |
using iterator = iter_impl<basic_json>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19531 |
/// a const iterator for a basic_json container |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19532 |
using const_iterator = iter_impl<const basic_json>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19533 |
/// a reverse iterator for a basic_json container |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19534 |
using reverse_iterator = json_reverse_iterator<typename basic_json::iterator>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19535 |
/// a const reverse iterator for a basic_json container |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19536 |
using const_reverse_iterator = json_reverse_iterator<typename basic_json::const_iterator>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19537 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19538 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19539 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19540 |
/// @brief returns the allocator associated with the container |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19541 |
/// @sa https://json.nlohmann.me/api/basic_json/get_allocator/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19542 |
static allocator_type get_allocator() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19543 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19544 |
return allocator_type(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19545 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19546 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19547 |
/// @brief returns version information on the library |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19548 |
/// @sa https://json.nlohmann.me/api/basic_json/meta/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19549 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19550 |
static basic_json meta() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19551 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19552 |
basic_json result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19553 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19554 |
result["copyright"] = "(C) 2013-2023 Niels Lohmann"; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19555 |
result["name"] = "JSON for Modern C++"; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19556 |
result["url"] = "https://github.com/nlohmann/json"; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19557 |
result["version"]["string"] = |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19558 |
detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR), '.', |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19559 |
std::to_string(NLOHMANN_JSON_VERSION_MINOR), '.', |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19560 |
std::to_string(NLOHMANN_JSON_VERSION_PATCH)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19561 |
result["version"]["major"] = NLOHMANN_JSON_VERSION_MAJOR; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19562 |
result["version"]["minor"] = NLOHMANN_JSON_VERSION_MINOR; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19563 |
result["version"]["patch"] = NLOHMANN_JSON_VERSION_PATCH; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19564 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19565 |
#ifdef _WIN32 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19566 |
result["platform"] = "win32"; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19567 |
#elif defined __linux__ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19568 |
result["platform"] = "linux"; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19569 |
#elif defined __APPLE__ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19570 |
result["platform"] = "apple"; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19571 |
#elif defined __unix__ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19572 |
result["platform"] = "unix"; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19573 |
#else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19574 |
result["platform"] = "unknown"; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19575 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19576 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19577 |
#if defined(__ICC) || defined(__INTEL_COMPILER) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19578 |
result["compiler"] = {{"family", "icc"}, {"version", __INTEL_COMPILER}}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19579 |
#elif defined(__clang__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19580 |
result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19581 |
#elif defined(__GNUC__) || defined(__GNUG__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19582 |
result["compiler"] = {{"family", "gcc"}, {"version", detail::concat( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19583 |
std::to_string(__GNUC__), '.', |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19584 |
std::to_string(__GNUC_MINOR__), '.', |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19585 |
std::to_string(__GNUC_PATCHLEVEL__)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19586 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19587 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19588 |
#elif defined(__HP_cc) || defined(__HP_aCC) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19589 |
result["compiler"] = "hp" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19590 |
#elif defined(__IBMCPP__) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19591 |
result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19592 |
#elif defined(_MSC_VER) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19593 |
result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19594 |
#elif defined(__PGI) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19595 |
result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19596 |
#elif defined(__SUNPRO_CC) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19597 |
result["compiler"] = {{"family", "sunpro"}, {"version", __SUNPRO_CC}}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19598 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19599 |
result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19600 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19601 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19602 |
#if defined(_MSVC_LANG) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19603 |
result["compiler"]["c++"] = std::to_string(_MSVC_LANG); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19604 |
#elif defined(__cplusplus) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19605 |
result["compiler"]["c++"] = std::to_string(__cplusplus); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19606 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19607 |
result["compiler"]["c++"] = "unknown"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19608 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19609 |
return result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19610 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19611 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19612 |
/////////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19613 |
// JSON value data types // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19614 |
/////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19615 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19616 |
/// @name JSON value data types |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19617 |
/// The data types to store a JSON value. These types are derived from |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19618 |
/// the template arguments passed to class @ref basic_json. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19619 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19620 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19621 |
/// @brief default object key comparator type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19622 |
/// The actual object key comparator type (@ref object_comparator_t) may be |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19623 |
/// different. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19624 |
/// @sa https://json.nlohmann.me/api/basic_json/default_object_comparator_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19625 |
#if defined(JSON_HAS_CPP_14) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19626 |
// use of transparent comparator avoids unnecessary repeated construction of temporaries |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19627 |
// in functions involving lookup by key with types other than object_t::key_type (aka. StringType) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19628 |
using default_object_comparator_t = std::less<>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19629 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19630 |
using default_object_comparator_t = std::less<StringType>; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19631 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19632 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19633 |
/// @brief a type for an object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19634 |
/// @sa https://json.nlohmann.me/api/basic_json/object_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19635 |
using object_t = ObjectType<StringType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19636 |
basic_json, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19637 |
default_object_comparator_t, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19638 |
AllocatorType<std::pair<const StringType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19639 |
basic_json>>>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19640 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19641 |
/// @brief a type for an array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19642 |
/// @sa https://json.nlohmann.me/api/basic_json/array_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19643 |
using array_t = ArrayType<basic_json, AllocatorType<basic_json>>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19644 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19645 |
/// @brief a type for a string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19646 |
/// @sa https://json.nlohmann.me/api/basic_json/string_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19647 |
using string_t = StringType; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19648 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19649 |
/// @brief a type for a boolean |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19650 |
/// @sa https://json.nlohmann.me/api/basic_json/boolean_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19651 |
using boolean_t = BooleanType; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19652 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19653 |
/// @brief a type for a number (integer) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19654 |
/// @sa https://json.nlohmann.me/api/basic_json/number_integer_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19655 |
using number_integer_t = NumberIntegerType; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19656 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19657 |
/// @brief a type for a number (unsigned) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19658 |
/// @sa https://json.nlohmann.me/api/basic_json/number_unsigned_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19659 |
using number_unsigned_t = NumberUnsignedType; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19660 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19661 |
/// @brief a type for a number (floating-point) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19662 |
/// @sa https://json.nlohmann.me/api/basic_json/number_float_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19663 |
using number_float_t = NumberFloatType; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19664 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19665 |
/// @brief a type for a packed binary type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19666 |
/// @sa https://json.nlohmann.me/api/basic_json/binary_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19667 |
using binary_t = nlohmann::byte_container_with_subtype<BinaryType>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19668 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19669 |
/// @brief object key comparator type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19670 |
/// @sa https://json.nlohmann.me/api/basic_json/object_comparator_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19671 |
using object_comparator_t = detail::actual_object_comparator_t<basic_json>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19672 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19673 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19674 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19675 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19676 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19677 |
/// helper for exception-safe object creation |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19678 |
template<typename T, typename... Args> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19679 |
JSON_HEDLEY_RETURNS_NON_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19680 |
static T* create(Args&& ... args) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19681 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19682 |
AllocatorType<T> alloc; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19683 |
using AllocatorTraits = std::allocator_traits<AllocatorType<T>>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19684 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19685 |
auto deleter = [&](T * obj) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19686 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19687 |
AllocatorTraits::deallocate(alloc, obj, 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19688 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19689 |
std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19690 |
AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19691 |
JSON_ASSERT(obj != nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19692 |
return obj.release(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19693 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19694 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19695 |
//////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19696 |
// JSON value storage // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19697 |
//////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19698 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19699 |
JSON_PRIVATE_UNLESS_TESTED: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19700 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19701 |
@brief a JSON value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19702 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19703 |
The actual storage for a JSON value of the @ref basic_json class. This |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19704 |
union combines the different storage types for the JSON value types |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19705 |
defined in @ref value_t. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19706 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19707 |
JSON type | value_t type | used type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19708 |
--------- | --------------- | ------------------------ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19709 |
object | object | pointer to @ref object_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19710 |
array | array | pointer to @ref array_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19711 |
string | string | pointer to @ref string_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19712 |
boolean | boolean | @ref boolean_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19713 |
number | number_integer | @ref number_integer_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19714 |
number | number_unsigned | @ref number_unsigned_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19715 |
number | number_float | @ref number_float_t |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19716 |
binary | binary | pointer to @ref binary_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19717 |
null | null | *no value is stored* |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19718 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19719 |
@note Variable-length types (objects, arrays, and strings) are stored as |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19720 |
pointers. The size of the union should not exceed 64 bits if the default |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19721 |
value types are used. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19722 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19723 |
@since version 1.0.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19724 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19725 |
union json_value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19726 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19727 |
/// object (stored with pointer to save storage) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19728 |
object_t* object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19729 |
/// array (stored with pointer to save storage) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19730 |
array_t* array; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19731 |
/// string (stored with pointer to save storage) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19732 |
string_t* string; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19733 |
/// binary (stored with pointer to save storage) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19734 |
binary_t* binary; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19735 |
/// boolean |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19736 |
boolean_t boolean; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19737 |
/// number (integer) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19738 |
number_integer_t number_integer; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19739 |
/// number (unsigned integer) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19740 |
number_unsigned_t number_unsigned; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19741 |
/// number (floating-point) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19742 |
number_float_t number_float; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19743 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19744 |
/// default constructor (for null values) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19745 |
json_value() = default; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19746 |
/// constructor for booleans |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19747 |
json_value(boolean_t v) noexcept : boolean(v) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19748 |
/// constructor for numbers (integer) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19749 |
json_value(number_integer_t v) noexcept : number_integer(v) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19750 |
/// constructor for numbers (unsigned) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19751 |
json_value(number_unsigned_t v) noexcept : number_unsigned(v) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19752 |
/// constructor for numbers (floating-point) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19753 |
json_value(number_float_t v) noexcept : number_float(v) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19754 |
/// constructor for empty values of a given type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19755 |
json_value(value_t t) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19756 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19757 |
switch (t) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19758 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19759 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19760 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19761 |
object = create<object_t>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19762 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19763 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19764 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19765 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19766 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19767 |
array = create<array_t>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19768 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19769 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19770 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19771 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19772 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19773 |
string = create<string_t>(""); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19774 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19775 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19776 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19777 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19778 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19779 |
binary = create<binary_t>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19780 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19781 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19782 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19783 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19784 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19785 |
boolean = static_cast<boolean_t>(false); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19786 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19787 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19788 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19789 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19790 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19791 |
number_integer = static_cast<number_integer_t>(0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19792 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19793 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19794 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19795 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19796 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19797 |
number_unsigned = static_cast<number_unsigned_t>(0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19798 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19799 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19800 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19801 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19802 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19803 |
number_float = static_cast<number_float_t>(0.0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19804 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19805 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19806 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19807 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19808 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19809 |
object = nullptr; // silence warning, see #821 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19810 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19811 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19812 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19813 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19814 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19815 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19816 |
object = nullptr; // silence warning, see #821 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19817 |
if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19818 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19819 |
JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.11.3", nullptr)); // LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19820 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19821 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19822 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19823 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19824 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19825 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19826 |
/// constructor for strings |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19827 |
json_value(const string_t& value) : string(create<string_t>(value)) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19828 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19829 |
/// constructor for rvalue strings |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19830 |
json_value(string_t&& value) : string(create<string_t>(std::move(value))) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19831 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19832 |
/// constructor for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19833 |
json_value(const object_t& value) : object(create<object_t>(value)) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19834 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19835 |
/// constructor for rvalue objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19836 |
json_value(object_t&& value) : object(create<object_t>(std::move(value))) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19837 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19838 |
/// constructor for arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19839 |
json_value(const array_t& value) : array(create<array_t>(value)) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19840 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19841 |
/// constructor for rvalue arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19842 |
json_value(array_t&& value) : array(create<array_t>(std::move(value))) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19843 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19844 |
/// constructor for binary arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19845 |
json_value(const typename binary_t::container_type& value) : binary(create<binary_t>(value)) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19846 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19847 |
/// constructor for rvalue binary arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19848 |
json_value(typename binary_t::container_type&& value) : binary(create<binary_t>(std::move(value))) {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19849 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19850 |
/// constructor for binary arrays (internal type) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19851 |
json_value(const binary_t& value) : binary(create<binary_t>(value)) {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19852 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19853 |
/// constructor for rvalue binary arrays (internal type) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19854 |
json_value(binary_t&& value) : binary(create<binary_t>(std::move(value))) {} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19855 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19856 |
void destroy(value_t t) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19857 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19858 |
if ( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19859 |
(t == value_t::object && object == nullptr) || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19860 |
(t == value_t::array && array == nullptr) || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19861 |
(t == value_t::string && string == nullptr) || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19862 |
(t == value_t::binary && binary == nullptr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19863 |
) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19864 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19865 |
//not initialized (e.g. due to exception in the ctor) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19866 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19867 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19868 |
if (t == value_t::array || t == value_t::object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19869 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19870 |
// flatten the current json_value to a heap-allocated stack |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19871 |
std::vector<basic_json> stack; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19872 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19873 |
// move the top-level items to stack |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19874 |
if (t == value_t::array) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19875 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19876 |
stack.reserve(array->size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19877 |
std::move(array->begin(), array->end(), std::back_inserter(stack)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19878 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19879 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19880 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19881 |
stack.reserve(object->size()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19882 |
for (auto&& it : *object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19883 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19884 |
stack.push_back(std::move(it.second)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19885 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19886 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19887 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19888 |
while (!stack.empty()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19889 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19890 |
// move the last item to local variable to be processed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19891 |
basic_json current_item(std::move(stack.back())); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19892 |
stack.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19893 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19894 |
// if current_item is array/object, move |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19895 |
// its children to the stack to be processed later |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19896 |
if (current_item.is_array()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19897 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19898 |
std::move(current_item.m_data.m_value.array->begin(), current_item.m_data.m_value.array->end(), std::back_inserter(stack)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19899 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19900 |
current_item.m_data.m_value.array->clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19901 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19902 |
else if (current_item.is_object()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19903 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19904 |
for (auto&& it : *current_item.m_data.m_value.object) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19905 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19906 |
stack.push_back(std::move(it.second)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19907 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19908 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19909 |
current_item.m_data.m_value.object->clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19910 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19911 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19912 |
// it's now safe that current_item get destructed |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19913 |
// since it doesn't have any children |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19914 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19915 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19916 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19917 |
switch (t) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19918 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19919 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19920 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19921 |
AllocatorType<object_t> alloc; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19922 |
std::allocator_traits<decltype(alloc)>::destroy(alloc, object); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19923 |
std::allocator_traits<decltype(alloc)>::deallocate(alloc, object, 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19924 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19925 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19926 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19927 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19928 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19929 |
AllocatorType<array_t> alloc; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19930 |
std::allocator_traits<decltype(alloc)>::destroy(alloc, array); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19931 |
std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19932 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19933 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19934 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19935 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19936 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19937 |
AllocatorType<string_t> alloc; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19938 |
std::allocator_traits<decltype(alloc)>::destroy(alloc, string); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19939 |
std::allocator_traits<decltype(alloc)>::deallocate(alloc, string, 1); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19940 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19941 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19942 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19943 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19944 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19945 |
AllocatorType<binary_t> alloc; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19946 |
std::allocator_traits<decltype(alloc)>::destroy(alloc, binary); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19947 |
std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19948 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19949 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19950 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19951 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19952 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19953 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19954 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19955 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19956 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19957 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19958 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19959 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19960 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19961 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19962 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19963 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19964 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19965 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19966 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19967 |
@brief checks the class invariants |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19968 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19969 |
This function asserts the class invariants. It needs to be called at the |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19970 |
end of every constructor to make sure that created objects respect the |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19971 |
invariant. Furthermore, it has to be called each time the type of a JSON |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19972 |
value is changed, because the invariant expresses a relationship between |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19973 |
@a m_type and @a m_value. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19974 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19975 |
Furthermore, the parent relation is checked for arrays and objects: If |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19976 |
@a check_parents true and the value is an array or object, then the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19977 |
container's elements must have the current value as parent. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19978 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19979 |
@param[in] check_parents whether the parent relation should be checked. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19980 |
The value is true by default and should only be set to false |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19981 |
during destruction of objects when the invariant does not |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19982 |
need to hold. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19983 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19984 |
void assert_invariant(bool check_parents = true) const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19985 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19986 |
JSON_ASSERT(m_data.m_type != value_t::object || m_data.m_value.object != nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19987 |
JSON_ASSERT(m_data.m_type != value_t::array || m_data.m_value.array != nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19988 |
JSON_ASSERT(m_data.m_type != value_t::string || m_data.m_value.string != nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19989 |
JSON_ASSERT(m_data.m_type != value_t::binary || m_data.m_value.binary != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
19990 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19991 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19992 |
JSON_TRY |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19993 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19994 |
// cppcheck-suppress assertWithSideEffect |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19995 |
JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json & j) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19996 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19997 |
return j.m_parent == this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19998 |
})); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
19999 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20000 |
JSON_CATCH(...) {} // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20001 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20002 |
static_cast<void>(check_parents); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20003 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20004 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20005 |
void set_parents() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20006 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20007 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20008 |
switch (m_data.m_type) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20009 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20010 |
case value_t::array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20011 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20012 |
for (auto& element : *m_data.m_value.array) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20013 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20014 |
element.m_parent = this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20015 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20016 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20017 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20018 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20019 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20020 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20021 |
for (auto& element : *m_data.m_value.object) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20022 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20023 |
element.second.m_parent = this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20024 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20025 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20026 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20027 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20028 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20029 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20030 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20031 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20032 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20033 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20034 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20035 |
case value_t::discarded: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20036 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20037 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20038 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20039 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20040 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20041 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20042 |
iterator set_parents(iterator it, typename iterator::difference_type count_set_parents) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20043 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20044 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20045 |
for (typename iterator::difference_type i = 0; i < count_set_parents; ++i) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20046 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20047 |
(it + i)->m_parent = this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20048 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20049 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20050 |
static_cast<void>(count_set_parents); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20051 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20052 |
return it; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20053 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20054 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20055 |
reference set_parent(reference j, std::size_t old_capacity = static_cast<std::size_t>(-1)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20056 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20057 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20058 |
if (old_capacity != static_cast<std::size_t>(-1)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20059 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20060 |
// see https://github.com/nlohmann/json/issues/2838 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20061 |
JSON_ASSERT(type() == value_t::array); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20062 |
if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20063 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20064 |
// capacity has changed: update all parents |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20065 |
set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20066 |
return j; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20067 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20068 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20069 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20070 |
// ordered_json uses a vector internally, so pointers could have |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20071 |
// been invalidated; see https://github.com/nlohmann/json/issues/2962 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20072 |
#ifdef JSON_HEDLEY_MSVC_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20073 |
#pragma warning(push ) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20074 |
#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20075 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20076 |
if (detail::is_ordered_map<object_t>::value) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20077 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20078 |
set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20079 |
return j; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20080 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20081 |
#ifdef JSON_HEDLEY_MSVC_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20082 |
#pragma warning( pop ) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20083 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20084 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20085 |
j.m_parent = this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20086 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20087 |
static_cast<void>(j); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20088 |
static_cast<void>(old_capacity); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20089 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20090 |
return j; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20091 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20092 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20093 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20094 |
////////////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20095 |
// JSON parser callback // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20096 |
////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20097 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20098 |
/// @brief parser event types |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20099 |
/// @sa https://json.nlohmann.me/api/basic_json/parse_event_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20100 |
using parse_event_t = detail::parse_event_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20101 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20102 |
/// @brief per-element parser callback type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20103 |
/// @sa https://json.nlohmann.me/api/basic_json/parser_callback_t/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20104 |
using parser_callback_t = detail::parser_callback_t<basic_json>; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20105 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20106 |
////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20107 |
// constructors // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20108 |
////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20109 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20110 |
/// @name constructors and destructors |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20111 |
/// Constructors of class @ref basic_json, copy/move constructor, copy |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20112 |
/// assignment, static functions creating objects, and the destructor. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20113 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20114 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20115 |
/// @brief create an empty value with a given type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20116 |
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20117 |
basic_json(const value_t v) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20118 |
: m_data(v) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20119 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20120 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20121 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20122 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20123 |
/// @brief create a null object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20124 |
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20125 |
basic_json(std::nullptr_t = nullptr) noexcept // NOLINT(bugprone-exception-escape) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20126 |
: basic_json(value_t::null) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20127 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20128 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20129 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20130 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20131 |
/// @brief create a JSON value from compatible types |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20132 |
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20133 |
template < typename CompatibleType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20134 |
typename U = detail::uncvref_t<CompatibleType>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20135 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20136 |
!detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20137 |
basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20138 |
JSONSerializer<U>::to_json(std::declval<basic_json_t&>(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20139 |
std::forward<CompatibleType>(val)))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20140 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20141 |
JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20142 |
set_parents(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20143 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20144 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20145 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20146 |
/// @brief create a JSON value from an existing one |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20147 |
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20148 |
template < typename BasicJsonType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20149 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20150 |
detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value, int > = 0 > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20151 |
basic_json(const BasicJsonType& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20152 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20153 |
using other_boolean_t = typename BasicJsonType::boolean_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20154 |
using other_number_float_t = typename BasicJsonType::number_float_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20155 |
using other_number_integer_t = typename BasicJsonType::number_integer_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20156 |
using other_number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20157 |
using other_string_t = typename BasicJsonType::string_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20158 |
using other_object_t = typename BasicJsonType::object_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20159 |
using other_array_t = typename BasicJsonType::array_t; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20160 |
using other_binary_t = typename BasicJsonType::binary_t; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20161 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20162 |
switch (val.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20163 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20164 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20165 |
JSONSerializer<other_boolean_t>::to_json(*this, val.template get<other_boolean_t>()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20166 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20167 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20168 |
JSONSerializer<other_number_float_t>::to_json(*this, val.template get<other_number_float_t>()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20169 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20170 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20171 |
JSONSerializer<other_number_integer_t>::to_json(*this, val.template get<other_number_integer_t>()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20172 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20173 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20174 |
JSONSerializer<other_number_unsigned_t>::to_json(*this, val.template get<other_number_unsigned_t>()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20175 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20176 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20177 |
JSONSerializer<other_string_t>::to_json(*this, val.template get_ref<const other_string_t&>()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20178 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20179 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20180 |
JSONSerializer<other_object_t>::to_json(*this, val.template get_ref<const other_object_t&>()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20181 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20182 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20183 |
JSONSerializer<other_array_t>::to_json(*this, val.template get_ref<const other_array_t&>()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20184 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20185 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20186 |
JSONSerializer<other_binary_t>::to_json(*this, val.template get_ref<const other_binary_t&>()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20187 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20188 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20189 |
*this = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20190 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20191 |
case value_t::discarded: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20192 |
m_data.m_type = value_t::discarded; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20193 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20194 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20195 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20196 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20197 |
JSON_ASSERT(m_data.m_type == val.type()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20198 |
set_parents(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20199 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20200 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20201 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20202 |
/// @brief create a container (array or object) from an initializer list |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20203 |
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20204 |
basic_json(initializer_list_t init, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20205 |
bool type_deduction = true, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20206 |
value_t manual_type = value_t::array) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20207 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20208 |
// check if each element is an array with two elements whose first |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20209 |
// element is a string |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20210 |
bool is_an_object = std::all_of(init.begin(), init.end(), |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20211 |
[](const detail::json_ref<basic_json>& element_ref) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20212 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20213 |
// The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20214 |
// (many string types can be constructed from 0 via its null-pointer guise, so we get a |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20215 |
// broken call to op[key_type], the wrong semantics and a 4804 warning on Windows) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20216 |
return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20217 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20218 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20219 |
// adjust type if type deduction is not wanted |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20220 |
if (!type_deduction) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20221 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20222 |
// if array is wanted, do not create an object though possible |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20223 |
if (manual_type == value_t::array) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20224 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20225 |
is_an_object = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20226 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20227 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20228 |
// if object is wanted but impossible, throw an exception |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20229 |
if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20230 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20231 |
JSON_THROW(type_error::create(301, "cannot create object from initializer list", nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20232 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20233 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20234 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20235 |
if (is_an_object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20236 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20237 |
// the initializer list is a list of pairs -> create object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20238 |
m_data.m_type = value_t::object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20239 |
m_data.m_value = value_t::object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20240 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20241 |
for (auto& element_ref : init) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20242 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20243 |
auto element = element_ref.moved_or_copied(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20244 |
m_data.m_value.object->emplace( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20245 |
std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20246 |
std::move((*element.m_data.m_value.array)[1])); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20247 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20248 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20249 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20250 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20251 |
// the initializer list describes an array -> create array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20252 |
m_data.m_type = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20253 |
m_data.m_value.array = create<array_t>(init.begin(), init.end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20254 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20255 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20256 |
set_parents(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20257 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20258 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20259 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20260 |
/// @brief explicitly create a binary array (without subtype) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20261 |
/// @sa https://json.nlohmann.me/api/basic_json/binary/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20262 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20263 |
static basic_json binary(const typename binary_t::container_type& init) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20264 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20265 |
auto res = basic_json(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20266 |
res.m_data.m_type = value_t::binary; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20267 |
res.m_data.m_value = init; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20268 |
return res; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20269 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20270 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20271 |
/// @brief explicitly create a binary array (with subtype) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20272 |
/// @sa https://json.nlohmann.me/api/basic_json/binary/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20273 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20274 |
static basic_json binary(const typename binary_t::container_type& init, typename binary_t::subtype_type subtype) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20275 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20276 |
auto res = basic_json(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20277 |
res.m_data.m_type = value_t::binary; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20278 |
res.m_data.m_value = binary_t(init, subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20279 |
return res; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20280 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20281 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20282 |
/// @brief explicitly create a binary array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20283 |
/// @sa https://json.nlohmann.me/api/basic_json/binary/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20284 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20285 |
static basic_json binary(typename binary_t::container_type&& init) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20286 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20287 |
auto res = basic_json(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20288 |
res.m_data.m_type = value_t::binary; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20289 |
res.m_data.m_value = std::move(init); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20290 |
return res; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20291 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20292 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20293 |
/// @brief explicitly create a binary array (with subtype) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20294 |
/// @sa https://json.nlohmann.me/api/basic_json/binary/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20295 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20296 |
static basic_json binary(typename binary_t::container_type&& init, typename binary_t::subtype_type subtype) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20297 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20298 |
auto res = basic_json(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20299 |
res.m_data.m_type = value_t::binary; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20300 |
res.m_data.m_value = binary_t(std::move(init), subtype); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20301 |
return res; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20302 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20303 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20304 |
/// @brief explicitly create an array from an initializer list |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20305 |
/// @sa https://json.nlohmann.me/api/basic_json/array/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20306 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20307 |
static basic_json array(initializer_list_t init = {}) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20308 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20309 |
return basic_json(init, false, value_t::array); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20310 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20311 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20312 |
/// @brief explicitly create an object from an initializer list |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20313 |
/// @sa https://json.nlohmann.me/api/basic_json/object/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20314 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20315 |
static basic_json object(initializer_list_t init = {}) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20316 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20317 |
return basic_json(init, false, value_t::object); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20318 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20319 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20320 |
/// @brief construct an array with count copies of given value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20321 |
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20322 |
basic_json(size_type cnt, const basic_json& val): |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20323 |
m_data{cnt, val} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20324 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20325 |
set_parents(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20326 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20327 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20328 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20329 |
/// @brief construct a JSON container given an iterator range |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20330 |
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20331 |
template < class InputIT, typename std::enable_if < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20332 |
std::is_same<InputIT, typename basic_json_t::iterator>::value || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20333 |
std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int >::type = 0 > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20334 |
basic_json(InputIT first, InputIT last) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20335 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20336 |
JSON_ASSERT(first.m_object != nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20337 |
JSON_ASSERT(last.m_object != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20338 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20339 |
// make sure iterator fits the current value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20340 |
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20341 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20342 |
JSON_THROW(invalid_iterator::create(201, "iterators are not compatible", nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20343 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20344 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20345 |
// copy type from first iterator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20346 |
m_data.m_type = first.m_object->m_data.m_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20347 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20348 |
// check if iterator range is complete for primitive values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20349 |
switch (m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20350 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20351 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20352 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20353 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20354 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20355 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20356 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20357 |
if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20358 |
|| !last.m_it.primitive_iterator.is_end())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20359 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20360 |
JSON_THROW(invalid_iterator::create(204, "iterators out of range", first.m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20361 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20362 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20363 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20364 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20365 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20366 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20367 |
case value_t::array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20368 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20369 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20370 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20371 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20372 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20373 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20374 |
switch (m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20375 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20376 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20377 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20378 |
m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20379 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20380 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20381 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20382 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20383 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20384 |
m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20385 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20386 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20387 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20388 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20389 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20390 |
m_data.m_value.number_float = first.m_object->m_data.m_value.number_float; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20391 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20392 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20393 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20394 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20395 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20396 |
m_data.m_value.boolean = first.m_object->m_data.m_value.boolean; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20397 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20398 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20399 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20400 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20401 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20402 |
m_data.m_value = *first.m_object->m_data.m_value.string; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20403 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20404 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20405 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20406 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20407 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20408 |
m_data.m_value.object = create<object_t>(first.m_it.object_iterator, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20409 |
last.m_it.object_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20410 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20411 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20412 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20413 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20414 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20415 |
m_data.m_value.array = create<array_t>(first.m_it.array_iterator, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20416 |
last.m_it.array_iterator); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20417 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20418 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20419 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20420 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20421 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20422 |
m_data.m_value = *first.m_object->m_data.m_value.binary; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20423 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20424 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20425 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20426 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20427 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20428 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20429 |
JSON_THROW(invalid_iterator::create(206, detail::concat("cannot construct with iterators from ", first.m_object->type_name()), first.m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20430 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20431 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20432 |
set_parents(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20433 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20434 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20435 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20436 |
/////////////////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20437 |
// other constructors and destructor // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20438 |
/////////////////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20439 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20440 |
template<typename JsonRef, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20441 |
detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20442 |
std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20443 |
basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20444 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20445 |
/// @brief copy constructor |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20446 |
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20447 |
basic_json(const basic_json& other) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20448 |
: json_base_class_t(other) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20449 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20450 |
m_data.m_type = other.m_data.m_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20451 |
// check of passed value is valid |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20452 |
other.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20453 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20454 |
switch (m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20455 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20456 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20457 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20458 |
m_data.m_value = *other.m_data.m_value.object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20459 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20460 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20461 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20462 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20463 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20464 |
m_data.m_value = *other.m_data.m_value.array; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20465 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20466 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20467 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20468 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20469 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20470 |
m_data.m_value = *other.m_data.m_value.string; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20471 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20472 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20473 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20474 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20475 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20476 |
m_data.m_value = other.m_data.m_value.boolean; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20477 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20478 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20479 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20480 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20481 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20482 |
m_data.m_value = other.m_data.m_value.number_integer; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20483 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20484 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20485 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20486 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20487 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20488 |
m_data.m_value = other.m_data.m_value.number_unsigned; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20489 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20490 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20491 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20492 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20493 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20494 |
m_data.m_value = other.m_data.m_value.number_float; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20495 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20496 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20497 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20498 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20499 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20500 |
m_data.m_value = *other.m_data.m_value.binary; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20501 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20502 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20503 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20504 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20505 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20506 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20507 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20508 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20509 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20510 |
set_parents(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20511 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20512 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20513 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20514 |
/// @brief move constructor |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20515 |
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20516 |
basic_json(basic_json&& other) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20517 |
: json_base_class_t(std::forward<json_base_class_t>(other)), |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20518 |
m_data(std::move(other.m_data)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20519 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20520 |
// check that passed value is valid |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20521 |
other.assert_invariant(false); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20522 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20523 |
// invalidate payload |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20524 |
other.m_data.m_type = value_t::null; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20525 |
other.m_data.m_value = {}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20526 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20527 |
set_parents(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20528 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20529 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20530 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20531 |
/// @brief copy assignment |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20532 |
/// @sa https://json.nlohmann.me/api/basic_json/operator=/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20533 |
basic_json& operator=(basic_json other) noexcept ( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20534 |
std::is_nothrow_move_constructible<value_t>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20535 |
std::is_nothrow_move_assignable<value_t>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20536 |
std::is_nothrow_move_constructible<json_value>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20537 |
std::is_nothrow_move_assignable<json_value>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20538 |
std::is_nothrow_move_assignable<json_base_class_t>::value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20539 |
) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20540 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20541 |
// check that passed value is valid |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20542 |
other.assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20543 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20544 |
using std::swap; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20545 |
swap(m_data.m_type, other.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20546 |
swap(m_data.m_value, other.m_data.m_value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20547 |
json_base_class_t::operator=(std::move(other)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20548 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20549 |
set_parents(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20550 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20551 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20552 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20553 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20554 |
/// @brief destructor |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20555 |
/// @sa https://json.nlohmann.me/api/basic_json/~basic_json/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20556 |
~basic_json() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20557 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20558 |
assert_invariant(false); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20559 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20560 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20561 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20562 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20563 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20564 |
/////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20565 |
// object inspection // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20566 |
/////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20567 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20568 |
/// @name object inspection |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20569 |
/// Functions to inspect the type of a JSON value. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20570 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20571 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20572 |
/// @brief serialization |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20573 |
/// @sa https://json.nlohmann.me/api/basic_json/dump/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20574 |
string_t dump(const int indent = -1, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20575 |
const char indent_char = ' ', |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20576 |
const bool ensure_ascii = false, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20577 |
const error_handler_t error_handler = error_handler_t::strict) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20578 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20579 |
string_t result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20580 |
serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20581 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20582 |
if (indent >= 0) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20583 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20584 |
s.dump(*this, true, ensure_ascii, static_cast<unsigned int>(indent)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20585 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20586 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20587 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20588 |
s.dump(*this, false, ensure_ascii, 0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20589 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20590 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20591 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20592 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20593 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20594 |
/// @brief return the type of the JSON value (explicit) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20595 |
/// @sa https://json.nlohmann.me/api/basic_json/type/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20596 |
constexpr value_t type() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20597 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20598 |
return m_data.m_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20599 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20600 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20601 |
/// @brief return whether type is primitive |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20602 |
/// @sa https://json.nlohmann.me/api/basic_json/is_primitive/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20603 |
constexpr bool is_primitive() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20604 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20605 |
return is_null() || is_string() || is_boolean() || is_number() || is_binary(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20606 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20607 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20608 |
/// @brief return whether type is structured |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20609 |
/// @sa https://json.nlohmann.me/api/basic_json/is_structured/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20610 |
constexpr bool is_structured() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20611 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20612 |
return is_array() || is_object(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20613 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20614 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20615 |
/// @brief return whether value is null |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20616 |
/// @sa https://json.nlohmann.me/api/basic_json/is_null/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20617 |
constexpr bool is_null() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20618 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20619 |
return m_data.m_type == value_t::null; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20620 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20621 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20622 |
/// @brief return whether value is a boolean |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20623 |
/// @sa https://json.nlohmann.me/api/basic_json/is_boolean/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20624 |
constexpr bool is_boolean() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20625 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20626 |
return m_data.m_type == value_t::boolean; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20627 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20628 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20629 |
/// @brief return whether value is a number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20630 |
/// @sa https://json.nlohmann.me/api/basic_json/is_number/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20631 |
constexpr bool is_number() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20632 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20633 |
return is_number_integer() || is_number_float(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20634 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20635 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20636 |
/// @brief return whether value is an integer number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20637 |
/// @sa https://json.nlohmann.me/api/basic_json/is_number_integer/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20638 |
constexpr bool is_number_integer() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20639 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20640 |
return m_data.m_type == value_t::number_integer || m_data.m_type == value_t::number_unsigned; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20641 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20642 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20643 |
/// @brief return whether value is an unsigned integer number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20644 |
/// @sa https://json.nlohmann.me/api/basic_json/is_number_unsigned/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20645 |
constexpr bool is_number_unsigned() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20646 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20647 |
return m_data.m_type == value_t::number_unsigned; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20648 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20649 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20650 |
/// @brief return whether value is a floating-point number |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20651 |
/// @sa https://json.nlohmann.me/api/basic_json/is_number_float/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20652 |
constexpr bool is_number_float() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20653 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20654 |
return m_data.m_type == value_t::number_float; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20655 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20656 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20657 |
/// @brief return whether value is an object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20658 |
/// @sa https://json.nlohmann.me/api/basic_json/is_object/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20659 |
constexpr bool is_object() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20660 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20661 |
return m_data.m_type == value_t::object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20662 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20663 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20664 |
/// @brief return whether value is an array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20665 |
/// @sa https://json.nlohmann.me/api/basic_json/is_array/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20666 |
constexpr bool is_array() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20667 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20668 |
return m_data.m_type == value_t::array; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20669 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20670 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20671 |
/// @brief return whether value is a string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20672 |
/// @sa https://json.nlohmann.me/api/basic_json/is_string/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20673 |
constexpr bool is_string() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20674 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20675 |
return m_data.m_type == value_t::string; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20676 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20677 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20678 |
/// @brief return whether value is a binary array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20679 |
/// @sa https://json.nlohmann.me/api/basic_json/is_binary/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20680 |
constexpr bool is_binary() const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20681 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20682 |
return m_data.m_type == value_t::binary; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20683 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20684 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20685 |
/// @brief return whether value is discarded |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20686 |
/// @sa https://json.nlohmann.me/api/basic_json/is_discarded/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20687 |
constexpr bool is_discarded() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20688 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20689 |
return m_data.m_type == value_t::discarded; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20690 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20691 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20692 |
/// @brief return the type of the JSON value (implicit) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20693 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_value_t/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20694 |
constexpr operator value_t() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20695 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20696 |
return m_data.m_type; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20697 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20698 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20699 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20700 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20701 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20702 |
////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20703 |
// value access // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20704 |
////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20705 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20706 |
/// get a boolean (explicit) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20707 |
boolean_t get_impl(boolean_t* /*unused*/) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20708 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20709 |
if (JSON_HEDLEY_LIKELY(is_boolean())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20710 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20711 |
return m_data.m_value.boolean; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20712 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20713 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20714 |
JSON_THROW(type_error::create(302, detail::concat("type must be boolean, but is ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20715 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20716 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20717 |
/// get a pointer to the value (object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20718 |
object_t* get_impl_ptr(object_t* /*unused*/) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20719 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20720 |
return is_object() ? m_data.m_value.object : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20721 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20722 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20723 |
/// get a pointer to the value (object) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20724 |
constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20725 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20726 |
return is_object() ? m_data.m_value.object : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20727 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20728 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20729 |
/// get a pointer to the value (array) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20730 |
array_t* get_impl_ptr(array_t* /*unused*/) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20731 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20732 |
return is_array() ? m_data.m_value.array : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20733 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20734 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20735 |
/// get a pointer to the value (array) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20736 |
constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20737 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20738 |
return is_array() ? m_data.m_value.array : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20739 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20740 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20741 |
/// get a pointer to the value (string) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20742 |
string_t* get_impl_ptr(string_t* /*unused*/) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20743 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20744 |
return is_string() ? m_data.m_value.string : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20745 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20746 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20747 |
/// get a pointer to the value (string) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20748 |
constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20749 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20750 |
return is_string() ? m_data.m_value.string : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20751 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20752 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20753 |
/// get a pointer to the value (boolean) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20754 |
boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20755 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20756 |
return is_boolean() ? &m_data.m_value.boolean : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20757 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20758 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20759 |
/// get a pointer to the value (boolean) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20760 |
constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20761 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20762 |
return is_boolean() ? &m_data.m_value.boolean : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20763 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20764 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20765 |
/// get a pointer to the value (integer number) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20766 |
number_integer_t* get_impl_ptr(number_integer_t* /*unused*/) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20767 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20768 |
return is_number_integer() ? &m_data.m_value.number_integer : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20769 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20770 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20771 |
/// get a pointer to the value (integer number) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20772 |
constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20773 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20774 |
return is_number_integer() ? &m_data.m_value.number_integer : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20775 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20776 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20777 |
/// get a pointer to the value (unsigned number) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20778 |
number_unsigned_t* get_impl_ptr(number_unsigned_t* /*unused*/) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20779 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20780 |
return is_number_unsigned() ? &m_data.m_value.number_unsigned : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20781 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20782 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20783 |
/// get a pointer to the value (unsigned number) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20784 |
constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20785 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20786 |
return is_number_unsigned() ? &m_data.m_value.number_unsigned : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20787 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20788 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20789 |
/// get a pointer to the value (floating-point number) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20790 |
number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20791 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20792 |
return is_number_float() ? &m_data.m_value.number_float : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20793 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20794 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20795 |
/// get a pointer to the value (floating-point number) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20796 |
constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20797 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20798 |
return is_number_float() ? &m_data.m_value.number_float : nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20799 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20800 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20801 |
/// get a pointer to the value (binary) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20802 |
binary_t* get_impl_ptr(binary_t* /*unused*/) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20803 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20804 |
return is_binary() ? m_data.m_value.binary : nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20805 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20806 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20807 |
/// get a pointer to the value (binary) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20808 |
constexpr const binary_t* get_impl_ptr(const binary_t* /*unused*/) const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20809 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20810 |
return is_binary() ? m_data.m_value.binary : nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20811 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20812 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20813 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20814 |
@brief helper function to implement get_ref() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20815 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20816 |
This function helps to implement get_ref() without code duplication for |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20817 |
const and non-const overloads |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20818 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20819 |
@tparam ThisType will be deduced as `basic_json` or `const basic_json` |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20820 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20821 |
@throw type_error.303 if ReferenceType does not match underlying value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20822 |
type of the current JSON |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20823 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20824 |
template<typename ReferenceType, typename ThisType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20825 |
static ReferenceType get_ref_impl(ThisType& obj) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20826 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20827 |
// delegate the call to get_ptr<>() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20828 |
auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20829 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20830 |
if (JSON_HEDLEY_LIKELY(ptr != nullptr)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20831 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20832 |
return *ptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20833 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20834 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20835 |
JSON_THROW(type_error::create(303, detail::concat("incompatible ReferenceType for get_ref, actual type is ", obj.type_name()), &obj)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20836 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20837 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20838 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20839 |
/// @name value access |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20840 |
/// Direct access to the stored value of a JSON value. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20841 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20842 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20843 |
/// @brief get a pointer value (implicit) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20844 |
/// @sa https://json.nlohmann.me/api/basic_json/get_ptr/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20845 |
template<typename PointerType, typename std::enable_if< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20846 |
std::is_pointer<PointerType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20847 |
auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20848 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20849 |
// delegate the call to get_impl_ptr<>() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20850 |
return get_impl_ptr(static_cast<PointerType>(nullptr)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20851 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20852 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20853 |
/// @brief get a pointer value (implicit) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20854 |
/// @sa https://json.nlohmann.me/api/basic_json/get_ptr/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20855 |
template < typename PointerType, typename std::enable_if < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20856 |
std::is_pointer<PointerType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20857 |
std::is_const<typename std::remove_pointer<PointerType>::type>::value, int >::type = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20858 |
constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20859 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20860 |
// delegate the call to get_impl_ptr<>() const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20861 |
return get_impl_ptr(static_cast<PointerType>(nullptr)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20862 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20863 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20864 |
private: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20865 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20866 |
@brief get a value (explicit) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20867 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20868 |
Explicit type conversion between the JSON value and a compatible value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20869 |
which is [CopyConstructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20870 |
and [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20871 |
The value is converted by calling the @ref json_serializer<ValueType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20872 |
`from_json()` method. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20873 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20874 |
The function is equivalent to executing |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20875 |
@code {.cpp} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20876 |
ValueType ret; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20877 |
JSONSerializer<ValueType>::from_json(*this, ret); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20878 |
return ret; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20879 |
@endcode |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20880 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20881 |
This overloads is chosen if: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20882 |
- @a ValueType is not @ref basic_json, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20883 |
- @ref json_serializer<ValueType> has a `from_json()` method of the form |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20884 |
`void from_json(const basic_json&, ValueType&)`, and |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20885 |
- @ref json_serializer<ValueType> does not have a `from_json()` method of |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20886 |
the form `ValueType from_json(const basic_json&)` |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20887 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20888 |
@tparam ValueType the returned value type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20889 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20890 |
@return copy of the JSON value, converted to @a ValueType |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20891 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20892 |
@throw what @ref json_serializer<ValueType> `from_json()` method throws |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20893 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20894 |
@liveexample{The example below shows several conversions from JSON values |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20895 |
to other types. There a few things to note: (1) Floating-point numbers can |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20896 |
be converted to integers\, (2) A JSON array can be converted to a standard |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20897 |
`std::vector<short>`\, (3) A JSON object can be converted to C++ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20898 |
associative containers such as `std::unordered_map<std::string\, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20899 |
json>`.,get__ValueType_const} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20900 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20901 |
@since version 2.1.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20902 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20903 |
template < typename ValueType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20904 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20905 |
detail::is_default_constructible<ValueType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20906 |
detail::has_from_json<basic_json_t, ValueType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20907 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20908 |
ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20909 |
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20910 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20911 |
auto ret = ValueType(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20912 |
JSONSerializer<ValueType>::from_json(*this, ret); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20913 |
return ret; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20914 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20915 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20916 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20917 |
@brief get a value (explicit); special case |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20918 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20919 |
Explicit type conversion between the JSON value and a compatible value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20920 |
which is **not** [CopyConstructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20921 |
and **not** [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible). |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20922 |
The value is converted by calling the @ref json_serializer<ValueType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20923 |
`from_json()` method. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20924 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20925 |
The function is equivalent to executing |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20926 |
@code {.cpp} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20927 |
return JSONSerializer<ValueType>::from_json(*this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20928 |
@endcode |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20929 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20930 |
This overloads is chosen if: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20931 |
- @a ValueType is not @ref basic_json and |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20932 |
- @ref json_serializer<ValueType> has a `from_json()` method of the form |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20933 |
`ValueType from_json(const basic_json&)` |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20934 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20935 |
@note If @ref json_serializer<ValueType> has both overloads of |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20936 |
`from_json()`, this one is chosen. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20937 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20938 |
@tparam ValueType the returned value type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20939 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20940 |
@return copy of the JSON value, converted to @a ValueType |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20941 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20942 |
@throw what @ref json_serializer<ValueType> `from_json()` method throws |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20943 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20944 |
@since version 2.1.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20945 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20946 |
template < typename ValueType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20947 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20948 |
detail::has_non_default_from_json<basic_json_t, ValueType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20949 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20950 |
ValueType get_impl(detail::priority_tag<1> /*unused*/) const noexcept(noexcept( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20951 |
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>()))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20952 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20953 |
return JSONSerializer<ValueType>::from_json(*this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20954 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20955 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20956 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20957 |
@brief get special-case overload |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20958 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20959 |
This overloads converts the current @ref basic_json in a different |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20960 |
@ref basic_json type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20961 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20962 |
@tparam BasicJsonType == @ref basic_json |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20963 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20964 |
@return a copy of *this, converted into @a BasicJsonType |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20965 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20966 |
@complexity Depending on the implementation of the called `from_json()` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20967 |
method. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20968 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20969 |
@since version 3.2.0 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20970 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20971 |
template < typename BasicJsonType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20972 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20973 |
detail::is_basic_json<BasicJsonType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20974 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20975 |
BasicJsonType get_impl(detail::priority_tag<2> /*unused*/) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20976 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20977 |
return *this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20978 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20979 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20980 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20981 |
@brief get special-case overload |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20982 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20983 |
This overloads avoids a lot of template boilerplate, it can be seen as the |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20984 |
identity method |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20985 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20986 |
@tparam BasicJsonType == @ref basic_json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20987 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20988 |
@return a copy of *this |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20989 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20990 |
@complexity Constant. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20991 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20992 |
@since version 2.1.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20993 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20994 |
template<typename BasicJsonType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20995 |
detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20996 |
std::is_same<BasicJsonType, basic_json_t>::value, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20997 |
int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
20998 |
basic_json get_impl(detail::priority_tag<3> /*unused*/) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
20999 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21000 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21001 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21002 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21003 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21004 |
@brief get a pointer value (explicit) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21005 |
@copydoc get() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21006 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21007 |
template<typename PointerType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21008 |
detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21009 |
std::is_pointer<PointerType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21010 |
int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21011 |
constexpr auto get_impl(detail::priority_tag<4> /*unused*/) const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21012 |
-> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21013 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21014 |
// delegate the call to get_ptr |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21015 |
return get_ptr<PointerType>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21016 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21017 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21018 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21019 |
/*! |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21020 |
@brief get a (pointer) value (explicit) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21021 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21022 |
Performs explicit type conversion between the JSON value and a compatible value if required. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21023 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21024 |
- If the requested type is a pointer to the internally stored JSON value that pointer is returned. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21025 |
No copies are made. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21026 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21027 |
- If the requested type is the current @ref basic_json, or a different @ref basic_json convertible |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21028 |
from the current @ref basic_json. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21029 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21030 |
- Otherwise the value is converted by calling the @ref json_serializer<ValueType> `from_json()` |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21031 |
method. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21032 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21033 |
@tparam ValueTypeCV the provided value type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21034 |
@tparam ValueType the returned value type |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21035 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21036 |
@return copy of the JSON value, converted to @tparam ValueType if necessary |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21037 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21038 |
@throw what @ref json_serializer<ValueType> `from_json()` method throws if conversion is required |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21039 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21040 |
@since version 2.1.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21041 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21042 |
template < typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21043 |
#if defined(JSON_HAS_CPP_14) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21044 |
constexpr |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21045 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21046 |
auto get() const noexcept( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21047 |
noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21048 |
-> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21049 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21050 |
// we cannot static_assert on ValueTypeCV being non-const, because |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21051 |
// there is support for get<const basic_json_t>(), which is why we |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21052 |
// still need the uncvref |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21053 |
static_assert(!std::is_reference<ValueTypeCV>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21054 |
"get() cannot be used with reference types, you might want to use get_ref()"); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21055 |
return get_impl<ValueType>(detail::priority_tag<4> {}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21056 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21057 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21058 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21059 |
@brief get a pointer value (explicit) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21060 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21061 |
Explicit pointer access to the internally stored JSON value. No copies are |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21062 |
made. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21063 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21064 |
@warning The pointer becomes invalid if the underlying JSON object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21065 |
changes. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21066 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21067 |
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21068 |
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21069 |
@ref number_unsigned_t, or @ref number_float_t. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21070 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21071 |
@return pointer to the internally stored JSON value if the requested |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21072 |
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21073 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21074 |
@complexity Constant. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21075 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21076 |
@liveexample{The example below shows how pointers to internal values of a |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21077 |
JSON value can be requested. Note that no type conversions are made and a |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21078 |
`nullptr` is returned if the value and the requested pointer type does not |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21079 |
match.,get__PointerType} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21080 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21081 |
@sa see @ref get_ptr() for explicit pointer-member access |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21082 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21083 |
@since version 1.0.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21084 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21085 |
template<typename PointerType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21086 |
std::is_pointer<PointerType>::value, int>::type = 0> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21087 |
auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21088 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21089 |
// delegate the call to get_ptr |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21090 |
return get_ptr<PointerType>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21091 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21092 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21093 |
/// @brief get a value (explicit) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21094 |
/// @sa https://json.nlohmann.me/api/basic_json/get_to/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21095 |
template < typename ValueType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21096 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21097 |
!detail::is_basic_json<ValueType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21098 |
detail::has_from_json<basic_json_t, ValueType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21099 |
int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21100 |
ValueType & get_to(ValueType& v) const noexcept(noexcept( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21101 |
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21102 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21103 |
JSONSerializer<ValueType>::from_json(*this, v); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21104 |
return v; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21105 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21106 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21107 |
// specialization to allow calling get_to with a basic_json value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21108 |
// see https://github.com/nlohmann/json/issues/2175 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21109 |
template<typename ValueType, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21110 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21111 |
detail::is_basic_json<ValueType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21112 |
int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21113 |
ValueType & get_to(ValueType& v) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21114 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21115 |
v = *this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21116 |
return v; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21117 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21118 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21119 |
template < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21120 |
typename T, std::size_t N, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21121 |
typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21122 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21123 |
detail::has_from_json<basic_json_t, Array>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21124 |
Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21125 |
noexcept(noexcept(JSONSerializer<Array>::from_json( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21126 |
std::declval<const basic_json_t&>(), v))) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21127 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21128 |
JSONSerializer<Array>::from_json(*this, v); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21129 |
return v; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21130 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21131 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21132 |
/// @brief get a reference value (implicit) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21133 |
/// @sa https://json.nlohmann.me/api/basic_json/get_ref/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21134 |
template<typename ReferenceType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21135 |
std::is_reference<ReferenceType>::value, int>::type = 0> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21136 |
ReferenceType get_ref() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21137 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21138 |
// delegate call to get_ref_impl |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21139 |
return get_ref_impl<ReferenceType>(*this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21140 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21141 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21142 |
/// @brief get a reference value (implicit) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21143 |
/// @sa https://json.nlohmann.me/api/basic_json/get_ref/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21144 |
template < typename ReferenceType, typename std::enable_if < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21145 |
std::is_reference<ReferenceType>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21146 |
std::is_const<typename std::remove_reference<ReferenceType>::type>::value, int >::type = 0 > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21147 |
ReferenceType get_ref() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21148 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21149 |
// delegate call to get_ref_impl |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21150 |
return get_ref_impl<ReferenceType>(*this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21151 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21152 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21153 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21154 |
@brief get a value (implicit) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21155 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21156 |
Implicit type conversion between the JSON value and a compatible value. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21157 |
The call is realized by calling @ref get() const. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21158 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21159 |
@tparam ValueType non-pointer type compatible to the JSON value, for |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21160 |
instance `int` for JSON integer numbers, `bool` for JSON booleans, or |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21161 |
`std::vector` types for JSON arrays. The character type of @ref string_t |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21162 |
as well as an initializer list of this type is excluded to avoid |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21163 |
ambiguities as these types implicitly convert to `std::string`. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21164 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21165 |
@return copy of the JSON value, converted to type @a ValueType |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21166 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21167 |
@throw type_error.302 in case passed type @a ValueType is incompatible |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21168 |
to the JSON value type (e.g., the JSON value is of type boolean, but a |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21169 |
string is requested); see example below |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21170 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21171 |
@complexity Linear in the size of the JSON value. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21172 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21173 |
@liveexample{The example below shows several conversions from JSON values |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21174 |
to other types. There a few things to note: (1) Floating-point numbers can |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21175 |
be converted to integers\, (2) A JSON array can be converted to a standard |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21176 |
`std::vector<short>`\, (3) A JSON object can be converted to C++ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21177 |
associative containers such as `std::unordered_map<std::string\, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21178 |
json>`.,operator__ValueType} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21179 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21180 |
@since version 1.0.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21181 |
*/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21182 |
template < typename ValueType, typename std::enable_if < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21183 |
detail::conjunction < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21184 |
detail::negation<std::is_pointer<ValueType>>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21185 |
detail::negation<std::is_same<ValueType, std::nullptr_t>>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21186 |
detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21187 |
detail::negation<std::is_same<ValueType, typename string_t::value_type>>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21188 |
detail::negation<detail::is_basic_json<ValueType>>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21189 |
detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21190 |
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21191 |
detail::negation<std::is_same<ValueType, std::string_view>>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21192 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21193 |
#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21194 |
detail::negation<std::is_same<ValueType, std::any>>, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21195 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21196 |
detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21197 |
>::value, int >::type = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21198 |
JSON_EXPLICIT operator ValueType() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21199 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21200 |
// delegate the call to get<>() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21201 |
return get<ValueType>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21202 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21203 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21204 |
/// @brief get a binary value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21205 |
/// @sa https://json.nlohmann.me/api/basic_json/get_binary/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21206 |
binary_t& get_binary() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21207 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21208 |
if (!is_binary()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21209 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21210 |
JSON_THROW(type_error::create(302, detail::concat("type must be binary, but is ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21211 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21212 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21213 |
return *get_ptr<binary_t*>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21214 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21215 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21216 |
/// @brief get a binary value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21217 |
/// @sa https://json.nlohmann.me/api/basic_json/get_binary/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21218 |
const binary_t& get_binary() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21219 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21220 |
if (!is_binary()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21221 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21222 |
JSON_THROW(type_error::create(302, detail::concat("type must be binary, but is ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21223 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21224 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21225 |
return *get_ptr<const binary_t*>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21226 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21227 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21228 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21229 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21230 |
//////////////////// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21231 |
// element access // |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21232 |
//////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21233 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21234 |
/// @name element access |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21235 |
/// Access to the JSON value. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21236 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21237 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21238 |
/// @brief access specified array element with bounds checking |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21239 |
/// @sa https://json.nlohmann.me/api/basic_json/at/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21240 |
reference at(size_type idx) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21241 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21242 |
// at only works for arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21243 |
if (JSON_HEDLEY_LIKELY(is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21244 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21245 |
JSON_TRY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21246 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21247 |
return set_parent(m_data.m_value.array->at(idx)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21248 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21249 |
JSON_CATCH (std::out_of_range&) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21250 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21251 |
// create better exception explanation |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21252 |
JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21253 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21254 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21255 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21256 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21257 |
JSON_THROW(type_error::create(304, detail::concat("cannot use at() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21258 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21259 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21260 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21261 |
/// @brief access specified array element with bounds checking |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21262 |
/// @sa https://json.nlohmann.me/api/basic_json/at/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21263 |
const_reference at(size_type idx) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21264 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21265 |
// at only works for arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21266 |
if (JSON_HEDLEY_LIKELY(is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21267 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21268 |
JSON_TRY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21269 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21270 |
return m_data.m_value.array->at(idx); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21271 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21272 |
JSON_CATCH (std::out_of_range&) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21273 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21274 |
// create better exception explanation |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21275 |
JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21276 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21277 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21278 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21279 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21280 |
JSON_THROW(type_error::create(304, detail::concat("cannot use at() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21281 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21282 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21283 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21284 |
/// @brief access specified object element with bounds checking |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21285 |
/// @sa https://json.nlohmann.me/api/basic_json/at/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21286 |
reference at(const typename object_t::key_type& key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21287 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21288 |
// at only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21289 |
if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21290 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21291 |
JSON_THROW(type_error::create(304, detail::concat("cannot use at() with ", type_name()), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21292 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21293 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21294 |
auto it = m_data.m_value.object->find(key); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21295 |
if (it == m_data.m_value.object->end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21296 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21297 |
JSON_THROW(out_of_range::create(403, detail::concat("key '", key, "' not found"), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21298 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21299 |
return set_parent(it->second); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21300 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21301 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21302 |
/// @brief access specified object element with bounds checking |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21303 |
/// @sa https://json.nlohmann.me/api/basic_json/at/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21304 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21305 |
detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21306 |
reference at(KeyType && key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21307 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21308 |
// at only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21309 |
if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21310 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21311 |
JSON_THROW(type_error::create(304, detail::concat("cannot use at() with ", type_name()), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21312 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21313 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21314 |
auto it = m_data.m_value.object->find(std::forward<KeyType>(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21315 |
if (it == m_data.m_value.object->end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21316 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21317 |
JSON_THROW(out_of_range::create(403, detail::concat("key '", string_t(std::forward<KeyType>(key)), "' not found"), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21318 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21319 |
return set_parent(it->second); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21320 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21321 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21322 |
/// @brief access specified object element with bounds checking |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21323 |
/// @sa https://json.nlohmann.me/api/basic_json/at/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21324 |
const_reference at(const typename object_t::key_type& key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21325 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21326 |
// at only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21327 |
if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21328 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21329 |
JSON_THROW(type_error::create(304, detail::concat("cannot use at() with ", type_name()), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21330 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21331 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21332 |
auto it = m_data.m_value.object->find(key); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21333 |
if (it == m_data.m_value.object->end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21334 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21335 |
JSON_THROW(out_of_range::create(403, detail::concat("key '", key, "' not found"), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21336 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21337 |
return it->second; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21338 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21339 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21340 |
/// @brief access specified object element with bounds checking |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21341 |
/// @sa https://json.nlohmann.me/api/basic_json/at/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21342 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21343 |
detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21344 |
const_reference at(KeyType && key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21345 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21346 |
// at only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21347 |
if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21348 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21349 |
JSON_THROW(type_error::create(304, detail::concat("cannot use at() with ", type_name()), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21350 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21351 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21352 |
auto it = m_data.m_value.object->find(std::forward<KeyType>(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21353 |
if (it == m_data.m_value.object->end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21354 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21355 |
JSON_THROW(out_of_range::create(403, detail::concat("key '", string_t(std::forward<KeyType>(key)), "' not found"), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21356 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21357 |
return it->second; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21358 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21359 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21360 |
/// @brief access specified array element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21361 |
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21362 |
reference operator[](size_type idx) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21363 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21364 |
// implicitly convert null value to an empty array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21365 |
if (is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21366 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21367 |
m_data.m_type = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21368 |
m_data.m_value.array = create<array_t>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21369 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21370 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21371 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21372 |
// operator[] only works for arrays |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21373 |
if (JSON_HEDLEY_LIKELY(is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21374 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21375 |
// fill up array with null values if given idx is outside range |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21376 |
if (idx >= m_data.m_value.array->size()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21377 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21378 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21379 |
// remember array size & capacity before resizing |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21380 |
const auto old_size = m_data.m_value.array->size(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21381 |
const auto old_capacity = m_data.m_value.array->capacity(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21382 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21383 |
m_data.m_value.array->resize(idx + 1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21384 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21385 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21386 |
if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21387 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21388 |
// capacity has changed: update all parents |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21389 |
set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21390 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21391 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21392 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21393 |
// set parent for values added above |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21394 |
set_parents(begin() + static_cast<typename iterator::difference_type>(old_size), static_cast<typename iterator::difference_type>(idx + 1 - old_size)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21395 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21396 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21397 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21398 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21399 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21400 |
return m_data.m_value.array->operator[](idx); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21401 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21402 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21403 |
JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a numeric argument with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21404 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21405 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21406 |
/// @brief access specified array element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21407 |
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21408 |
const_reference operator[](size_type idx) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21409 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21410 |
// const operator[] only works for arrays |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21411 |
if (JSON_HEDLEY_LIKELY(is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21412 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21413 |
return m_data.m_value.array->operator[](idx); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21414 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21415 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21416 |
JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a numeric argument with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21417 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21418 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21419 |
/// @brief access specified object element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21420 |
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21421 |
reference operator[](typename object_t::key_type key) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21422 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21423 |
// implicitly convert null value to an empty object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21424 |
if (is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21425 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21426 |
m_data.m_type = value_t::object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21427 |
m_data.m_value.object = create<object_t>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21428 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21429 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21430 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21431 |
// operator[] only works for objects |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21432 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21433 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21434 |
auto result = m_data.m_value.object->emplace(std::move(key), nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21435 |
return set_parent(result.first->second); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21436 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21437 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21438 |
JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21439 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21440 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21441 |
/// @brief access specified object element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21442 |
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21443 |
const_reference operator[](const typename object_t::key_type& key) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21444 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21445 |
// const operator[] only works for objects |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21446 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21447 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21448 |
auto it = m_data.m_value.object->find(key); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21449 |
JSON_ASSERT(it != m_data.m_value.object->end()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21450 |
return it->second; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21451 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21452 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21453 |
JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21454 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21455 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21456 |
// these two functions resolve a (const) char * ambiguity affecting Clang and MSVC |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21457 |
// (they seemingly cannot be constrained to resolve the ambiguity) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21458 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21459 |
reference operator[](T* key) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21460 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21461 |
return operator[](typename object_t::key_type(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21462 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21463 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21464 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21465 |
const_reference operator[](T* key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21466 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21467 |
return operator[](typename object_t::key_type(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21468 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21469 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21470 |
/// @brief access specified object element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21471 |
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21472 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21473 |
detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21474 |
reference operator[](KeyType && key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21475 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21476 |
// implicitly convert null value to an empty object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21477 |
if (is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21478 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21479 |
m_data.m_type = value_t::object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21480 |
m_data.m_value.object = create<object_t>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21481 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21482 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21483 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21484 |
// operator[] only works for objects |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21485 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21486 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21487 |
auto result = m_data.m_value.object->emplace(std::forward<KeyType>(key), nullptr); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21488 |
return set_parent(result.first->second); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21489 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21490 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21491 |
JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21492 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21493 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21494 |
/// @brief access specified object element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21495 |
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21496 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21497 |
detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21498 |
const_reference operator[](KeyType && key) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21499 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21500 |
// const operator[] only works for objects |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21501 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21502 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21503 |
auto it = m_data.m_value.object->find(std::forward<KeyType>(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21504 |
JSON_ASSERT(it != m_data.m_value.object->end()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21505 |
return it->second; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21506 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21507 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21508 |
JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21509 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21510 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21511 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21512 |
template<typename KeyType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21513 |
using is_comparable_with_object_key = detail::is_comparable < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21514 |
object_comparator_t, const typename object_t::key_type&, KeyType >; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21515 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21516 |
template<typename ValueType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21517 |
using value_return_type = std::conditional < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21518 |
detail::is_c_string_uncvref<ValueType>::value, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21519 |
string_t, typename std::decay<ValueType>::type >; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21520 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21521 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21522 |
/// @brief access specified object element with default value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21523 |
/// @sa https://json.nlohmann.me/api/basic_json/value/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21524 |
template < class ValueType, detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21525 |
!detail::is_transparent<object_comparator_t>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21526 |
&& detail::is_getable<basic_json_t, ValueType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21527 |
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21528 |
ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21529 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21530 |
// value only works for objects |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21531 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21532 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21533 |
// if key is found, return value and given default value otherwise |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21534 |
const auto it = find(key); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21535 |
if (it != end()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21536 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21537 |
return it->template get<ValueType>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21538 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21539 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21540 |
return default_value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21541 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21542 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21543 |
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21544 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21545 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21546 |
/// @brief access specified object element with default value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21547 |
/// @sa https://json.nlohmann.me/api/basic_json/value/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21548 |
template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21549 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21550 |
!detail::is_transparent<object_comparator_t>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21551 |
&& detail::is_getable<basic_json_t, ReturnType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21552 |
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21553 |
ReturnType value(const typename object_t::key_type& key, ValueType && default_value) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21554 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21555 |
// value only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21556 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21557 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21558 |
// if key is found, return value and given default value otherwise |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21559 |
const auto it = find(key); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21560 |
if (it != end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21561 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21562 |
return it->template get<ReturnType>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21563 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21564 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21565 |
return std::forward<ValueType>(default_value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21566 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21567 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21568 |
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21569 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21570 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21571 |
/// @brief access specified object element with default value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21572 |
/// @sa https://json.nlohmann.me/api/basic_json/value/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21573 |
template < class ValueType, class KeyType, detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21574 |
detail::is_transparent<object_comparator_t>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21575 |
&& !detail::is_json_pointer<KeyType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21576 |
&& is_comparable_with_object_key<KeyType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21577 |
&& detail::is_getable<basic_json_t, ValueType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21578 |
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21579 |
ValueType value(KeyType && key, const ValueType& default_value) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21580 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21581 |
// value only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21582 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21583 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21584 |
// if key is found, return value and given default value otherwise |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21585 |
const auto it = find(std::forward<KeyType>(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21586 |
if (it != end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21587 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21588 |
return it->template get<ValueType>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21589 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21590 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21591 |
return default_value; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21592 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21593 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21594 |
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21595 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21596 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21597 |
/// @brief access specified object element via JSON Pointer with default value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21598 |
/// @sa https://json.nlohmann.me/api/basic_json/value/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21599 |
template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21600 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21601 |
detail::is_transparent<object_comparator_t>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21602 |
&& !detail::is_json_pointer<KeyType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21603 |
&& is_comparable_with_object_key<KeyType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21604 |
&& detail::is_getable<basic_json_t, ReturnType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21605 |
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21606 |
ReturnType value(KeyType && key, ValueType && default_value) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21607 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21608 |
// value only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21609 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21610 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21611 |
// if key is found, return value and given default value otherwise |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21612 |
const auto it = find(std::forward<KeyType>(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21613 |
if (it != end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21614 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21615 |
return it->template get<ReturnType>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21616 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21617 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21618 |
return std::forward<ValueType>(default_value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21619 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21620 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21621 |
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21622 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21623 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21624 |
/// @brief access specified object element via JSON Pointer with default value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21625 |
/// @sa https://json.nlohmann.me/api/basic_json/value/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21626 |
template < class ValueType, detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21627 |
detail::is_getable<basic_json_t, ValueType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21628 |
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21629 |
ValueType value(const json_pointer& ptr, const ValueType& default_value) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21630 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21631 |
// value only works for objects |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21632 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21633 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21634 |
// if pointer resolves a value, return it or use default value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21635 |
JSON_TRY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21636 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21637 |
return ptr.get_checked(this).template get<ValueType>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21638 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21639 |
JSON_INTERNAL_CATCH (out_of_range&) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21640 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21641 |
return default_value; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21642 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21643 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21644 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21645 |
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21646 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21647 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21648 |
/// @brief access specified object element via JSON Pointer with default value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21649 |
/// @sa https://json.nlohmann.me/api/basic_json/value/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21650 |
template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21651 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21652 |
detail::is_getable<basic_json_t, ReturnType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21653 |
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21654 |
ReturnType value(const json_pointer& ptr, ValueType && default_value) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21655 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21656 |
// value only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21657 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21658 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21659 |
// if pointer resolves a value, return it or use default value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21660 |
JSON_TRY |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21661 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21662 |
return ptr.get_checked(this).template get<ReturnType>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21663 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21664 |
JSON_INTERNAL_CATCH (out_of_range&) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21665 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21666 |
return std::forward<ValueType>(default_value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21667 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21668 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21669 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21670 |
JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21671 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21672 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21673 |
template < class ValueType, class BasicJsonType, detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21674 |
detail::is_basic_json<BasicJsonType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21675 |
&& detail::is_getable<basic_json_t, ValueType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21676 |
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21677 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21678 |
ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, const ValueType& default_value) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21679 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21680 |
return value(ptr.convert(), default_value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21681 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21682 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21683 |
template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21684 |
detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21685 |
detail::is_basic_json<BasicJsonType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21686 |
&& detail::is_getable<basic_json_t, ReturnType>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21687 |
&& !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21688 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21689 |
ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType && default_value) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21690 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21691 |
return value(ptr.convert(), std::forward<ValueType>(default_value)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21692 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21693 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21694 |
/// @brief access the first element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21695 |
/// @sa https://json.nlohmann.me/api/basic_json/front/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21696 |
reference front() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21697 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21698 |
return *begin(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21699 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21700 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21701 |
/// @brief access the first element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21702 |
/// @sa https://json.nlohmann.me/api/basic_json/front/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21703 |
const_reference front() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21704 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21705 |
return *cbegin(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21706 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21707 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21708 |
/// @brief access the last element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21709 |
/// @sa https://json.nlohmann.me/api/basic_json/back/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21710 |
reference back() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21711 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21712 |
auto tmp = end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21713 |
--tmp; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21714 |
return *tmp; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21715 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21716 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21717 |
/// @brief access the last element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21718 |
/// @sa https://json.nlohmann.me/api/basic_json/back/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21719 |
const_reference back() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21720 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21721 |
auto tmp = cend(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21722 |
--tmp; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21723 |
return *tmp; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21724 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21725 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21726 |
/// @brief remove element given an iterator |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21727 |
/// @sa https://json.nlohmann.me/api/basic_json/erase/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21728 |
template < class IteratorType, detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21729 |
std::is_same<IteratorType, typename basic_json_t::iterator>::value || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21730 |
std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int > = 0 > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21731 |
IteratorType erase(IteratorType pos) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21732 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21733 |
// make sure iterator fits the current value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21734 |
if (JSON_HEDLEY_UNLIKELY(this != pos.m_object)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21735 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21736 |
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21737 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21738 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21739 |
IteratorType result = end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21740 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21741 |
switch (m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21742 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21743 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21744 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21745 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21746 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21747 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21748 |
case value_t::binary: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21749 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21750 |
if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21751 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21752 |
JSON_THROW(invalid_iterator::create(205, "iterator out of range", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21753 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21754 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21755 |
if (is_string()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21756 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21757 |
AllocatorType<string_t> alloc; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21758 |
std::allocator_traits<decltype(alloc)>::destroy(alloc, m_data.m_value.string); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21759 |
std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21760 |
m_data.m_value.string = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21761 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21762 |
else if (is_binary()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21763 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21764 |
AllocatorType<binary_t> alloc; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21765 |
std::allocator_traits<decltype(alloc)>::destroy(alloc, m_data.m_value.binary); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21766 |
std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21767 |
m_data.m_value.binary = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21768 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21769 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21770 |
m_data.m_type = value_t::null; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21771 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21772 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21773 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21774 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21775 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21776 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21777 |
result.m_it.object_iterator = m_data.m_value.object->erase(pos.m_it.object_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21778 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21779 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21780 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21781 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21782 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21783 |
result.m_it.array_iterator = m_data.m_value.array->erase(pos.m_it.array_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21784 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21785 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21786 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21787 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21788 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21789 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21790 |
JSON_THROW(type_error::create(307, detail::concat("cannot use erase() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21791 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21792 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21793 |
return result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21794 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21795 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21796 |
/// @brief remove elements given an iterator range |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21797 |
/// @sa https://json.nlohmann.me/api/basic_json/erase/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21798 |
template < class IteratorType, detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21799 |
std::is_same<IteratorType, typename basic_json_t::iterator>::value || |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21800 |
std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int > = 0 > |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21801 |
IteratorType erase(IteratorType first, IteratorType last) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21802 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21803 |
// make sure iterator fits the current value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21804 |
if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21805 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21806 |
JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21807 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21808 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21809 |
IteratorType result = end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21810 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21811 |
switch (m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21812 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21813 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21814 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21815 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21816 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21817 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21818 |
case value_t::binary: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21819 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21820 |
if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21821 |
|| !last.m_it.primitive_iterator.is_end())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21822 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21823 |
JSON_THROW(invalid_iterator::create(204, "iterators out of range", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21824 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21825 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21826 |
if (is_string()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21827 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21828 |
AllocatorType<string_t> alloc; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21829 |
std::allocator_traits<decltype(alloc)>::destroy(alloc, m_data.m_value.string); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21830 |
std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21831 |
m_data.m_value.string = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21832 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21833 |
else if (is_binary()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21834 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21835 |
AllocatorType<binary_t> alloc; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21836 |
std::allocator_traits<decltype(alloc)>::destroy(alloc, m_data.m_value.binary); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21837 |
std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21838 |
m_data.m_value.binary = nullptr; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21839 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21840 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21841 |
m_data.m_type = value_t::null; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21842 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21843 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21844 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21845 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21846 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21847 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21848 |
result.m_it.object_iterator = m_data.m_value.object->erase(first.m_it.object_iterator, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21849 |
last.m_it.object_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21850 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21851 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21852 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21853 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21854 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21855 |
result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21856 |
last.m_it.array_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21857 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21858 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21859 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21860 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21861 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21862 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21863 |
JSON_THROW(type_error::create(307, detail::concat("cannot use erase() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21864 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21865 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21866 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21867 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21868 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21869 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21870 |
template < typename KeyType, detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21871 |
detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21872 |
size_type erase_internal(KeyType && key) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21873 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21874 |
// this erase only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21875 |
if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21876 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21877 |
JSON_THROW(type_error::create(307, detail::concat("cannot use erase() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21878 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21879 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21880 |
return m_data.m_value.object->erase(std::forward<KeyType>(key)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21881 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21882 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21883 |
template < typename KeyType, detail::enable_if_t < |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21884 |
!detail::has_erase_with_key_type<basic_json_t, KeyType>::value, int > = 0 > |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21885 |
size_type erase_internal(KeyType && key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21886 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21887 |
// this erase only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21888 |
if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21889 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21890 |
JSON_THROW(type_error::create(307, detail::concat("cannot use erase() with ", type_name()), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21891 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21892 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21893 |
const auto it = m_data.m_value.object->find(std::forward<KeyType>(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21894 |
if (it != m_data.m_value.object->end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21895 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21896 |
m_data.m_value.object->erase(it); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21897 |
return 1; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21898 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21899 |
return 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21900 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21901 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21902 |
public: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21903 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21904 |
/// @brief remove element from a JSON object given a key |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21905 |
/// @sa https://json.nlohmann.me/api/basic_json/erase/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21906 |
size_type erase(const typename object_t::key_type& key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21907 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21908 |
// the indirection via erase_internal() is added to avoid making this |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21909 |
// function a template and thus de-rank it during overload resolution |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21910 |
return erase_internal(key); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21911 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21912 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21913 |
/// @brief remove element from a JSON object given a key |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21914 |
/// @sa https://json.nlohmann.me/api/basic_json/erase/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21915 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21916 |
detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21917 |
size_type erase(KeyType && key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21918 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21919 |
return erase_internal(std::forward<KeyType>(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21920 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21921 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21922 |
/// @brief remove element from a JSON array given an index |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21923 |
/// @sa https://json.nlohmann.me/api/basic_json/erase/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21924 |
void erase(const size_type idx) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21925 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21926 |
// this erase only works for arrays |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21927 |
if (JSON_HEDLEY_LIKELY(is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21928 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21929 |
if (JSON_HEDLEY_UNLIKELY(idx >= size())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21930 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21931 |
JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21932 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21933 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21934 |
m_data.m_value.array->erase(m_data.m_value.array->begin() + static_cast<difference_type>(idx)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21935 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21936 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21937 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21938 |
JSON_THROW(type_error::create(307, detail::concat("cannot use erase() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21939 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21940 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21941 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21942 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21943 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21944 |
//////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21945 |
// lookup // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21946 |
//////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21947 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21948 |
/// @name lookup |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21949 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21950 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21951 |
/// @brief find an element in a JSON object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21952 |
/// @sa https://json.nlohmann.me/api/basic_json/find/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21953 |
iterator find(const typename object_t::key_type& key) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21954 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21955 |
auto result = end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21956 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21957 |
if (is_object()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21958 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21959 |
result.m_it.object_iterator = m_data.m_value.object->find(key); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21960 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21961 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21962 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21963 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21964 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21965 |
/// @brief find an element in a JSON object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21966 |
/// @sa https://json.nlohmann.me/api/basic_json/find/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21967 |
const_iterator find(const typename object_t::key_type& key) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21968 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21969 |
auto result = cend(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21970 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21971 |
if (is_object()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21972 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21973 |
result.m_it.object_iterator = m_data.m_value.object->find(key); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21974 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21975 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21976 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21977 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21978 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21979 |
/// @brief find an element in a JSON object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21980 |
/// @sa https://json.nlohmann.me/api/basic_json/find/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21981 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21982 |
detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21983 |
iterator find(KeyType && key) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21984 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21985 |
auto result = end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21986 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21987 |
if (is_object()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21988 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21989 |
result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21990 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21991 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21992 |
return result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21993 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
21994 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21995 |
/// @brief find an element in a JSON object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21996 |
/// @sa https://json.nlohmann.me/api/basic_json/find/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21997 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21998 |
detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
21999 |
const_iterator find(KeyType && key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22000 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22001 |
auto result = cend(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22002 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22003 |
if (is_object()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22004 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22005 |
result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(key)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22006 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22007 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22008 |
return result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22009 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22010 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22011 |
/// @brief returns the number of occurrences of a key in a JSON object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22012 |
/// @sa https://json.nlohmann.me/api/basic_json/count/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22013 |
size_type count(const typename object_t::key_type& key) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22014 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22015 |
// return 0 for all nonobject types |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22016 |
return is_object() ? m_data.m_value.object->count(key) : 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22017 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22018 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22019 |
/// @brief returns the number of occurrences of a key in a JSON object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22020 |
/// @sa https://json.nlohmann.me/api/basic_json/count/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22021 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22022 |
detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22023 |
size_type count(KeyType && key) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22024 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22025 |
// return 0 for all nonobject types |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22026 |
return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(key)) : 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22027 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22028 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22029 |
/// @brief check the existence of an element in a JSON object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22030 |
/// @sa https://json.nlohmann.me/api/basic_json/contains/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22031 |
bool contains(const typename object_t::key_type& key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22032 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22033 |
return is_object() && m_data.m_value.object->find(key) != m_data.m_value.object->end(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22034 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22035 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22036 |
/// @brief check the existence of an element in a JSON object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22037 |
/// @sa https://json.nlohmann.me/api/basic_json/contains/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22038 |
template<class KeyType, detail::enable_if_t< |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22039 |
detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22040 |
bool contains(KeyType && key) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22041 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22042 |
return is_object() && m_data.m_value.object->find(std::forward<KeyType>(key)) != m_data.m_value.object->end(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22043 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22044 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22045 |
/// @brief check the existence of an element in a JSON object given a JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22046 |
/// @sa https://json.nlohmann.me/api/basic_json/contains/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22047 |
bool contains(const json_pointer& ptr) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22048 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22049 |
return ptr.contains(this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22050 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22051 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22052 |
template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22053 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22054 |
bool contains(const typename ::nlohmann::json_pointer<BasicJsonType>& ptr) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22055 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22056 |
return ptr.contains(this); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22057 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22058 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22059 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22060 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22061 |
/////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22062 |
// iterators // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22063 |
/////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22064 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22065 |
/// @name iterators |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22066 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22067 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22068 |
/// @brief returns an iterator to the first element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22069 |
/// @sa https://json.nlohmann.me/api/basic_json/begin/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22070 |
iterator begin() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22071 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22072 |
iterator result(this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22073 |
result.set_begin(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22074 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22075 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22076 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22077 |
/// @brief returns an iterator to the first element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22078 |
/// @sa https://json.nlohmann.me/api/basic_json/begin/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22079 |
const_iterator begin() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22080 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22081 |
return cbegin(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22082 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22083 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22084 |
/// @brief returns a const iterator to the first element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22085 |
/// @sa https://json.nlohmann.me/api/basic_json/cbegin/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22086 |
const_iterator cbegin() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22087 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22088 |
const_iterator result(this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22089 |
result.set_begin(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22090 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22091 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22092 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22093 |
/// @brief returns an iterator to one past the last element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22094 |
/// @sa https://json.nlohmann.me/api/basic_json/end/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22095 |
iterator end() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22096 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22097 |
iterator result(this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22098 |
result.set_end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22099 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22100 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22101 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22102 |
/// @brief returns an iterator to one past the last element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22103 |
/// @sa https://json.nlohmann.me/api/basic_json/end/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22104 |
const_iterator end() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22105 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22106 |
return cend(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22107 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22108 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22109 |
/// @brief returns an iterator to one past the last element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22110 |
/// @sa https://json.nlohmann.me/api/basic_json/cend/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22111 |
const_iterator cend() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22112 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22113 |
const_iterator result(this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22114 |
result.set_end(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22115 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22116 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22117 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22118 |
/// @brief returns an iterator to the reverse-beginning |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22119 |
/// @sa https://json.nlohmann.me/api/basic_json/rbegin/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22120 |
reverse_iterator rbegin() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22121 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22122 |
return reverse_iterator(end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22123 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22124 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22125 |
/// @brief returns an iterator to the reverse-beginning |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22126 |
/// @sa https://json.nlohmann.me/api/basic_json/rbegin/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22127 |
const_reverse_iterator rbegin() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22128 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22129 |
return crbegin(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22130 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22131 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22132 |
/// @brief returns an iterator to the reverse-end |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22133 |
/// @sa https://json.nlohmann.me/api/basic_json/rend/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22134 |
reverse_iterator rend() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22135 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22136 |
return reverse_iterator(begin()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22137 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22138 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22139 |
/// @brief returns an iterator to the reverse-end |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22140 |
/// @sa https://json.nlohmann.me/api/basic_json/rend/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22141 |
const_reverse_iterator rend() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22142 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22143 |
return crend(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22144 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22145 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22146 |
/// @brief returns a const reverse iterator to the last element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22147 |
/// @sa https://json.nlohmann.me/api/basic_json/crbegin/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22148 |
const_reverse_iterator crbegin() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22149 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22150 |
return const_reverse_iterator(cend()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22151 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22152 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22153 |
/// @brief returns a const reverse iterator to one before the first |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22154 |
/// @sa https://json.nlohmann.me/api/basic_json/crend/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22155 |
const_reverse_iterator crend() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22156 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22157 |
return const_reverse_iterator(cbegin()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22158 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22159 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22160 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22161 |
/// @brief wrapper to access iterator member functions in range-based for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22162 |
/// @sa https://json.nlohmann.me/api/basic_json/items/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22163 |
/// @deprecated This function is deprecated since 3.1.0 and will be removed in |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22164 |
/// version 4.0.0 of the library. Please use @ref items() instead; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22165 |
/// that is, replace `json::iterator_wrapper(j)` with `j.items()`. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22166 |
JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22167 |
static iteration_proxy<iterator> iterator_wrapper(reference ref) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22168 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22169 |
return ref.items(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22170 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22171 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22172 |
/// @brief wrapper to access iterator member functions in range-based for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22173 |
/// @sa https://json.nlohmann.me/api/basic_json/items/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22174 |
/// @deprecated This function is deprecated since 3.1.0 and will be removed in |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22175 |
/// version 4.0.0 of the library. Please use @ref items() instead; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22176 |
/// that is, replace `json::iterator_wrapper(j)` with `j.items()`. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22177 |
JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22178 |
static iteration_proxy<const_iterator> iterator_wrapper(const_reference ref) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22179 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22180 |
return ref.items(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22181 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22182 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22183 |
/// @brief helper to access iterator member functions in range-based for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22184 |
/// @sa https://json.nlohmann.me/api/basic_json/items/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22185 |
iteration_proxy<iterator> items() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22186 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22187 |
return iteration_proxy<iterator>(*this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22188 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22189 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22190 |
/// @brief helper to access iterator member functions in range-based for |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22191 |
/// @sa https://json.nlohmann.me/api/basic_json/items/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22192 |
iteration_proxy<const_iterator> items() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22193 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22194 |
return iteration_proxy<const_iterator>(*this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22195 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22196 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22197 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22198 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22199 |
////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22200 |
// capacity // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22201 |
////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22202 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22203 |
/// @name capacity |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22204 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22205 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22206 |
/// @brief checks whether the container is empty. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22207 |
/// @sa https://json.nlohmann.me/api/basic_json/empty/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22208 |
bool empty() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22209 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22210 |
switch (m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22211 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22212 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22213 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22214 |
// null values are empty |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22215 |
return true; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22216 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22217 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22218 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22219 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22220 |
// delegate call to array_t::empty() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22221 |
return m_data.m_value.array->empty(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22222 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22223 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22224 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22225 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22226 |
// delegate call to object_t::empty() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22227 |
return m_data.m_value.object->empty(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22228 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22229 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22230 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22231 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22232 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22233 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22234 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22235 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22236 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22237 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22238 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22239 |
// all other types are nonempty |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22240 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22241 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22242 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22243 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22244 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22245 |
/// @brief returns the number of elements |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22246 |
/// @sa https://json.nlohmann.me/api/basic_json/size/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22247 |
size_type size() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22248 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22249 |
switch (m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22250 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22251 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22252 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22253 |
// null values are empty |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22254 |
return 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22255 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22256 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22257 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22258 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22259 |
// delegate call to array_t::size() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22260 |
return m_data.m_value.array->size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22261 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22262 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22263 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22264 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22265 |
// delegate call to object_t::size() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22266 |
return m_data.m_value.object->size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22267 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22268 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22269 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22270 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22271 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22272 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22273 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22274 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22275 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22276 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22277 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22278 |
// all other types have size 1 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22279 |
return 1; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22280 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22281 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22282 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22283 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22284 |
/// @brief returns the maximum possible number of elements |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22285 |
/// @sa https://json.nlohmann.me/api/basic_json/max_size/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22286 |
size_type max_size() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22287 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22288 |
switch (m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22289 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22290 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22291 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22292 |
// delegate call to array_t::max_size() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22293 |
return m_data.m_value.array->max_size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22294 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22295 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22296 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22297 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22298 |
// delegate call to object_t::max_size() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22299 |
return m_data.m_value.object->max_size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22300 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22301 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22302 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22303 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22304 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22305 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22306 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22307 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22308 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22309 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22310 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22311 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22312 |
// all other types have max_size() == size() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22313 |
return size(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22314 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22315 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22316 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22317 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22318 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22319 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22320 |
/////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22321 |
// modifiers // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22322 |
/////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22323 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22324 |
/// @name modifiers |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22325 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22326 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22327 |
/// @brief clears the contents |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22328 |
/// @sa https://json.nlohmann.me/api/basic_json/clear/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22329 |
void clear() noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22330 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22331 |
switch (m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22332 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22333 |
case value_t::number_integer: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22334 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22335 |
m_data.m_value.number_integer = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22336 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22337 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22338 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22339 |
case value_t::number_unsigned: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22340 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22341 |
m_data.m_value.number_unsigned = 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22342 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22343 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22344 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22345 |
case value_t::number_float: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22346 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22347 |
m_data.m_value.number_float = 0.0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22348 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22349 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22350 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22351 |
case value_t::boolean: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22352 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22353 |
m_data.m_value.boolean = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22354 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22355 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22356 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22357 |
case value_t::string: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22358 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22359 |
m_data.m_value.string->clear(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22360 |
break; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22361 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22362 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22363 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22364 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22365 |
m_data.m_value.binary->clear(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22366 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22367 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22368 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22369 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22370 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22371 |
m_data.m_value.array->clear(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22372 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22373 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22374 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22375 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22376 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22377 |
m_data.m_value.object->clear(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22378 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22379 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22380 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22381 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22382 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22383 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22384 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22385 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22386 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22387 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22388 |
/// @brief add an object to an array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22389 |
/// @sa https://json.nlohmann.me/api/basic_json/push_back/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22390 |
void push_back(basic_json&& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22391 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22392 |
// push_back only works for null objects or arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22393 |
if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22394 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22395 |
JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22396 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22397 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22398 |
// transform null object into an array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22399 |
if (is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22400 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22401 |
m_data.m_type = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22402 |
m_data.m_value = value_t::array; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22403 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22404 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22405 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22406 |
// add element to array (move semantics) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22407 |
const auto old_capacity = m_data.m_value.array->capacity(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22408 |
m_data.m_value.array->push_back(std::move(val)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22409 |
set_parent(m_data.m_value.array->back(), old_capacity); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22410 |
// if val is moved from, basic_json move constructor marks it null, so we do not call the destructor |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22411 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22412 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22413 |
/// @brief add an object to an array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22414 |
/// @sa https://json.nlohmann.me/api/basic_json/operator+=/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22415 |
reference operator+=(basic_json&& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22416 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22417 |
push_back(std::move(val)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22418 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22419 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22420 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22421 |
/// @brief add an object to an array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22422 |
/// @sa https://json.nlohmann.me/api/basic_json/push_back/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22423 |
void push_back(const basic_json& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22424 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22425 |
// push_back only works for null objects or arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22426 |
if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22427 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22428 |
JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22429 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22430 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22431 |
// transform null object into an array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22432 |
if (is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22433 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22434 |
m_data.m_type = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22435 |
m_data.m_value = value_t::array; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22436 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22437 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22438 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22439 |
// add element to array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22440 |
const auto old_capacity = m_data.m_value.array->capacity(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22441 |
m_data.m_value.array->push_back(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22442 |
set_parent(m_data.m_value.array->back(), old_capacity); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22443 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22444 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22445 |
/// @brief add an object to an array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22446 |
/// @sa https://json.nlohmann.me/api/basic_json/operator+=/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22447 |
reference operator+=(const basic_json& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22448 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22449 |
push_back(val); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22450 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22451 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22452 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22453 |
/// @brief add an object to an object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22454 |
/// @sa https://json.nlohmann.me/api/basic_json/push_back/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22455 |
void push_back(const typename object_t::value_type& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22456 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22457 |
// push_back only works for null objects or objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22458 |
if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22459 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22460 |
JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22461 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22462 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22463 |
// transform null object into an object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22464 |
if (is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22465 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22466 |
m_data.m_type = value_t::object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22467 |
m_data.m_value = value_t::object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22468 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22469 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22470 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22471 |
// add element to object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22472 |
auto res = m_data.m_value.object->insert(val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22473 |
set_parent(res.first->second); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22474 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22475 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22476 |
/// @brief add an object to an object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22477 |
/// @sa https://json.nlohmann.me/api/basic_json/operator+=/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22478 |
reference operator+=(const typename object_t::value_type& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22479 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22480 |
push_back(val); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22481 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22482 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22483 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22484 |
/// @brief add an object to an object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22485 |
/// @sa https://json.nlohmann.me/api/basic_json/push_back/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22486 |
void push_back(initializer_list_t init) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22487 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22488 |
if (is_object() && init.size() == 2 && (*init.begin())->is_string()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22489 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22490 |
basic_json&& key = init.begin()->moved_or_copied(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22491 |
push_back(typename object_t::value_type( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22492 |
std::move(key.get_ref<string_t&>()), (init.begin() + 1)->moved_or_copied())); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22493 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22494 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22495 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22496 |
push_back(basic_json(init)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22497 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22498 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22499 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22500 |
/// @brief add an object to an object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22501 |
/// @sa https://json.nlohmann.me/api/basic_json/operator+=/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22502 |
reference operator+=(initializer_list_t init) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22503 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22504 |
push_back(init); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22505 |
return *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22506 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22507 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22508 |
/// @brief add an object to an array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22509 |
/// @sa https://json.nlohmann.me/api/basic_json/emplace_back/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22510 |
template<class... Args> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22511 |
reference emplace_back(Args&& ... args) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22512 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22513 |
// emplace_back only works for null objects or arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22514 |
if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22515 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22516 |
JSON_THROW(type_error::create(311, detail::concat("cannot use emplace_back() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22517 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22518 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22519 |
// transform null object into an array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22520 |
if (is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22521 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22522 |
m_data.m_type = value_t::array; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22523 |
m_data.m_value = value_t::array; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22524 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22525 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22526 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22527 |
// add element to array (perfect forwarding) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22528 |
const auto old_capacity = m_data.m_value.array->capacity(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22529 |
m_data.m_value.array->emplace_back(std::forward<Args>(args)...); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22530 |
return set_parent(m_data.m_value.array->back(), old_capacity); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22531 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22532 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22533 |
/// @brief add an object to an object if key does not exist |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22534 |
/// @sa https://json.nlohmann.me/api/basic_json/emplace/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22535 |
template<class... Args> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22536 |
std::pair<iterator, bool> emplace(Args&& ... args) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22537 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22538 |
// emplace only works for null objects or arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22539 |
if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object()))) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22540 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22541 |
JSON_THROW(type_error::create(311, detail::concat("cannot use emplace() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22542 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22543 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22544 |
// transform null object into an object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22545 |
if (is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22546 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22547 |
m_data.m_type = value_t::object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22548 |
m_data.m_value = value_t::object; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22549 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22550 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22551 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22552 |
// add element to array (perfect forwarding) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22553 |
auto res = m_data.m_value.object->emplace(std::forward<Args>(args)...); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22554 |
set_parent(res.first->second); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22555 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22556 |
// create result iterator and set iterator to the result of emplace |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22557 |
auto it = begin(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22558 |
it.m_it.object_iterator = res.first; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22559 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22560 |
// return pair of iterator and boolean |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22561 |
return {it, res.second}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22562 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22563 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22564 |
/// Helper for insertion of an iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22565 |
/// @note: This uses std::distance to support GCC 4.8, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22566 |
/// see https://github.com/nlohmann/json/pull/1257 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22567 |
template<typename... Args> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22568 |
iterator insert_iterator(const_iterator pos, Args&& ... args) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22569 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22570 |
iterator result(this); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22571 |
JSON_ASSERT(m_data.m_value.array != nullptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22572 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22573 |
auto insert_pos = std::distance(m_data.m_value.array->begin(), pos.m_it.array_iterator); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22574 |
m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22575 |
result.m_it.array_iterator = m_data.m_value.array->begin() + insert_pos; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22576 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22577 |
// This could have been written as: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22578 |
// result.m_it.array_iterator = m_data.m_value.array->insert(pos.m_it.array_iterator, cnt, val); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22579 |
// but the return value of insert is missing in GCC 4.8, so it is written this way instead. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22580 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22581 |
set_parents(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22582 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22583 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22584 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22585 |
/// @brief inserts element into array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22586 |
/// @sa https://json.nlohmann.me/api/basic_json/insert/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22587 |
iterator insert(const_iterator pos, const basic_json& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22588 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22589 |
// insert only works for arrays |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22590 |
if (JSON_HEDLEY_LIKELY(is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22591 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22592 |
// check if iterator pos fits to this JSON value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22593 |
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22594 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22595 |
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22596 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22597 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22598 |
// insert to array and return iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22599 |
return insert_iterator(pos, val); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22600 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22601 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22602 |
JSON_THROW(type_error::create(309, detail::concat("cannot use insert() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22603 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22604 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22605 |
/// @brief inserts element into array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22606 |
/// @sa https://json.nlohmann.me/api/basic_json/insert/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22607 |
iterator insert(const_iterator pos, basic_json&& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22608 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22609 |
return insert(pos, val); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22610 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22611 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22612 |
/// @brief inserts copies of element into array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22613 |
/// @sa https://json.nlohmann.me/api/basic_json/insert/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22614 |
iterator insert(const_iterator pos, size_type cnt, const basic_json& val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22615 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22616 |
// insert only works for arrays |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22617 |
if (JSON_HEDLEY_LIKELY(is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22618 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22619 |
// check if iterator pos fits to this JSON value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22620 |
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22621 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22622 |
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22623 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22624 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22625 |
// insert to array and return iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22626 |
return insert_iterator(pos, cnt, val); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22627 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22628 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22629 |
JSON_THROW(type_error::create(309, detail::concat("cannot use insert() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22630 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22631 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22632 |
/// @brief inserts range of elements into array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22633 |
/// @sa https://json.nlohmann.me/api/basic_json/insert/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22634 |
iterator insert(const_iterator pos, const_iterator first, const_iterator last) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22635 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22636 |
// insert only works for arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22637 |
if (JSON_HEDLEY_UNLIKELY(!is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22638 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22639 |
JSON_THROW(type_error::create(309, detail::concat("cannot use insert() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22640 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22641 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22642 |
// check if iterator pos fits to this JSON value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22643 |
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22644 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22645 |
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22646 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22647 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22648 |
// check if range iterators belong to the same JSON object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22649 |
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22650 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22651 |
JSON_THROW(invalid_iterator::create(210, "iterators do not fit", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22652 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22653 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22654 |
if (JSON_HEDLEY_UNLIKELY(first.m_object == this)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22655 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22656 |
JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22657 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22658 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22659 |
// insert to array and return iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22660 |
return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22661 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22662 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22663 |
/// @brief inserts elements from initializer list into array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22664 |
/// @sa https://json.nlohmann.me/api/basic_json/insert/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22665 |
iterator insert(const_iterator pos, initializer_list_t ilist) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22666 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22667 |
// insert only works for arrays |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22668 |
if (JSON_HEDLEY_UNLIKELY(!is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22669 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22670 |
JSON_THROW(type_error::create(309, detail::concat("cannot use insert() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22671 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22672 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22673 |
// check if iterator pos fits to this JSON value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22674 |
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22675 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22676 |
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22677 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22678 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22679 |
// insert to array and return iterator |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22680 |
return insert_iterator(pos, ilist.begin(), ilist.end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22681 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22682 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22683 |
/// @brief inserts range of elements into object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22684 |
/// @sa https://json.nlohmann.me/api/basic_json/insert/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22685 |
void insert(const_iterator first, const_iterator last) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22686 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22687 |
// insert only works for objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22688 |
if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22689 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22690 |
JSON_THROW(type_error::create(309, detail::concat("cannot use insert() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22691 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22692 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22693 |
// check if range iterators belong to the same JSON object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22694 |
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22695 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22696 |
JSON_THROW(invalid_iterator::create(210, "iterators do not fit", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22697 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22698 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22699 |
// passed iterators must belong to objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22700 |
if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22701 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22702 |
JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22703 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22704 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22705 |
m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22706 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22707 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22708 |
/// @brief updates a JSON object from another object, overwriting existing keys |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22709 |
/// @sa https://json.nlohmann.me/api/basic_json/update/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22710 |
void update(const_reference j, bool merge_objects = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22711 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22712 |
update(j.begin(), j.end(), merge_objects); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22713 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22714 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22715 |
/// @brief updates a JSON object from another object, overwriting existing keys |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22716 |
/// @sa https://json.nlohmann.me/api/basic_json/update/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22717 |
void update(const_iterator first, const_iterator last, bool merge_objects = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22718 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22719 |
// implicitly convert null value to an empty object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22720 |
if (is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22721 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22722 |
m_data.m_type = value_t::object; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22723 |
m_data.m_value.object = create<object_t>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22724 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22725 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22726 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22727 |
if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22728 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22729 |
JSON_THROW(type_error::create(312, detail::concat("cannot use update() with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22730 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22731 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22732 |
// check if range iterators belong to the same JSON object |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22733 |
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22734 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22735 |
JSON_THROW(invalid_iterator::create(210, "iterators do not fit", this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22736 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22737 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22738 |
// passed iterators must belong to objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22739 |
if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22740 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22741 |
JSON_THROW(type_error::create(312, detail::concat("cannot use update() with ", first.m_object->type_name()), first.m_object)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22742 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22743 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22744 |
for (auto it = first; it != last; ++it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22745 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22746 |
if (merge_objects && it.value().is_object()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22747 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22748 |
auto it2 = m_data.m_value.object->find(it.key()); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22749 |
if (it2 != m_data.m_value.object->end()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22750 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22751 |
it2->second.update(it.value(), true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22752 |
continue; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22753 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22754 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22755 |
m_data.m_value.object->operator[](it.key()) = it.value(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22756 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22757 |
m_data.m_value.object->operator[](it.key()).m_parent = this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22758 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22759 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22760 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22761 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22762 |
/// @brief exchanges the values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22763 |
/// @sa https://json.nlohmann.me/api/basic_json/swap/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22764 |
void swap(reference other) noexcept ( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22765 |
std::is_nothrow_move_constructible<value_t>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22766 |
std::is_nothrow_move_assignable<value_t>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22767 |
std::is_nothrow_move_constructible<json_value>::value&& // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22768 |
std::is_nothrow_move_assignable<json_value>::value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22769 |
) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22770 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22771 |
std::swap(m_data.m_type, other.m_data.m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22772 |
std::swap(m_data.m_value, other.m_data.m_value); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22773 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22774 |
set_parents(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22775 |
other.set_parents(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22776 |
assert_invariant(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22777 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22778 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22779 |
/// @brief exchanges the values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22780 |
/// @sa https://json.nlohmann.me/api/basic_json/swap/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22781 |
friend void swap(reference left, reference right) noexcept ( |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22782 |
std::is_nothrow_move_constructible<value_t>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22783 |
std::is_nothrow_move_assignable<value_t>::value&& |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22784 |
std::is_nothrow_move_constructible<json_value>::value&& // NOLINT(cppcoreguidelines-noexcept-swap,performance-noexcept-swap) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22785 |
std::is_nothrow_move_assignable<json_value>::value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22786 |
) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22787 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22788 |
left.swap(right); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22789 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22790 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22791 |
/// @brief exchanges the values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22792 |
/// @sa https://json.nlohmann.me/api/basic_json/swap/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22793 |
void swap(array_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22794 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22795 |
// swap only works for arrays |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22796 |
if (JSON_HEDLEY_LIKELY(is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22797 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22798 |
using std::swap; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22799 |
swap(*(m_data.m_value.array), other); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22800 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22801 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22802 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22803 |
JSON_THROW(type_error::create(310, detail::concat("cannot use swap(array_t&) with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22804 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22805 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22806 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22807 |
/// @brief exchanges the values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22808 |
/// @sa https://json.nlohmann.me/api/basic_json/swap/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22809 |
void swap(object_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22810 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22811 |
// swap only works for objects |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22812 |
if (JSON_HEDLEY_LIKELY(is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22813 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22814 |
using std::swap; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22815 |
swap(*(m_data.m_value.object), other); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22816 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22817 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22818 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22819 |
JSON_THROW(type_error::create(310, detail::concat("cannot use swap(object_t&) with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22820 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22821 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22822 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22823 |
/// @brief exchanges the values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22824 |
/// @sa https://json.nlohmann.me/api/basic_json/swap/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22825 |
void swap(string_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22826 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22827 |
// swap only works for strings |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22828 |
if (JSON_HEDLEY_LIKELY(is_string())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22829 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22830 |
using std::swap; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22831 |
swap(*(m_data.m_value.string), other); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22832 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22833 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22834 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22835 |
JSON_THROW(type_error::create(310, detail::concat("cannot use swap(string_t&) with ", type_name()), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22836 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22837 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22838 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22839 |
/// @brief exchanges the values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22840 |
/// @sa https://json.nlohmann.me/api/basic_json/swap/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22841 |
void swap(binary_t& other) // NOLINT(bugprone-exception-escape,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22842 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22843 |
// swap only works for strings |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22844 |
if (JSON_HEDLEY_LIKELY(is_binary())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22845 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22846 |
using std::swap; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22847 |
swap(*(m_data.m_value.binary), other); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22848 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22849 |
else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22850 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22851 |
JSON_THROW(type_error::create(310, detail::concat("cannot use swap(binary_t&) with ", type_name()), this)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22852 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22853 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22854 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22855 |
/// @brief exchanges the values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22856 |
/// @sa https://json.nlohmann.me/api/basic_json/swap/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22857 |
void swap(typename binary_t::container_type& other) // NOLINT(bugprone-exception-escape) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22858 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22859 |
// swap only works for strings |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22860 |
if (JSON_HEDLEY_LIKELY(is_binary())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22861 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22862 |
using std::swap; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22863 |
swap(*(m_data.m_value.binary), other); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22864 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22865 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22866 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22867 |
JSON_THROW(type_error::create(310, detail::concat("cannot use swap(binary_t::container_type&) with ", type_name()), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22868 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22869 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22870 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22871 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22872 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22873 |
////////////////////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22874 |
// lexicographical comparison operators // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22875 |
////////////////////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22876 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22877 |
/// @name lexicographical comparison operators |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22878 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22879 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22880 |
// note parentheses around operands are necessary; see |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22881 |
// https://github.com/nlohmann/json/issues/1530 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22882 |
#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22883 |
const auto lhs_type = lhs.type(); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22884 |
const auto rhs_type = rhs.type(); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22885 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22886 |
if (lhs_type == rhs_type) /* NOLINT(readability/braces) */ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22887 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22888 |
switch (lhs_type) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22889 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22890 |
case value_t::array: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22891 |
return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22892 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22893 |
case value_t::object: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22894 |
return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22895 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22896 |
case value_t::null: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22897 |
return (null_result); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22898 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22899 |
case value_t::string: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22900 |
return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22901 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22902 |
case value_t::boolean: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22903 |
return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22904 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22905 |
case value_t::number_integer: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22906 |
return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22907 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22908 |
case value_t::number_unsigned: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22909 |
return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22910 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22911 |
case value_t::number_float: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22912 |
return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22913 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22914 |
case value_t::binary: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22915 |
return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22916 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22917 |
case value_t::discarded: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22918 |
default: \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22919 |
return (unordered_result); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22920 |
} \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22921 |
} \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22922 |
else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22923 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22924 |
return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22925 |
} \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22926 |
else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22927 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22928 |
return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22929 |
} \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22930 |
else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22931 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22932 |
return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22933 |
} \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22934 |
else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22935 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22936 |
return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22937 |
} \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22938 |
else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22939 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22940 |
return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22941 |
} \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22942 |
else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22943 |
{ \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22944 |
return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22945 |
} \ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22946 |
else if(compares_unordered(lhs, rhs))\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22947 |
{\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22948 |
return (unordered_result);\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22949 |
}\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22950 |
\ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22951 |
return (default_result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22952 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22953 |
JSON_PRIVATE_UNLESS_TESTED: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22954 |
// returns true if: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22955 |
// - any operand is NaN and the other operand is of number type |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22956 |
// - any operand is discarded |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22957 |
// in legacy mode, discarded values are considered ordered if |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22958 |
// an operation is computed as an odd number of inverses of others |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22959 |
static bool compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22960 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22961 |
if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number()) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22962 |
|| (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number())) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22963 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22964 |
return true; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22965 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22966 |
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22967 |
return (lhs.is_discarded() || rhs.is_discarded()) && !inverse; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22968 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22969 |
static_cast<void>(inverse); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22970 |
return lhs.is_discarded() || rhs.is_discarded(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22971 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22972 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22973 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22974 |
private: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22975 |
bool compares_unordered(const_reference rhs, bool inverse = false) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22976 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22977 |
return compares_unordered(*this, rhs, inverse); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22978 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22979 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22980 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22981 |
#if JSON_HAS_THREE_WAY_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22982 |
/// @brief comparison: equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22983 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22984 |
bool operator==(const_reference rhs) const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22985 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22986 |
#ifdef __GNUC__ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22987 |
#pragma GCC diagnostic push |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22988 |
#pragma GCC diagnostic ignored "-Wfloat-equal" |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22989 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22990 |
const_reference lhs = *this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22991 |
JSON_IMPLEMENT_OPERATOR( ==, true, false, false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22992 |
#ifdef __GNUC__ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22993 |
#pragma GCC diagnostic pop |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22994 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22995 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
22996 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22997 |
/// @brief comparison: equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22998 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
22999 |
template<typename ScalarType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23000 |
requires std::is_scalar_v<ScalarType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23001 |
bool operator==(ScalarType rhs) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23002 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23003 |
return *this == basic_json(rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23004 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23005 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23006 |
/// @brief comparison: not equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23007 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23008 |
bool operator!=(const_reference rhs) const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23009 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23010 |
if (compares_unordered(rhs, true)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23011 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23012 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23013 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23014 |
return !operator==(rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23015 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23016 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23017 |
/// @brief comparison: 3-way |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23018 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23019 |
std::partial_ordering operator<=>(const_reference rhs) const noexcept // *NOPAD* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23020 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23021 |
const_reference lhs = *this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23022 |
// default_result is used if we cannot compare values. In that case, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23023 |
// we compare types. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23024 |
JSON_IMPLEMENT_OPERATOR(<=>, // *NOPAD* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23025 |
std::partial_ordering::equivalent, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23026 |
std::partial_ordering::unordered, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23027 |
lhs_type <=> rhs_type) // *NOPAD* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23028 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23029 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23030 |
/// @brief comparison: 3-way |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23031 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23032 |
template<typename ScalarType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23033 |
requires std::is_scalar_v<ScalarType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23034 |
std::partial_ordering operator<=>(ScalarType rhs) const noexcept // *NOPAD* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23035 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23036 |
return *this <=> basic_json(rhs); // *NOPAD* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23037 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23038 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23039 |
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23040 |
// all operators that are computed as an odd number of inverses of others |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23041 |
// need to be overloaded to emulate the legacy comparison behavior |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23042 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23043 |
/// @brief comparison: less than or equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23044 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_le/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23045 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23046 |
bool operator<=(const_reference rhs) const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23047 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23048 |
if (compares_unordered(rhs, true)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23049 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23050 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23051 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23052 |
return !(rhs < *this); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23053 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23054 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23055 |
/// @brief comparison: less than or equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23056 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_le/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23057 |
template<typename ScalarType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23058 |
requires std::is_scalar_v<ScalarType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23059 |
bool operator<=(ScalarType rhs) const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23060 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23061 |
return *this <= basic_json(rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23062 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23063 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23064 |
/// @brief comparison: greater than or equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23065 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23066 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23067 |
bool operator>=(const_reference rhs) const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23068 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23069 |
if (compares_unordered(rhs, true)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23070 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23071 |
return false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23072 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23073 |
return !(*this < rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23074 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23075 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23076 |
/// @brief comparison: greater than or equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23077 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23078 |
template<typename ScalarType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23079 |
requires std::is_scalar_v<ScalarType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23080 |
bool operator>=(ScalarType rhs) const noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23081 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23082 |
return *this >= basic_json(rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23083 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23084 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23085 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23086 |
/// @brief comparison: equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23087 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23088 |
friend bool operator==(const_reference lhs, const_reference rhs) noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23089 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23090 |
#ifdef __GNUC__ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23091 |
#pragma GCC diagnostic push |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23092 |
#pragma GCC diagnostic ignored "-Wfloat-equal" |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23093 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23094 |
JSON_IMPLEMENT_OPERATOR( ==, true, false, false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23095 |
#ifdef __GNUC__ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23096 |
#pragma GCC diagnostic pop |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23097 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23098 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23099 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23100 |
/// @brief comparison: equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23101 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23102 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23103 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23104 |
friend bool operator==(const_reference lhs, ScalarType rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23105 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23106 |
return lhs == basic_json(rhs); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23107 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23108 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23109 |
/// @brief comparison: equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23110 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23111 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23112 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23113 |
friend bool operator==(ScalarType lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23114 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23115 |
return basic_json(lhs) == rhs; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23116 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23117 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23118 |
/// @brief comparison: not equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23119 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23120 |
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23121 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23122 |
if (compares_unordered(lhs, rhs, true)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23123 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23124 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23125 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23126 |
return !(lhs == rhs); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23127 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23128 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23129 |
/// @brief comparison: not equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23130 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23131 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23132 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23133 |
friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23134 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23135 |
return lhs != basic_json(rhs); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23136 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23137 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23138 |
/// @brief comparison: not equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23139 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23140 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23141 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23142 |
friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23143 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23144 |
return basic_json(lhs) != rhs; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23145 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23146 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23147 |
/// @brief comparison: less than |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23148 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_lt/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23149 |
friend bool operator<(const_reference lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23150 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23151 |
// default_result is used if we cannot compare values. In that case, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23152 |
// we compare types. Note we have to call the operator explicitly, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23153 |
// because MSVC has problems otherwise. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23154 |
JSON_IMPLEMENT_OPERATOR( <, false, false, operator<(lhs_type, rhs_type)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23155 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23156 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23157 |
/// @brief comparison: less than |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23158 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_lt/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23159 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23160 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23161 |
friend bool operator<(const_reference lhs, ScalarType rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23162 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23163 |
return lhs < basic_json(rhs); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23164 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23165 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23166 |
/// @brief comparison: less than |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23167 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_lt/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23168 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23169 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23170 |
friend bool operator<(ScalarType lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23171 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23172 |
return basic_json(lhs) < rhs; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23173 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23174 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23175 |
/// @brief comparison: less than or equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23176 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_le/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23177 |
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23178 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23179 |
if (compares_unordered(lhs, rhs, true)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23180 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23181 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23182 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23183 |
return !(rhs < lhs); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23184 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23185 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23186 |
/// @brief comparison: less than or equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23187 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_le/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23188 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23189 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23190 |
friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23191 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23192 |
return lhs <= basic_json(rhs); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23193 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23194 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23195 |
/// @brief comparison: less than or equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23196 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_le/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23197 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23198 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23199 |
friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23200 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23201 |
return basic_json(lhs) <= rhs; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23202 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23203 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23204 |
/// @brief comparison: greater than |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23205 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_gt/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23206 |
friend bool operator>(const_reference lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23207 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23208 |
// double inverse |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23209 |
if (compares_unordered(lhs, rhs)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23210 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23211 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23212 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23213 |
return !(lhs <= rhs); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23214 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23215 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23216 |
/// @brief comparison: greater than |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23217 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_gt/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23218 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23219 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23220 |
friend bool operator>(const_reference lhs, ScalarType rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23221 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23222 |
return lhs > basic_json(rhs); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23223 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23224 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23225 |
/// @brief comparison: greater than |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23226 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_gt/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23227 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23228 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23229 |
friend bool operator>(ScalarType lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23230 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23231 |
return basic_json(lhs) > rhs; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23232 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23233 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23234 |
/// @brief comparison: greater than or equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23235 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23236 |
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23237 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23238 |
if (compares_unordered(lhs, rhs, true)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23239 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23240 |
return false; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23241 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23242 |
return !(lhs < rhs); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23243 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23244 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23245 |
/// @brief comparison: greater than or equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23246 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23247 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23248 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23249 |
friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23250 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23251 |
return lhs >= basic_json(rhs); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23252 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23253 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23254 |
/// @brief comparison: greater than or equal |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23255 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23256 |
template<typename ScalarType, typename std::enable_if< |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23257 |
std::is_scalar<ScalarType>::value, int>::type = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23258 |
friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23259 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23260 |
return basic_json(lhs) >= rhs; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23261 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23262 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23263 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23264 |
#undef JSON_IMPLEMENT_OPERATOR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23265 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23266 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23267 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23268 |
/////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23269 |
// serialization // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23270 |
/////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23271 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23272 |
/// @name serialization |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23273 |
/// @{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23274 |
#ifndef JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23275 |
/// @brief serialize to stream |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23276 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23277 |
friend std::ostream& operator<<(std::ostream& o, const basic_json& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23278 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23279 |
// read width member and use it as indentation parameter if nonzero |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23280 |
const bool pretty_print = o.width() > 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23281 |
const auto indentation = pretty_print ? o.width() : 0; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23282 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23283 |
// reset width to 0 for subsequent calls to this stream |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23284 |
o.width(0); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23285 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23286 |
// do the actual serialization |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23287 |
serializer s(detail::output_adapter<char>(o), o.fill()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23288 |
s.dump(j, pretty_print, false, static_cast<unsigned int>(indentation)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23289 |
return o; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23290 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23291 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23292 |
/// @brief serialize to stream |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23293 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23294 |
/// @deprecated This function is deprecated since 3.0.0 and will be removed in |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23295 |
/// version 4.0.0 of the library. Please use |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23296 |
/// operator<<(std::ostream&, const basic_json&) instead; that is, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23297 |
/// replace calls like `j >> o;` with `o << j;`. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23298 |
JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23299 |
friend std::ostream& operator>>(const basic_json& j, std::ostream& o) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23300 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23301 |
return o << j; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23302 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23303 |
#endif // JSON_NO_IO |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23304 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23305 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23306 |
///////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23307 |
// deserialization // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23308 |
///////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23309 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23310 |
/// @name deserialization |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23311 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23312 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23313 |
/// @brief deserialize from a compatible input |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23314 |
/// @sa https://json.nlohmann.me/api/basic_json/parse/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23315 |
template<typename InputType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23316 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23317 |
static basic_json parse(InputType&& i, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23318 |
const parser_callback_t cb = nullptr, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23319 |
const bool allow_exceptions = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23320 |
const bool ignore_comments = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23321 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23322 |
basic_json result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23323 |
parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(true, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23324 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23325 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23326 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23327 |
/// @brief deserialize from a pair of character iterators |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23328 |
/// @sa https://json.nlohmann.me/api/basic_json/parse/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23329 |
template<typename IteratorType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23330 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23331 |
static basic_json parse(IteratorType first, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23332 |
IteratorType last, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23333 |
const parser_callback_t cb = nullptr, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23334 |
const bool allow_exceptions = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23335 |
const bool ignore_comments = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23336 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23337 |
basic_json result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23338 |
parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(true, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23339 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23340 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23341 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23342 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23343 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23344 |
static basic_json parse(detail::span_input_adapter&& i, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23345 |
const parser_callback_t cb = nullptr, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23346 |
const bool allow_exceptions = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23347 |
const bool ignore_comments = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23348 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23349 |
basic_json result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23350 |
parser(i.get(), cb, allow_exceptions, ignore_comments).parse(true, result); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23351 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23352 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23353 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23354 |
/// @brief check if the input is valid JSON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23355 |
/// @sa https://json.nlohmann.me/api/basic_json/accept/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23356 |
template<typename InputType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23357 |
static bool accept(InputType&& i, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23358 |
const bool ignore_comments = false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23359 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23360 |
return parser(detail::input_adapter(std::forward<InputType>(i)), nullptr, false, ignore_comments).accept(true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23361 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23362 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23363 |
/// @brief check if the input is valid JSON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23364 |
/// @sa https://json.nlohmann.me/api/basic_json/accept/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23365 |
template<typename IteratorType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23366 |
static bool accept(IteratorType first, IteratorType last, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23367 |
const bool ignore_comments = false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23368 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23369 |
return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23370 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23371 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23372 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23373 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23374 |
static bool accept(detail::span_input_adapter&& i, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23375 |
const bool ignore_comments = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23376 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23377 |
return parser(i.get(), nullptr, false, ignore_comments).accept(true); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23378 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23379 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23380 |
/// @brief generate SAX events |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23381 |
/// @sa https://json.nlohmann.me/api/basic_json/sax_parse/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23382 |
template <typename InputType, typename SAX> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23383 |
JSON_HEDLEY_NON_NULL(2) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23384 |
static bool sax_parse(InputType&& i, SAX* sax, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23385 |
input_format_t format = input_format_t::json, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23386 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23387 |
const bool ignore_comments = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23388 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23389 |
auto ia = detail::input_adapter(std::forward<InputType>(i)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23390 |
return format == input_format_t::json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23391 |
? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23392 |
: detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23393 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23394 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23395 |
/// @brief generate SAX events |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23396 |
/// @sa https://json.nlohmann.me/api/basic_json/sax_parse/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23397 |
template<class IteratorType, class SAX> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23398 |
JSON_HEDLEY_NON_NULL(3) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23399 |
static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23400 |
input_format_t format = input_format_t::json, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23401 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23402 |
const bool ignore_comments = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23403 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23404 |
auto ia = detail::input_adapter(std::move(first), std::move(last)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23405 |
return format == input_format_t::json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23406 |
? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23407 |
: detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23408 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23409 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23410 |
/// @brief generate SAX events |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23411 |
/// @sa https://json.nlohmann.me/api/basic_json/sax_parse/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23412 |
/// @deprecated This function is deprecated since 3.8.0 and will be removed in |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23413 |
/// version 4.0.0 of the library. Please use |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23414 |
/// sax_parse(ptr, ptr + len) instead. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23415 |
template <typename SAX> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23416 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23417 |
JSON_HEDLEY_NON_NULL(2) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23418 |
static bool sax_parse(detail::span_input_adapter&& i, SAX* sax, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23419 |
input_format_t format = input_format_t::json, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23420 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23421 |
const bool ignore_comments = false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23422 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23423 |
auto ia = i.get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23424 |
return format == input_format_t::json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23425 |
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23426 |
? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23427 |
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23428 |
: detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23429 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23430 |
#ifndef JSON_NO_IO |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23431 |
/// @brief deserialize from stream |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23432 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_gtgt/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23433 |
/// @deprecated This stream operator is deprecated since 3.0.0 and will be removed in |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23434 |
/// version 4.0.0 of the library. Please use |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23435 |
/// operator>>(std::istream&, basic_json&) instead; that is, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23436 |
/// replace calls like `j << i;` with `i >> j;`. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23437 |
JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23438 |
friend std::istream& operator<<(basic_json& j, std::istream& i) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23439 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23440 |
return operator>>(i, j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23441 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23442 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23443 |
/// @brief deserialize from stream |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23444 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_gtgt/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23445 |
friend std::istream& operator>>(std::istream& i, basic_json& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23446 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23447 |
parser(detail::input_adapter(i)).parse(false, j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23448 |
return i; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23449 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23450 |
#endif // JSON_NO_IO |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23451 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23452 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23453 |
/////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23454 |
// convenience functions // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23455 |
/////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23456 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23457 |
/// @brief return the type as string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23458 |
/// @sa https://json.nlohmann.me/api/basic_json/type_name/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23459 |
JSON_HEDLEY_RETURNS_NON_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23460 |
const char* type_name() const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23461 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23462 |
switch (m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23463 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23464 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23465 |
return "null"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23466 |
case value_t::object: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23467 |
return "object"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23468 |
case value_t::array: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23469 |
return "array"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23470 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23471 |
return "string"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23472 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23473 |
return "boolean"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23474 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23475 |
return "binary"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23476 |
case value_t::discarded: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23477 |
return "discarded"; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23478 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23479 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23480 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23481 |
default: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23482 |
return "number"; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23483 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23484 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23485 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23486 |
JSON_PRIVATE_UNLESS_TESTED: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23487 |
////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23488 |
// member variables // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23489 |
////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23490 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23491 |
struct data |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23492 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23493 |
/// the type of the current element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23494 |
value_t m_type = value_t::null; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23495 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23496 |
/// the value of the current element |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23497 |
json_value m_value = {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23498 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23499 |
data(const value_t v) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23500 |
: m_type(v), m_value(v) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23501 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23502 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23503 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23504 |
data(size_type cnt, const basic_json& val) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23505 |
: m_type(value_t::array) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23506 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23507 |
m_value.array = create<array_t>(cnt, val); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23508 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23509 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23510 |
data() noexcept = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23511 |
data(data&&) noexcept = default; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23512 |
data(const data&) noexcept = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23513 |
data& operator=(data&&) noexcept = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23514 |
data& operator=(const data&) noexcept = delete; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23515 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23516 |
~data() noexcept |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23517 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23518 |
m_value.destroy(m_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23519 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23520 |
}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23521 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23522 |
data m_data = {}; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23523 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23524 |
#if JSON_DIAGNOSTICS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23525 |
/// a pointer to a parent value (for debugging purposes) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23526 |
basic_json* m_parent = nullptr; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23527 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23528 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23529 |
////////////////////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23530 |
// binary serialization/deserialization // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23531 |
////////////////////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23532 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23533 |
/// @name binary serialization/deserialization support |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23534 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23535 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23536 |
public: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23537 |
/// @brief create a CBOR serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23538 |
/// @sa https://json.nlohmann.me/api/basic_json/to_cbor/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23539 |
static std::vector<std::uint8_t> to_cbor(const basic_json& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23540 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23541 |
std::vector<std::uint8_t> result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23542 |
to_cbor(j, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23543 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23544 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23545 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23546 |
/// @brief create a CBOR serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23547 |
/// @sa https://json.nlohmann.me/api/basic_json/to_cbor/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23548 |
static void to_cbor(const basic_json& j, detail::output_adapter<std::uint8_t> o) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23549 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23550 |
binary_writer<std::uint8_t>(o).write_cbor(j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23551 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23552 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23553 |
/// @brief create a CBOR serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23554 |
/// @sa https://json.nlohmann.me/api/basic_json/to_cbor/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23555 |
static void to_cbor(const basic_json& j, detail::output_adapter<char> o) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23556 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23557 |
binary_writer<char>(o).write_cbor(j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23558 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23559 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23560 |
/// @brief create a MessagePack serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23561 |
/// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23562 |
static std::vector<std::uint8_t> to_msgpack(const basic_json& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23563 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23564 |
std::vector<std::uint8_t> result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23565 |
to_msgpack(j, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23566 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23567 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23568 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23569 |
/// @brief create a MessagePack serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23570 |
/// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23571 |
static void to_msgpack(const basic_json& j, detail::output_adapter<std::uint8_t> o) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23572 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23573 |
binary_writer<std::uint8_t>(o).write_msgpack(j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23574 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23575 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23576 |
/// @brief create a MessagePack serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23577 |
/// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23578 |
static void to_msgpack(const basic_json& j, detail::output_adapter<char> o) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23579 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23580 |
binary_writer<char>(o).write_msgpack(j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23581 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23582 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23583 |
/// @brief create a UBJSON serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23584 |
/// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23585 |
static std::vector<std::uint8_t> to_ubjson(const basic_json& j, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23586 |
const bool use_size = false, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23587 |
const bool use_type = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23588 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23589 |
std::vector<std::uint8_t> result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23590 |
to_ubjson(j, result, use_size, use_type); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23591 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23592 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23593 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23594 |
/// @brief create a UBJSON serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23595 |
/// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23596 |
static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23597 |
const bool use_size = false, const bool use_type = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23598 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23599 |
binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23600 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23601 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23602 |
/// @brief create a UBJSON serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23603 |
/// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23604 |
static void to_ubjson(const basic_json& j, detail::output_adapter<char> o, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23605 |
const bool use_size = false, const bool use_type = false) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23606 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23607 |
binary_writer<char>(o).write_ubjson(j, use_size, use_type); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23608 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23609 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23610 |
/// @brief create a BJData serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23611 |
/// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23612 |
static std::vector<std::uint8_t> to_bjdata(const basic_json& j, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23613 |
const bool use_size = false, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23614 |
const bool use_type = false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23615 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23616 |
std::vector<std::uint8_t> result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23617 |
to_bjdata(j, result, use_size, use_type); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23618 |
return result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23619 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23620 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23621 |
/// @brief create a BJData serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23622 |
/// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23623 |
static void to_bjdata(const basic_json& j, detail::output_adapter<std::uint8_t> o, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23624 |
const bool use_size = false, const bool use_type = false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23625 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23626 |
binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type, true, true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23627 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23628 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23629 |
/// @brief create a BJData serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23630 |
/// @sa https://json.nlohmann.me/api/basic_json/to_bjdata/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23631 |
static void to_bjdata(const basic_json& j, detail::output_adapter<char> o, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23632 |
const bool use_size = false, const bool use_type = false) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23633 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23634 |
binary_writer<char>(o).write_ubjson(j, use_size, use_type, true, true); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23635 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23636 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23637 |
/// @brief create a BSON serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23638 |
/// @sa https://json.nlohmann.me/api/basic_json/to_bson/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23639 |
static std::vector<std::uint8_t> to_bson(const basic_json& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23640 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23641 |
std::vector<std::uint8_t> result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23642 |
to_bson(j, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23643 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23644 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23645 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23646 |
/// @brief create a BSON serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23647 |
/// @sa https://json.nlohmann.me/api/basic_json/to_bson/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23648 |
static void to_bson(const basic_json& j, detail::output_adapter<std::uint8_t> o) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23649 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23650 |
binary_writer<std::uint8_t>(o).write_bson(j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23651 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23652 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23653 |
/// @brief create a BSON serialization of a given JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23654 |
/// @sa https://json.nlohmann.me/api/basic_json/to_bson/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23655 |
static void to_bson(const basic_json& j, detail::output_adapter<char> o) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23656 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23657 |
binary_writer<char>(o).write_bson(j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23658 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23659 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23660 |
/// @brief create a JSON value from an input in CBOR format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23661 |
/// @sa https://json.nlohmann.me/api/basic_json/from_cbor/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23662 |
template<typename InputType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23663 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23664 |
static basic_json from_cbor(InputType&& i, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23665 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23666 |
const bool allow_exceptions = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23667 |
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23668 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23669 |
basic_json result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23670 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23671 |
auto ia = detail::input_adapter(std::forward<InputType>(i)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23672 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23673 |
return res ? result : basic_json(value_t::discarded); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23674 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23675 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23676 |
/// @brief create a JSON value from an input in CBOR format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23677 |
/// @sa https://json.nlohmann.me/api/basic_json/from_cbor/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23678 |
template<typename IteratorType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23679 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23680 |
static basic_json from_cbor(IteratorType first, IteratorType last, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23681 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23682 |
const bool allow_exceptions = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23683 |
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23684 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23685 |
basic_json result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23686 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23687 |
auto ia = detail::input_adapter(std::move(first), std::move(last)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23688 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23689 |
return res ? result : basic_json(value_t::discarded); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23690 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23691 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23692 |
template<typename T> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23693 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23694 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23695 |
static basic_json from_cbor(const T* ptr, std::size_t len, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23696 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23697 |
const bool allow_exceptions = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23698 |
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23699 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23700 |
return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23701 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23702 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23703 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23704 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23705 |
static basic_json from_cbor(detail::span_input_adapter&& i, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23706 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23707 |
const bool allow_exceptions = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23708 |
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23709 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23710 |
basic_json result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23711 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23712 |
auto ia = i.get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23713 |
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23714 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23715 |
return res ? result : basic_json(value_t::discarded); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23716 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23717 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23718 |
/// @brief create a JSON value from an input in MessagePack format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23719 |
/// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23720 |
template<typename InputType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23721 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23722 |
static basic_json from_msgpack(InputType&& i, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23723 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23724 |
const bool allow_exceptions = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23725 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23726 |
basic_json result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23727 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23728 |
auto ia = detail::input_adapter(std::forward<InputType>(i)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23729 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23730 |
return res ? result : basic_json(value_t::discarded); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23731 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23732 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23733 |
/// @brief create a JSON value from an input in MessagePack format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23734 |
/// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23735 |
template<typename IteratorType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23736 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23737 |
static basic_json from_msgpack(IteratorType first, IteratorType last, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23738 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23739 |
const bool allow_exceptions = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23740 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23741 |
basic_json result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23742 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23743 |
auto ia = detail::input_adapter(std::move(first), std::move(last)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23744 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23745 |
return res ? result : basic_json(value_t::discarded); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23746 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23747 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23748 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23749 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23750 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23751 |
static basic_json from_msgpack(const T* ptr, std::size_t len, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23752 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23753 |
const bool allow_exceptions = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23754 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23755 |
return from_msgpack(ptr, ptr + len, strict, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23756 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23757 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23758 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23759 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23760 |
static basic_json from_msgpack(detail::span_input_adapter&& i, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23761 |
const bool strict = true, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23762 |
const bool allow_exceptions = true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23763 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23764 |
basic_json result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23765 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23766 |
auto ia = i.get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23767 |
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23768 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23769 |
return res ? result : basic_json(value_t::discarded); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23770 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23771 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23772 |
/// @brief create a JSON value from an input in UBJSON format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23773 |
/// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23774 |
template<typename InputType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23775 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23776 |
static basic_json from_ubjson(InputType&& i, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23777 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23778 |
const bool allow_exceptions = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23779 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23780 |
basic_json result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23781 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23782 |
auto ia = detail::input_adapter(std::forward<InputType>(i)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23783 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23784 |
return res ? result : basic_json(value_t::discarded); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23785 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23786 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23787 |
/// @brief create a JSON value from an input in UBJSON format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23788 |
/// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23789 |
template<typename IteratorType> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23790 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23791 |
static basic_json from_ubjson(IteratorType first, IteratorType last, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23792 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23793 |
const bool allow_exceptions = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23794 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23795 |
basic_json result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23796 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23797 |
auto ia = detail::input_adapter(std::move(first), std::move(last)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23798 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23799 |
return res ? result : basic_json(value_t::discarded); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23800 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23801 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23802 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23803 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23804 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23805 |
static basic_json from_ubjson(const T* ptr, std::size_t len, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23806 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23807 |
const bool allow_exceptions = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23808 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23809 |
return from_ubjson(ptr, ptr + len, strict, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23810 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23811 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23812 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23813 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23814 |
static basic_json from_ubjson(detail::span_input_adapter&& i, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23815 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23816 |
const bool allow_exceptions = true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23817 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23818 |
basic_json result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23819 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23820 |
auto ia = i.get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23821 |
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23822 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23823 |
return res ? result : basic_json(value_t::discarded); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23824 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23825 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23826 |
/// @brief create a JSON value from an input in BJData format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23827 |
/// @sa https://json.nlohmann.me/api/basic_json/from_bjdata/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23828 |
template<typename InputType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23829 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23830 |
static basic_json from_bjdata(InputType&& i, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23831 |
const bool strict = true, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23832 |
const bool allow_exceptions = true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23833 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23834 |
basic_json result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23835 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23836 |
auto ia = detail::input_adapter(std::forward<InputType>(i)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23837 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23838 |
return res ? result : basic_json(value_t::discarded); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23839 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23840 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23841 |
/// @brief create a JSON value from an input in BJData format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23842 |
/// @sa https://json.nlohmann.me/api/basic_json/from_bjdata/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23843 |
template<typename IteratorType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23844 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23845 |
static basic_json from_bjdata(IteratorType first, IteratorType last, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23846 |
const bool strict = true, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23847 |
const bool allow_exceptions = true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23848 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23849 |
basic_json result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23850 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23851 |
auto ia = detail::input_adapter(std::move(first), std::move(last)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23852 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23853 |
return res ? result : basic_json(value_t::discarded); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23854 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23855 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23856 |
/// @brief create a JSON value from an input in BSON format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23857 |
/// @sa https://json.nlohmann.me/api/basic_json/from_bson/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23858 |
template<typename InputType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23859 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23860 |
static basic_json from_bson(InputType&& i, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23861 |
const bool strict = true, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23862 |
const bool allow_exceptions = true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23863 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23864 |
basic_json result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23865 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23866 |
auto ia = detail::input_adapter(std::forward<InputType>(i)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23867 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23868 |
return res ? result : basic_json(value_t::discarded); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23869 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23870 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23871 |
/// @brief create a JSON value from an input in BSON format |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23872 |
/// @sa https://json.nlohmann.me/api/basic_json/from_bson/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23873 |
template<typename IteratorType> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23874 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23875 |
static basic_json from_bson(IteratorType first, IteratorType last, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23876 |
const bool strict = true, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23877 |
const bool allow_exceptions = true) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23878 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23879 |
basic_json result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23880 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23881 |
auto ia = detail::input_adapter(std::move(first), std::move(last)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23882 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23883 |
return res ? result : basic_json(value_t::discarded); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23884 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23885 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23886 |
template<typename T> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23887 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23888 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23889 |
static basic_json from_bson(const T* ptr, std::size_t len, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23890 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23891 |
const bool allow_exceptions = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23892 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23893 |
return from_bson(ptr, ptr + len, strict, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23894 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23895 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23896 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23897 |
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len)) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23898 |
static basic_json from_bson(detail::span_input_adapter&& i, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23899 |
const bool strict = true, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23900 |
const bool allow_exceptions = true) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23901 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23902 |
basic_json result; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23903 |
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23904 |
auto ia = i.get(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23905 |
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23906 |
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23907 |
return res ? result : basic_json(value_t::discarded); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23908 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23909 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23910 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23911 |
////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23912 |
// JSON Pointer support // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23913 |
////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23914 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23915 |
/// @name JSON Pointer functions |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23916 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23917 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23918 |
/// @brief access specified element via JSON Pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23919 |
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23920 |
reference operator[](const json_pointer& ptr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23921 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23922 |
return ptr.get_unchecked(this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23923 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23924 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23925 |
template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23926 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23927 |
reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23928 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23929 |
return ptr.get_unchecked(this); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23930 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23931 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23932 |
/// @brief access specified element via JSON Pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23933 |
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23934 |
const_reference operator[](const json_pointer& ptr) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23935 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23936 |
return ptr.get_unchecked(this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23937 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23938 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23939 |
template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23940 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23941 |
const_reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23942 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23943 |
return ptr.get_unchecked(this); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23944 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23945 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23946 |
/// @brief access specified element via JSON Pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23947 |
/// @sa https://json.nlohmann.me/api/basic_json/at/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23948 |
reference at(const json_pointer& ptr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23949 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23950 |
return ptr.get_checked(this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23951 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23952 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23953 |
template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23954 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23955 |
reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23956 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23957 |
return ptr.get_checked(this); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23958 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23959 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23960 |
/// @brief access specified element via JSON Pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23961 |
/// @sa https://json.nlohmann.me/api/basic_json/at/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23962 |
const_reference at(const json_pointer& ptr) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23963 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23964 |
return ptr.get_checked(this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23965 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23966 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23967 |
template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value, int> = 0> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23968 |
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer<basic_json::string_t>) // NOLINT(readability/alt_tokens) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23969 |
const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23970 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23971 |
return ptr.get_checked(this); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23972 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23973 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23974 |
/// @brief return flattened JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23975 |
/// @sa https://json.nlohmann.me/api/basic_json/flatten/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23976 |
basic_json flatten() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23977 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23978 |
basic_json result(value_t::object); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23979 |
json_pointer::flatten("", *this, result); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23980 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23981 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23982 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23983 |
/// @brief unflatten a previously flattened JSON value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23984 |
/// @sa https://json.nlohmann.me/api/basic_json/unflatten/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23985 |
basic_json unflatten() const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23986 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23987 |
return json_pointer::unflatten(*this); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23988 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23989 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23990 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23991 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23992 |
////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23993 |
// JSON Patch functions // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23994 |
////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23995 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23996 |
/// @name JSON Patch functions |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23997 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
23998 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
23999 |
/// @brief applies a JSON patch in-place without copying the object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24000 |
/// @sa https://json.nlohmann.me/api/basic_json/patch/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24001 |
void patch_inplace(const basic_json& json_patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24002 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24003 |
basic_json& result = *this; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24004 |
// the valid JSON Patch operations |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24005 |
enum class patch_operations {add, remove, replace, move, copy, test, invalid}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24006 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24007 |
const auto get_op = [](const std::string & op) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24008 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24009 |
if (op == "add") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24010 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24011 |
return patch_operations::add; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24012 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24013 |
if (op == "remove") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24014 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24015 |
return patch_operations::remove; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24016 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24017 |
if (op == "replace") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24018 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24019 |
return patch_operations::replace; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24020 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24021 |
if (op == "move") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24022 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24023 |
return patch_operations::move; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24024 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24025 |
if (op == "copy") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24026 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24027 |
return patch_operations::copy; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24028 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24029 |
if (op == "test") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24030 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24031 |
return patch_operations::test; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24032 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24033 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24034 |
return patch_operations::invalid; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24035 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24036 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24037 |
// wrapper for "add" operation; add value at ptr |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24038 |
const auto operation_add = [&result](json_pointer & ptr, basic_json val) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24039 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24040 |
// adding to the root of the target document means replacing it |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24041 |
if (ptr.empty()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24042 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24043 |
result = val; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24044 |
return; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24045 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24046 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24047 |
// make sure the top element of the pointer exists |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24048 |
json_pointer const top_pointer = ptr.top(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24049 |
if (top_pointer != ptr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24050 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24051 |
result.at(top_pointer); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24052 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24053 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24054 |
// get reference to parent of JSON pointer ptr |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24055 |
const auto last_path = ptr.back(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24056 |
ptr.pop_back(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24057 |
// parent must exist when performing patch add per RFC6902 specs |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24058 |
basic_json& parent = result.at(ptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24059 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24060 |
switch (parent.m_data.m_type) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24061 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24062 |
case value_t::null: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24063 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24064 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24065 |
// use operator[] to add value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24066 |
parent[last_path] = val; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24067 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24068 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24069 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24070 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24071 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24072 |
if (last_path == "-") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24073 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24074 |
// special case: append to back |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24075 |
parent.push_back(val); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24076 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24077 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24078 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24079 |
const auto idx = json_pointer::template array_index<basic_json_t>(last_path); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24080 |
if (JSON_HEDLEY_UNLIKELY(idx > parent.size())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24081 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24082 |
// avoid undefined behavior |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24083 |
JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), &parent)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24084 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24085 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24086 |
// default case: insert add offset |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24087 |
parent.insert(parent.begin() + static_cast<difference_type>(idx), val); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24088 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24089 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24090 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24091 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24092 |
// if there exists a parent it cannot be primitive |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24093 |
case value_t::string: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24094 |
case value_t::boolean: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24095 |
case value_t::number_integer: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24096 |
case value_t::number_unsigned: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24097 |
case value_t::number_float: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24098 |
case value_t::binary: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24099 |
case value_t::discarded: // LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24100 |
default: // LCOV_EXCL_LINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24101 |
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24102 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24103 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24104 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24105 |
// wrapper for "remove" operation; remove value at ptr |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24106 |
const auto operation_remove = [this, & result](json_pointer & ptr) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24107 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24108 |
// get reference to parent of JSON pointer ptr |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24109 |
const auto last_path = ptr.back(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24110 |
ptr.pop_back(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24111 |
basic_json& parent = result.at(ptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24112 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24113 |
// remove child |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24114 |
if (parent.is_object()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24115 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24116 |
// perform range check |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24117 |
auto it = parent.find(last_path); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24118 |
if (JSON_HEDLEY_LIKELY(it != parent.end())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24119 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24120 |
parent.erase(it); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24121 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24122 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24123 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24124 |
JSON_THROW(out_of_range::create(403, detail::concat("key '", last_path, "' not found"), this)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24125 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24126 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24127 |
else if (parent.is_array()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24128 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24129 |
// note erase performs range check |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24130 |
parent.erase(json_pointer::template array_index<basic_json_t>(last_path)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24131 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24132 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24133 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24134 |
// type check: top level value must be an array |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24135 |
if (JSON_HEDLEY_UNLIKELY(!json_patch.is_array())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24136 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24137 |
JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", &json_patch)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24138 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24139 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24140 |
// iterate and apply the operations |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24141 |
for (const auto& val : json_patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24142 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24143 |
// wrapper to get a value for an operation |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24144 |
const auto get_value = [&val](const std::string & op, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24145 |
const std::string & member, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24146 |
bool string_type) -> basic_json & |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24147 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24148 |
// find value |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24149 |
auto it = val.m_data.m_value.object->find(member); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24150 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24151 |
// context-sensitive error message |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24152 |
const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\''); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24153 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24154 |
// check if desired value is present |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24155 |
if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24156 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24157 |
// NOLINTNEXTLINE(performance-inefficient-string-concatenation) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24158 |
JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg, " must have member '", member, "'"), &val)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24159 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24160 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24161 |
// check if result is of type string |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24162 |
if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24163 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24164 |
// NOLINTNEXTLINE(performance-inefficient-string-concatenation) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24165 |
JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg, " must have string member '", member, "'"), &val)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24166 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24167 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24168 |
// no error: return value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24169 |
return it->second; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24170 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24171 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24172 |
// type check: every element of the array must be an object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24173 |
if (JSON_HEDLEY_UNLIKELY(!val.is_object())) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24174 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24175 |
JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", &val)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24176 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24177 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24178 |
// collect mandatory members |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24179 |
const auto op = get_value("op", "op", true).template get<std::string>(); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24180 |
const auto path = get_value(op, "path", true).template get<std::string>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24181 |
json_pointer ptr(path); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24182 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24183 |
switch (get_op(op)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24184 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24185 |
case patch_operations::add: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24186 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24187 |
operation_add(ptr, get_value("add", "value", false)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24188 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24189 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24190 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24191 |
case patch_operations::remove: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24192 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24193 |
operation_remove(ptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24194 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24195 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24196 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24197 |
case patch_operations::replace: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24198 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24199 |
// the "path" location must exist - use at() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24200 |
result.at(ptr) = get_value("replace", "value", false); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24201 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24202 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24203 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24204 |
case patch_operations::move: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24205 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24206 |
const auto from_path = get_value("move", "from", true).template get<std::string>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24207 |
json_pointer from_ptr(from_path); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24208 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24209 |
// the "from" location must exist - use at() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24210 |
basic_json const v = result.at(from_ptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24211 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24212 |
// The move operation is functionally identical to a |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24213 |
// "remove" operation on the "from" location, followed |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24214 |
// immediately by an "add" operation at the target |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24215 |
// location with the value that was just removed. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24216 |
operation_remove(from_ptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24217 |
operation_add(ptr, v); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24218 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24219 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24220 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24221 |
case patch_operations::copy: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24222 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24223 |
const auto from_path = get_value("copy", "from", true).template get<std::string>(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24224 |
const json_pointer from_ptr(from_path); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24225 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24226 |
// the "from" location must exist - use at() |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24227 |
basic_json const v = result.at(from_ptr); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24228 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24229 |
// The copy is functionally identical to an "add" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24230 |
// operation at the target location using the value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24231 |
// specified in the "from" member. |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24232 |
operation_add(ptr, v); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24233 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24234 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24235 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24236 |
case patch_operations::test: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24237 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24238 |
bool success = false; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24239 |
JSON_TRY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24240 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24241 |
// check if "value" matches the one at "path" |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24242 |
// the "path" location must exist - use at() |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24243 |
success = (result.at(ptr) == get_value("test", "value", false)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24244 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24245 |
JSON_INTERNAL_CATCH (out_of_range&) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24246 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24247 |
// ignore out of range errors: success remains false |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24248 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24249 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24250 |
// throw an exception if test fails |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24251 |
if (JSON_HEDLEY_UNLIKELY(!success)) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24252 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24253 |
JSON_THROW(other_error::create(501, detail::concat("unsuccessful: ", val.dump()), &val)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24254 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24255 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24256 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24257 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24258 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24259 |
case patch_operations::invalid: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24260 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24261 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24262 |
// op must be "add", "remove", "replace", "move", "copy", or |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24263 |
// "test" |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24264 |
JSON_THROW(parse_error::create(105, 0, detail::concat("operation value '", op, "' is invalid"), &val)); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24265 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24266 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24267 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24268 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24269 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24270 |
/// @brief applies a JSON patch to a copy of the current object |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24271 |
/// @sa https://json.nlohmann.me/api/basic_json/patch/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24272 |
basic_json patch(const basic_json& json_patch) const |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24273 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24274 |
basic_json result = *this; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24275 |
result.patch_inplace(json_patch); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24276 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24277 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24278 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24279 |
/// @brief creates a diff as a JSON patch |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24280 |
/// @sa https://json.nlohmann.me/api/basic_json/diff/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24281 |
JSON_HEDLEY_WARN_UNUSED_RESULT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24282 |
static basic_json diff(const basic_json& source, const basic_json& target, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24283 |
const std::string& path = "") |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24284 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24285 |
// the patch |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24286 |
basic_json result(value_t::array); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24287 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24288 |
// if the values are the same, return empty patch |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24289 |
if (source == target) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24290 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24291 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24292 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24293 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24294 |
if (source.type() != target.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24295 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24296 |
// different types: replace value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24297 |
result.push_back( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24298 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24299 |
{"op", "replace"}, {"path", path}, {"value", target} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24300 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24301 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24302 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24303 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24304 |
switch (source.type()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24305 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24306 |
case value_t::array: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24307 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24308 |
// first pass: traverse common elements |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24309 |
std::size_t i = 0; |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24310 |
while (i < source.size() && i < target.size()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24311 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24312 |
// recursive call to compare array values at index i |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24313 |
auto temp_diff = diff(source[i], target[i], detail::concat(path, '/', std::to_string(i))); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24314 |
result.insert(result.end(), temp_diff.begin(), temp_diff.end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24315 |
++i; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24316 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24317 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24318 |
// We now reached the end of at least one array |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24319 |
// in a second pass, traverse the remaining elements |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24320 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24321 |
// remove my remaining elements |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24322 |
const auto end_index = static_cast<difference_type>(result.size()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24323 |
while (i < source.size()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24324 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24325 |
// add operations in reverse order to avoid invalid |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24326 |
// indices |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24327 |
result.insert(result.begin() + end_index, object( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24328 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24329 |
{"op", "remove"}, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24330 |
{"path", detail::concat(path, '/', std::to_string(i))} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24331 |
})); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24332 |
++i; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24333 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24334 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24335 |
// add other remaining elements |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24336 |
while (i < target.size()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24337 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24338 |
result.push_back( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24339 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24340 |
{"op", "add"}, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24341 |
{"path", detail::concat(path, "/-")}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24342 |
{"value", target[i]} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24343 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24344 |
++i; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24345 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24346 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24347 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24348 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24349 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24350 |
case value_t::object: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24351 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24352 |
// first pass: traverse this object's elements |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24353 |
for (auto it = source.cbegin(); it != source.cend(); ++it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24354 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24355 |
// escape the key name to be used in a JSON patch |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24356 |
const auto path_key = detail::concat(path, '/', detail::escape(it.key())); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24357 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24358 |
if (target.find(it.key()) != target.end()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24359 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24360 |
// recursive call to compare object values at key it |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24361 |
auto temp_diff = diff(it.value(), target[it.key()], path_key); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24362 |
result.insert(result.end(), temp_diff.begin(), temp_diff.end()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24363 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24364 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24365 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24366 |
// found a key that is not in o -> remove it |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24367 |
result.push_back(object( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24368 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24369 |
{"op", "remove"}, {"path", path_key} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24370 |
})); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24371 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24372 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24373 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24374 |
// second pass: traverse other object's elements |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24375 |
for (auto it = target.cbegin(); it != target.cend(); ++it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24376 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24377 |
if (source.find(it.key()) == source.end()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24378 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24379 |
// found a key that is not in this -> add it |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24380 |
const auto path_key = detail::concat(path, '/', detail::escape(it.key())); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24381 |
result.push_back( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24382 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24383 |
{"op", "add"}, {"path", path_key}, |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24384 |
{"value", it.value()} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24385 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24386 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24387 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24388 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24389 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24390 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24391 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24392 |
case value_t::null: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24393 |
case value_t::string: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24394 |
case value_t::boolean: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24395 |
case value_t::number_integer: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24396 |
case value_t::number_unsigned: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24397 |
case value_t::number_float: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24398 |
case value_t::binary: |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24399 |
case value_t::discarded: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24400 |
default: |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24401 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24402 |
// both primitive type: replace value |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24403 |
result.push_back( |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24404 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24405 |
{"op", "replace"}, {"path", path}, {"value", target} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24406 |
}); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24407 |
break; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24408 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24409 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24410 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24411 |
return result; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24412 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24413 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24414 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24415 |
//////////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24416 |
// JSON Merge Patch functions // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24417 |
//////////////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24418 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24419 |
/// @name JSON Merge Patch functions |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24420 |
/// @{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24421 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24422 |
/// @brief applies a JSON Merge Patch |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24423 |
/// @sa https://json.nlohmann.me/api/basic_json/merge_patch/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24424 |
void merge_patch(const basic_json& apply_patch) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24425 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24426 |
if (apply_patch.is_object()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24427 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24428 |
if (!is_object()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24429 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24430 |
*this = object(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24431 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24432 |
for (auto it = apply_patch.begin(); it != apply_patch.end(); ++it) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24433 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24434 |
if (it.value().is_null()) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24435 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24436 |
erase(it.key()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24437 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24438 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24439 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24440 |
operator[](it.key()).merge_patch(it.value()); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24441 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24442 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24443 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24444 |
else |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24445 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24446 |
*this = apply_patch; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24447 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24448 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24449 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24450 |
/// @} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24451 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24452 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24453 |
/// @brief user-defined to_string function for JSON values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24454 |
/// @sa https://json.nlohmann.me/api/basic_json/to_string/ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24455 |
NLOHMANN_BASIC_JSON_TPL_DECLARATION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24456 |
std::string to_string(const NLOHMANN_BASIC_JSON_TPL& j) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24457 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24458 |
return j.dump(); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24459 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24460 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24461 |
inline namespace literals |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24462 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24463 |
inline namespace json_literals |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24464 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24465 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24466 |
/// @brief user-defined string literal for JSON values |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24467 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24468 |
JSON_HEDLEY_NON_NULL(1) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24469 |
#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24470 |
inline nlohmann::json operator ""_json(const char* s, std::size_t n) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24471 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24472 |
inline nlohmann::json operator "" _json(const char* s, std::size_t n) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24473 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24474 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24475 |
return nlohmann::json::parse(s, s + n); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24476 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24477 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24478 |
/// @brief user-defined string literal for JSON pointer |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24479 |
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24480 |
JSON_HEDLEY_NON_NULL(1) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24481 |
#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24482 |
inline nlohmann::json::json_pointer operator ""_json_pointer(const char* s, std::size_t n) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24483 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24484 |
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24485 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24486 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24487 |
return nlohmann::json::json_pointer(std::string(s, n)); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24488 |
} |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24489 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24490 |
} // namespace json_literals |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24491 |
} // namespace literals |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24492 |
NLOHMANN_JSON_NAMESPACE_END |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24493 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24494 |
/////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24495 |
// nonmember support // |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24496 |
/////////////////////// |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24497 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24498 |
namespace std // NOLINT(cert-dcl58-cpp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24499 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24500 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24501 |
/// @brief hash value for JSON objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24502 |
/// @sa https://json.nlohmann.me/api/basic_json/std_hash/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24503 |
NLOHMANN_BASIC_JSON_TPL_DECLARATION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24504 |
struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL> // NOLINT(cert-dcl58-cpp) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24505 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24506 |
std::size_t operator()(const nlohmann::NLOHMANN_BASIC_JSON_TPL& j) const |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24507 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24508 |
return nlohmann::detail::hash(j); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24509 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24510 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24511 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24512 |
// specialization for std::less<value_t> |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24513 |
template<> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24514 |
struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24515 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24516 |
/*! |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24517 |
@brief compare two value_t enum values |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24518 |
@since version 3.0.0 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24519 |
*/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24520 |
bool operator()(::nlohmann::detail::value_t lhs, |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24521 |
::nlohmann::detail::value_t rhs) const noexcept |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24522 |
{ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24523 |
#if JSON_HAS_THREE_WAY_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24524 |
return std::is_lt(lhs <=> rhs); // *NOPAD* |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24525 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24526 |
return ::nlohmann::detail::operator<(lhs, rhs); |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24527 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24528 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24529 |
}; |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24530 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24531 |
// C++20 prohibit function specialization in the std namespace. |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24532 |
#ifndef JSON_HAS_CPP_20 |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24533 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24534 |
/// @brief exchanges the values of two JSON objects |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24535 |
/// @sa https://json.nlohmann.me/api/basic_json/std_swap/ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24536 |
NLOHMANN_BASIC_JSON_TPL_DECLARATION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24537 |
inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24538 |
is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&& // NOLINT(misc-redundant-expression,cppcoreguidelines-noexcept-swap,performance-noexcept-swap) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24539 |
is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value) |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24540 |
{ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24541 |
j1.swap(j2); |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24542 |
} |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24543 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24544 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24545 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24546 |
} // namespace std |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24547 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24548 |
#if JSON_USE_GLOBAL_UDLS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24549 |
#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24550 |
using nlohmann::literals::json_literals::operator ""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24551 |
using nlohmann::literals::json_literals::operator ""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24552 |
#else |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24553 |
using nlohmann::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24554 |
using nlohmann::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24555 |
#endif |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24556 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24557 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24558 |
// #include <nlohmann/detail/macro_unscope.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24559 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24560 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24561 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24562 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24563 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24564 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24565 |
// SPDX-License-Identifier: MIT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24566 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24567 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24568 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24569 |
// restore clang diagnostic settings |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24570 |
#if defined(__clang__) |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24571 |
#pragma clang diagnostic pop |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24572 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24573 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24574 |
// clean up |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24575 |
#undef JSON_ASSERT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24576 |
#undef JSON_INTERNAL_CATCH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24577 |
#undef JSON_THROW |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24578 |
#undef JSON_PRIVATE_UNLESS_TESTED |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24579 |
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24580 |
#undef NLOHMANN_BASIC_JSON_TPL |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24581 |
#undef JSON_EXPLICIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24582 |
#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24583 |
#undef JSON_INLINE_VARIABLE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24584 |
#undef JSON_NO_UNIQUE_ADDRESS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24585 |
#undef JSON_DISABLE_ENUM_SERIALIZATION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24586 |
#undef JSON_USE_GLOBAL_UDLS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24587 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24588 |
#ifndef JSON_TEST_KEEP_MACROS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24589 |
#undef JSON_CATCH |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24590 |
#undef JSON_TRY |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24591 |
#undef JSON_HAS_CPP_11 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24592 |
#undef JSON_HAS_CPP_14 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24593 |
#undef JSON_HAS_CPP_17 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24594 |
#undef JSON_HAS_CPP_20 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24595 |
#undef JSON_HAS_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24596 |
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24597 |
#undef JSON_HAS_THREE_WAY_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24598 |
#undef JSON_HAS_RANGES |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24599 |
#undef JSON_HAS_STATIC_RTTI |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24600 |
#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24601 |
#endif |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24602 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24603 |
// #include <nlohmann/thirdparty/hedley/hedley_undef.hpp> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24604 |
// __ _____ _____ _____ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24605 |
// __| | __| | | | JSON for Modern C++ |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24606 |
// | | |__ | | | | | | version 3.11.3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24607 |
// |_____|_____|_____|_|___| https://github.com/nlohmann/json |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24608 |
// |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24609 |
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me> |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24610 |
// SPDX-License-Identifier: MIT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24611 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24612 |
|
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24613 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24614 |
#undef JSON_HEDLEY_ALWAYS_INLINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24615 |
#undef JSON_HEDLEY_ARM_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24616 |
#undef JSON_HEDLEY_ARM_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24617 |
#undef JSON_HEDLEY_ARRAY_PARAM |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24618 |
#undef JSON_HEDLEY_ASSUME |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24619 |
#undef JSON_HEDLEY_BEGIN_C_DECLS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24620 |
#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24621 |
#undef JSON_HEDLEY_CLANG_HAS_BUILTIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24622 |
#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24623 |
#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24624 |
#undef JSON_HEDLEY_CLANG_HAS_EXTENSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24625 |
#undef JSON_HEDLEY_CLANG_HAS_FEATURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24626 |
#undef JSON_HEDLEY_CLANG_HAS_WARNING |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24627 |
#undef JSON_HEDLEY_COMPCERT_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24628 |
#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24629 |
#undef JSON_HEDLEY_CONCAT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24630 |
#undef JSON_HEDLEY_CONCAT3 |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24631 |
#undef JSON_HEDLEY_CONCAT3_EX |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24632 |
#undef JSON_HEDLEY_CONCAT_EX |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24633 |
#undef JSON_HEDLEY_CONST |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24634 |
#undef JSON_HEDLEY_CONSTEXPR |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24635 |
#undef JSON_HEDLEY_CONST_CAST |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24636 |
#undef JSON_HEDLEY_CPP_CAST |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24637 |
#undef JSON_HEDLEY_CRAY_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24638 |
#undef JSON_HEDLEY_CRAY_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24639 |
#undef JSON_HEDLEY_C_DECL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24640 |
#undef JSON_HEDLEY_DEPRECATED |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24641 |
#undef JSON_HEDLEY_DEPRECATED_FOR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24642 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24643 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24644 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24645 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24646 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24647 |
#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24648 |
#undef JSON_HEDLEY_DIAGNOSTIC_POP |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24649 |
#undef JSON_HEDLEY_DIAGNOSTIC_PUSH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24650 |
#undef JSON_HEDLEY_DMC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24651 |
#undef JSON_HEDLEY_DMC_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24652 |
#undef JSON_HEDLEY_EMPTY_BASES |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24653 |
#undef JSON_HEDLEY_EMSCRIPTEN_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24654 |
#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24655 |
#undef JSON_HEDLEY_END_C_DECLS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24656 |
#undef JSON_HEDLEY_FLAGS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24657 |
#undef JSON_HEDLEY_FLAGS_CAST |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24658 |
#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24659 |
#undef JSON_HEDLEY_GCC_HAS_BUILTIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24660 |
#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24661 |
#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24662 |
#undef JSON_HEDLEY_GCC_HAS_EXTENSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24663 |
#undef JSON_HEDLEY_GCC_HAS_FEATURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24664 |
#undef JSON_HEDLEY_GCC_HAS_WARNING |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24665 |
#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24666 |
#undef JSON_HEDLEY_GCC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24667 |
#undef JSON_HEDLEY_GCC_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24668 |
#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24669 |
#undef JSON_HEDLEY_GNUC_HAS_BUILTIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24670 |
#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24671 |
#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24672 |
#undef JSON_HEDLEY_GNUC_HAS_EXTENSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24673 |
#undef JSON_HEDLEY_GNUC_HAS_FEATURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24674 |
#undef JSON_HEDLEY_GNUC_HAS_WARNING |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24675 |
#undef JSON_HEDLEY_GNUC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24676 |
#undef JSON_HEDLEY_GNUC_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24677 |
#undef JSON_HEDLEY_HAS_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24678 |
#undef JSON_HEDLEY_HAS_BUILTIN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24679 |
#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24680 |
#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24681 |
#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24682 |
#undef JSON_HEDLEY_HAS_EXTENSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24683 |
#undef JSON_HEDLEY_HAS_FEATURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24684 |
#undef JSON_HEDLEY_HAS_WARNING |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24685 |
#undef JSON_HEDLEY_IAR_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24686 |
#undef JSON_HEDLEY_IAR_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24687 |
#undef JSON_HEDLEY_IBM_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24688 |
#undef JSON_HEDLEY_IBM_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24689 |
#undef JSON_HEDLEY_IMPORT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24690 |
#undef JSON_HEDLEY_INLINE |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24691 |
#undef JSON_HEDLEY_INTEL_CL_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24692 |
#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24693 |
#undef JSON_HEDLEY_INTEL_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24694 |
#undef JSON_HEDLEY_INTEL_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24695 |
#undef JSON_HEDLEY_IS_CONSTANT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24696 |
#undef JSON_HEDLEY_IS_CONSTEXPR_ |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24697 |
#undef JSON_HEDLEY_LIKELY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24698 |
#undef JSON_HEDLEY_MALLOC |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24699 |
#undef JSON_HEDLEY_MCST_LCC_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24700 |
#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24701 |
#undef JSON_HEDLEY_MESSAGE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24702 |
#undef JSON_HEDLEY_MSVC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24703 |
#undef JSON_HEDLEY_MSVC_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24704 |
#undef JSON_HEDLEY_NEVER_INLINE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24705 |
#undef JSON_HEDLEY_NON_NULL |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24706 |
#undef JSON_HEDLEY_NO_ESCAPE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24707 |
#undef JSON_HEDLEY_NO_RETURN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24708 |
#undef JSON_HEDLEY_NO_THROW |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24709 |
#undef JSON_HEDLEY_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24710 |
#undef JSON_HEDLEY_PELLES_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24711 |
#undef JSON_HEDLEY_PELLES_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24712 |
#undef JSON_HEDLEY_PGI_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24713 |
#undef JSON_HEDLEY_PGI_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24714 |
#undef JSON_HEDLEY_PREDICT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24715 |
#undef JSON_HEDLEY_PRINTF_FORMAT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24716 |
#undef JSON_HEDLEY_PRIVATE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24717 |
#undef JSON_HEDLEY_PUBLIC |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24718 |
#undef JSON_HEDLEY_PURE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24719 |
#undef JSON_HEDLEY_REINTERPRET_CAST |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24720 |
#undef JSON_HEDLEY_REQUIRE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24721 |
#undef JSON_HEDLEY_REQUIRE_CONSTEXPR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24722 |
#undef JSON_HEDLEY_REQUIRE_MSG |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24723 |
#undef JSON_HEDLEY_RESTRICT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24724 |
#undef JSON_HEDLEY_RETURNS_NON_NULL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24725 |
#undef JSON_HEDLEY_SENTINEL |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24726 |
#undef JSON_HEDLEY_STATIC_ASSERT |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24727 |
#undef JSON_HEDLEY_STATIC_CAST |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24728 |
#undef JSON_HEDLEY_STRINGIFY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24729 |
#undef JSON_HEDLEY_STRINGIFY_EX |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24730 |
#undef JSON_HEDLEY_SUNPRO_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24731 |
#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24732 |
#undef JSON_HEDLEY_TINYC_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24733 |
#undef JSON_HEDLEY_TINYC_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24734 |
#undef JSON_HEDLEY_TI_ARMCL_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24735 |
#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24736 |
#undef JSON_HEDLEY_TI_CL2000_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24737 |
#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24738 |
#undef JSON_HEDLEY_TI_CL430_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24739 |
#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24740 |
#undef JSON_HEDLEY_TI_CL6X_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24741 |
#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24742 |
#undef JSON_HEDLEY_TI_CL7X_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24743 |
#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24744 |
#undef JSON_HEDLEY_TI_CLPRU_VERSION |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24745 |
#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24746 |
#undef JSON_HEDLEY_TI_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24747 |
#undef JSON_HEDLEY_TI_VERSION_CHECK |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24748 |
#undef JSON_HEDLEY_UNAVAILABLE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24749 |
#undef JSON_HEDLEY_UNLIKELY |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24750 |
#undef JSON_HEDLEY_UNPREDICTABLE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24751 |
#undef JSON_HEDLEY_UNREACHABLE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24752 |
#undef JSON_HEDLEY_UNREACHABLE_RETURN |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24753 |
#undef JSON_HEDLEY_VERSION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24754 |
#undef JSON_HEDLEY_VERSION_DECODE_MAJOR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24755 |
#undef JSON_HEDLEY_VERSION_DECODE_MINOR |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24756 |
#undef JSON_HEDLEY_VERSION_DECODE_REVISION |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24757 |
#undef JSON_HEDLEY_VERSION_ENCODE |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24758 |
#undef JSON_HEDLEY_WARNING |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24759 |
#undef JSON_HEDLEY_WARN_UNUSED_RESULT |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24760 |
#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG |
| e55872f1 |
Poul Sander |
2024-05-11 19:26 |
24761 |
#undef JSON_HEDLEY_FALL_THROUGH |
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24762 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24763 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24764 |
|
| 2660ccea |
Poul Sander |
2023-09-22 19:25 |
24765 |
#endif // INCLUDE_NLOHMANN_JSON_HPP_ |
|
|
1970-01-01 00:00 |
24766 |
|