43#ifndef USHER_OPENCV_JSON_HPP
44#define USHER_OPENCV_JSON_HPP
46#include <opencv2/core.hpp>
47#include <opencv2/core/persistence.hpp>
57#include <initializer_list>
64#include <system_error>
96 std::vector<std::shared_ptr<Node>>
array;
97 std::map<std::string, std::shared_ptr<Node>>
object;
113 using std::runtime_error::runtime_error;
116 using Field = std::pair<std::string, Value>;
150 template <
typename Number,
151 typename = std::enable_if_t<std::is_integral_v<Number> &&
152 !std::is_same_v<Number, bool>>>
154 if constexpr (std::is_signed_v<Number>) {
156 node_->signed_number =
static_cast<int64_t
>(
value);
159 node_->unsigned_number =
static_cast<uint64_t
>(
value);
167 template <
typename Number,
168 typename = std::enable_if_t<std::is_floating_point_v<Number>>,
172 node_->real_number =
static_cast<double>(
value);
211 for (
const auto &field : fields)
212 value.set(field.first, field.second);
228 for (
const auto &item : values)
229 value.push_back(item);
241 template <
typename Iterator>
243 return parse(std::string(first, last));
252 return parse(std::string(input ? input :
""));
265 cv::FileStorage storage(normalized, cv::FileStorage::READ |
266 cv::FileStorage::MEMORY |
267 cv::FileStorage::FORMAT_JSON);
268 if (!storage.isOpened())
269 throw exception(
"OpenCV FileStorage could not open JSON input");
271 }
catch (
const cv::Exception &
error) {
272 throw exception(std::string(
"invalid OpenCV JSON: ") +
error.what());
337 return lookup(key.c_str(),
false);
352 Value at(
const std::string &key)
const {
return at(key.c_str()); }
375 throw exception(
"JSON array index out of range");
376 return at(
static_cast<size_t>(index));
386 throw exception(
"JSON array index out of range");
401 template <
typename Type> Type
get()
const {
402 if constexpr (std::is_same_v<Type, Value>)
404 else if constexpr (std::is_same_v<Type, std::string>) {
406 throw exception(
"JSON value is not a string");
407 return node_->string;
408 }
else if constexpr (std::is_same_v<Type, bool>) {
410 throw exception(
"JSON value is not a boolean");
411 return node_->boolean;
412 }
else if constexpr (std::is_floating_point_v<Type>) {
414 throw exception(
"JSON value is not numeric");
417 ?
static_cast<double>(
node_->signed_number)
418 :
static_cast<double>(
node_->unsigned_number);
419 if (!std::isfinite(number) ||
420 number < -std::numeric_limits<Type>::max() ||
421 number > std::numeric_limits<Type>::max())
422 throw exception(
"JSON number is out of range");
423 return static_cast<Type
>(number);
424 }
else if constexpr (std::is_integral_v<Type> && std::is_signed_v<Type>) {
426 throw exception(
"JSON value is not an integer");
427 const long double number =
429 ?
static_cast<long double>(
node_->signed_number)
430 :
static_cast<long double>(
node_->unsigned_number);
431 if (number < std::numeric_limits<Type>::min() ||
432 number > std::numeric_limits<Type>::max())
433 throw exception(
"JSON integer is out of range");
434 return static_cast<Type
>(number);
435 }
else if constexpr (std::is_integral_v<Type> && std::is_unsigned_v<Type>) {
437 throw exception(
"JSON value is not an integer");
438 const long double number =
440 ?
static_cast<long double>(
node_->signed_number)
441 :
static_cast<long double>(
node_->unsigned_number);
442 if (number < 0 || number > std::numeric_limits<Type>::max())
443 throw exception(
"JSON integer is out of range");
444 return static_cast<Type
>(number);
447 throw exception(
"JSON array has unexpected length");
449 for (
size_t index = 0; index <
result.size(); ++index)
454 throw exception(
"JSON value is not an array");
457 for (
size_t index = 0; index <
size(); ++index)
461 static_assert(!
sizeof(Type),
"unsupported JSON conversion type");
472 template <
typename Type> Type
value(
const char *key, Type fallback)
const {
482 std::string
value(
const char *key,
const char *fallback)
const {
483 return contains(key) ?
at(key).
get<std::string>() : std::string(fallback);
493 std::vector<std::pair<std::string, Value>>
items()
const {
495 throw exception(
"JSON value is not an object");
496 std::vector<std::pair<std::string, Value>>
result;
498 for (
const auto &item :
node_->object)
499 result.emplace_back(item.first,
Value(item.second));
522 template <
typename Type>
void set(
const std::string &key, Type
value) {
552 for (
const auto &item : other.
items())
553 set(item.first, item.second);
565 std::string
dump(
int indent = -1,
char =
' ',
bool =
false)
const {
579 const auto append_string = [&
output](
const std::string &text) {
580 static constexpr char hex[] =
"0123456789abcdef";
582 for (
size_t index = 0; index < text.size();) {
583 const unsigned char first =
static_cast<unsigned char>(text[index]);
584 if (first ==
'"' || first ==
'\\') {
586 output.push_back(
static_cast<char>(first));
588 }
else if (first < 0x20) {
589 const char *escape = first ==
'\b' ?
"\\b"
590 : first ==
'\f' ?
"\\f"
591 : first ==
'\n' ?
"\\n"
592 : first ==
'\r' ?
"\\r"
593 : first ==
'\t' ?
"\\t"
599 output.push_back(hex[first >> 4]);
600 output.push_back(hex[first & 0x0f]);
603 }
else if (first < 0x80) {
604 output.push_back(
static_cast<char>(first));
607 uint32_t codepoint = 0;
609 if ((first & 0xe0) == 0xc0) {
610 codepoint = first & 0x1f;
612 }
else if ((first & 0xf0) == 0xe0) {
613 codepoint = first & 0x0f;
615 }
else if ((first & 0xf8) == 0xf0) {
616 codepoint = first & 0x07;
619 throw exception(
"invalid UTF-8 in JSON string");
620 if (index +
count > text.size())
621 throw exception(
"truncated UTF-8 in JSON string");
622 for (
size_t offset = 1; offset <
count; ++offset) {
623 const unsigned char next =
624 static_cast<unsigned char>(text[index + offset]);
625 if ((next & 0xc0) != 0x80)
626 throw exception(
"invalid UTF-8 in JSON string");
627 codepoint = (codepoint << 6) | (next & 0x3f);
629 const auto append_hex = [&
output](uint16_t unit) {
631 output.push_back(hex[(unit >> 12) & 0xf]);
632 output.push_back(hex[(unit >> 8) & 0xf]);
633 output.push_back(hex[(unit >> 4) & 0xf]);
634 output.push_back(hex[unit & 0xf]);
637 if (codepoint <= 0xffff)
638 append_hex(
static_cast<uint16_t
>(codepoint));
640 codepoint -= 0x10000;
641 append_hex(
static_cast<uint16_t
>(0xd800 + (codepoint >> 10)));
642 append_hex(
static_cast<uint16_t
>(0xdc00 + (codepoint & 0x3ff)));
649 const auto append = [&](
auto &&self,
650 const std::shared_ptr<Node> &node) ->
void {
651 switch (node->kind) {
656 output += node->boolean ?
"true" :
"false";
659 output += std::to_string(node->signed_number);
662 output += std::to_string(node->unsigned_number);
667 std::to_chars(buffer, buffer +
sizeof(buffer), node->real_number,
668 std::chars_format::general);
669 if (
result.ec != std::errc{})
670 throw exception(
"cannot format JSON number");
671 const std::string formatted(buffer,
result.ptr);
674 if (formatted.find_first_of(
".eE") == std::string::npos)
679 append_string(node->string);
683 for (
size_t index = 0; index < node->array.size(); ++index) {
686 self(self, node->array[index]);
693 for (
const auto &item : node->object) {
697 append_string(item.first);
699 self(self, item.second);
706 append(append,
node_);
728 return !(left == right);
739 throw exception(
"JSON values are not strings");
740 return left.
node_->string < right.
node_->string;
752 template <
typename Type,
size_t Count>
762 template <
typename Type,
typename Allocator>
768 explicit Value(std::shared_ptr<Node> node) :
node_(std::move(node)) {}
803 static void write_node(cv::FileStorage &storage,
const std::string &key,
817 static std::shared_ptr<Node>
clone(
const std::shared_ptr<Node> &source);
824 static bool equal_nodes(
const std::shared_ptr<Node> &left,
825 const std::shared_ptr<Node> &right);
833 Value lookup(
const char *key,
bool required)
const;
836inline std::shared_ptr<Node>
Value::clone(
const std::shared_ptr<Node> &source) {
837 auto result = std::make_shared<Node>(*source);
841 for (
const auto &item : source->array)
843 for (
const auto &item : source->object)
844 result->object.emplace(item.first,
clone(item.second));
849 const std::shared_ptr<Node> &right) {
856 if (numeric(left->kind) && numeric(right->kind)) {
859 return left->signed_number >= 0 &&
860 static_cast<uint64_t
>(left->signed_number) ==
861 right->unsigned_number;
863 return right->signed_number >= 0 &&
864 left->unsigned_number ==
865 static_cast<uint64_t
>(right->signed_number);
866 const long double left_number =
868 ?
static_cast<long double>(left->signed_number)
870 ?
static_cast<long double>(left->unsigned_number)
871 :
static_cast<long double>(left->real_number);
872 const long double right_number =
874 ?
static_cast<long double>(right->signed_number)
876 ?
static_cast<long double>(right->unsigned_number)
877 :
static_cast<long double>(right->real_number);
878 return left_number == right_number;
880 if (left->kind != right->kind)
882 switch (left->kind) {
886 return left->boolean == right->boolean;
888 return left->signed_number == right->signed_number;
890 return left->unsigned_number == right->unsigned_number;
892 return left->real_number == right->real_number;
894 return left->string == right->string;
896 if (left->array.size() != right->array.size())
898 for (
size_t i = 0; i < left->array.size(); ++i)
903 if (left->object.size() != right->object.size())
905 for (
const auto &item : left->object) {
906 auto found = right->object.find(item.first);
907 if (found == right->object.end() ||
918 throw exception(
"JSON value is not an object");
919 auto found =
node_->object.find(key);
920 if (found ==
node_->object.end()) {
922 throw exception(std::string(
"missing JSON field: ") + key);
925 return Value(found->second);
929 if (
value.is_string() &&
930 value.node_->string.find(
"__USHER_OPENCV_JSON_") != std::string::npos)
931 throw exception(
"JSON string uses a reserved OpenCV bridge token");
936 if (input.find(
"__USHER_OPENCV_JSON_") != std::string::npos)
937 throw exception(
"JSON input uses a reserved OpenCV bridge token");
939 output.reserve(input.size() + 32);
940 bool in_string =
false;
941 const auto hex_value = [](
char character) ->
int {
942 if (character >=
'0' && character <=
'9')
943 return character -
'0';
944 if (character >=
'a' && character <=
'f')
945 return character -
'a' + 10;
946 if (character >=
'A' && character <=
'F')
947 return character -
'A' + 10;
950 const auto unicode_escape = [&](
size_t offset,
951 uint32_t *codepoint) ->
size_t {
952 if (offset + 4 > input.size())
953 throw exception(
"truncated JSON Unicode escape");
955 for (
size_t digit = 0; digit < 4; ++digit) {
956 const int nibble = hex_value(input[offset + digit]);
958 throw exception(
"invalid JSON Unicode escape");
964 const auto append_utf8 = [&
output](uint32_t codepoint) {
965 if (codepoint <= 0x7f)
966 output.push_back(
static_cast<char>(codepoint));
967 else if (codepoint <= 0x7ff) {
968 output.push_back(
static_cast<char>(0xc0 | (codepoint >> 6)));
969 output.push_back(
static_cast<char>(0x80 | (codepoint & 0x3f)));
970 }
else if (codepoint <= 0xffff) {
971 output.push_back(
static_cast<char>(0xe0 | (codepoint >> 12)));
972 output.push_back(
static_cast<char>(0x80 | ((codepoint >> 6) & 0x3f)));
973 output.push_back(
static_cast<char>(0x80 | (codepoint & 0x3f)));
975 output.push_back(
static_cast<char>(0xf0 | (codepoint >> 18)));
976 output.push_back(
static_cast<char>(0x80 | ((codepoint >> 12) & 0x3f)));
977 output.push_back(
static_cast<char>(0x80 | ((codepoint >> 6) & 0x3f)));
978 output.push_back(
static_cast<char>(0x80 | (codepoint & 0x3f)));
981 for (
size_t i = 0; i < input.size();) {
982 const char c = input[i];
991 if (i + 1 >= input.size())
992 throw exception(
"truncated JSON string escape");
993 const char escaped = input[i + 1];
994 if (escaped ==
'/') {
999 if (escaped ==
'u') {
1000 uint32_t codepoint = 0;
1001 size_t next = unicode_escape(i + 2, &codepoint);
1003 if (codepoint >= 0xd800 && codepoint <= 0xdbff) {
1004 if (next + 6 > input.size() || input[next] !=
'\\' ||
1005 input[next + 1] !=
'u')
1006 throw exception(
"unpaired JSON high surrogate");
1008 next = unicode_escape(next + 2, &low);
1009 if (low < 0xdc00 || low > 0xdfff)
1010 throw exception(
"invalid JSON surrogate pair");
1011 codepoint = 0x10000 + ((codepoint - 0xd800) << 10) + (low - 0xdc00);
1012 }
else if (codepoint >= 0xdc00 && codepoint <= 0xdfff) {
1013 throw exception(
"unpaired JSON low surrogate");
1015 append_utf8(codepoint);
1019 if (std::string_view(
"\\\"nrtbf").find(escaped) ==
1020 std::string_view::npos)
1021 throw exception(
"invalid JSON string escape");
1023 output.push_back(escaped);
1037 const auto token = [&](
const char *text,
const char *replacement) {
1038 const size_t length = std::char_traits<char>::length(text);
1040 i == 0 || !(std::isalnum(
static_cast<unsigned char>(input[i - 1])) ||
1041 input[i - 1] ==
'_');
1042 const size_t end = i + length;
1044 end >= input.size() ||
1045 !(std::isalnum(
static_cast<unsigned char>(input[end])) ||
1047 if (!left || !right || input.compare(i, length, text) != 0)
1056 if (token(
"null",
"__USHER_OPENCV_JSON_NULL__") ||
1057 token(
"true",
"__USHER_OPENCV_JSON_TRUE__") ||
1058 token(
"false",
"__USHER_OPENCV_JSON_FALSE__"))
1060 if (c ==
'-' || std::isdigit(
static_cast<unsigned char>(c))) {
1062 while (end < input.size() &&
1063 (std::isdigit(
static_cast<unsigned char>(input[end])) ||
1064 input[end] ==
'-' || input[end] ==
'+' || input[end] ==
'.' ||
1065 input[end] ==
'e' || input[end] ==
'E'))
1067 const std::string number = input.substr(i, end - i);
1068 if (number.find_first_of(
".eE") == std::string::npos) {
1070 const char *prefix = !number.empty() && number[0] ==
'-'
1071 ?
"\"__USHER_OPENCV_JSON_INT__"
1072 :
"\"__USHER_OPENCV_JSON_UINT__";
1090 if (source.isMap()) {
1092 for (
auto iterator = source.begin(); iterator != source.end(); ++iterator) {
1093 const cv::FileNode
child = *iterator;
1098 if (source.isSeq()) {
1100 for (
auto iterator = source.begin(); iterator != source.end(); ++iterator)
1104 if (source.isString()) {
1105 const std::string text =
static_cast<std::string
>(source);
1106 if (text ==
"__USHER_OPENCV_JSON_NULL__")
1108 if (text ==
"__USHER_OPENCV_JSON_TRUE__")
1110 if (text ==
"__USHER_OPENCV_JSON_FALSE__")
1111 return Value(
false);
1112 const auto parse_integer = [&text](
const char *prefix,
1113 bool is_unsigned) ->
Value {
1114 const size_t prefix_length = std::char_traits<char>::length(prefix);
1115 if (text.compare(0, prefix_length, prefix) != 0 ||
1116 text.size() < prefix_length + 2 ||
1117 text.compare(text.size() - 2, 2,
"__") != 0)
1119 const std::string digits =
1120 text.substr(prefix_length, text.size() - prefix_length - 2);
1123 uint64_t number = 0;
1124 const auto result = std::from_chars(
1125 digits.data(), digits.data() + digits.size(), number);
1126 if (
result.ec != std::errc{} ||
1127 result.ptr != digits.data() + digits.size())
1128 throw exception(
"invalid unsigned JSON integer");
1129 return Value(number);
1133 std::from_chars(digits.data(), digits.data() + digits.size(), number);
1134 if (
result.ec != std::errc{} ||
1135 result.ptr != digits.data() + digits.size())
1136 throw exception(
"invalid signed JSON integer");
1137 return Value(number);
1139 if (text.compare(0, 26,
"__USHER_OPENCV_JSON_UINT__") == 0)
1140 return parse_integer(
"__USHER_OPENCV_JSON_UINT__",
true);
1141 if (text.compare(0, 25,
"__USHER_OPENCV_JSON_INT__") == 0)
1142 return parse_integer(
"__USHER_OPENCV_JSON_INT__",
false);
1146 return Value(
static_cast<int>(source));
1147 if (source.isReal())
1148 return Value(
static_cast<double>(source));
1149 throw exception(
"unsupported OpenCV JSON value type");
1154 const auto write_key = [&] {
1158 switch (
value.node_->kind) {
1161 storage <<
"__USHER_OPENCV_JSON_NULL__";
1165 storage << (
value.node_->boolean ?
"__USHER_OPENCV_JSON_TRUE__"
1166 :
"__USHER_OPENCV_JSON_FALSE__");
1171 storage << (
"__USHER_OPENCV_JSON_INT__" +
1172 std::to_string(
value.node_->signed_number) +
"__");
1176 storage << (
"__USHER_OPENCV_JSON_UINT__" +
1177 std::to_string(
value.node_->unsigned_number) +
"__");
1181 storage <<
value.node_->real_number;
1186 storage <<
value.node_->string;
1189 storage.startWriteStruct(has_key ? key :
"", cv::FileNode::MAP);
1190 for (
const auto &item :
value.node_->object)
1192 storage.endWriteStruct();
1195 storage.startWriteStruct(has_key ? key :
"", cv::FileNode::SEQ);
1196 for (
const auto &item :
value.node_->array)
1198 storage.endWriteStruct();
1204 cv::FileStorage storage(
"", cv::FileStorage::WRITE | cv::FileStorage::MEMORY |
1205 cv::FileStorage::FORMAT_JSON);
1206 if (!storage.isOpened())
1207 throw exception(
"cannot open OpenCV JSON writer");
1208 if (
value.is_object()) {
1209 for (
const auto &item :
value.node_->object)
1214 std::string
output = storage.releaseAndGetString();
1216 const auto replace_token = [&
output](
const std::string &
marker,
1217 const std::string &replacement) {
1218 const std::string quoted =
"\"" +
marker +
"\"";
1219 size_t position = 0;
1220 while ((position =
output.find(quoted, position)) != std::string::npos) {
1221 output.replace(position, quoted.size(), replacement);
1222 position += replacement.size();
1225 replace_token(
"__USHER_OPENCV_JSON_NULL__",
"null");
1226 replace_token(
"__USHER_OPENCV_JSON_TRUE__",
"true");
1227 replace_token(
"__USHER_OPENCV_JSON_FALSE__",
"false");
1228 const auto replace_integer = [&
output](
const char *prefix) {
1229 size_t position = 0;
1230 while ((position =
output.find(prefix, position)) != std::string::npos) {
1231 const size_t start = position;
1232 const size_t digits = position + std::char_traits<char>::length(prefix);
1233 const size_t end =
output.find(
"__\"", digits);
1234 if (end == std::string::npos)
1236 const size_t quoted_start =
start - 1;
1237 output.replace(quoted_start, end + 3 - quoted_start,
1238 output.substr(digits, end - digits));
1239 position = quoted_start + 1;
1242 replace_integer(
"__USHER_OPENCV_JSON_INT__");
1243 replace_integer(
"__USHER_OPENCV_JSON_UINT__");
1246 std::string compact;
1247 compact.reserve(
output.size());
1249 bool in_string =
false, escaped =
false;
1250 for (
char character :
output) {
1252 compact.push_back(character);
1255 else if (character ==
'\\')
1257 else if (character ==
'"')
1259 }
else if (character ==
'"') {
1261 compact.push_back(character);
1262 }
else if (character !=
' ' && character !=
'\t' && character !=
'\n' &&
1263 character !=
'\r') {
1264 compact.push_back(character);
Adapter errors exposed independently of OpenCV's exception type.
Value at(int index) const
Reject a negative position before any size_t cast can wrap it.
std::vector< std::pair< std::string, Value > > items() const
Snapshot object names and shared child handles in map order.
Value(Value &&) noexcept=default
Transfer node ownership; only destruction/reassignment is assumed for the source.
static Value parse(Iterator first, Iterator last)
Copy a byte range and delegate parsing to the string overload.
Value & operator=(Value &&) noexcept=default
Move/rebind ownership without recursively cloning nodes.
Value(std::nullptr_t)
Construct null from the C++ nullptr tag.
Type get() const
Convert explicitly while preserving the distinction between types.
static void write_node(cv::FileStorage &storage, const std::string &key, const Value &value, bool has_key)
Recursively emit containers and protect types unsupported by FileStorage.
static Value object(std::initializer_list< Field > fields)
Build an object by cloning each supplied member value.
Value at(const std::string &key) const
Require a member through the terminated-name interface.
std::pair< std::string, Value > Field
One named value supplied to an object factory.
Value lookup(const char *key, bool required) const
Centralize required/optional member policy without copying a found child.
static Value array(std::initializer_list< Value > values)
Build an ordered array by cloning each supplied value.
void set(const std::string &key, Type value)
Construct a supported native value before applying member insertion policy.
Value at(size_t index) const
Check both the array kind and its actual vector extent.
Value(Number value)
Store floating-point input as a double, not an integer-shaped value.
Value(Number value)
Store native integral input in its signed or unsigned 64-bit category.
Value at(const char *key) const
Require an object member instead of substituting null.
friend bool operator!=(const Value &left, const Value &right)
Negate structural equality using the same numeric policy.
Value(bool value)
Construct a boolean without confusing it with an integral payload.
void update(const Value &other)
Shallow-merge object members while deep-copying each replacement value.
void push_back(const Value &value)
Clone an element, append it in order and select array kind.
bool is_array() const
Inspect the array tag.
void set(const std::string &key, const Value &value)
Clone a member value, replace any matching key and select object kind.
bool is_number_unsigned() const
Inspect unsigned storage rather than testing a number's sign.
Value(const std::string &value)
Own a complete byte string rather than borrowing external storage.
std::string dump_sorted() const
Produce compact map-ordered output without FileStorage formatting.
Value(const Value &other)
Recursively detach a copy so later mutation does not alias the source.
bool contains(const std::string &key) const
Check a member name through the C-string lookup interface.
static Value parse(const std::string &input)
Normalize compatibility tokens, parse with OpenCV and detach the tree.
Value operator[](const std::string &key) const
Perform optional lookup through the terminated-name overload.
bool is_string() const
Inspect the string tag.
std::shared_ptr< Node > node_
Value operator[](size_t index) const
Select an array element with the same bounds policy as at().
static bool equal_nodes(const std::shared_ptr< Node > &left, const std::shared_ptr< Node > &right)
Compare active payloads and recursively compare container contents.
static Value from_node(const cv::FileNode &source)
Recursively detach a FileNode and restore compatibility sentinel types.
static void require_unreserved(const Value &value)
Reject the marker namespace in a directly supplied string value.
size_t size() const
Count container entries, not string bytes or scalar payload size.
static std::string write_opencv(const Value &value, int indent)
Write through FileStorage, restore marked scalars and optionally compact.
Value(const char *value)
Copy a terminated string; a null pointer selects an empty string.
bool is_number() const
Test all three numeric categories without treating bool as numeric.
std::string dump(int indent=-1, char=' ', bool=false) const
Serialize with OpenCV and restore native JSON scalar tokens.
Type value(const char *key, Type fallback) const
Use a default only for absence, never to hide an invalid present value.
static Value array()
Make an empty array.
static Value parse(const char *input)
Parse terminated input; use a range/stdstring for an explicit extent.
friend bool operator==(const Value &left, const Value &right)
Compare tree contents rather than shared-pointer identity.
Value operator[](const char *key) const
Look up a shared child handle, using null for a missing member.
static std::shared_ptr< Node > clone(const std::shared_ptr< Node > &source)
Clone child nodes recursively to implement ordinary value-copy semantics.
Value operator[](int index) const
Check signed array indices before conversion to an unsigned extent.
void push_back(Type value)
Construct a native value before applying array insertion policy.
static Value object()
Make an empty object.
friend bool operator<(const Value &left, const Value &right)
Order string values only, rather than inventing an ordering across JSON kinds.
Value()
Allocate a fresh null node instead of using a shared mutable singleton.
Value(std::shared_ptr< Node > node)
Construct a shared child view without invoking public deep-copy semantics.
bool is_null() const
Inspect the null tag.
std::string value(const char *key, const char *fallback) const
Provide a string-valued default rather than returning a borrowed pointer.
bool contains(const char *key) const
Check member presence without interpreting a null value as missing.
static std::string normalize_for_opencv(const std::string &input)
Adapt tokens outside strings and decode string escapes for FileStorage.
bool is_object() const
Inspect the object tag.
bool is_number_integer() const
Test signed/unsigned storage without accepting a real such as 1.0.
static bool start(uint32_t session)
Admit a nonzero session and discard correlation from the previous one.
uint8_t marker[LWIR_THERMAL_HEADER_BYTES+LWIR_THERMAL_CHUNK_CAPACITY]
struct jpeg_error_mgr error
OpenCV-backed JSON values and the internal tree supporting them.
Heap-backed tagged storage independent of a FileStorage lifetime.
std::map< std::string, std::shared_ptr< Node > > object
Kind
Active payload category; boolean is distinct from integer storage.
std::vector< std::shared_ptr< Node > > array
False primary trait; unsupported conversions must not masquerade as arrays.
False primary trait for dynamic-vector conversion detection.
struct usher_control_result result