4#ifndef GREM_CORE_FORMATS_JSON_HPP
5#define GREM_CORE_FORMATS_JSON_HPP
33#include <initializer_list>
38#include <memory_resource>
45#include <system_error>
54struct NoSerializerOverride {};
55struct NoDeserializerOverride {};
59template <
template <
typename>
typename Allocator>
62template <
template <
typename>
typename Allocator,
typename Predicate>
65template <
template <
typename>
typename Allocator>
68template <
template <
typename>
typename Allocator,
typename U>
71template <
template <
typename>
typename Allocator,
typename Predicate>
124 output.push_back(
':');
127 output.push_back(
':');
129 output.push_back(
' ');
131 output.append(what());
217template <
template <
typename>
typename Allocator>
221template <
template <
typename>
typename Allocator>
239template <
template <
typename>
typename Allocator>
257template <
template <
typename>
typename Allocator>
279 template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel>
290 std::allocator_traits<
315 [[nodiscard]]
bool empty() const noexcept;
323 template <typename P>
326 template <typename P>
329 template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel>
330 void insert(InputIterator first, Sentinel last);
332 template <typename R>
335 template <typename... Args>
338 template <typename... Args>
341 template <typename... Args>
344 template <typename... Args>
347 template <typename... Args>
350 template <typename... Args>
369 [[nodiscard]]
bool operator==(const
ObjectBase& other) const noexcept;
370 [[nodiscard]] std::partial_ordering operator<=>(const
ObjectBase& other) const noexcept;
372 template <typename Predicate>
396template <
template <
typename>
typename Allocator>
416 template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel>
428 std::allocator_traits<
442 [[nodiscard]]
bool empty() const noexcept;
466 [[nodiscard]]
bool operator==(const
ArrayBase& other) const;
467 [[nodiscard]] std::partial_ordering operator<=>(const
ArrayBase& other) const noexcept;
469 template <typename U>
472 template <typename Predicate>
480 template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel>
481 void assign(InputIterator first, Sentinel last);
483 template <typename R>
490 template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel>
493 template <typename R>
495 template <typename R>
498 template <typename... Args>
507 template <typename... Args>
537template <template <typename> typename Allocator>
600 : allocator(allocator) {}
637 : Base(std::in_place_type<Boolean>, value)
638 , allocator(allocator) {}
657 : Base(std::in_place_type<
StringBase<Allocator>>, value, allocator)
668 : Base(std::in_place_type<
StringBase<Allocator>>, value)
772 :
VariantBase(std::launder(reinterpret_cast<const char*>(value)), allocator) {
773 static_assert(
sizeof(char) ==
sizeof(char8_t));
774 static_assert(
alignof(char) ==
alignof(char8_t));
847 : Base(std::in_place_type<Number>,
static_cast<Number>(value))
848 , allocator(allocator) {}
868 : Base(std::in_place_type<
ObjectBase<Allocator>>, value, allocator)
879 : Base(std::in_place_type<
ObjectBase<Allocator>>, value)
910 : Base(std::in_place_type<
ArrayBase<Allocator>>, value, allocator)
921 : Base(std::in_place_type<
ArrayBase<Allocator>>, value)
948 : Base(
static_cast<const Base&
>(other))
951 :
match(
static_cast<Base&
>(*
this))(
956 [&](ObjectBase<Allocator>& value) ->
allocator_type {
return value.get_allocator(); },
965 : Base(std::move(
static_cast<Base&
>(other)))
968 :
match(
static_cast<Base&
>(*
this))(
973 [&](ObjectBase<Allocator>& value) ->
allocator_type {
return value.get_allocator(); },
978 :
VariantBase(std::move(other), other.get_allocator()) {}
982 if (
this == &other) {
985 if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value) {
986 if constexpr (!std::allocator_traits<allocator_type>::is_always_equal::value) {
993 static_cast<Base&
>(*this) =
static_cast<const Base&
>(other);
994 if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value) {
995 match(
static_cast<Base&
>(*
this))([&](
auto& value) ->
void {
996 if constexpr (
requires { value.get_allocator(); }) {
997 allocator = value.get_allocator();
1006 std::allocator_traits<
1007 allocator_type>::propagate_on_container_move_assignment::value ||
1008 std::allocator_traits<allocator_type>::is_always_equal::value) {
1009 if (
this == &other) {
1013 if constexpr (!std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value && !std::allocator_traits<allocator_type>::is_always_equal::value) {
1014 if (allocator != other.allocator) {
1016 [&](
const Null&) ->
void {},
1026 static_cast<Base&
>(*this) = std::move(
static_cast<Base&
>(other));
1027 if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value) {
1028 match(
static_cast<Base&
>(*
this))([&](
auto& value) ->
void {
1029 if constexpr (
requires { value.get_allocator(); }) {
1030 allocator = value.get_allocator();
1032 allocator = other.allocator;
1073 return static_cast<const Base&
>(*this) ==
static_cast<const Base&
>(other);
1084 return std::compare_partial_order_fallback(
static_cast<const Base&
>(*
this),
static_cast<const Base&
>(other));
1101template <
template <
typename>
typename Allocator>
1194 , source(other.source) {}
1202 , source(other.source) {}
1212 std::allocator_traits<
1213 allocator_type>::propagate_on_container_move_assignment::value ||
1214 std::allocator_traits<allocator_type>::is_always_equal::value) =
default;
1264 return std::move(*this).template
as<Null>();
1278 return std::move(*this).template
as<Null>();
1470 return std::move(*this).template
as<Number>();
1485 return std::move(*this).template
as<Number>();
1499 template <
typename T>
1503 if (
trunc(number) != number) {
1504 throw json::Error{
"Expected an integer.", source};
1510 return static_cast<T
>(number);
1692 if (
const auto it =
object.
find(key); it !=
object.end()) {
1712 if (
const auto it =
object.
find(key); it !=
object.end()) {
1732 const auto it =
object.find(key);
1733 if (it ==
object.end()) {
1752 const auto it =
object.find(key);
1753 if (it ==
object.end()) {
1772 const auto it =
object.
find(key);
1773 if (it ==
object.end()) {
1776 return std::move(it->second);
1792 const auto it =
object.
find(key);
1793 if (it ==
object.end()) {
1796 return std::move(it->second);
1825 return &array[
index];
1845 return &array[
index];
1867 return array[
index];
1886 return array[
index];
1905 return std::move(array[
index]);
1924 return std::move(array[
index]);
1972 return std::move(*this).getProperty(key).getNull();
1989 return std::move(*this).getProperty(key).getNull();
2037 return std::move(*this).getItem(
index).getNull();
2053 return std::move(*this).getItem(
index).getNull();
2104 return std::move(*this).getProperty(key).getBoolean();
2122 return std::move(*this).getProperty(key).getBoolean();
2170 return std::move(*this).getItem(
index).getBoolean();
2186 return std::move(*this).getItem(
index).getBoolean();
2237 return std::move(*this).getProperty(key).getString();
2255 return std::move(*this).getProperty(key).getString();
2303 return std::move(*this).getItem(
index).getString();
2319 return std::move(*this).getItem(
index).getString();
2370 return std::move(*this).getProperty(key).getNumber();
2388 return std::move(*this).getProperty(key).getNumber();
2408 template <
typename T>
2458 return std::move(*this).getItem(
index).getNumber();
2474 return std::move(*this).getItem(
index).getNumber();
2494 template <
typename T>
2547 return std::move(*this).getProperty(key).getObject();
2565 return std::move(*this).getProperty(key).getObject();
2613 return std::move(*this).getItem(
index).getObject();
2629 return std::move(*this).getItem(
index).getObject();
2680 return std::move(*this).getProperty(key).getArray();
2698 return std::move(*this).getProperty(key).getArray();
2746 return std::move(*this).getItem(
index).getArray();
2762 return std::move(*this).getItem(
index).getArray();
2804 return codePoint ==
'\t' || codePoint ==
'\n' || codePoint ==
'\v' || codePoint ==
'\f' || codePoint ==
'\r' || codePoint ==
' ' || codePoint == 0x00A0 ||
2805 codePoint == 0x1680 || (codePoint >= 0x2000 && codePoint <= 0x200A) || codePoint == 0x2028 || codePoint == 0x2029 || codePoint == 0x202F || codePoint == 0x205F ||
2806 codePoint == 0x3000 || codePoint == 0xFEFF;
2817 return codePoint ==
',' || codePoint ==
':' || codePoint ==
'[' || codePoint ==
']' || codePoint ==
'{' || codePoint ==
'}';
2830 return codePoint ==
'\n' || codePoint ==
'\r' || codePoint == 0x2028 || codePoint == 0x2029;
2862template <
template <
typename>
typename Allocator>
2875template <
typename It,
template <
typename>
typename Allocator = std::allocator>
2899 , allocator(allocator) {}
2905 , source(other.source)
2906 , currentCodePoint(other.currentCodePoint)
2907 , allocator(allocator) {}
2913 , source(other.source)
2914 , currentCodePoint(other.currentCodePoint)
2915 , allocator(allocator) {}
2926 :
Lexer(std::move(other), other.get_allocator()) {}
2930 if (
this == &other) {
2935 source = other.source;
2936 currentCodePoint = other.currentCodePoint;
2937 if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value) {
2938 allocator = other.allocator;
2945 if (
this == &other) {
2950 source = other.source;
2951 currentCodePoint = other.currentCodePoint;
2952 if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value) {
2953 allocator = other.allocator;
2982 if (hasReachedEnd()) {
2986 case '{': [[fallthrough]];
2987 case '}': [[fallthrough]];
2988 case '[': [[fallthrough]];
2989 case ']': [[fallthrough]];
2990 case ':': [[fallthrough]];
2991 case ',':
return scanPunctuator();
2992 case '\"': [[fallthrough]];
2993 case '\'':
return scanString();
2994 case '0': [[fallthrough]];
2995 case '1': [[fallthrough]];
2996 case '2': [[fallthrough]];
2997 case '3': [[fallthrough]];
2998 case '4': [[fallthrough]];
2999 case '5': [[fallthrough]];
3000 case '6': [[fallthrough]];
3001 case '7': [[fallthrough]];
3002 case '8': [[fallthrough]];
3003 case '9': [[fallthrough]];
3004 case '+': [[fallthrough]];
3005 case '-': [[fallthrough]];
3006 case '.':
return scanNumber();
3007 default:
return scanIdentifier();
3012 void skipWhitespace() {
3013 while (!hasReachedEnd()) {
3016 skipLineTerminatorSequence();
3020 }
else if (peek() ==
'/') {
3022 if (hasReachedEnd()) {
3023 throw json::Error{
"Invalid token.", source};
3025 if (peek() ==
'/') {
3027 while (!hasReachedEnd()) {
3029 skipLineTerminatorSequence();
3034 }
else if (peek() ==
'*') {
3036 while (!hasReachedEnd()) {
3038 skipLineTerminatorSequence();
3039 }
else if (peek() ==
'*') {
3041 if (!hasReachedEnd() && peek() ==
'/') {
3050 throw json::Error{
"Invalid token.", source};
3058 void skipLineTerminatorSequence() {
3059 if (peek() ==
'\r') {
3061 if (!hasReachedEnd() && peek() ==
'\n') {
3072 if (!currentCodePoint) {
3075 currentCodePoint.reset();
3079 [[nodiscard]]
bool hasReachedEnd() const noexcept {
3080 return it == end && !currentCodePoint;
3083 [[nodiscard]]
char32_t peek()
const {
3084 if (!currentCodePoint) {
3085 currentCodePoint = *it++;
3087 return *currentCodePoint;
3090 [[nodiscard]] Optional<char32_t> lookahead()
const {
3091 if (!currentCodePoint) {
3092 currentCodePoint = *it++;
3100 [[nodiscard]] Token scanPunctuator() {
3101 StringBase<Allocator>
string{1,
static_cast<char>(peek()), allocator};
3102 const SourceLocation punctuatorSource = source;
3105 case ',': type = TokenType::PUNCTUATOR_COMMA;
break;
3106 case ':': type = TokenType::PUNCTUATOR_COLON;
break;
3107 case '[': type = TokenType::PUNCTUATOR_OPEN_SQUARE_BRACKET;
break;
3108 case ']': type = TokenType::PUNCTUATOR_CLOSE_SQUARE_BRACKET;
break;
3109 case '{': type = TokenType::PUNCTUATOR_OPEN_CURLY_BRACE;
break;
3110 case '}': type = TokenType::PUNCTUATOR_CLOSE_CURLY_BRACE;
break;
3114 return {.string = std::move(
string), .source = punctuatorSource, .type = type};
3117 [[nodiscard]] Token scanString() {
3118 const char32_t quoteCharacter = peek();
3119 StringBase<Allocator>
string{allocator};
3120 const SourceLocation stringSource = source;
3122 while (!hasReachedEnd()) {
3124 throw json::Error{
"Invalid UTF-8.", source};
3126 if (peek() == quoteCharacter) {
3128 return {.string = std::move(
string), .source = stringSource, .type = TokenType::STRING};
3131 throw json::Error{
"Unexpected line terminator in string.", source};
3133 if (peek() !=
'\\') {
3135 string.append(StringView{std::launder(
reinterpret_cast<const char*
>(codePointUTF8.data())), codePointUTF8.size()});
3140 if (hasReachedEnd()) {
3141 throw json::Error{
"Empty escape sequence.", source};
3144 skipLineTerminatorSequence();
3148 case '\"':
string.push_back(
'\"');
break;
3149 case '\'':
string.push_back(
'\'');
break;
3150 case '\\':
string.push_back(
'\\');
break;
3151 case 'b':
string.push_back(
'\b');
break;
3152 case 'f':
string.push_back(
'\f');
break;
3153 case 'n':
string.push_back(
'\n');
break;
3154 case 'r':
string.push_back(
'\r');
break;
3155 case 't':
string.push_back(
'\t');
break;
3156 case 'v':
string.push_back(
'\v');
break;
3157 case '0': [[fallthrough]];
3158 case '1': [[fallthrough]];
3159 case '2': [[fallthrough]];
3160 case '3': [[fallthrough]];
3161 case '4': [[fallthrough]];
3162 case '5': [[fallthrough]];
3163 case '6': [[fallthrough]];
3164 case '7': [[fallthrough]];
3165 case '8': [[fallthrough]];
3166 case '9': scanNumericEscapeSequence(
string, 1, 3, 8, [](
char32_t codePoint)
noexcept ->
bool {
return (codePoint >=
'0' && codePoint <=
'7'); });
continue;
3169 scanNumericEscapeSequence(
string, 2, 2, 16, [](
char32_t codePoint)
noexcept ->
bool {
3170 return (codePoint >=
'0' && codePoint <=
'9') || (codePoint >=
'a' && codePoint <=
'f') || (codePoint >=
'A' && codePoint <=
'F');
3175 scanNumericEscapeSequence(
string, 4, 4, 16, [](
char32_t codePoint)
noexcept ->
bool {
3176 return (codePoint >=
'0' && codePoint <=
'9') || (codePoint >=
'a' && codePoint <=
'f') || (codePoint >=
'A' && codePoint <=
'F');
3181 scanNumericEscapeSequence(
string, 8, 8, 16, [](
char32_t codePoint)
noexcept ->
bool {
3182 return (codePoint >=
'0' && codePoint <=
'9') || (codePoint >=
'a' && codePoint <=
'f') || (codePoint >=
'A' && codePoint <=
'F');
3187 string.append(StringView{std::launder(
reinterpret_cast<const char*
>(codePointUTF8.data())), codePointUTF8.size()});
3193 throw json::Error{
"Missing end of string quote character.", source};
3196 [[nodiscard]] Token scanNumber() {
3197 StringBase<Allocator>
string{allocator};
3198 const SourceLocation numberSource = source;
3199 bool negative =
false;
3200 if (peek() ==
'+') {
3202 }
else if (peek() ==
'-') {
3203 string.push_back(
'-');
3207 if (hasReachedEnd()) {
3208 throw json::Error{
"Missing number.", source};
3210 if (peek() ==
'I') {
3211 if (scanIdentifier().type == TokenType::NUMBER_POSITIVE_INFINITY) {
3214 throw json::Error{
"Invalid number.", numberSource};
3216 if (peek() ==
'N') {
3217 if (scanIdentifier().type == TokenType::NUMBER_POSITIVE_NAN) {
3218 return {.string{allocator}, .source = numberSource, .type = (negative) ? TokenType::NUMBER_NEGATIVE_NAN :
TokenType::
NUMBER_POSITIVE_NAN};
3220 throw json::Error{
"Invalid number.", numberSource};
3222 TokenType type = TokenType::NUMBER_DECIMAL;
3223 if (!hasReachedEnd() && peek() ==
'0') {
3224 string.push_back(
'0');
3226 if (!hasReachedEnd() && (peek() ==
'b' || peek() ==
'B')) {
3227 string.push_back(
'b');
3229 type = TokenType::NUMBER_BINARY;
3230 }
else if (!hasReachedEnd() && (peek() ==
'x' || peek() ==
'X')) {
3231 string.push_back(
'x');
3233 type = TokenType::NUMBER_HEXADECIMAL;
3234 }
else if (hasReachedEnd() || peek() !=
'.') {
3235 type = TokenType::NUMBER_OCTAL;
3238 bool eNotation =
false;
3239 bool fraction =
false;
3240 while (!hasReachedEnd()) {
3241 if (peek() ==
'.') {
3242 if (lookahead() ==
'.') {
3245 if (type != TokenType::NUMBER_DECIMAL) {
3249 throw json::Error{
"Decimal point in E notation exponent.", source};
3252 throw json::Error{
"Multiple decimal points in number.", source};
3254 string.push_back(
'.');
3257 }
else if ((peek() ==
'e' || peek() ==
'E') && type != TokenType::NUMBER_HEXADECIMAL) {
3258 if (type != TokenType::NUMBER_DECIMAL) {
3262 throw json::Error{
"Multiple exponent symbols in E notation.", source};
3264 string.push_back(
'e');
3268 if (hasReachedEnd()) {
3269 throw json::Error{
"Missing exponent in E notation.", source};
3271 if (peek() >=
'0' && peek() <=
'9') {
3272 string.push_back(
static_cast<char>(peek()));
3274 }
else if ((peek() ==
'+' || peek() ==
'-')) {
3275 string.push_back(
static_cast<char>(peek()));
3277 if (!hasReachedEnd() && peek() >=
'0' && peek() <=
'9') {
3278 string.push_back(
static_cast<char>(peek()));
3281 throw json::Error{
"Missing exponent in E notation.", source};
3285 (type == TokenType::NUMBER_BINARY && (peek() ==
'0' || peek() ==
'1')) ||
3286 (type == TokenType::NUMBER_OCTAL && (peek() >=
'0' && peek() <=
'7')) ||
3287 (type == TokenType::NUMBER_DECIMAL && (peek() >=
'0' && peek() <=
'9')) ||
3288 (type == TokenType::NUMBER_HEXADECIMAL && ((peek() >=
'0' && peek() <=
'9') || (peek() >=
'a' && peek() <=
'f') || (peek() >=
'A' && peek() <=
'F')))) {
3289 string.push_back(
static_cast<char>(peek()));
3291 }
else if (peek() ==
'_') {
3297 if (!hasReachedEnd()) {
3299 throw json::Error{
"Invalid character after number.", source};
3302 return {.string = std::move(
string), .source = numberSource, .type = type};
3305 [[nodiscard]] Token scanIdentifier() {
3306 StringBase<Allocator>
string{allocator};
3307 const SourceLocation identifierSource = source;
3310 throw json::Error{
"Invalid UTF-8.", source};
3313 string.append(StringView{std::launder(
reinterpret_cast<const char*
>(codePointUTF8.data())), codePointUTF8.size()});
3316 TokenType type = TokenType::IDENTIFIER_NAME;
3317 if (
string ==
"null") {
3319 type = TokenType::IDENTIFIER_NULL;
3320 }
else if (
string ==
"false") {
3322 type = TokenType::IDENTIFIER_FALSE;
3323 }
else if (
string ==
"true") {
3325 type = TokenType::IDENTIFIER_TRUE;
3326 }
else if (
string ==
"Infinity") {
3328 type = TokenType::NUMBER_POSITIVE_INFINITY;
3329 }
else if (
string ==
"NaN") {
3331 type = TokenType::NUMBER_POSITIVE_NAN;
3333 return {.string = std::move(
string), .source = identifierSource, .type = type};
3336 void scanNumericEscapeSequence(StringBase<Allocator>& output,
size_t minDigitCount,
size_t maxDigitCount,
int radix,
bool (*isDigit)(
char32_t)
noexcept) {
3337 const SourceLocation escapeSequenceSource = source;
3338 StringBase<Allocator> digits{allocator};
3339 digits.reserve(maxDigitCount);
3340 while (digits.size() < maxDigitCount && !hasReachedEnd() && isDigit(peek())) {
3341 digits.push_back(
static_cast<char>(peek()));
3344 if (digits.size() < minDigitCount) {
3345 throw json::Error{
"Invalid escape sequence length.", escapeSequenceSource};
3347 const char*
const digitsBegin = digits.data();
3348 const char*
const digitsEnd = digitsBegin + digits.size();
3349 uint32_t codePointValue = 0;
3350 if (
const std::from_chars_result parseResult = std::from_chars(digitsBegin, digitsEnd, codePointValue, radix);
3351 parseResult.ec != std::errc{} || parseResult.ptr != digitsEnd || !
unicode::isValidCodePoint(
static_cast<char32_t>(codePointValue))) {
3352 throw json::Error{
"Invalid code point value.", escapeSequenceSource};
3355 output.append(StringView{std::launder(
reinterpret_cast<const char*
>(codePointUTF8.data())), codePointUTF8.size()});
3358 mutable unicode::UTF8Iterator<It> it;
3359 unicode::UTF8Sentinel end;
3360 SourceLocation source;
3361 mutable Optional<char32_t> currentCodePoint{};
3362 [[no_unique_address]] allocator_type allocator;
3373template <
typename It,
template <
typename>
typename Allocator = std::allocator>
3425 (void)std::move(value);
3491 template <
typename Visitor>
3499 if constexpr (
requires {
visitor.visitNull(source, value); }) {
3500 visitor.visitNull(source, value);
3507 if constexpr (
requires {
visitor.visitBoolean(source, value); }) {
3508 visitor.visitBoolean(source, value);
3515 if constexpr (
requires {
visitor.visitString(source, std::move(value)); }) {
3516 visitor.visitString(source, std::move(value));
3523 if constexpr (
requires {
visitor.visitNumber(source, value); }) {
3524 visitor.visitNumber(source, value);
3531 if constexpr (
requires {
visitor.visitObject(source, parser); }) {
3532 visitor.visitObject(source, parser);
3539 if constexpr (
requires {
visitor.visitArray(source, parser); }) {
3540 visitor.visitArray(source, parser);
3581 template <
typename Visitor>
3589 if constexpr (
requires {
visitor.visitProperty(source, std::move(key), parser); }) {
3590 visitor.visitProperty(source, std::move(key), parser);
3627 : lexer(std::
move(lexer), allocator) {}
3639 :
Parser(
Lexer<It, Allocator>{codePoints.
begin(), codePoints.
end(), source, allocator}) {}
3651 :
Parser(
unicode::UTF8View{jsonString}, source, allocator) {}
3664 :
Parser(
unicode::UTF8View{jsonString}, source, allocator) {}
3674 explicit Parser(std::istream& stream,
const SourceLocation& source = {},
const allocator_type& allocator = allocator_type())
3675 requires(
same_as<It, std::istreambuf_iterator<char>>)
3686 explicit Parser(std::streambuf* streambuf,
const SourceLocation& source = {},
const allocator_type& allocator = allocator_type())
3687 requires(
same_as<It, std::istreambuf_iterator<char>>)
3692 : lexer(other.lexer, allocator) {
3693 if (other.currentToken) {
3694 currentToken = Token{
3695 .string{other.currentToken->string, allocator},
3696 .source = other.currentToken->source,
3697 .type = other.currentToken->type,
3704 : lexer(std::move(other.lexer), allocator) {
3705 if (other.currentToken) {
3706 currentToken =
Token{
3707 .string{std::move(other.currentToken->string), allocator},
3708 .source = other.currentToken->source,
3709 .type = other.currentToken->type,
3723 :
Parser(std::move(other), other.get_allocator()) {}
3737 return lexer.get_allocator();
3765 throw json::Error{
"Multiple top-level values.", token.source};
3791 switch (
const Token& token =
peek(); token.type) {
3795 visitor.visitNull(token.source,
Null{});
3799 visitor.visitBoolean(token.source,
Boolean{false});
3803 visitor.visitBoolean(token.source,
Boolean{true});
3810 visitor.visitArray(source, *
this);
3816 visitor.visitObject(source, *
this);
3827 visitor.visitNumber(token.source,
Number{Limits<Number>::INF});
3831 visitor.visitNumber(token.source,
Number{-Limits<Number>::INF});
3835 visitor.visitNumber(token.source,
Number{Limits<Number>::QUIET_NAN});
3839 visitor.visitNumber(token.source,
Number{-Limits<Number>::QUIET_NAN});
3862 throw json::Error{
"Expected an object.", token.source};
3867 switch (
const Token& token =
peek(); token.type) {
3890 throw json::Error{
"Expected a colon.", token.source};
3893 visitor.visitProperty(source, std::move(key), *
this);
3894 if (
peek().source == source) {
3903 throw json::Error{
"Expected a comma or closing brace.", token.source};
3930 throw json::Error{
"Expected an array.", token.source};
3945 throw json::Error{
"Expected a comma or closing bracket.", token.source};
3981 template <
typename Visitor>
3983 parseFile(
static_cast<ValueVisitor&&
>(ConcreteValueVisitor<Visitor>{std::move(visitor)}));
3989 template <
typename Visitor>
3991 parseValue(
static_cast<ValueVisitor&&
>(ConcreteValueVisitor<Visitor>{std::move(visitor)}));
3997 template <
typename Visitor>
3999 parseObject(
static_cast<PropertyVisitor&&
>(ConcretePropertyVisitor<Visitor>{std::move(visitor)}));
4005 template <
typename Visitor>
4007 parseArray(
static_cast<ValueVisitor&&
>(ConcreteValueVisitor<Visitor>{std::move(visitor)}));
4062 throw json::Error{
"Multiple top-level values.", token.source};
4089 struct Visitor final : ValueVisitor {
4095 , allocator(allocator) {}
4108 return std::move(*result);
4127 switch (token.
type) {
4167 switch (token.
type) {
4190 switch (
peek().type) {
4214 switch (token.
type) {
4254 switch (token.
type) {
4282 switch (
peek().type) {
4313 switch (token.
type) {
4315 struct Visitor final : PropertyVisitor {
4322 result.emplace(std::move(key), parser.
parseValue());
4368 switch (token.
type) {
4370 struct Visitor final : ValueVisitor {
4421 if (!currentToken) {
4424 currentToken.reset();
4446 if (!currentToken) {
4447 currentToken = lexer.scan();
4449 return *currentToken;
4466 if (!currentToken) {
4467 currentToken = lexer.scan();
4469 Token result = std::move(*currentToken);
4470 currentToken.reset();
4475 [[nodiscard]]
static Number parseNumberContents(
const Token& token,
int radix) {
4476 const char* numberStringBegin = token.string.c_str();
4477 const char*
const numberStringEnd = token.string.data() + token.string.size();
4478 char* endPointer =
const_cast<char*
>(numberStringEnd);
4480 const double numberValue = std::strtod(numberStringBegin, &endPointer);
4481 if (endPointer != numberStringEnd) {
4482 throw json::Error{
"Invalid number.", token.source};
4484 return Number{numberValue};
4486 bool negative =
false;
4487 if (!token.string.empty() && token.string.front() ==
'-') {
4489 ++numberStringBegin;
4491 const unsigned long long integerNumberValue = std::strtoull(numberStringBegin, &endPointer, radix);
4492 if (endPointer != numberStringEnd) {
4493 throw json::Error{
"Invalid number.", token.source};
4495 const double numberValue =
static_cast<double>(integerNumberValue);
4496 return Number{(negative) ? -numberValue : numberValue};
4499 mutable Lexer<It, Allocator> lexer;
4500 mutable Optional<Token> currentToken{};
4506template <
template <
typename>
typename Allocator>
4518template <
template <
typename>
typename Allocator>
4529template <
typename T>
4530[[nodiscard]]
size_t getRecursiveSize(
const T& value);
4550template <
typename T>
4568template <
typename T>
4594template <
typename T,
typename SerializerOverr
ide = detail::NoSerializerOverr
ide>
4622template <
typename T,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
4623void deserialize(std::istream& stream, T& value,
const DeserializationOptions& options = {}, DeserializerOverride deserializerOverride = {},
const SourceLocation& source = {});
4640template <
template <
typename>
typename Allocator>
4664template <
template <
typename>
typename Allocator>
4669 stream.setstate(std::istream::failbit);
4689template <
template <
typename>
typename Allocator>
4713template <
template <
typename>
typename Allocator>
4718 stream.setstate(std::istream::failbit);
4738template <
template <
typename>
typename Allocator>
4762template <
template <
typename>
typename Allocator>
4767 stream.setstate(std::istream::failbit);
4787template <
template <
typename>
typename Allocator>
4811template <
template <
typename>
typename Allocator>
4816 stream.setstate(std::istream::failbit);
4846template <
typename T,
typename SerializerOverr
ide = detail::NoSerializerOverr
ide,
typename Allocator = std::allocator<
char>>
4848 SerializerOverride serializerOverride = {},
const Allocator& allocator = Allocator()) {
4849 std::basic_ostringstream<char, std::char_traits<char>, Allocator> stream{std::ios_base::out, allocator};
4851 return std::move(stream).str();
4880template <
typename T,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide,
typename Allocator = std::allocator<
char>>
4882 DeserializerOverride deserializerOverride = {},
const SourceLocation& source = {}) {
4883 std::basic_istringstream<char, std::char_traits<char>, Allocator> stream{std::move(
string)};
4914template <
typename T,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide,
typename Allocator = std::allocator<
char>>
4916 DeserializerOverride deserializerOverride = {},
const SourceLocation& source = {}) {
4927 std::ostream& stream;
4943 , options(options) {}
4979 for (
size_t i = 0; i <
options.indentation; ++i) {
4990 stream <<
options.newlineString;
5010 write((value) ?
"true" :
"false");
5021 constexpr CStringView HEXADECIMAL_DIGITS =
"0123456789ABCDEF";
5023 for (
const char ch : value) {
5024 if (ch >=
' ' && ch <=
'~' && ch !=
'\"' && ch !=
'\\') {
5029 case '\"':
write(
'\"');
break;
5030 case '\\':
write(
'\\');
break;
5031 case '\b':
write(
'b');
break;
5032 case '\f':
write(
'f');
break;
5033 case '\n':
write(
'n');
break;
5034 case '\r':
write(
'r');
break;
5035 case '\t':
write(
't');
break;
5036 case '\v':
write(
'v');
break;
5037 case '\0':
write(
'0');
break;
5040 write(HEXADECIMAL_DIGITS[(bit_cast<uint8_t>(ch) >> 4) & 0x0F]);
5041 write(HEXADECIMAL_DIGITS[(bit_cast<uint8_t>(ch) & 0x0F)]);
5058 static_assert(
sizeof(char8_t) ==
sizeof(char));
5073 if constexpr (
requires {
StringView{value}; }) {
5078 std::ostringstream stringStream{};
5092 if (std::isnan(value)) {
5093 if (std::signbit(value)) {
5098 }
else if (std::isinf(value)) {
5099 if (std::signbit(value)) {
5100 stream <<
"-Infinity";
5102 stream <<
"Infinity";
5106 const std::to_chars_result result = std::to_chars(chars, chars +
sizeof(chars) - 1, value);
5109 stream << static_cast<const char*>(chars);
5137 if (propertyCountHint <=
options.prettyPrintMaxSingleLineObjectPropertyCount) {
5139 callback(WriteSmallPrettyObjectProperty{*
this, empty});
5145 callback(WriteLargePrettyObjectProperty{*
this, empty});
5153 bool successor =
false;
5154 callback(WriteCompactObjectProperty{*
this, successor});
5195 template <
typename SerializerOverr
ide = detail::NoSerializerOverr
ide>
5196 void writeObject(
const auto& value, SerializerOverride serializerOverride = {}) {
5197 const size_t propertyCountHint = detail::getRecursiveSize(value) - 1;
5198 writeCustomObject(propertyCountHint, [&](
auto writeProperty) ->
void {
5199 for (
const auto& element : value) {
5200 writeProperty(element.first, element.second, [&](
const auto& v) ->
void { serialize(v, serializerOverride); });
5228 if (itemCountHint <=
options.prettyPrintMaxSingleLineArrayItemCount) {
5229 bool successor =
false;
5230 callback(WriteSmallPrettyArrayItem{*
this, successor});
5233 callback(WriteLargePrettyArrayItem{*
this, empty});
5241 bool successor =
false;
5242 callback(WriteCompactArrayItem{*
this, successor});
5282 template <
typename SerializerOverr
ide = detail::NoSerializerOverr
ide>
5283 void writeArray(
const auto& value, SerializerOverride serializerOverride = {}) {
5284 const size_t itemCountHint = detail::getRecursiveSize(value) - 1;
5285 writeCustomArray(itemCountHint, [&](
auto writeItem) ->
void {
5286 if constexpr (
requires {
5290 for (
const auto& element : value) {
5291 writeItem(element, [&](
const auto& v) ->
void { serialize(v, serializerOverride); });
5294 const size_t n = std::size(value);
5295 for (
size_t i = 0; i < n; ++i) {
5296 const auto& element = value[i];
5297 writeItem(element, [&](
const auto& v) ->
void {
serialize(v, serializerOverride); });
5320 template <
typename SerializerOverr
ide = detail::NoSerializerOverr
ide>
5321 void writeOptional(
const auto& value, SerializerOverride serializerOverride = {}) {
5345 template <
typename Aggregate,
typename SerializerOverr
ide = detail::NoSerializerOverr
ide>
5347 const size_t propertyCountHint = detail::getRecursiveSize(value) - 1;
5348 writeCustomObject(propertyCountHint, [&](
auto writeProperty) ->
void {
5350 writeProperty(name, field, [&](
const auto& f) ->
void {
serialize(f, serializerOverride); });
5370 template <
typename Aggregate,
typename SerializerOverr
ide = detail::NoSerializerOverr
ide>
5372 const size_t itemCountHint = detail::getRecursiveSize(value) - 1;
5373 writeCustomArray(itemCountHint, [&](
auto writeItem) ->
void {
5375 writeItem(field, [&](
const auto& f) ->
void {
serialize(f, serializerOverride); });
5395 template <
typename T,
typename SerializerOverr
ide = detail::NoSerializerOverr
ide>
5396 void serialize(
const T& value, SerializerOverride serializerOverride = {});
5399 struct WriteSmallPrettyObjectProperty {
5403 void operator()(
const auto& key,
const auto& value,
auto writeValue) {
5410 writer.writeString(key);
5415 void operator()(
const auto& key,
const auto& value) {
5416 (*this)(key, value, [&](
const auto& value) ->
void { writer.serialize(value); });
5420 struct WriteLargePrettyObjectProperty {
5424 void operator()(
const auto& key,
const auto& value,
auto writeValue) {
5426 writer.writeNewline();
5427 writer.options.indentation += writer.options.relativeIndentation;
5428 writer.writeIndentation();
5432 writer.writeNewline();
5433 writer.writeIndentation();
5435 writer.writeString(key);
5440 void operator()(
const auto& key,
const auto& value) {
5441 (*this)(key, value, [&](
const auto& value) ->
void { writer.serialize(value); });
5445 struct WriteCompactObjectProperty {
5449 void operator()(
const auto& key,
const auto& value,
auto writeValue) {
5454 writer.writeString(key);
5459 void operator()(
const auto& key,
const auto& value) {
5460 (*this)(key, value, [&](
const auto& value) ->
void { writer.serialize(value); });
5464 struct WriteSmallPrettyArrayItem {
5468 void operator()(
const auto& value,
auto writeValue) {
5476 void operator()(
const auto& value) {
5477 (*this)(value, [&](
const auto& value) ->
void { writer.serialize(value); });
5481 struct WriteLargePrettyArrayItem {
5485 void operator()(
const auto& value,
auto writeValue) {
5487 writer.writeNewline();
5488 writer.options.indentation += writer.options.relativeIndentation;
5489 writer.writeIndentation();
5493 writer.writeNewline();
5494 writer.writeIndentation();
5499 void operator()(
const auto& value) {
5500 (*this)(value, [&](
const auto& value) ->
void { writer.serialize(value); });
5504 struct WriteCompactArrayItem {
5508 void operator()(
const auto& value,
auto writeValue) {
5516 void operator()(
const auto& value) {
5517 (*this)(value, [&](
const auto& value) ->
void { writer.serialize(value); });
5527 using It = std::istreambuf_iterator<char>;
5549 : parser(stream, source)
5550 , options(options) {}
5587 return parser.peekIsNull();
5610 value = parser.parseBoolean();
5649 return parser.peekIsBoolean();
5689 value = parser.parseString();
5712 convertString(value, std::move(
string), source);
5751 return parser.peekIsString();
5791 value = parser.parseNumber();
5811 template <
typename T>
5816 if (
trunc(number) != number) {
5817 throw json::Error{
"Expected an integer.", source};
5823 value =
static_cast<T
>(number);
5862 return parser.peekIsNumber();
5881 template <
typename T>
5931 throw json::Error{
"Expected an object.", token.source};
5939 propertyKey = std::move(token.string);
5941 throw json::Error{
"Expected a string or a name identifier.", token.source};
5944 throw json::Error{
"Expected a colon.", token.source};
5947 readProperty(propertySource, propertyKey);
5948 if (parser.peek().source == propertySource) {
5951 const Token token = parser.eat();
5961 throw json::Error{
"Expected a comma or closing brace.", token.source};
5988 value = parser.parseObject();
6023 template <
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
6027 throw json::Error{
"Expected an object.", token.source};
6030 if (parser.
peek().
type == TokenType::PUNCTUATOR_CLOSE_CURLY_BRACE) {
6034 std::remove_cvref_t<
decltype(std::begin(value)->first)> propertyKey{};
6035 std::remove_cvref_t<
decltype(std::begin(value)->second)> propertyValue{};
6036 if (Token token = parser.
eat(); token.
type == TokenType::STRING || token.type == TokenType::IDENTIFIER_NAME) {
6037 convertString(propertyKey, std::move(token.string), token.source);
6039 throw json::Error{
"Expected a string or a name identifier.", token.source};
6041 if (
const Token token = parser.
eat(); token.
type != TokenType::PUNCTUATOR_COLON) {
6042 throw json::Error{
"Expected a colon.", token.source};
6045 value.emplace(std::move(propertyKey), std::move(propertyValue));
6046 const Token token = parser.
eat();
6047 if (token.type == TokenType::PUNCTUATOR_CLOSE_CURLY_BRACE) {
6050 if (token.type == TokenType::PUNCTUATOR_COMMA) {
6051 if (parser.
peek().
type == TokenType::PUNCTUATOR_CLOSE_CURLY_BRACE) {
6056 throw json::Error{
"Expected a comma or closing brace.", token.source};
6108 template <
typename Object>
6130 return parser.peekIsObject();
6174 throw json::Error{
"Expected an array.", token.source};
6181 readItem(itemSource);
6182 if (parser.peek().source == itemSource) {
6185 const Token token = parser.eat();
6195 throw json::Error{
"Expected a comma or closing bracket.", token.source};
6222 value = parser.parseArray();
6255 template <
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
6259 throw json::Error{
"Expected an array.", token.source};
6262 if (parser.
peek().
type == TokenType::PUNCTUATOR_CLOSE_SQUARE_BRACKET) {
6266 std::remove_cvref_t<
decltype(*std::begin(value))> item{};
6268 value.push_back(std::move(item));
6269 const Token token = parser.
eat();
6270 if (token.type == TokenType::PUNCTUATOR_CLOSE_SQUARE_BRACKET) {
6273 if (token.type == TokenType::PUNCTUATOR_COMMA) {
6274 if (parser.
peek().
type == TokenType::PUNCTUATOR_CLOSE_SQUARE_BRACKET) {
6279 throw json::Error{
"Expected a comma or closing bracket.", token.source};
6329 template <
typename Array>
6351 return parser.peekIsArray();
6390 value =
static_cast<Variant&&
>(parser.parseValue());
6413 value = parser.parseValue();
6465 template <
typename T,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
6472 std::remove_cvref_t<
decltype(*value)> result{};
6474 value = std::move(result);
6504 template <
typename Aggregate,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
6508 if (fieldName == name) {
6548 template <
typename Aggregate,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
6550 return readCustomObject([&](
const SourceLocation&,
const String& key) ->
void { readAggregateField(key, value, deserializerOverride); });
6579 template <
typename Aggregate,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
6582 readAggregateObject(result, deserializerOverride);
6614 template <
typename Aggregate,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
6618 throw json::Error{
"Expected an array.", token.source};
6620 if (parser.
peek().
type == TokenType::PUNCTUATOR_CLOSE_SQUARE_BRACKET) {
6624 const SourceLocation source = parser.
peek().
source;
6629 const Token nextToken = parser.
peek();
6630 if (nextToken.type == TokenType::PUNCTUATOR_CLOSE_SQUARE_BRACKET) {
6633 if (nextToken.type == TokenType::PUNCTUATOR_COMMA) {
6635 if (parser.
peek().
type == TokenType::PUNCTUATOR_CLOSE_SQUARE_BRACKET) {
6639 throw json::Error{
"Expected a comma or closing bracket.", nextToken.source};
6642 const Token token = parser.
eat();
6643 if (token.type != TokenType::PUNCTUATOR_CLOSE_SQUARE_BRACKET) {
6674 template <
typename Aggregate,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
6677 readAggregateArray(result, deserializerOverride);
6696 template <
typename T,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
6697 void deserialize(T& value, DeserializerOverride deserializerOverride = {});
6716 template <
typename T,
typename DeserializerOverr
ide = detail::NoDeserializerOverr
ide>
6717 [[nodiscard]] T
deserialize(DeserializerOverride deserializerOverride = {}) {
6719 deserialize(result, deserializerOverride);
6724 static void convertString(
auto& value, String&&
string,
const SourceLocation& source) {
6725 if constexpr (
requires { value = std::move(
string); }) {
6726 value = std::move(
string);
6727 }
else if constexpr (
requires { value =
String{}; }) {
6728 value =
String{std::move(
string)};
6729 }
else if constexpr (
requires { value =
UTF8String{}; }) {
6730 value =
UTF8String{
string.begin(),
string.end()};
6737template <
typename T,
typename SerializerOverr
ide>
6742template <
typename T,
typename DeserializerOverr
ide>
6751template <
typename Base,
typename Callback>
6752struct VisitNull : Base {
6753 [[no_unique_address]] Callback callback;
6755 VisitNull(Callback callback)
6756 : callback(std::move(callback)) {}
6758 VisitNull(Base base, Callback callback)
6759 : Base(std::
move(base))
6760 , callback(std::
move(callback)) {}
6762 void visitNull(
const SourceLocation& source, Null value) {
6763 callback(source, value);
6766 template <
typename NewBase>
6767 [[nodiscard]]
auto operator|(NewBase other) && {
6768 return VisitNull<NewBase, Callback>{std::move(other), std::move(callback)};
6772template <
typename Base,
typename Callback>
6773struct VisitBoolean : Base {
6774 [[no_unique_address]] Callback callback;
6776 VisitBoolean(Callback callback)
6777 : callback(std::
move(callback)) {}
6779 VisitBoolean(Base base, Callback callback)
6780 : Base(std::
move(base))
6781 , callback(std::
move(callback)) {}
6783 void visitBoolean(
const SourceLocation& source, Boolean value) {
6784 callback(source, value);
6787 template <
typename NewBase>
6788 [[nodiscard]]
auto operator|(NewBase other) && {
6789 return VisitBoolean<NewBase, Callback>{std::move(other), std::move(callback)};
6793template <
typename Base,
typename Callback>
6794struct VisitString : Base {
6795 [[no_unique_address]] Callback callback;
6797 VisitString(Callback callback)
6798 : callback(std::
move(callback)) {}
6800 VisitString(Base base, Callback callback)
6801 : Base(std::
move(base))
6802 , callback(std::
move(callback)) {}
6804 void visitString(
const SourceLocation& source, String&& value) {
6805 callback(source, std::move(value));
6808 template <
typename NewBase>
6809 [[nodiscard]]
auto operator|(NewBase other) && {
6810 return VisitString<NewBase, Callback>{std::move(other), std::move(callback)};
6814template <
typename Base,
typename Callback>
6815struct VisitNumber : Base {
6816 [[no_unique_address]] Callback callback;
6818 VisitNumber(Callback callback)
6819 : callback(std::
move(callback)) {}
6821 VisitNumber(Base base, Callback callback)
6822 : Base(std::
move(base))
6823 , callback(std::
move(callback)) {}
6825 void visitNumber(
const SourceLocation& source, Number value) {
6826 callback(source, value);
6829 template <
typename NewBase>
6830 [[nodiscard]]
auto operator|(NewBase other) && {
6831 return VisitNumber<NewBase, Callback>{std::move(other), std::move(callback)};
6835template <
typename Base,
typename Callback>
6836struct VisitObject : Base {
6837 [[no_unique_address]] Callback callback;
6839 VisitObject(Callback callback)
6840 : callback(std::
move(callback)) {}
6842 VisitObject(Base base, Callback callback)
6843 : Base(std::
move(base))
6844 , callback(std::
move(callback)) {}
6846 void visitObject(
const SourceLocation& source,
auto& parser) {
6847 callback(source, parser);
6850 template <
typename NewBase>
6851 [[nodiscard]]
auto operator|(NewBase other) && {
6852 return VisitObject<NewBase, Callback>{std::move(other), std::move(callback)};
6856template <
typename Base,
typename Callback>
6857struct VisitArray : Base {
6858 [[no_unique_address]] Callback callback;
6860 VisitArray(Callback callback)
6861 : callback(std::
move(callback)) {}
6863 VisitArray(Base base, Callback callback)
6864 : Base(std::
move(base))
6865 , callback(std::
move(callback)) {}
6867 void visitArray(
const SourceLocation& source,
auto& parser) {
6868 callback(source, parser);
6871 template <
typename NewBase>
6872 [[nodiscard]]
auto operator|(NewBase other) && {
6873 return VisitArray<NewBase, Callback>{std::move(other), std::move(callback)};
6877template <
typename Base,
typename Callback>
6878struct VisitProperty : Base {
6879 [[no_unique_address]] Callback callback;
6881 VisitProperty(Callback callback)
6882 : callback(std::
move(callback)) {}
6884 VisitProperty(Base base, Callback callback)
6885 : Base(std::
move(base))
6886 , callback(std::
move(callback)) {}
6888 template <
template <
typename>
typename Allocator>
6889 void visitProperty(
const SourceLocation& source, StringBase<Allocator>&& key,
auto& parser) {
6890 callback(source, std::move(key), parser);
6893 template <
typename NewBase>
6894 [[nodiscard]]
auto operator|(NewBase other) && {
6895 return VisitProperty<NewBase, Callback>{std::move(other), std::move(callback)};
6923template <
typename Callback>
6924[[nodiscard]]
inline auto onNull(Callback callback) {
6925 return detail::VisitNull<detail::NoVisitor, Callback>{std::move(callback)};
6950template <
typename Callback>
6952 return detail::VisitBoolean<detail::NoVisitor, Callback>{std::move(callback)};
6977template <
typename Callback>
6979 return detail::VisitString<detail::NoVisitor, Callback>{std::move(callback)};
7004template <
typename Callback>
7006 return detail::VisitNumber<detail::NoVisitor, Callback>{std::move(callback)};
7031template <
typename Callback>
7033 return detail::VisitObject<detail::NoVisitor, Callback>{std::move(callback)};
7058template <
typename Callback>
7059[[nodiscard]]
inline auto onArray(Callback callback) {
7060 return detail::VisitArray<detail::NoVisitor, Callback>{std::move(callback)};
7078template <
typename Callback>
7080 return detail::VisitProperty<detail::NoVisitor, Callback>{std::move(callback)};
7085template <
template <
typename>
typename Allocator>
7088template <
template <
typename>
typename Allocator>
7089consteval void derivedFromObjectBaseTest(
const ObjectBase<Allocator>&);
7091template <
template <
typename>
typename Allocator>
7092consteval void derivedFromArrayBaseTest(
const ArrayBase<Allocator>&);
7094template <
template <
typename>
typename Allocator>
7095consteval void derivedFromVariantBaseTest(
const VariantBase<Allocator>&);
7097template <
typename T>
7098concept derived_from_string_base =
requires(
const T t) { detail::derivedFromStringBaseTest(t); };
7100template <
typename T>
7101concept derived_from_object_base =
requires(
const T t) { detail::derivedFromObjectBaseTest(t); };
7103template <
typename T>
7104concept derived_from_array_base =
requires(
const T t) { detail::derivedFromArrayBaseTest(t); };
7106template <
typename T>
7107concept derived_from_raw_value_base =
requires(
const T t) { detail::derivedFromVariantBaseTest(t); };
7109template <
typename T>
7112 requires(
const T value) {
7113 static_cast<bool>(value);
7114 static_cast<bool>(!value);
7118template <
typename T>
7119concept serializable_as_string =
7120 derived_from_string_base<T> ||
7121 requires(
const T input,
T output) {
7125 requires(
const T input,
T output) {
7130template <
typename T>
7131concept serializable_as_string_view =
7135template <
typename T>
7136concept serializable_as_duration =
7137 requires(
const T input,
T output,
const DurationBase<Number, Ratio<1, 1>> seconds) {
7138 duration_cast<DurationBase<Number, Ratio<1, 1>>>(input);
7139 output = duration_cast<T>(seconds);
7142template <
typename T>
7143concept serializable_as_array =
7144 requires(Reader& reader, Writer& writer,
const T input,
T output,
const size_t i) {
7146 writer.serialize(input[i]);
7147 reader.deserialize(output[i]);
7150template <
typename T>
7151concept serializable_as_map =
7152 derived_from_object_base<T> ||
7153 requires(Reader& reader, Writer& writer,
const T input,
T output) {
7154 writer.writeString(std::begin(input)->first);
7155 writer.serialize(std::begin(input)->second);
7158 std::remove_cvref_t<
decltype(std::begin(output)->first)>{};
7159 std::remove_cvref_t<
decltype(std::begin(output)->second)>{};
7160 reader.readString(std::begin(output)->first);
7161 reader.deserialize(std::begin(output)->second);
7162 output.emplace(std::remove_cvref_t<
decltype(std::begin(output)->first)>{}, std::remove_cvref_t<
decltype(std::begin(output)->second)>{});
7165template <
typename T>
7166concept serializable_as_list =
7167 derived_from_array_base<T> ||
7168 requires(Reader& reader, Writer& writer,
const T input,
T output) {
7169 writer.serialize(*std::begin(input));
7172 std::remove_cvref_t<
decltype(*std::begin(output))>{};
7173 reader.deserialize(*std::begin(output));
7174 output.push_back(std::remove_cvref_t<
decltype(*std::begin(output))>{});
7177template <
typename T>
7178concept serializable_as_optional =
7180 requires(Reader& reader, Writer& writer,
const T input,
T output, std::remove_cvref_t<
decltype(*output)> result) {
7181 static_cast<bool>(input);
7182 writer.serialize(*input);
7185 std::remove_cvref_t<
decltype(*output)>{};
7186 reader.deserialize(result);
7187 output = std::move(result);
7190template <
typename T>
7191inline size_t getRecursiveSize(
const T& value) {
7192 if constexpr (derived_from_raw_value_base<T>) {
7193 return match(value)([&](
const auto& v) ->
size_t {
return getRecursiveSize(v); });
7194 }
else if constexpr (serializable_as_string<T> || serializable_as_string_view<T> || serializable_as_duration<T>) {
7196 }
else if constexpr (serializable_as_map<T>) {
7197 if constexpr (nullable<T>) {
7203 for (
const auto& kv : value) {
7204 result += getRecursiveSize(kv.second);
7207 }
else if constexpr (serializable_as_list<T> || serializable_as_array<T>) {
7208 if constexpr (nullable<T>) {
7214 if constexpr (
requires {
7218 for (
const auto& v : value) {
7219 result += getRecursiveSize(v);
7222 const size_t n = std::size(value);
7223 for (
size_t i = 0; i < n; ++i) {
7224 const auto& v = value[i];
7225 result += getRecursiveSize(v);
7229 }
else if constexpr (serializable_as_optional<T>) {
7231 }
else if constexpr (aggregate<T>) {
7232 if constexpr (nullable<T>) {
7238 meta::forEachField(value, [&](
const auto& v) ->
void { result += getRecursiveSize(v); });
7249struct Serializer<
Null> {
7250 void serializeTo(Writer& writer, Null) {
7256struct Serializer<std::nullptr_t> {
7257 void serializeTo(Writer& writer, std::nullptr_t) {
7264 void serializeTo(Writer& writer, Boolean value) {
7265 writer.writeBoolean(value);
7269template <strict_arithmetic Arithmetic>
7270struct Serializer<Arithmetic> {
7271 void serializeTo(Writer& writer, Arithmetic value) {
7272 writer.writeNumber(
static_cast<Number>(value));
7277struct Serializer<char> {
7278 void serializeTo(Writer& writer,
char value) {
7279 writer.writeString(StringView{&value, 1});
7284struct Serializer<char8_t> {
7285 void serializeTo(Writer& writer,
char8_t value) {
7286 writer.writeString(UTF8StringView{&value, 1});
7290template <
template <
typename>
typename Allocator>
7292 void serializeTo(Writer& writer,
const StringBase<Allocator>& value) {
7293 writer.writeString(value);
7297template <
template <
typename>
typename Allocator>
7298struct Serializer<ObjectBase<Allocator>> {
7299 void serializeTo(Writer& writer,
const ObjectBase<Allocator>& value) {
7300 writer.writeObject(value);
7304template <
template <
typename>
typename Allocator>
7305struct Serializer<ArrayBase<Allocator>> {
7306 void serializeTo(Writer& writer,
const ArrayBase<Allocator>& value) {
7307 writer.writeArray(value);
7311template <
template <
typename>
typename Allocator>
7312struct Serializer<VariantBase<Allocator>> {
7313 void serializeTo(Writer& writer,
const VariantBase<Allocator>& value) {
7314 match(value)([&](
const auto& v) ->
void { writer.serialize(v); });
7318template <
template <
typename>
typename Allocator>
7319struct Serializer<ValueBase<Allocator>> : Serializer<VariantBase<Allocator>> {};
7322struct Deserializer<
Null> {
7323 void deserializeFrom(Reader& reader, Null&) {
7329struct Deserializer<std::nullptr_t> {
7330 void deserializeFrom(Reader& reader, std::nullptr_t&) {
7337 void deserializeFrom(Reader& reader, Boolean& value) {
7338 reader.readBoolean(value);
7342template <strict_arithmetic Arithmetic>
7343struct Deserializer<Arithmetic> {
7344 void deserializeFrom(Reader& reader, Arithmetic& value) {
7345 reader.readNumber(value);
7350struct Deserializer<char> {
7351 void deserializeFrom(Reader& reader,
char& value) {
7353 const SourceLocation source = reader.readString(
string);
7354 if (
string.size() != 1) {
7355 throw json::Error{
"Expected only a single character.", source};
7357 value =
string.front();
7362struct Deserializer<char8_t> {
7363 void deserializeFrom(Reader& reader,
char8_t& value) {
7365 const SourceLocation source = reader.readString(
string);
7366 if (
string.size() !=
sizeof(
char8_t)) {
7367 throw json::Error{
"Expected only a single UTF-8 code unit.", source};
7369 memcpy(&value,
string.data(),
sizeof(
char8_t));
7374struct Deserializer<
String> {
7375 void deserializeFrom(Reader& reader, String& value) {
7376 reader.readString(value);
7381struct Deserializer<
Object> {
7382 void deserializeFrom(Reader& reader, Object& value) {
7383 reader.readObject(value);
7388struct Deserializer<
Array> {
7389 void deserializeFrom(Reader& reader, Array& value) {
7390 reader.readArray(value);
7396 void deserializeFrom(Reader& reader, Variant& value) {
7397 reader.readValue(value);
7402struct Deserializer<
Value> {
7403 void deserializeFrom(Reader& reader, Value& value) {
7404 reader.readValue(value);
7409template <
typename T,
typename SerializerOverr
ide>
7411 using X = std::remove_cvref_t<T>;
7412 if constexpr (
requires { serializerOverride(*
this, value); }) {
7413 serializerOverride(*
this, value);
7417 if constexpr (detail::nullable<X>) {
7423 if constexpr (detail::serializable_as_string<X> || detail::serializable_as_string_view<X>) {
7425 }
else if constexpr (detail::serializable_as_duration<X>) {
7427 }
else if constexpr (detail::serializable_as_map<X>) {
7429 }
else if constexpr (detail::serializable_as_list<X>) {
7431 }
else if constexpr (detail::serializable_as_array<X>) {
7432 using Element = std::remove_cvref_t<
decltype(value[
size_t{0}])>;
7434 requires(
const T t,
const size_t i) {
7437 } && !detail::serializable_as_array<Element> &&
requires(Element e) { X{e}; }) {
7438 const Element& element = value[
size_t{0}];
7439 if (
all(
equal(value, X{element}))) {
7445 }
else if constexpr (detail::serializable_as_optional<X>) {
7452 if (!found && value == type) {
7463template <
typename T,
typename DeserializerOverr
ide>
7465 using X = std::remove_cvref_t<T>;
7466 if constexpr (
requires { deserializerOverride(*
this, value); }) {
7467 deserializerOverride(*
this, value);
7470 }
else if constexpr (detail::serializable_as_string<X>) {
7472 }
else if constexpr (detail::serializable_as_duration<X>) {
7476 }
else if constexpr (detail::serializable_as_map<X>) {
7478 }
else if constexpr (detail::serializable_as_list<X>) {
7480 }
else if constexpr (detail::serializable_as_array<X>) {
7482 const size_t size = std::size(value);
7483 using Element = std::remove_cvref_t<
decltype(value[index])>;
7485 requires(
const T t,
const size_t i) {
7488 } && !detail::serializable_as_array<Element> &&
requires(Element e) { X{e}; }) {
7490 value = X{
deserialize<std::remove_cvref_t<
decltype(value[index])>>(deserializerOverride)};
7495 if (index >= size) {
7501 if (index != size) {
7504 }
else if constexpr (detail::serializable_as_optional<X>) {
7513 if (!result &&
string == name) {
7518 throw json::Error{
"Invalid type \"" +
string +
"\".", source};
7526template <
template <
typename>
typename Allocator>
7530template <
template <
typename>
typename Allocator>
7532 : membersSortedByName(allocator) {}
7534template <
template <
typename>
typename Allocator>
7537template <
template <
typename>
typename Allocator>
7539 : membersSortedByName(other.membersSortedByName, allocator) {}
7541template <
template <
typename>
typename Allocator>
7545template <
template <
typename>
typename Allocator>
7547 : membersSortedByName(std::move(other.membersSortedByName), allocator) {}
7549template <
template <
typename>
typename Allocator>
7551 :
ObjectBase(std::move(other), other.get_allocator()) {}
7553template <
template <
typename>
typename Allocator>
7556template <
template <
typename>
typename Allocator>
7558 std::allocator_traits<
7559 allocator_type>::propagate_on_container_move_assignment::value ||
7560 std::allocator_traits<allocator_type>::is_always_equal::value) =
default;
7562template <
template <
typename>
typename Allocator>
7563template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel>
7565 : membersSortedByName(first, last, allocator) {
7566 sort(membersSortedByName, Compare{});
7568 membersSortedByName.erase(newEnd, membersSortedByName.end());
7571template <
template <
typename>
typename Allocator>
7575template <
template <
typename>
typename Allocator>
7577 membersSortedByName = ilist;
7578 sort(membersSortedByName, Compare{});
7580 membersSortedByName.
erase(newEnd, membersSortedByName.end());
7584template <
template <
typename>
typename Allocator>
7586 return membersSortedByName.get_allocator();
7589template <
template <
typename>
typename Allocator>
7591 if (
const auto it =
find(key); it !=
end()) {
7594 throw std::out_of_range{
"JSON object does not contain key \"" +
grem::String{key} +
"\"."};
7597template <
template <
typename>
typename Allocator>
7599 if (
const auto it =
find(key); it !=
end()) {
7602 throw std::out_of_range{
"JSON object does not contain key \"" +
grem::String{key} +
"\"."};
7605template <
template <
typename>
typename Allocator>
7610template <
template <
typename>
typename Allocator>
7615template <
template <
typename>
typename Allocator>
7617 return membersSortedByName.begin();
7620template <
template <
typename>
typename Allocator>
7622 return membersSortedByName.begin();
7625template <
template <
typename>
typename Allocator>
7627 return membersSortedByName.cbegin();
7630template <
template <
typename>
typename Allocator>
7632 return membersSortedByName.end();
7635template <
template <
typename>
typename Allocator>
7637 return membersSortedByName.end();
7640template <
template <
typename>
typename Allocator>
7642 return membersSortedByName.cend();
7645template <
template <
typename>
typename Allocator>
7647 return membersSortedByName.rbegin();
7650template <
template <
typename>
typename Allocator>
7652 return membersSortedByName.rbegin();
7655template <
template <
typename>
typename Allocator>
7657 return membersSortedByName.crbegin();
7660template <
template <
typename>
typename Allocator>
7662 return membersSortedByName.rend();
7665template <
template <
typename>
typename Allocator>
7667 return membersSortedByName.rend();
7670template <
template <
typename>
typename Allocator>
7672 return membersSortedByName.crend();
7675template <
template <
typename>
typename Allocator>
7677 return membersSortedByName.empty();
7680template <
template <
typename>
typename Allocator>
7682 return membersSortedByName.size();
7685template <
template <
typename>
typename Allocator>
7687 return membersSortedByName.max_size();
7690template <
template <
typename>
typename Allocator>
7692 return membersSortedByName.capacity();
7695template <
template <
typename>
typename Allocator>
7697 membersSortedByName.clear();
7700template <
template <
typename>
typename Allocator>
7702 membersSortedByName.reserve(newCapacity);
7705template <
template <
typename>
typename Allocator>
7706template <
typename P>
7708 return emplace(std::forward<P>(value));
7711template <
template <
typename>
typename Allocator>
7712template <
typename P>
7717template <
template <
typename>
typename Allocator>
7718template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel>
7720 const size_t offset = membersSortedByName.size();
7722 while (first != last) {
7723 membersSortedByName.push_back(*first++);
7725 const auto newMembersBegin = membersSortedByName.begin() +
static_cast<ptrdiff_t
>(offset);
7726 sort(
Subrange{newMembersBegin, membersSortedByName.end()}, Compare{});
7729 membersSortedByName.resize(offset);
7734template <
template <
typename>
typename Allocator>
7736 insert(ilist.begin(), ilist.end());
7739template <
template <
typename>
typename Allocator>
7740template <
typename R>
7742 insert(std::begin(r), std::end(r));
7745template <
template <
typename>
typename Allocator>
7746template <
typename... Args>
7748 value_type value{std::forward<Args>(args)...};
7750 if (first != last) {
7751 return {first,
false};
7753 const auto it = membersSortedByName.insert(last, std::move(value));
7757template <
template <
typename>
typename Allocator>
7758template <
typename... Args>
7760 return emplace(std::forward<Args>(args)...).first;
7763template <
template <
typename>
typename Allocator>
7764template <
typename... Args>
7767 if (first != last) {
7768 return {first,
false};
7770 const auto it = membersSortedByName.emplace(last, std::piecewise_construct, std::forward_as_tuple(k), std::forward_as_tuple(std::forward<Args>(args)...));
7774template <
template <
typename>
typename Allocator>
7775template <
typename... Args>
7778 if (first != last) {
7779 return {first,
false};
7781 const auto it = membersSortedByName.emplace(last, std::piecewise_construct, std::forward_as_tuple(std::move(k)), std::forward_as_tuple(std::forward<Args>(args)...));
7785template <
template <
typename>
typename Allocator>
7786template <
typename... Args>
7788 return try_emplace(k, std::forward<Args>(args)...);
7791template <
template <
typename>
typename Allocator>
7792template <
typename... Args>
7794 return try_emplace(std::move(k), std::forward<Args>(args)...);
7797template <
template <
typename>
typename Allocator>
7799 return membersSortedByName.erase(pos);
7802template <
template <
typename>
typename Allocator>
7806 membersSortedByName.erase(first, last);
7810template <
template <
typename>
typename Allocator>
7812 membersSortedByName.swap(other.membersSortedByName);
7815template <
template <
typename>
typename Allocator>
7820template <
template <
typename>
typename Allocator>
7823 return static_cast<size_type>(last - first);
7826template <
template <
typename>
typename Allocator>
7828 return count(key) > 0;
7831template <
template <
typename>
typename Allocator>
7833 if (
const auto [first, last] =
equal_range(key); first != last) {
7839template <
template <
typename>
typename Allocator>
7841 if (
const auto [first, last] =
equal_range(key); first != last) {
7847template <
template <
typename>
typename Allocator>
7849 const auto [first, last] =
equalRange(membersSortedByName, key, Compare{});
7850 return {first, last};
7853template <
template <
typename>
typename Allocator>
7855 const auto [first, last] =
equalRange(membersSortedByName, key, Compare{});
7856 return {first, last};
7859template <
template <
typename>
typename Allocator>
7861 return lowerBound(membersSortedByName, key, Compare{});
7864template <
template <
typename>
typename Allocator>
7866 return lowerBound(membersSortedByName, key, Compare{});
7869template <
template <
typename>
typename Allocator>
7871 return upperBound(membersSortedByName, key, Compare{});
7874template <
template <
typename>
typename Allocator>
7876 return upperBound(membersSortedByName, key, Compare{});
7879template <
template <
typename>
typename Allocator>
7881 return membersSortedByName == other.membersSortedByName;
7884template <
template <
typename>
typename Allocator>
7886 return std::compare_partial_order_fallback(membersSortedByName, other.membersSortedByName);
7889template <
template <
typename>
typename Allocator,
typename Predicate>
7891 return erase_if(container.membersSortedByName, predicate);
7894template <
template <
typename>
typename Allocator>
7895inline bool ObjectBase<Allocator>::Compare::operator()(
const value_type& a,
const value_type& b)
const noexcept {
7896 return a.first < b.first;
7899template <
template <
typename>
typename Allocator>
7900inline bool ObjectBase<Allocator>::Compare::operator()(
const value_type& a,
StringView b)
const noexcept {
7904template <
template <
typename>
typename Allocator>
7905inline bool ObjectBase<Allocator>::Compare::operator()(
StringView a,
const value_type& b)
const noexcept {
7909template <
template <
typename>
typename Allocator>
7910inline bool ObjectBase<Allocator>::Compare::operator()(
StringView a,
StringView b)
const noexcept {
7914template <
template <
typename>
typename Allocator>
7918template <
template <
typename>
typename Allocator>
7920 : values(allocator) {}
7922template <
template <
typename>
typename Allocator>
7925template <
template <
typename>
typename Allocator>
7927 : values(other.values, allocator) {}
7929template <
template <
typename>
typename Allocator>
7933template <
template <
typename>
typename Allocator>
7935 : values(std::move(other.values), allocator) {}
7937template <
template <
typename>
typename Allocator>
7939 :
ArrayBase(std::move(other), other.get_allocator()) {}
7941template <
template <
typename>
typename Allocator>
7944template <
template <
typename>
typename Allocator>
7946 std::allocator_traits<
7947 allocator_type>::propagate_on_container_move_assignment::value ||
7948 std::allocator_traits<allocator_type>::is_always_equal::value) =
default;
7950template <
template <
typename>
typename Allocator>
7951template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel>
7953 : values(first, last, allocator) {}
7955template <
template <
typename>
typename Allocator>
7957 : values(
count, value, allocator) {}
7959template <
template <
typename>
typename Allocator>
7961 : values(ilist, allocator) {}
7963template <
template <
typename>
typename Allocator>
7969template <
template <
typename>
typename Allocator>
7971 values.swap(other.values);
7974template <
template <
typename>
typename Allocator>
7979template <
template <
typename>
typename Allocator>
7981 return values.get_allocator();
7984template <
template <
typename>
typename Allocator>
7986 return values.data();
7989template <
template <
typename>
typename Allocator>
7991 return values.data();
7994template <
template <
typename>
typename Allocator>
7996 return values.size();
7999template <
template <
typename>
typename Allocator>
8001 return values.max_size();
8004template <
template <
typename>
typename Allocator>
8006 return values.capacity();
8009template <
template <
typename>
typename Allocator>
8011 return values.empty();
8014template <
template <
typename>
typename Allocator>
8016 return values.begin();
8019template <
template <
typename>
typename Allocator>
8021 return values.begin();
8024template <
template <
typename>
typename Allocator>
8026 return values.cbegin();
8029template <
template <
typename>
typename Allocator>
8031 return values.end();
8034template <
template <
typename>
typename Allocator>
8036 return values.end();
8039template <
template <
typename>
typename Allocator>
8041 return values.cend();
8044template <
template <
typename>
typename Allocator>
8046 return values.rbegin();
8049template <
template <
typename>
typename Allocator>
8051 return values.rbegin();
8054template <
template <
typename>
typename Allocator>
8056 return values.crbegin();
8059template <
template <
typename>
typename Allocator>
8061 return values.rend();
8064template <
template <
typename>
typename Allocator>
8066 return values.rend();
8069template <
template <
typename>
typename Allocator>
8071 return values.crend();
8074template <
template <
typename>
typename Allocator>
8076 return values.front();
8079template <
template <
typename>
typename Allocator>
8081 return values.front();
8084template <
template <
typename>
typename Allocator>
8086 return values.back();
8089template <
template <
typename>
typename Allocator>
8091 return values.back();
8094template <
template <
typename>
typename Allocator>
8096 if (pos < values.size()) {
8099 throw std::out_of_range{
"JSON array does not contain item [" +
toString(pos) +
"]."};
8102template <
template <
typename>
typename Allocator>
8104 if (pos < values.size()) {
8107 throw std::out_of_range{
"JSON array does not contain item [" +
toString(pos) +
"]."};
8110template <
template <
typename>
typename Allocator>
8115template <
template <
typename>
typename Allocator>
8120template <
template <
typename>
typename Allocator>
8122 return values == other.values;
8125template <
template <
typename>
typename Allocator>
8127 return std::compare_partial_order_fallback(values, other.values);
8130template <
template <
typename>
typename Allocator,
typename U>
8132 return erase(container.values, value);
8135template <
template <
typename>
typename Allocator,
typename Predicate>
8137 return erase_if(container.values, predicate);
8140template <
template <
typename>
typename Allocator>
8145template <
template <
typename>
typename Allocator>
8147 values.reserve(newCapacity);
8150template <
template <
typename>
typename Allocator>
8152 values.shrink_to_fit();
8155template <
template <
typename>
typename Allocator>
8157 values.assign(
count, value);
8160template <
template <
typename>
typename Allocator>
8161template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel>
8163 values.assign(first, last);
8166template <
template <
typename>
typename Allocator>
8168 values.assign(ilist);
8171template <
template <
typename>
typename Allocator>
8172template <
typename R>
8174 values.assign_range(std::forward<R>(r));
8177template <
template <
typename>
typename Allocator>
8179 return values.insert(pos, value);
8182template <
template <
typename>
typename Allocator>
8184 return values.insert(pos, std::move(value));
8187template <
template <
typename>
typename Allocator>
8189 return values.insert(pos,
count, value);
8192template <
template <
typename>
typename Allocator>
8193template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel>
8195 return values.insert(pos, first, last);
8198template <
template <
typename>
typename Allocator>
8200 return values.insert(pos, ilist);
8203template <
template <
typename>
typename Allocator>
8204template <
typename R>
8206 return values.insert_range(pos, std::forward<R>(r));
8209template <
template <
typename>
typename Allocator>
8210template <
typename R>
8212 values.append_range(std::forward<R>(r));
8215template <
template <
typename>
typename Allocator>
8216template <
typename... Args>
8218 return values.emplace(pos, std::forward<Args>(args)...);
8221template <
template <
typename>
typename Allocator>
8223 return values.erase(pos);
8226template <
template <
typename>
typename Allocator>
8228 return values.erase(first, last);
8231template <
template <
typename>
typename Allocator>
8233 values.push_back(value);
8236template <
template <
typename>
typename Allocator>
8238 values.push_back(std::move(value));
8241template <
template <
typename>
typename Allocator>
8242template <
typename... Args>
8244 return values.emplace_back(std::forward<Args>(args)...);
8247template <
template <
typename>
typename Allocator>
8252template <
template <
typename>
typename Allocator>
8254 values.resize(
count);
8257template <
template <
typename>
typename Allocator>
8259 values.resize(
count, value);
8262template <
template <
typename>
typename Allocator>
8267template <
template <
typename>
typename Allocator>
8269 static_assert(
sizeof(char) ==
sizeof(char8_t));
8270 static_assert(
alignof(char) ==
alignof(char8_t));
8271 return parse(
UTF8StringView{std::launder(
reinterpret_cast<const char8_t*
>(jsonString.data())), jsonString.size()}, source, allocator);
8274template <
template <
typename>
typename Allocator>
8279template <
template <
typename>
typename Allocator>
8285template <
template <
typename>
typename Allocator>
8287 static_assert(
sizeof(char) ==
sizeof(char8_t));
8288 static_assert(
alignof(char) ==
alignof(char8_t));
8289 return parse(
UTF8StringView{std::launder(
reinterpret_cast<const char8_t*
>(jsonString.data())), jsonString.size()}, source, allocator);
#define GREM_ASSERT(expression)
Definition assertions.hpp:77
#define GREM_ALWAYS_INLINE
Definition attributes.hpp:10
Definition ArrayList.hpp:27
typename std::allocator_traits< Allocator >::size_type size_type
Definition ArrayList.hpp:34
typename std::allocator_traits< Allocator >::const_pointer const_pointer
Definition ArrayList.hpp:39
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition ArrayList.hpp:43
const value_type & const_reference
Definition ArrayList.hpp:37
typename std::allocator_traits< Allocator >::pointer pointer
Definition ArrayList.hpp:38
value_type & reference
Definition ArrayList.hpp:36
typename std::allocator_traits< Allocator >::difference_type difference_type
Definition ArrayList.hpp:35
pointer iterator
Definition ArrayList.hpp:40
const_pointer const_iterator
Definition ArrayList.hpp:41
std::reverse_iterator< iterator > reverse_iterator
Definition ArrayList.hpp:42
Base exception type for runtime errors.
Definition Error.hpp:38
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Definition Subrange.hpp:88
Tagged union value type that holds a value of one of the given types.
Definition Variant.hpp:293
constexpr T & emplace(Args &&... args)
Construct an alternative given its type, destroying the old value.
Definition Variant.hpp:591
friend class Variant
Definition Variant.hpp:1402
constexpr index_type index() const noexcept
Get the alternative index of the currently active value held by the variant.
Definition Variant.hpp:716
constexpr bool is() const noexcept
Check if the variant currently holds the alternative with the given type.
Definition Variant.hpp:740
constexpr T & as() &noexcept
Access the underlying value with the given type without a safety check.
Definition Variant.hpp:784
constexpr bool valueless_by_exception() const noexcept
Check if the variant is in the valueless by exception state.
Definition Variant.hpp:726
JSON array type whose API mimics that of std::vector<Value>.
Definition json.hpp:397
allocator_type get_allocator() const noexcept
iterator insert_range(const_iterator pos, R &&r)
typename ArrayList< value_type >::const_iterator const_iterator
Definition json.hpp:408
typename ArrayList< value_type >::pointer pointer
Definition json.hpp:405
size_type size() const noexcept
ArrayBase & operator=(const ArrayBase &other)
Allocator< value_type > allocator_type
Definition json.hpp:402
friend size_type erase_if(ArrayBase &container, Predicate predicate)
Definition json.hpp:8136
typename ArrayList< value_type >::const_pointer const_pointer
Definition json.hpp:406
bool empty() const noexcept
iterator begin() noexcept
reverse_iterator rbegin() noexcept
size_type max_size() const noexcept
typename ArrayList< value_type >::difference_type difference_type
Definition json.hpp:401
const_iterator cend() const noexcept
typename ArrayList< value_type >::const_reference const_reference
Definition json.hpp:404
typename ArrayList< value_type >::const_reverse_iterator const_reverse_iterator
Definition json.hpp:410
const_reverse_iterator crbegin() const noexcept
ArrayBase() noexcept
Definition json.hpp:7915
bool operator==(const ArrayBase &other) const
Definition json.hpp:8121
ValueBase< Allocator > value_type
Definition json.hpp:399
size_type capacity() const noexcept
void swap(ArrayBase &other) noexcept
typename ArrayList< value_type >::reverse_iterator reverse_iterator
Definition json.hpp:409
reference operator[](size_type pos)
Definition json.hpp:8111
reference emplace_back(Args &&... args)
void resize(size_type count)
iterator emplace(const_iterator pos, Args &&... args)
typename ArrayList< value_type >::iterator iterator
Definition json.hpp:407
reverse_iterator rend() noexcept
std::partial_ordering operator<=>(const ArrayBase &other) const noexcept
Definition json.hpp:8126
const_reverse_iterator crend() const noexcept
void reserve(size_type newCapacity)
reference at(size_type pos)
typename ArrayList< value_type >::size_type size_type
Definition json.hpp:400
friend size_type erase(ArrayBase &container, const U &value)
Definition json.hpp:8131
void push_back(const value_type &value)
const_iterator cbegin() const noexcept
typename ArrayList< value_type >::reference reference
Definition json.hpp:403
iterator insert(const_iterator pos, const value_type &value)
void assign(size_type count, const value_type &value)
Lexical analyzer for scanning and tokenizing input in the JSON5 format.
Definition json.hpp:2876
Token scan()
Scan and consume the next token from the input.
Definition json.hpp:2980
Lexer & operator=(Lexer &&other) noexcept
Move assignment.
Definition json.hpp:2944
Lexer & operator=(const Lexer &other)
Copy assignment.
Definition json.hpp:2929
Lexer(Lexer &&other, const allocator_type &allocator) noexcept
Move constructor.
Definition json.hpp:2910
Allocator< VariantBase< Allocator > > allocator_type
Allocator type used by the lexer.
Definition json.hpp:2879
TokenBase< Allocator > Token
Token type of the lexer.
Definition json.hpp:2882
Lexer(const Lexer &other)
Copy constructor.
Definition json.hpp:2921
allocator_type get_allocator() const noexcept
Get the allocator used by the lexer.
Definition json.hpp:2963
Lexer(const Lexer &other, const allocator_type &allocator)
Copy constructor.
Definition json.hpp:2902
Lexer(Lexer &&other) noexcept
Move constructor.
Definition json.hpp:2925
Lexer(unicode::UTF8Iterator< It > it, unicode::UTF8Sentinel end, const SourceLocation &source, const allocator_type &allocator=allocator_type())
Construct a lexer with a Unicode iterator pair as input.
Definition json.hpp:2895
~Lexer()=default
Destructor.
JSON object type whose API mimics that of std::map<String, Value>.
Definition json.hpp:258
std::partial_ordering operator<=>(const ObjectBase &other) const noexcept
Definition json.hpp:7885
iterator erase(const_iterator pos)
typename ArrayList< value_type >::reverse_iterator reverse_iterator
Definition json.hpp:272
const_reverse_iterator crbegin() const noexcept
void reserve(size_type newCapacity)
reverse_iterator rend() noexcept
Pair< iterator, bool > insert(P &&value)
typename ArrayList< value_type >::const_reference const_reference
Definition json.hpp:267
ObjectBase() noexcept
Definition json.hpp:7527
Pair< iterator, bool > emplace(Args &&... args)
reverse_iterator rbegin() noexcept
mapped_type & operator[](const key_type &k)
Definition json.hpp:7606
const_iterator cbegin() const noexcept
bool operator==(const ObjectBase &other) const noexcept
Definition json.hpp:7880
typename ArrayList< value_type >::const_pointer const_pointer
Definition json.hpp:269
Pair< iterator, bool > try_emplace(const key_type &k, Args &&... args)
size_type size() const noexcept
ObjectBase & operator=(const ObjectBase &other)
Pair< StringBase< Allocator >, ValueBase< Allocator > > value_type
Definition json.hpp:262
typename ArrayList< value_type >::const_reverse_iterator const_reverse_iterator
Definition json.hpp:273
typename ArrayList< value_type >::iterator iterator
Definition json.hpp:270
const_iterator cend() const noexcept
typename ArrayList< value_type >::const_iterator const_iterator
Definition json.hpp:271
void swap(ObjectBase &other) noexcept
bool contains(StringView key) const noexcept
size_type capacity() const noexcept
iterator find(StringView key) noexcept
friend size_type erase_if(ObjectBase &container, Predicate predicate)
Definition json.hpp:7890
size_type max_size() const noexcept
bool empty() const noexcept
typename ArrayList< value_type >::reference reference
Definition json.hpp:266
allocator_type get_allocator() const noexcept
iterator lower_bound(StringView key) noexcept
typename ArrayList< value_type >::size_type size_type
Definition json.hpp:263
ValueBase< Allocator > mapped_type
Definition json.hpp:261
size_type count(StringView key) const noexcept
iterator upper_bound(StringView key) noexcept
StringBase< Allocator > key_type
Definition json.hpp:260
iterator begin() noexcept
Pair< iterator, iterator > equal_range(StringView key) noexcept
Allocator< value_type > allocator_type
Definition json.hpp:265
const_reverse_iterator crend() const noexcept
typename ArrayList< value_type >::difference_type difference_type
Definition json.hpp:264
mapped_type & at(StringView key)
iterator emplace_hint(const_iterator hint, Args &&... args)
Polymorphic interface for visitation-based parsing of JSON object properties.
Definition json.hpp:3551
~PropertyVisitor()=default
virtual void visitProperty(const SourceLocation &source, StringBase< Allocator > &&key, Parser &parser)=0
Callback for each object property.
Polymorphic interface for visitation-based parsing of JSON values.
Definition json.hpp:3385
virtual void visitArray(const SourceLocation &source, Parser &parser)
Callback for arrays.
Definition json.hpp:3476
virtual void visitBoolean(const SourceLocation &source, Boolean value)
Callback for values of type Boolean.
Definition json.hpp:3410
virtual void visitNumber(const SourceLocation &source, Number value)
Callback for values of type Number.
Definition json.hpp:3438
virtual void visitObject(const SourceLocation &source, Parser &parser)
Callback for objects.
Definition json.hpp:3457
virtual void visitString(const SourceLocation &source, StringBase< Allocator > &&value)
Callback for values of type String.
Definition json.hpp:3424
virtual void visitNull(const SourceLocation &source, Null value)
Callback for values of type Null.
Definition json.hpp:3396
Syntactic analyzer for parsing input in the JSON5 format obtained from a json::Lexer.
Definition json.hpp:3374
Boolean parseBoolean()
Definition json.hpp:4165
bool peekIsNull() const
Definition json.hpp:4147
ValueBase< Allocator > parseValue()
Definition json.hpp:4088
void advance()
Definition json.hpp:4420
const Token & peek() const
Definition json.hpp:4445
Parser & operator=(const Parser &)=default
void parseArray(ValueVisitor &visitor)
Read a single JSON array from the input and visit each of its values.
Definition json.hpp:3928
bool peekIsString() const
Definition json.hpp:4234
allocator_type get_allocator() const noexcept
Definition json.hpp:3736
Parser(const Parser &other)
Definition json.hpp:3718
bool peekIsBoolean() const
Definition json.hpp:4189
void parseObject(Visitor visitor)
Definition json.hpp:3998
Parser(Parser &&other, const allocator_type &allocator) noexcept
Definition json.hpp:3703
Token eat()
Definition json.hpp:4465
void parseObject(PropertyVisitor &&visitor)
Definition json.hpp:3967
bool peekIsObject() const
Definition json.hpp:4347
void parseFile(ValueVisitor &visitor)
Definition json.hpp:3762
Allocator< ValueBase< Allocator > > allocator_type
Allocator type used by the parser.
Definition json.hpp:3377
void parseValue(Visitor visitor)
Definition json.hpp:3990
Parser(unicode::UTF8View codePoints, const SourceLocation &source={}, const allocator_type &allocator=allocator_type())
Definition json.hpp:3638
StringBase< Allocator > parseString()
Definition json.hpp:4212
void parseArray(ValueVisitor &&visitor)
Definition json.hpp:3974
Parser(StringView jsonString, const SourceLocation &source={}, const allocator_type &allocator=allocator_type())
Definition json.hpp:3663
Number parseNumber()
Definition json.hpp:4252
void parseFile(Visitor visitor)
Definition json.hpp:3982
bool peekIsNumber() const
Definition json.hpp:4281
Parser & operator=(Parser &&) noexcept=default
void parseArray(Visitor visitor)
Definition json.hpp:4006
void parseFile(ValueVisitor &&visitor)
Definition json.hpp:3953
bool peekIsArray() const
Definition json.hpp:4407
Parser(std::istream &stream, const SourceLocation &source={}, const allocator_type &allocator=allocator_type())
Definition json.hpp:3674
ArrayBase< Allocator > parseArray()
Definition json.hpp:4366
void skipValue()
Definition json.hpp:4039
void parseObject(PropertyVisitor &visitor)
Read a single JSON object from the input and visit each of its properties.
Definition json.hpp:3860
Parser(std::streambuf *streambuf, const SourceLocation &source={}, const allocator_type &allocator=allocator_type())
Definition json.hpp:3686
Null parseNull()
Definition json.hpp:4125
TokenBase< Allocator > Token
Token type of the parser.
Definition json.hpp:3380
Parser(UTF8StringView jsonString, const SourceLocation &source={}, const allocator_type &allocator=allocator_type())
Definition json.hpp:3650
void parseValue(ValueVisitor &visitor)
Read a single JSON value from the input and visit it.
Definition json.hpp:3790
ValueBase< Allocator > parseFile()
Definition json.hpp:4059
Parser(Lexer< It, Allocator > lexer, const allocator_type &allocator=allocator_type())
Construct a parser with an existing lexer as input.
Definition json.hpp:3626
void skipFile()
Definition json.hpp:4023
Parser(Parser &&other) noexcept
Definition json.hpp:3722
void parseValue(ValueVisitor &&visitor)
Definition json.hpp:3960
ObjectBase< Allocator > parseObject()
Definition json.hpp:4311
Parser(const Parser &other, const allocator_type &allocator)
Definition json.hpp:3691
JSON value with an associated SourceLocation.
Definition json.hpp:1102
GREM_ALWAYS_INLINE Number && getNumberItem(size_t index) &&
Get an item of the Array in this value as a Number, throwing an exception if this value is not actual...
Definition json.hpp:2457
GREM_ALWAYS_INLINE const Array & getArrayItem(size_t index) const &&
Get an item of the Array in this value as an Array, throwing an exception if this value is not actual...
Definition json.hpp:2761
GREM_ALWAYS_INLINE Boolean && getBooleanItem(size_t index) &&
Get an item of the Array in this value as a Boolean, throwing an exception if this value is not actua...
Definition json.hpp:2169
GREM_ALWAYS_INLINE Boolean && getBoolean() &&
Get this value as a Boolean, throwing an exception if it is not actually a boolean.
Definition json.hpp:1328
GREM_ALWAYS_INLINE T getNumberProperty(StringView key) const
Get a property of the Object in this value as a Number, throwing an exception if this value is not ac...
Definition json.hpp:2409
GREM_ALWAYS_INLINE const ObjectBase< Allocator > & getObject() const &
Get this value as an Object, throwing an exception if it is not actually an object.
Definition json.hpp:1545
ValueBase(ValueBase &&other) noexcept=default
Move constructor.
GREM_ALWAYS_INLINE const ObjectBase< Allocator > && getObject() const &&
Get this value as an Object, throwing an exception if it is not actually an object.
Definition json.hpp:1575
GREM_ALWAYS_INLINE String && getStringItem(size_t index) &&
Get an item of the Array in this value as a String, throwing an exception if this value is not actual...
Definition json.hpp:2302
GREM_ALWAYS_INLINE T getNumberItem(size_t index) const
Get an item of the Array in this value as a Number, throwing an exception if this value is not actual...
Definition json.hpp:2495
GREM_ALWAYS_INLINE Array & getArrayItem(size_t index) &
Get an item of the Array in this value as an Array, throwing an exception if this value is not actual...
Definition json.hpp:2713
GREM_ALWAYS_INLINE const Null & getNullProperty(StringView key) const &
Get a property of the Object in this value as Null, throwing an exception if this value is not actual...
Definition json.hpp:1955
GREM_ALWAYS_INLINE const String & getStringItem(size_t index) const &
Get an item of the Array in this value as a String, throwing an exception if this value is not actual...
Definition json.hpp:2286
GREM_ALWAYS_INLINE const Object & getObjectItem(size_t index) const &&
Get an item of the Array in this value as an Object, throwing an exception if this value is not actua...
Definition json.hpp:2628
GREM_ALWAYS_INLINE const Null & getNullItem(size_t index) const &
Get an item of the Array in this value as Null, throwing an exception if this value is not actually a...
Definition json.hpp:2020
GREM_ALWAYS_INLINE const Array & getArrayProperty(StringView key) const &&
Get a property of the Object in this value as an Array, throwing an exception if this value is not ac...
Definition json.hpp:2697
GREM_ALWAYS_INLINE Object & getObjectProperty(StringView key) &
Get a property of the Object in this value as an Object, throwing an exception if this value is not a...
Definition json.hpp:2512
GREM_ALWAYS_INLINE const StringBase< Allocator > && getString() const &&
Get this value as a String, throwing an exception if it is not actually a string.
Definition json.hpp:1412
GREM_ALWAYS_INLINE Number && getNumberProperty(StringView key) &&
Get a property of the Object in this value as a Number, throwing an exception if this value is not ac...
Definition json.hpp:2369
GREM_ALWAYS_INLINE const StringBase< Allocator > & getString() const &
Get this value as a String, throwing an exception if it is not actually a string.
Definition json.hpp:1367
GREM_ALWAYS_INLINE const String & getStringItem(size_t index) const &&
Get an item of the Array in this value as a String, throwing an exception if this value is not actual...
Definition json.hpp:2318
ValueBase(VariantBase< Allocator > value, const SourceLocation &source, const allocator_type &allocator)
Construct a JSON value with an associated source location.
Definition json.hpp:1184
GREM_ALWAYS_INLINE Boolean && getBooleanProperty(StringView key) &&
Get a property of the Object in this value as a Boolean, throwing an exception if this value is not a...
Definition json.hpp:2103
GREM_ALWAYS_INLINE const ValueBase< Allocator > & getProperty(StringView key) const &
Get a property of the Object in this value, throwing an exception if it is not actually an object or ...
Definition json.hpp:1750
GREM_ALWAYS_INLINE const Boolean & getBoolean() const &
Get this value as a Boolean, throwing an exception if it is not actually a boolean.
Definition json.hpp:1313
ValueBase(const ValueBase &other, const allocator_type &allocator) noexcept
Copy constructor.
Definition json.hpp:1192
GREM_ALWAYS_INLINE bool isString() const noexcept
Check if this value is of type String.
Definition json.hpp:1355
GREM_ALWAYS_INLINE const Boolean && getBoolean() const &&
Get this value as a Boolean, throwing an exception if it is not actually a boolean.
Definition json.hpp:1343
GREM_ALWAYS_INLINE const Number & getNumberItem(size_t index) const &
Get an item of the Array in this value as a Number, throwing an exception if this value is not actual...
Definition json.hpp:2441
GREM_ALWAYS_INLINE Null && getNull() &&
Get this value as Null, throwing an exception if it is not actually null.
Definition json.hpp:1260
GREM_ALWAYS_INLINE const Number && getNumber() const &&
Get this value as a Number, throwing an exception if it is not actually a number.
Definition json.hpp:1481
GREM_ALWAYS_INLINE const ValueBase< Allocator > & getItem(size_t index) const &
Get an item of the Array in this value, throwing an exception if it is not actually an array or if th...
Definition json.hpp:1881
GREM_ALWAYS_INLINE String & getStringProperty(StringView key) &
Get a property of the Object in this value as a String, throwing an exception if this value is not ac...
Definition json.hpp:2202
GREM_ALWAYS_INLINE ObjectBase< Allocator > & getObject() &
Get this value as an Object, throwing an exception if it is not actually an object.
Definition json.hpp:1530
GREM_ALWAYS_INLINE const Boolean & getBooleanItem(size_t index) const &
Get an item of the Array in this value as a Boolean, throwing an exception if this value is not actua...
Definition json.hpp:2153
GREM_ALWAYS_INLINE bool isNull() const noexcept
Check if this value is of type Null.
Definition json.hpp:1221
ValueBase(const ValueBase &other)=default
Copy constructor.
GREM_ALWAYS_INLINE Boolean & getBoolean() &
Get this value as a Boolean, throwing an exception if it is not actually a boolean.
Definition json.hpp:1298
GREM_ALWAYS_INLINE ValueBase< Allocator > && getItem(size_t index) &&
Get an item of the Array in this value, throwing an exception if it is not actually an array or if th...
Definition json.hpp:1900
GREM_ALWAYS_INLINE Array & getArrayProperty(StringView key) &
Get a property of the Object in this value as an Array, throwing an exception if this value is not ac...
Definition json.hpp:2645
GREM_ALWAYS_INLINE Null && getNullItem(size_t index) &&
Get an item of the Array in this value as Null, throwing an exception if this value is not actually a...
Definition json.hpp:2036
GREM_ALWAYS_INLINE Array && getArrayProperty(StringView key) &&
Get a property of the Object in this value as an Array, throwing an exception if this value is not ac...
Definition json.hpp:2679
GREM_ALWAYS_INLINE const ArrayBase< Allocator > & getArray() const &
Get this value as an Array, throwing an exception if it is not actually an array.
Definition json.hpp:1629
GREM_ALWAYS_INLINE const Object & getObjectProperty(StringView key) const &
Get a property of the Object in this value as an Object, throwing an exception if this value is not a...
Definition json.hpp:2529
ValueBase(VariantBase< Allocator > value)
Construct a JSON value.
Definition json.hpp:1164
GREM_ALWAYS_INLINE ObjectBase< Allocator > && getObject() &&
Get this value as an Object, throwing an exception if it is not actually an object.
Definition json.hpp:1560
GREM_ALWAYS_INLINE const Number & getNumberItem(size_t index) const &&
Get an item of the Array in this value as a Number, throwing an exception if this value is not actual...
Definition json.hpp:2473
GREM_ALWAYS_INLINE bool isObject() const noexcept
Check if this value is of type Object.
Definition json.hpp:1518
GREM_ALWAYS_INLINE Boolean & getBooleanProperty(StringView key) &
Get a property of the Object in this value as a Boolean, throwing an exception if this value is not a...
Definition json.hpp:2069
GREM_ALWAYS_INLINE const ValueBase< Allocator > * findItem(size_t index) const noexcept
Get an item of the Array in this value, returning nullptr if it is not actually an array or if the in...
Definition json.hpp:1841
GREM_ALWAYS_INLINE ValueBase< Allocator > * findItem(size_t index) noexcept
Get an item of the Array in this value, returning nullptr if it is not actually an array or if the in...
Definition json.hpp:1821
GREM_ALWAYS_INLINE const ArrayBase< Allocator > && getArray() const &&
Get this value as an Array, throwing an exception if it is not actually an array.
Definition json.hpp:1659
GREM_ALWAYS_INLINE String & getStringItem(size_t index) &
Get an item of the Array in this value as a String, throwing an exception if this value is not actual...
Definition json.hpp:2270
ValueBase & operator=(const ValueBase &other)=default
Copy assignment.
GREM_ALWAYS_INLINE SourceLocation getSource() const noexcept
Get the source location of this value.
Definition json.hpp:2770
GREM_ALWAYS_INLINE const String & getStringProperty(StringView key) const &&
Get a property of the Object in this value as a String, throwing an exception if this value is not ac...
Definition json.hpp:2254
GREM_ALWAYS_INLINE ArrayBase< Allocator > && getArray() &&
Get this value as an Array, throwing an exception if it is not actually an array.
Definition json.hpp:1644
~ValueBase()=default
Destructor.
GREM_ALWAYS_INLINE ValueBase< Allocator > & getProperty(StringView key) &
Get a property of the Object in this value, throwing an exception if it is not actually an object or ...
Definition json.hpp:1730
GREM_ALWAYS_INLINE StringBase< Allocator > && getString() &&
Get this value as a String, throwing an exception if it is not actually a string.
Definition json.hpp:1397
GREM_ALWAYS_INLINE const Object & getObjectItem(size_t index) const &
Get an item of the Array in this value as an Object, throwing an exception if this value is not actua...
Definition json.hpp:2596
GREM_ALWAYS_INLINE const Number & getNumber() const &
Get this value as a Number, throwing an exception if it is not actually a number.
Definition json.hpp:1451
GREM_ALWAYS_INLINE Number & getNumberItem(size_t index) &
Get an item of the Array in this value as a Number, throwing an exception if this value is not actual...
Definition json.hpp:2425
GREM_ALWAYS_INLINE ArrayBase< Allocator > & getArray() &
Get this value as an Array, throwing an exception if it is not actually an array.
Definition json.hpp:1614
GREM_ALWAYS_INLINE const Null & getNullItem(size_t index) const &&
Get an item of the Array in this value as Null, throwing an exception if this value is not actually a...
Definition json.hpp:2052
GREM_ALWAYS_INLINE bool isNumber() const noexcept
Check if this value is of type Number.
Definition json.hpp:1424
GREM_ALWAYS_INLINE Object && getObjectItem(size_t index) &&
Get an item of the Array in this value as an Object, throwing an exception if this value is not actua...
Definition json.hpp:2612
GREM_ALWAYS_INLINE const Number & getNumberProperty(StringView key) const &
Get a property of the Object in this value as a Number, throwing an exception if this value is not ac...
Definition json.hpp:2352
ValueBase & operator=(ValueBase &&other) noexcept(std::allocator_traits< allocator_type >::propagate_on_container_move_assignment::value||//NOLINT(cppcoreguidelines-noexcept-move-operations, performance-noexcept-move-constructor) std::allocator_traits< allocator_type >::is_always_equal::value)=default
Move assignment.
GREM_ALWAYS_INLINE const Boolean & getBooleanItem(size_t index) const &&
Get an item of the Array in this value as a Boolean, throwing an exception if this value is not actua...
Definition json.hpp:2185
GREM_ALWAYS_INLINE T getNumber() const
Get this value as a Number, throwing an exception if it is not actually a number, or not the correct ...
Definition json.hpp:1500
GREM_ALWAYS_INLINE bool hasProperty(StringView key) const noexcept
Check if this value is of type Object and has a property with a given key.
Definition json.hpp:1675
GREM_ALWAYS_INLINE Boolean & getBooleanItem(size_t index) &
Get an item of the Array in this value as a Boolean, throwing an exception if this value is not actua...
Definition json.hpp:2137
GREM_ALWAYS_INLINE Array && getArrayItem(size_t index) &&
Get an item of the Array in this value as an Array, throwing an exception if this value is not actual...
Definition json.hpp:2745
ValueBase(VariantBase< Allocator > value, const allocator_type &allocator)
Construct a JSON value.
Definition json.hpp:1156
GREM_ALWAYS_INLINE const Null & getNull() const &&
Get this value as Null, throwing an exception if it is not actually null.
Definition json.hpp:1274
GREM_ALWAYS_INLINE const Array & getArrayProperty(StringView key) const &
Get a property of the Object in this value as an Array, throwing an exception if this value is not ac...
Definition json.hpp:2662
GREM_ALWAYS_INLINE ValueBase< Allocator > & getItem(size_t index) &
Get an item of the Array in this value, throwing an exception if it is not actually an array or if th...
Definition json.hpp:1862
GREM_ALWAYS_INLINE Object && getObjectProperty(StringView key) &&
Get a property of the Object in this value as an Object, throwing an exception if this value is not a...
Definition json.hpp:2546
GREM_ALWAYS_INLINE Null && getNullProperty(StringView key) &&
Get a property of the Object in this value as Null, throwing an exception if this value is not actual...
Definition json.hpp:1971
GREM_ALWAYS_INLINE String && getStringProperty(StringView key) &&
Get a property of the Object in this value as a String, throwing an exception if this value is not ac...
Definition json.hpp:2236
GREM_ALWAYS_INLINE Null & getNullProperty(StringView key) &
Get a property of the Object in this value as Null, throwing an exception if this value is not actual...
Definition json.hpp:1939
GREM_ALWAYS_INLINE Number && getNumber() &&
Get this value as a Number, throwing an exception if it is not actually a number.
Definition json.hpp:1466
GREM_ALWAYS_INLINE bool isArray() const noexcept
Check if this value is of type Array.
Definition json.hpp:1587
static ValueBase parse(UTF8StringView jsonString, const SourceLocation &source={}, const allocator_type &allocator=allocator_type())
Parse a value of any JSON type from a UTF-8 JSON string.
Definition json.hpp:8280
GREM_ALWAYS_INLINE const Boolean & getBooleanProperty(StringView key) const &
Get a property of the Object in this value as a Boolean, throwing an exception if this value is not a...
Definition json.hpp:2086
GREM_ALWAYS_INLINE const Null & getNullProperty(StringView key) const &&
Get a property of the Object in this value as Null, throwing an exception if this value is not actual...
Definition json.hpp:1988
GREM_ALWAYS_INLINE Null & getNull() &
Get this value as Null, throwing an exception if it is not actually null.
Definition json.hpp:1232
GREM_ALWAYS_INLINE const String & getStringProperty(StringView key) const &
Get a property of the Object in this value as a String, throwing an exception if this value is not ac...
Definition json.hpp:2219
GREM_ALWAYS_INLINE ValueBase< Allocator > * findProperty(StringView key) noexcept
Get a property of the Object in this value, returning nullptr if it is not actually an object or if t...
Definition json.hpp:1689
GREM_ALWAYS_INLINE Object & getObjectItem(size_t index) &
Get an item of the Array in this value as an Object, throwing an exception if this value is not actua...
Definition json.hpp:2580
GREM_ALWAYS_INLINE ValueBase< Allocator > && getProperty(StringView key) &&
Get a property of the Object in this value, throwing an exception if it is not actually an object or ...
Definition json.hpp:1770
GREM_ALWAYS_INLINE Number & getNumberProperty(StringView key) &
Get a property of the Object in this value as a Number, throwing an exception if this value is not ac...
Definition json.hpp:2335
GREM_ALWAYS_INLINE const Number & getNumberProperty(StringView key) const &&
Get a property of the Object in this value as a Number, throwing an exception if this value is not ac...
Definition json.hpp:2387
GREM_ALWAYS_INLINE bool hasItem(size_t index) const noexcept
Check if this value is of type Array and has an item at the given index.
Definition json.hpp:1807
GREM_ALWAYS_INLINE StringBase< Allocator > & getString() &
Get this value as a String, throwing an exception if it is not actually a string.
Definition json.hpp:1382
ValueBase(ValueBase &&other, const allocator_type &allocator) noexcept
Move constructor.
Definition json.hpp:1200
GREM_ALWAYS_INLINE const ValueBase< Allocator > && getProperty(StringView key) const &&
Get a property of the Object in this value, throwing an exception if it is not actually an object or ...
Definition json.hpp:1790
GREM_ALWAYS_INLINE const Array & getArrayItem(size_t index) const &
Get an item of the Array in this value as an Array, throwing an exception if this value is not actual...
Definition json.hpp:2729
ValueBase(VariantBase< Allocator > value, const SourceLocation &source)
Construct a JSON value with an associated source location.
Definition json.hpp:1173
GREM_ALWAYS_INLINE bool isBoolean() const noexcept
Check if this value is of type Boolean.
Definition json.hpp:1286
GREM_ALWAYS_INLINE size_t getArraySize() const
Get the size of the Array in this value, throwing an exception if it is not actually an array.
Definition json.hpp:1599
GREM_ALWAYS_INLINE Number & getNumber() &
Get this value as a Number, throwing an exception if it is not actually a number.
Definition json.hpp:1436
GREM_ALWAYS_INLINE bool operator==(const ValueBase &other) const
Compare this value to another for equality.
Definition json.hpp:2782
GREM_ALWAYS_INLINE const ValueBase< Allocator > && getItem(size_t index) const &&
Get an item of the Array in this value, throwing an exception if it is not actually an array or if th...
Definition json.hpp:1919
GREM_ALWAYS_INLINE const Null & getNull() const &
Get this value as Null, throwing an exception if it is not actually null.
Definition json.hpp:1246
GREM_ALWAYS_INLINE Null & getNullItem(size_t index) &
Get an item of the Array in this value as Null, throwing an exception if this value is not actually a...
Definition json.hpp:2004
GREM_ALWAYS_INLINE const Object & getObjectProperty(StringView key) const &&
Get a property of the Object in this value as an Object, throwing an exception if this value is not a...
Definition json.hpp:2564
static ValueBase parse(StringView jsonString, const SourceLocation &source={}, const allocator_type &allocator=allocator_type())
Parse a value of any JSON type from a JSON string interpreted as UTF-8.
Definition json.hpp:8286
GREM_ALWAYS_INLINE const ValueBase< Allocator > * findProperty(StringView key) const noexcept
Get a property of the Object in this value, returning nullptr if it is not actually an object or if t...
Definition json.hpp:1709
GREM_ALWAYS_INLINE const Boolean & getBooleanProperty(StringView key) const &&
Get a property of the Object in this value as a Boolean, throwing an exception if this value is not a...
Definition json.hpp:2121
JSON value type.
Definition json.hpp:538
VariantBase(std::nullptr_t, const allocator_type &allocator) noexcept
Construct a Null value.
Definition json.hpp:621
VariantBase(StringBase< Allocator > &&value, const allocator_type &allocator) noexcept
Construct a String value from the given underlying value.
Definition json.hpp:677
VariantBase & operator=(VariantBase &&other) noexcept(std::allocator_traits< allocator_type >::propagate_on_container_move_assignment::value||//NOLINT(cppcoreguidelines-noexcept-move-operations, performance-noexcept-move-constructor) std::allocator_traits< allocator_type >::is_always_equal::value)
Move assignment.
Definition json.hpp:1005
VariantBase(const VariantBase &other)
Copy constructor.
Definition json.hpp:960
VariantBase(const ArrayBase< Allocator > &value)
Construct an Array value with the given underlying value.
Definition json.hpp:920
VariantBase(const ObjectBase< Allocator > &value, const allocator_type &allocator)
Construct an Object value with the given underlying value.
Definition json.hpp:867
VariantBase(ArrayBase< Allocator > &&value) noexcept
Construct an Array value from the given underlying value.
Definition json.hpp:939
VariantBase(ObjectBase< Allocator > &&value, const allocator_type &allocator) noexcept
Construct an Object value from the given underlying value.
Definition json.hpp:888
GREM_ALWAYS_INLINE bool operator==(const VariantBase &other) const
Compare this value to another for equality.
Definition json.hpp:1072
VariantBase(ArrayBase< Allocator > &&value, const allocator_type &allocator) noexcept
Construct an Array value from the given underlying value.
Definition json.hpp:930
StringBase< Allocator > toString(const SerializationOptions &options={}, const allocator_type &stringAllocator=allocator_type()) const
Get a JSON string representation of the value.
Definition json.hpp:8275
VariantBase(StringBase< Allocator > &&value) noexcept
Construct a String value from the given underlying value.
Definition json.hpp:686
VariantBase(Null, const allocator_type &allocator) noexcept
Construct a Null value.
Definition json.hpp:607
VariantBase(Boolean value) noexcept
Construct a Boolean value with the given underlying value.
Definition json.hpp:645
VariantBase(UTF8CStringView value, const allocator_type &allocator)
Construct a String value with the given underlying value.
Definition json.hpp:824
VariantBase(const StringBase< Allocator > &value, const allocator_type &allocator)
Construct a String value with the given underlying value.
Definition json.hpp:656
VariantBase(const char8_t *value)
Construct a String value with the given underlying value.
Definition json.hpp:786
VariantBase(const StringBase< Allocator > &value)
Construct a String value with the given underlying value.
Definition json.hpp:667
VariantBase(const VariantBase &other, const allocator_type &allocator) noexcept
Copy constructor.
Definition json.hpp:947
static ValueBase< Allocator > parse(UTF8StringView jsonString, const SourceLocation &source={}, const allocator_type &allocator=allocator_type())
Parse a value of any JSON type from a UTF-8 JSON string.
Definition json.hpp:8263
VariantBase(UTF8StringView value, const allocator_type &allocator)
Construct a String value with the given underlying value.
Definition json.hpp:799
GREM_ALWAYS_INLINE std::partial_ordering operator<=>(const VariantBase &other) const
Compare this value to another.
Definition json.hpp:1083
VariantBase(Null) noexcept
Construct a Null value.
Definition json.hpp:613
VariantBase(CStringView value, const allocator_type &allocator)
Construct a String value with the given underlying value.
Definition json.hpp:747
VariantBase(UTF8StringView value)
Construct a String value with the given underlying value.
Definition json.hpp:811
Allocator< VariantBase > allocator_type
Allocator type used by the value.
Definition json.hpp:544
VariantBase(strict_arithmetic auto value) noexcept
Construct a Number value with the given underlying value.
Definition json.hpp:856
VariantBase(StringView value)
Construct a String value with the given underlying value.
Definition json.hpp:735
VariantBase(VariantBase &&other) noexcept
Move constructor.
Definition json.hpp:977
VariantBase(ObjectBase< Allocator > &&value) noexcept
Construct an Object value from the given underlying value.
Definition json.hpp:897
VariantBase(const ArrayBase< Allocator > &value, const allocator_type &allocator)
Construct an Array value with the given underlying value.
Definition json.hpp:909
VariantBase(UTF8CStringView value)
Construct a String value with the given underlying value.
Definition json.hpp:836
allocator_type get_allocator() const noexcept
Definition json.hpp:1044
VariantBase(const ObjectBase< Allocator > &value)
Construct an Object value with the given underlying value.
Definition json.hpp:878
static ValueBase< Allocator > parse(StringView jsonString, const SourceLocation &source={}, const allocator_type &allocator=allocator_type())
Parse a value of any JSON type from a JSON string interpreted as UTF-8.
Definition json.hpp:8268
VariantBase() noexcept
Construct a Null value.
Definition json.hpp:591
~VariantBase()=default
Destructor.
VariantBase(CStringView value)
Construct a String value with the given underlying value.
Definition json.hpp:758
VariantBase(Boolean value, const allocator_type &allocator) noexcept
Construct a Boolean value with the given underlying value.
Definition json.hpp:636
VariantBase(std::nullptr_t) noexcept
Construct a Null value.
Definition json.hpp:627
VariantBase(const char8_t *value, const allocator_type &allocator)
Construct a String value with the given underlying value.
Definition json.hpp:771
VariantBase(const char *value)
Construct a String value with the given underlying value.
Definition json.hpp:712
VariantBase(const allocator_type &allocator) noexcept
Construct a Null value.
Definition json.hpp:599
VariantBase(StringView value, const allocator_type &allocator)
Construct a String value with the given underlying value.
Definition json.hpp:724
VariantBase(VariantBase &&other, const allocator_type &allocator) noexcept
Move constructor.
Definition json.hpp:964
VariantBase(strict_arithmetic auto value, const allocator_type &allocator) noexcept
Construct a Number value with the given underlying value.
Definition json.hpp:846
VariantBase & operator=(const VariantBase &other)
Copy assignment.
Definition json.hpp:981
VariantBase(const char *value, const allocator_type &allocator)
Construct a String value with the given underlying value.
Definition json.hpp:700
Iterator type for decoding Unicode code points from a UTF-8 string, wrapping an existing iterator for...
Definition unicode.hpp:176
Non-owning view type for decoding Unicode code points from a contiguous UTF-8 string.
Definition unicode.hpp:317
constexpr sentinel end() const noexcept
Definition unicode.hpp:342
constexpr const iterator & begin() const noexcept
Definition unicode.hpp:338
Definition concepts.hpp:100
Definition concepts.hpp:47
Definition concepts.hpp:94
Definition concepts.hpp:67
Definition concepts.hpp:106
Definition concepts.hpp:35
Definition concepts.hpp:91
@ U
'u'
Definition keyboard.hpp:91
@ T
't'
Definition keyboard.hpp:90
Definition aliases.hpp:15
constexpr bool isPunctuationCharacter(char32_t codePoint) noexcept
Check if a Unicode code point is considered to be punctuation in JSON5.
Definition json.hpp:2816
auto onNumber(Callback callback)
Build a Parser::ValueVisitor that handles Number values with a given callback function.
Definition json.hpp:7005
void deserialize(std::istream &stream, T &value, const DeserializationOptions &options={}, DeserializerOverride deserializerOverride={}, const SourceLocation &source={})
Deserialize a value of any JSON-serializable type from an input stream.
Definition json.hpp:6743
StreamParserBase< std::allocator > StreamParser
Parser for reading UTF-8-encoded JSON input stream buffers using the default allocator.
Definition json.hpp:4525
void swap(ObjectBase< Allocator > &a, ObjectBase< Allocator > &b) noexcept
Definition json.hpp:7816
json::VariantBase< std::allocator > Variant
JSON value type using the default allocator.
Definition json.hpp:1094
ArrayBase< Allocator >::size_type erase(ArrayBase< Allocator > &container, const U &value)
Definition json.hpp:8131
constexpr bool isWhitespace(char32_t codePoint) noexcept
Check if a Unicode code point is considered to be whitespace in JSON5.
Definition json.hpp:2803
json::ObjectBase< std::allocator > Object
JSON object type using the default allocator.
Definition json.hpp:389
StringParserBase< std::allocator > StringParser
Parser for reading contiguous UTF-8-encoded JSON strings using the default allocator.
Definition json.hpp:4513
auto onArray(Callback callback)
Build a Parser::ValueVisitor that handles arrays with a given callback function.
Definition json.hpp:7059
auto onProperty(Callback callback)
Build a Parser::PropertyVisitor that handles object properties with a given callback function.
Definition json.hpp:7079
Parser< std::istreambuf_iterator< char >, Allocator > StreamParserBase
Parser for reading UTF-8-encoded JSON input stream buffers.
Definition json.hpp:4519
Parser< const char8_t *, Allocator > StringParserBase
Parser for reading contiguous UTF-8-encoded JSON strings.
Definition json.hpp:4507
double Number
JSON number type.
Definition json.hpp:250
TokenType
Type of a scanned JSON5 token.
Definition json.hpp:2836
@ PUNCTUATOR_OPEN_CURLY_BRACE
Open curly brace '{' symbol.
Definition json.hpp:2846
@ NUMBER_OCTAL
Octal number literal, e.g. 0777.
Definition json.hpp:2850
@ IDENTIFIER_FALSE
Keyword false.
Definition json.hpp:2839
@ PUNCTUATOR_CLOSE_CURLY_BRACE
Closing curly brace '}' symbol.
Definition json.hpp:2847
@ NUMBER_BINARY
Binary number literal, e.g. 0b0000000111111111.
Definition json.hpp:2849
@ PUNCTUATOR_COLON
Colon ':' symbol.
Definition json.hpp:2843
@ NUMBER_NEGATIVE_INFINITY
Keyword -Infinity.
Definition json.hpp:2854
@ END_OF_FILE
End-of-file marker.
Definition json.hpp:2837
@ PUNCTUATOR_CLOSE_SQUARE_BRACKET
Closing square bracket ']' symbol.
Definition json.hpp:2845
@ STRING
Quoted string literal, e.g. "abc".
Definition json.hpp:2848
@ NUMBER_POSITIVE_NAN
Keyword NaN.
Definition json.hpp:2855
@ IDENTIFIER_NAME
Unquoted identifier, e.g. abc.
Definition json.hpp:2841
@ NUMBER_DECIMAL
Decimal number literal, e.g. 511.
Definition json.hpp:2851
@ IDENTIFIER_NULL
Keyword null.
Definition json.hpp:2838
@ NUMBER_POSITIVE_INFINITY
Keyword Infinity.
Definition json.hpp:2853
@ IDENTIFIER_TRUE
Keyword true.
Definition json.hpp:2840
@ NUMBER_NEGATIVE_NAN
Keyword -NaN.
Definition json.hpp:2856
@ NUMBER_HEXADECIMAL
Hexadecimal number literal, e.g. 0x01FF.
Definition json.hpp:2852
@ PUNCTUATOR_OPEN_SQUARE_BRACKET
Open square bracket '[' symbol.
Definition json.hpp:2844
@ PUNCTUATOR_COMMA
Comma ',' symbol.
Definition json.hpp:2842
json::ArrayBase< std::allocator > Array
JSON array type using the default allocator.
Definition json.hpp:522
std::istream & operator>>(std::istream &stream, ObjectBase< Allocator > &value)
Read a JSON object from an input stream using the default deserialization options.
Definition json.hpp:4665
void deserializeFromString(grem::StringBase< char, std::char_traits< char >, Allocator > string, T &value, const DeserializationOptions &options={}, DeserializerOverride deserializerOverride={}, const SourceLocation &source={})
Deserialize a value of any JSON-serializable type from a string.
Definition json.hpp:4881
std::ostream & operator<<(std::ostream &stream, const ObjectBase< Allocator > &value)
Write a JSON object to an output stream using the default serialization options.
Definition json.hpp:4641
auto onNull(Callback callback)
Build a Parser::ValueVisitor that handles Null values with a given callback function.
Definition json.hpp:6924
grem::StringBase< char, std::char_traits< char >, Allocator< char > > StringBase
JSON string type.
Definition json.hpp:240
Monostate Null
JSON null type.
Definition json.hpp:227
auto onObject(Callback callback)
Build a Parser::ValueVisitor that handles objects with a given callback function.
Definition json.hpp:7032
void serialize(std::ostream &stream, const T &value, const SerializationOptions &options={}, SerializerOverride serializerOverride={})
Serialize a value of any JSON-serializable type to an output stream.
Definition json.hpp:6738
StringBase< std::allocator > String
JSON string type using the default allocator.
Definition json.hpp:245
json::ValueBase< std::allocator > Value
JSON value type with an associated SourceLocation using the default allocator.
Definition json.hpp:2794
bool Boolean
JSON boolean type.
Definition json.hpp:232
grem::StringBase< char, std::char_traits< char >, Allocator > serializeToString(const T &value, const SerializationOptions &options={}, SerializerOverride serializerOverride={}, const Allocator &allocator=Allocator())
Serialize a value of any JSON-serializable type to a string.
Definition json.hpp:4847
constexpr bool isLineTerminatorCharacter(char32_t codePoint) noexcept
Check if a Unicode code point marks the beginning of a line terminator sequence in JSON5.
Definition json.hpp:2829
auto onString(Callback callback)
Build a Parser::ValueVisitor that handles String values with a given callback function.
Definition json.hpp:6978
auto onBoolean(Callback callback)
Build a Parser::ValueVisitor that handles Boolean values with a given callback function.
Definition json.hpp:6951
ObjectBase< Allocator >::size_type erase_if(ObjectBase< Allocator > &container, Predicate predicate)
Definition json.hpp:7890
grem::json::ArrayBase< std::pmr::polymorphic_allocator > Array
Definition json.hpp:8300
grem::json::StringParserBase< std::pmr::polymorphic_allocator > StringParser
Definition json.hpp:8303
grem::json::StreamParserBase< std::pmr::polymorphic_allocator > StreamParser
Definition json.hpp:8304
grem::json::ValueBase< std::pmr::polymorphic_allocator > Value
Definition json.hpp:8302
grem::json::ObjectBase< std::pmr::polymorphic_allocator > Object
Definition json.hpp:8299
grem::json::StringBase< std::pmr::polymorphic_allocator > String
Definition json.hpp:8298
grem::json::VariantBase< std::pmr::polymorphic_allocator > Variant
Definition json.hpp:8301
Definition Allocation.hpp:554
Definition aliases.hpp:21
constexpr bool isValidCodePoint(char32_t codePoint) noexcept
Check if a 32-bit unsigned integer value falls within the valid ranges for a Unicode code point.
Definition unicode.hpp:28
constexpr InplaceBuffer< char8_t, 4 > encodeUTF8FromCodePoint(char32_t codePoint) noexcept
Encode a Unicode code point into a sequence of UTF-8 code units.
Definition unicode.hpp:136
String toString(int value)
Definition String.hpp:23
CStringViewBase< char8_t, std::char_traits< char8_t > > UTF8CStringView
Definition CStringView.hpp:636
constexpr auto find(input_range auto &&range, const auto &value)
Definition algorithms.hpp:242
constexpr auto unique(forward_range auto &&range)
Definition algorithms.hpp:577
constexpr auto count(input_range auto &&range, const auto &value)
Definition algorithms.hpp:234
constexpr auto lowerBound(forward_range auto &&sortedRange, const auto &value, auto compare)
Definition algorithms.hpp:426
constexpr auto inplaceMerge(bidirectional_range auto &&sortedRange, auto middleIterator)
Definition algorithms.hpp:497
constexpr auto equalRange(forward_range auto &&sortedRange, const auto &value, auto compare)
Definition algorithms.hpp:465
std::ratio< Num, Den > Ratio
Definition time.hpp:19
constexpr auto move(input_range auto &&range, auto outputIterator)
Definition algorithms.hpp:669
String formatString(FormatString< Args... > format, const Args &... args)
Format specification syntax examples:
Definition formatting.hpp:448
GREM_ALWAYS_INLINE constexpr vec< 1, T > GREM_VECTORCALL operator|(vec< 1, T > a, vec< 1, T > b)
Definition math.hpp:1752
constexpr void sort(random_access_range auto &&range)
Definition algorithms.hpp:505
constexpr auto upperBound(forward_range auto &&sortedRange, const auto &value)
Definition algorithms.hpp:457
std::chrono::duration< Rep, Period > DurationBase
Definition time.hpp:39
constexpr bool equal(input_range auto &&rangeA, input_range auto &&rangeB)
Definition algorithms.hpp:358
GREM_ALWAYS_INLINE constexpr vec< N, T > GREM_VECTORCALL trunc(vec< N, T > a)
Definition math.hpp:1420
StringBase< char, std::char_traits< char >, std::allocator< char > > String
Definition String.hpp:17
constexpr bool contains(input_range auto &&range, const auto &value)
Definition algorithms.hpp:299
constexpr detail::Matcher< V > match(V &&variant)
Choose a function overload to execute based on the active alternative of a variant.
Definition Variant.hpp:1922
StringBase< char8_t, std::char_traits< char8_t >, std::allocator< char8_t > > UTF8String
Definition String.hpp:18
StringViewBase< char, std::char_traits< char > > StringView
Definition StringView.hpp:16
std::basic_string< CharT, Traits, Allocator > StringBase
Definition String.hpp:15
GREM_ALWAYS_INLINE constexpr bool GREM_VECTORCALL all(bool a)
Definition math.hpp:1285
StringViewBase< char8_t, std::char_traits< char8_t > > UTF8StringView
Definition StringView.hpp:17
CStringViewBase< char, std::char_traits< char > > CStringView
Definition CStringView.hpp:635
Definition fundamentals.hpp:27
static constexpr T MAX
Definition fundamentals.hpp:29
static constexpr T MIN
Definition fundamentals.hpp:28
Unit type for representing an empty alternative in Variant.
Definition Variant.hpp:242
T1 first
Definition Pair.hpp:57
Options for JSON deserialization.
Definition json.hpp:214
Base template to specialize in order to implement JSON deserialization for a specific type.
Definition json.hpp:4569
Exception type for errors originating from the JSON API.
Definition json.hpp:103
size_t lineNumber
Line number, starting at 1 for the first line.
Definition json.hpp:108
SourceLocation getSource() const noexcept
Definition json.hpp:138
Error(const auto &message, const SourceLocation &source)
Definition json.hpp:116
bool messageAttachesToPrecedingFilepath() const noexcept override
Definition json.hpp:134
size_t columnNumber
Column number, starting at 1 for the first column.
Definition json.hpp:114
void writeMessage(String &output) const override
Definition json.hpp:121
void visitProperty(const SourceLocation &source, StringBase< Allocator > &&key, Parser &parser) override
Callback for each object property.
Definition json.hpp:3588
Visitor visitor
Definition json.hpp:3583
ConcretePropertyVisitor(Visitor visitor)
Definition json.hpp:3585
void visitString(const SourceLocation &source, StringBase< Allocator > &&value) override
Callback for values of type String.
Definition json.hpp:3514
void visitNull(const SourceLocation &source, Null value) override
Callback for values of type Null.
Definition json.hpp:3498
Visitor visitor
Definition json.hpp:3493
void visitObject(const SourceLocation &source, Parser &parser) override
Callback for objects.
Definition json.hpp:3530
void visitArray(const SourceLocation &source, Parser &parser) override
Callback for arrays.
Definition json.hpp:3538
ConcreteValueVisitor(Visitor visitor)
Definition json.hpp:3495
void visitNumber(const SourceLocation &source, Number value) override
Callback for values of type Number.
Definition json.hpp:3522
void visitBoolean(const SourceLocation &source, Boolean value) override
Callback for values of type Boolean.
Definition json.hpp:3506
Implementation of PropertyVisitor that skips over the parsed property and discards the result.
Definition json.hpp:3614
void visitProperty(const SourceLocation &source, StringBase< Allocator > &&key, Parser &parser) override
Callback for each object property.
Definition json.hpp:3616
Implementation of ValueVisitor that skips over the parsed value and discards the result.
Definition json.hpp:3599
void visitBoolean(const SourceLocation &source, Boolean value) override
Callback for values of type Boolean.
Definition json.hpp:3602
void visitNumber(const SourceLocation &source, Number value) override
Callback for values of type Number.
Definition json.hpp:3604
void visitArray(const SourceLocation &source, Parser &parser) override
Callback for arrays.
Definition json.hpp:3606
void visitObject(const SourceLocation &source, Parser &parser) override
Callback for objects.
Definition json.hpp:3605
void visitString(const SourceLocation &source, StringBase< Allocator > &&value) override
Callback for values of type String.
Definition json.hpp:3603
void visitNull(const SourceLocation &source, Null value) override
Callback for values of type Null.
Definition json.hpp:3601
Stateful wrapper object of an input stream for JSON deserialization.
Definition json.hpp:5525
bool nextIsString() const
Check if the next value of the input is a JSON value of type String.
Definition json.hpp:5750
String readString()
Read a single JSON value of type String from the input.
Definition json.hpp:5730
Optional< SourceLocation > readAggregateField(StringView fieldName, Aggregate &aggregate, DeserializerOverride deserializerOverride={})
Read a single JSON value from the input into any value into a specific named field of an aggregate wh...
Definition json.hpp:6505
Optional< Number > readNumberOrNull()
Read a single nullable JSON value of type Number from the input.
Definition json.hpp:5899
Aggregate readAggregateObject(DeserializerOverride deserializerOverride={})
Read a single JSON value from the input into any value of aggregate type whose fields are deserializa...
Definition json.hpp:6580
bool nextIsArray() const
Check if the next value of the input is a JSON value of type Array.
Definition json.hpp:6350
SourceLocation readBoolean(Boolean &value)
Read a single JSON value of type Boolean from the input.
Definition json.hpp:5608
Optional< Array > readArrayOrNull()
Read a single nullable JSON value of type Array from the input.
Definition json.hpp:6365
Reader(std::istream &stream, const SourceLocation &source={}, const DeserializationOptions &options={})
Construct a reader with an input stream as input.
Definition json.hpp:5548
SourceLocation readValue(Value &value)
Read a single JSON value from the input.
Definition json.hpp:6411
Array readArray()
Read a single JSON array from the input into any container of elements that are default-constructible...
Definition json.hpp:6330
SourceLocation readCustomArray(auto readItem)
Read a single JSON array from the input, using a callback function for reading its items.
Definition json.hpp:6171
bool nextIsNull() const
Check if the next value of the input is a JSON value of type Null.
Definition json.hpp:5586
Object readObject()
Read a single JSON object from the input into any container of key-value pairs where the key and valu...
Definition json.hpp:6109
Aggregate readAggregateArray(DeserializerOverride deserializerOverride={})
Read a single JSON value from the input into any value of aggregate type whose fields are deserializa...
Definition json.hpp:6675
T readNumber()
Read a single JSON value of type Number from the input.
Definition json.hpp:5882
bool nextIsBoolean() const
Check if the next value of the input is a JSON value of type Boolean.
Definition json.hpp:5648
DeserializationOptions options
The current options of the deserialization process.
Definition json.hpp:5538
T deserialize(DeserializerOverride deserializerOverride={})
Read a JSON value from the input into any value that is deserializable from JSON using its correspond...
Definition json.hpp:6717
SourceLocation readNumber(T &value)
Read a single JSON value of type Number from the input into any value that Number can be explicitly c...
Definition json.hpp:5812
Optional< Boolean > readBooleanOrNull()
Read a single nullable JSON value of type Boolean from the input.
Definition json.hpp:5663
SourceLocation readAggregateObject(Aggregate &value, DeserializerOverride deserializerOverride={})
Read a single JSON value from the input into any value of aggregate type whose fields are deserializa...
Definition json.hpp:6549
SourceLocation readNumber(Number &value)
Read a single JSON value of type Number from the input.
Definition json.hpp:5789
SourceLocation readArray(Array &value)
Read a single JSON value of type Array from the input.
Definition json.hpp:6220
Optional< Object > readObjectOrNull()
Read a single nullable JSON value of type Object from the input.
Definition json.hpp:6144
Array readArray()
Read a single JSON value of type Array from the input.
Definition json.hpp:6300
typename Parser< It >::Token Token
Token type of the reader's parser.
Definition json.hpp:5533
SourceLocation readString(String &value)
Read a single JSON value of type String from the input.
Definition json.hpp:5687
SourceLocation readArray(auto &value, DeserializerOverride deserializerOverride={})
Read a single JSON array from the input into any container of elements that are default-constructible...
Definition json.hpp:6256
Value readValue()
Read a single JSON value from the input.
Definition json.hpp:6430
SourceLocation readObject(Object &value)
Read a single JSON value of type Object from the input.
Definition json.hpp:5986
bool nextIsObject() const
Check if the next value of the input is a JSON value of type Object.
Definition json.hpp:6129
void deserialize(T &value, DeserializerOverride deserializerOverride={})
Read a JSON value from the input into any value that is deserializable from JSON using its correspond...
Definition json.hpp:7464
Number readNumber()
Read a single JSON value of type Number from the input.
Definition json.hpp:5841
Object readObject()
Read a single JSON value of type Object from the input.
Definition json.hpp:6077
bool nextIsNumber() const
Check if the next value of the input is a JSON value of type Number.
Definition json.hpp:5861
SourceLocation readString(auto &value)
Read a single JSON value of type String from the input into any value that can be assigned from a sta...
Definition json.hpp:5709
SourceLocation readAggregateArray(Aggregate &value, DeserializerOverride deserializerOverride={})
Read a single JSON value from the input into any value of aggregate type whose fields are deserializa...
Definition json.hpp:6615
SourceLocation readCustomObject(auto readProperty)
Read a single JSON object from the input, using a callback function for reading its properties.
Definition json.hpp:5928
Boolean readBoolean()
Read a single JSON value of type Boolean from the input.
Definition json.hpp:5628
SourceLocation readOptional(T &value, DeserializerOverride deserializerOverride={})
Read a single nullable JSON value from the input into any value that is default-constructible,...
Definition json.hpp:6466
SourceLocation readNull()
Read a single JSON value of type Null from the input.
Definition json.hpp:5566
SourceLocation readObject(auto &value, DeserializerOverride deserializerOverride={})
Read a single JSON object from the input into any container of key-value pairs where the key and valu...
Definition json.hpp:6024
SourceLocation readValue(Variant &value)
Read a single JSON value from the input.
Definition json.hpp:6388
Optional< String > readStringOrNull()
Read a single nullable JSON value of type String from the input.
Definition json.hpp:5765
Options for JSON serialization.
Definition json.hpp:146
size_t relativeIndentation
The number of indentation characters that each new level of indentation will add.
Definition json.hpp:157
CStringView newlineString
Null-terminated ASCII string representing the newline sequence to use when performing line breaks.
Definition json.hpp:208
char indentationCharacter
The character to use when performing indentation.
Definition json.hpp:162
size_t indentation
The starting indentation level, expressed as the number of indentation characters.
Definition json.hpp:151
bool prettyPrint
Format the output in a way that is nicely human-readable.
Definition json.hpp:172
size_t prettyPrintMaxSingleLineObjectPropertyCount
Maximum size of an object before it is split into multiple lines when pretty printing.
Definition json.hpp:186
size_t prettyPrintMaxSingleLineArrayItemCount
Maximum size of an array before it is split into multiple lines when pretty printing.
Definition json.hpp:200
Base template to specialize in order to implement JSON serialization for a specific type.
Definition json.hpp:4551
Line and column numbers of a location in a JSON source string.
Definition json.hpp:77
size_t lineNumber
Line number, starting at 1 for the first line.
Definition json.hpp:82
size_t columnNumber
Column number, starting at 1 for the first column.
Definition json.hpp:88
constexpr bool operator==(const SourceLocation &other) const =default
Compare this source location to another for equality.
Token data scanned from JSON.
Definition json.hpp:2863
SourceLocation source
Location of the scanned string in the JSON source string.
Definition json.hpp:2865
StringBase< Allocator > string
Scanned string.
Definition json.hpp:2864
TokenType type
Scanned token type.
Definition json.hpp:2866
Stateful wrapper object of an output stream for JSON serialization.
Definition json.hpp:4925
void writeNewline()
Write a newline sequence to the output.
Definition json.hpp:4989
void writeCustomArray(size_t itemCountHint, auto callback)
Write a single JSON array to the output, using a callback function for writing out the items.
Definition json.hpp:5225
SerializationOptions options
The current options of the serialization process.
Definition json.hpp:4933
void writeNumber(Number value)
Write a single JSON value of type Number to the output.
Definition json.hpp:5091
void writeIndentation()
Write a sequence of indentation characters to the output.
Definition json.hpp:4978
void writeOptional(const auto &value, SerializerOverride serializerOverride={})
Write a single JSON value to the output from any value that supports conversion to bool and the deref...
Definition json.hpp:5321
void writeCustomObject(size_t propertyCountHint, auto callback)
Write a single JSON object to the output, using a callback function for writing out the properties.
Definition json.hpp:5134
void writeAggregateArray(const Aggregate &value, SerializerOverride serializerOverride={})
Write a single JSON value to the output from any value of aggregate type.
Definition json.hpp:5371
void serialize(const T &value, SerializerOverride serializerOverride={})
Write any JSON-serializable value to the output using its corresponding implementation of Serializer.
Definition json.hpp:7410
void writeNull()
Write a single JSON value of type Null to the output.
Definition json.hpp:4998
void writeAggregateObject(const Aggregate &value, SerializerOverride serializerOverride={})
Write a single JSON value to the output from any value of aggregate type.
Definition json.hpp:5346
Writer(std::ostream &stream, const SerializationOptions &options={})
Construct a writer with an output stream as output.
Definition json.hpp:4941
void writeBoolean(Boolean value)
Write a single JSON value of type Boolean to the output.
Definition json.hpp:5009
void writeString(UTF8StringView value)
Write a single JSON value of type String to the output from a raw UTF8 string.
Definition json.hpp:5057
void writeArray(const auto &value, SerializerOverride serializerOverride={})
Write a single JSON array to the output from any range of JSON-serializable values.
Definition json.hpp:5283
void writeString(const auto &value)
Write a single JSON value of type String to the output from any string-view-like or JSON-serializable...
Definition json.hpp:5072
void writeCustomArray(auto callback)
Write a single JSON array to the output, using a callback function for writing out the items.
Definition json.hpp:5264
void write(char ch)
Write a single raw char to the output without any extra formatting.
Definition json.hpp:4952
void writeObject(const auto &value, SerializerOverride serializerOverride={})
Write a single JSON object to the output from any range of JSON-serializable key-value pairs.
Definition json.hpp:5196
void writeCustomObject(auto callback)
Write a single JSON object to the output, using a callback function for writing out the properties.
Definition json.hpp:5177
void write(StringView raw)
Write a raw sequence of chars to the output without any extra formatting.
Definition json.hpp:4963
void writeString(StringView value)
Write a single JSON value of type String to the output from a raw string.
Definition json.hpp:5020
Sentinel type for UTF8Iterator.
Definition unicode.hpp:166