1#ifndef SOURCEMETA_CORE_JSON_VALUE_H_
2#define SOURCEMETA_CORE_JSON_VALUE_H_
4#ifndef SOURCEMETA_CORE_JSON_EXPORT
5#include <sourcemeta/core/json_export.h>
8#include <sourcemeta/core/json_array.h>
9#include <sourcemeta/core/json_hash.h>
10#include <sourcemeta/core/json_object.h>
12#include <sourcemeta/core/numeric.h>
13#include <sourcemeta/core/preprocessor.h>
23#include <initializer_list>
35namespace sourcemeta::core {
39class SOURCEMETA_CORE_JSON_EXPORT
JSON {
50 template <
typename T>
using Allocator = std::allocator<T>;
52 using String = std::basic_string<Char, CharTraits, Allocator<Char>>;
54 using StringView = std::basic_string_view<Char, CharTraits>;
69 enum class Type : std::uint8_t {
106 const std::size_t index,
const String &property)>;
124 explicit JSON(
const std::int64_t value);
134 explicit JSON(
const std::size_t value);
144 explicit JSON(
const int value);
148 template <
typename T = std::
int64_t>
149 explicit JSON(
const long value)
150 requires(!std::is_same_v<T, std::int64_t>)
152 this->data_integer = value;
163 explicit JSON(
const double value);
173 explicit JSON(
const float value);
182 explicit JSON(
const bool value);
191 explicit JSON(
const std::nullptr_t);
219 explicit JSON(
const std::basic_string_view<Char, CharTraits> &value);
247 explicit JSON(std::initializer_list<typename Object::pair_value_type> values);
262 auto operator=(const
JSON &) ->
JSON &;
263 auto operator=(
JSON &&) noexcept ->
JSON &;
332 static auto
size(const
String &value) noexcept -> std::
size_t;
338 auto operator<(const
JSON &other) const ->
bool;
339 auto operator<=(const
JSON &other) const ->
bool;
340 auto operator>(const
JSON &other) const ->
bool;
341 auto operator>=(const
JSON &other) const ->
bool;
355 auto operator==(const
JSON &other) const ->
bool;
356 auto operator!=(const
JSON &) const ->
bool = default;
371 auto operator+(const
JSON &other) const ->
JSON;
386 auto operator-(const
JSON &other) const ->
JSON;
402 auto operator+=(const
JSON &additive) ->
JSON &;
418 auto operator-=(const
JSON &substractive) ->
JSON &;
433 [[nodiscard]] SOURCEMETA_FORCEINLINE inline auto
is_boolean() const noexcept
447 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto is_null() const noexcept
461 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto is_integer() const noexcept
475 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto is_real() const noexcept
490 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto is_integral() const noexcept
492 switch (this->
type()) {
496 Real integral_part = 0.0;
497 return std::modf(this->
to_real(), &integral_part) == 0.0;
518 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto is_number() const noexcept
546 [[nodiscard]] SOURCEMETA_FORCEINLINE inline auto
is_string() const noexcept
561 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto is_array() const noexcept
576 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto is_object() const noexcept
592 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto is_decimal() const noexcept
606 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto type() const noexcept
608 return this->current_type;
626 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto to_boolean() const noexcept
629 return this->data_boolean;
644 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto to_integer() const noexcept
647 return this->data_integer;
662 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto to_real() const noexcept
665 assert(!std::isinf(this->data_real));
666 assert(!std::isnan(this->data_real));
667 return this->data_real;
682 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto to_decimal() const noexcept
685 assert(this->data_decimal.is_finite());
686 assert(!this->data_decimal.is_nan());
687 return this->data_decimal;
702 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto to_string() const noexcept
705 return this->data_string;
745 [[nodiscard]] SOURCEMETA_FORCEINLINE inline auto
as_array() const noexcept
748 return this->data_array;
763 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto as_array() noexcept
766 return this->data_array;
791 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto as_object() noexcept
794 return this->data_object;
815 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto as_object() const noexcept
818 return this->data_object;
833 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto as_real() const ->
Real {
856 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto as_integer() const
862 const auto truncated{std::trunc(this->
to_real())};
863 if (truncated <
static_cast<Real>(std::numeric_limits<Integer>::min()) ||
864 truncated >=
static_cast<Real>(std::numeric_limits<Integer>::max())) {
865 throw std::out_of_range{
866 "The real number does not fit in a 64-bit integer"};
869 return static_cast<Integer>(truncated);
871 const auto integral{this->
to_decimal().to_integral()};
872 if (!integral.is_int64()) {
873 throw std::out_of_range{
874 "The decimal number does not fit in a 64-bit integer"};
877 return integral.to_int64();
903 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
904 at(
const typename Array::size_type index)
const ->
const JSON & {
906 assert(index < this->
size());
907 return this->data_array.data.at(index);
928 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
929 at(
const typename Array::size_type index) ->
JSON & {
931 assert(index < this->
size());
932 return this->data_array.data.at(index);
947 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto at(
const String &key)
const
951 const auto &
object{this->data_object};
952 return object.at(key,
object.hash(key));
956 template <
typename T>
957 requires std::same_as<std::remove_cvref_t<T>, StringView>
958 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto at(T key)
const
962 const auto &
object{this->data_object};
963 return object.at(key,
object.hash(key));
980 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
981 at(
const String &key,
const typename Object::hash_type hash)
const
985 return this->data_object.at(key, hash);
990 template <
typename T>
991 requires std::same_as<std::remove_cvref_t<T>, StringView>
992 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
993 at(T key,
const typename Object::hash_type hash)
const ->
const JSON & {
996 return this->data_object.at(key, hash);
1011 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto at(
const String &key)
1015 auto &
object{this->data_object};
1016 return object.at(key,
object.hash(key));
1020 template <
typename T>
1021 requires std::same_as<std::remove_cvref_t<T>, StringView>
1022 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto at(T key) ->
JSON & {
1025 auto &
object{this->data_object};
1026 return object.at(key,
object.hash(key));
1043 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1047 return this->data_object.at(key, hash);
1052 template <
typename T>
1053 requires std::same_as<std::remove_cvref_t<T>, StringView>
1054 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1055 at(T key,
const typename Object::hash_type hash) ->
JSON & {
1058 return this->data_object.at(key, hash);
1081 ->
const JSON & =
delete;
1100 const typename Object::hash_type hash,
1101 const JSON &otherwise)
const ->
const JSON &;
1106 const typename Object::hash_type hash,
1107 JSON &&otherwise)
const ->
const JSON & =
delete;
1121 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto front() ->
JSON & {
1123 assert(!this->
empty());
1124 return this->data_array.data.front();
1139 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto front() const
1142 assert(!this->
empty());
1143 return this->data_array.data.front();
1158 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto back() ->
JSON & {
1160 assert(!this->
empty());
1161 return this->data_array.data.back();
1176 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto back() const
1179 assert(!this->
empty());
1180 return this->data_array.data.back();
1207 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto size() const -> std::
size_t {
1246 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto array_size() const
1249 return this->data_array.data.size();
1267 return this->data_object.size();
1282 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto byte_size() const
1285 return this->data_string.size();
1354 [[nodiscard]] SOURCEMETA_FORCEINLINE inline auto
empty() const ->
bool {
1356 return this->data_object.empty();
1358 return this->data_array.data.empty();
1360 return this->data_string.empty();
1378 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1381 const auto &
object{this->data_object};
1382 return object.try_at(key,
object.hash(key));
1386 template <
typename T>
1387 requires std::same_as<std::remove_cvref_t<T>, StringView>
1388 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto try_at(T key)
const
1391 const auto &
object{this->data_object};
1392 return object.try_at(key,
object.hash(key));
1411 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1415 const auto &
object{this->data_object};
1416 return object.try_at(key, hash);
1421 template <
typename T>
1422 requires std::same_as<std::remove_cvref_t<T>, StringView>
1423 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1424 try_at(T key,
const typename Object::hash_type hash)
const ->
const JSON * {
1426 const auto &
object{this->data_object};
1427 return object.try_at(key, hash);
1447 auto &
object{this->data_object};
1448 return object.try_at(key,
object.hash(key));
1452 template <
typename T>
1453 requires std::same_as<std::remove_cvref_t<T>, StringView>
1454 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto try_at(T key) ->
JSON * {
1456 auto &
object{this->data_object};
1457 return object.try_at(key,
object.hash(key));
1475 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1478 return this->data_object.try_at(key, hash);
1483 template <
typename T>
1484 requires std::same_as<std::remove_cvref_t<T>, StringView>
1485 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1488 return this->data_object.try_at(key, hash);
1515 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1517 typename Object::size_type &start)
const ->
const JSON * {
1519 const auto &
object{this->data_object};
1520 return object.try_at(key, hash, start);
1525 template <
typename T>
1526 requires std::same_as<std::remove_cvref_t<T>, StringView>
1527 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1528 try_at(T key,
const typename Object::hash_type hash,
1529 typename Object::size_type &start)
const ->
const JSON * {
1531 const auto &
object{this->data_object};
1532 return object.try_at(key, hash, start);
1547 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1550 const auto &
object{this->data_object};
1551 return object.defines(key,
object.hash(key));
1556 template <
typename T>
1557 requires std::same_as<std::remove_cvref_t<T>, StringView>
1558 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto defines(T key)
const
1561 const auto &
object{this->data_object};
1562 return object.defines(key,
object.hash(key));
1579 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1583 return this->data_object.defines(key, hash);
1588 template <
typename T>
1589 requires std::same_as<std::remove_cvref_t<T>, StringView>
1590 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1591 defines(T key,
const typename Object::hash_type hash)
const ->
bool {
1593 return this->data_object.defines(key, hash);
1608 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1609 defines(
const typename Array::size_type index)
const ->
bool {
1610 return this->
defines(std::to_string(index));
1628 template <
typename Iterator>
1629 [[nodiscard]]
auto defines_any(Iterator begin, Iterator end)
const ->
bool {
1631 return std::any_of(begin, end, [
this](
const auto &key) ->
auto {
1648 [[nodiscard]]
auto defines_any(std::initializer_list<String> keys)
const
1692 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1694 const typename Object::hash_type hash,
1697 const auto *member{this->
try_at(key, hash)};
1698 return member !=
nullptr && member->is_array() && member->contains(value);
1712 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto
1734 for (
const auto &element : this->
as_array()) {
1735 if (!element.is_string()) {
1767 [[nodiscard]]
auto includes(
const String::value_type input)
const -> bool;
1847 -> std::pair<std::reference_wrapper<const
JSON>,
bool>;
1867 -> std::pair<std::reference_wrapper<const
JSON>,
bool>;
1887 template <typename T>
1888 requires std::same_as<std::remove_cvref_t<T>,
StringView>
1891 this->data_object.emplace(
String{key}, value);
1911 template <
typename T>
1912 requires std::same_as<std::remove_cvref_t<T>,
StringView>
1915 this->data_object.emplace(
String{key}, std::move(value));
1932 const String &other) -> void;
1958 template <
typename T>
1959 requires std::same_as<std::remove_cvref_t<T>,
StringView>
1963 this->
assign(key, value);
1988 template <
typename T>
1989 requires std::same_as<std::remove_cvref_t<T>,
StringView>
1993 this->
assign(key, std::move(value));
2048 SOURCEMETA_FORCEINLINE
inline auto
2050 const typename Object::hash_type hash,
2052 if (!value.empty()) {
2091 const typename Object::hash_type hash,
2092 const std::span<const StringView> values) ->
void {
2093 if (values.empty()) {
2098 for (
const auto value : values) {
2099 array.push_back(
JSON{value});
2120 const std::span<const StringView> values) ->
void {
2138 template <
typename T>
2139 requires std::same_as<std::remove_cvref_t<T>,
StringView>
2140 auto erase(T key) ->
typename Object::size_type {
2142 return this->data_object.erase(key);
2166 template <
typename Iterator>
2169 for (
auto iterator = first; iterator != last; ++iterator) {
2170 this->data_object.erase(*iterator);
2208 auto erase(
typename Array::const_iterator position) ->
2209 typename Array::iterator;
2224 auto erase(
typename Array::const_iterator first,
2225 typename Array::const_iterator last) ->
typename Array::iterator;
2284 template <
typename Iterator>
2288 for (
auto iterator = first; iterator != last; ++iterator) {
2289 whitelist.insert(*iterator);
2293 for (
const auto &pair : this->
as_object()) {
2294 if (!whitelist.contains(pair.first)) {
2295 blacklist.insert(pair.first);
2299 this->
erase_keys(blacklist.cbegin(), blacklist.cend());
2504#if defined(_MSC_VER)
2505#pragma warning(disable : 4251)
2519 static_assert(
sizeof(
Decimal) <=
sizeof(String));
2520#if defined(_MSC_VER)
2521#pragma warning(default : 4251)
2523 auto maybe_destruct_union() -> void;
static constexpr auto hash(const String &key) noexcept -> hash_type
Definition json_object.h:181
SOURCEMETA_FORCEINLINE auto is_number() const noexcept -> bool
Definition json_value.h:518
SOURCEMETA_FORCEINLINE auto type() const noexcept -> Type
Definition json_value.h:606
SOURCEMETA_FORCEINLINE auto try_at(const String &key) -> JSON *
Definition json_value.h:1444
JSON(const Array &value)
A copy constructor for the array type.
SOURCEMETA_FORCEINLINE auto try_at(const String &key, const typename Object::hash_type hash, typename Object::size_type &start) const -> const JSON *
Definition json_value.h:1516
JSON(const std::nullptr_t)
double Real
The real type used by the JSON document.
Definition json_value.h:48
auto assign_assume_new(String &&key, JSON &&value, Object::hash_type hash) -> JSON &
char Char
The character type used by the JSON document.
Definition json_value.h:42
SOURCEMETA_FORCEINLINE auto try_at(T key) const -> const JSON *
This method tries to retrieve an object element by string view key.
Definition json_value.h:1388
SOURCEMETA_FORCEINLINE auto at(T key, const typename Object::hash_type hash) -> JSON &
Definition json_value.h:1055
auto assign_assume_new(const String &key, JSON &&value) -> void
SOURCEMETA_FORCEINLINE auto try_at(const String &key, const typename Object::hash_type hash) -> JSON *
Definition json_value.h:1476
JSON(std::initializer_list< typename Object::pair_value_type > values)
std::function< void( const ParsePhase phase, const Type type, const std::uint64_t line, const std::uint64_t column, const ParseContext context, const std::size_t index, const String &property)> ParseCallback
Definition json_value.h:103
auto rename(const JSON::String &key, JSON::String &&to) -> void
auto defines_any(std::initializer_list< String > keys) const -> bool
std::int64_t Integer
The integer type used by the JSON document.
Definition json_value.h:46
auto at_or(const String &key, const typename Object::hash_type hash, JSON &&otherwise) const -> const JSON &=delete
SOURCEMETA_FORCEINLINE auto try_at(const String &key, const typename Object::hash_type hash) const -> const JSON *
Definition json_value.h:1412
SOURCEMETA_FORCEINLINE auto to_decimal() const noexcept -> const Decimal &
Definition json_value.h:682
SOURCEMETA_FORCEINLINE auto as_array() const noexcept -> const Array &
Definition json_value.h:745
SOURCEMETA_FORCEINLINE auto defines(const String &key, const typename Object::hash_type hash) const -> bool
Definition json_value.h:1580
SOURCEMETA_FORCEINLINE auto at(T key) const -> const JSON &
This method retrieves an object element by string view key.
Definition json_value.h:958
SOURCEMETA_FORCEINLINE auto to_boolean() const noexcept -> bool
Definition json_value.h:626
SOURCEMETA_FORCEINLINE auto as_object() noexcept -> Object &
Definition json_value.h:791
SOURCEMETA_FORCEINLINE auto as_object() const noexcept -> const Object &
Definition json_value.h:815
std::char_traits< Char > CharTraits
The character traits used by the JSON document.
Definition json_value.h:44
auto unique_keys() const -> bool
auto erase(const String &key) -> typename Object::size_type
static auto make_array() -> JSON
SOURCEMETA_FORCEINLINE auto at(const String &key, const typename Object::hash_type hash) -> JSON &
Definition json_value.h:1044
SOURCEMETA_FORCEINLINE auto size() const -> std::size_t
Definition json_value.h:1207
auto erase_keys(Iterator first, Iterator last) -> void
Definition json_value.h:2167
auto reorder(const KeyComparison &compare) -> void
auto into_array() -> void
SOURCEMETA_FORCEINLINE auto try_at(T key, const typename Object::hash_type hash) -> JSON *
Definition json_value.h:1486
auto into(const JSON &other) -> void
std::basic_string< Char, CharTraits, Allocator< Char > > String
The string type used by the JSON document.
Definition json_value.h:52
auto contains(const StringView element) const -> bool
auto erase(T key) -> typename Object::size_type
This method deletes an object key by string view.
Definition json_value.h:2140
std::bitset< 8 > TypeSet
A set of types.
Definition json_value.h:89
auto is_positive() const noexcept -> bool
SOURCEMETA_FORCEINLINE auto to_real() const noexcept -> Real
Definition json_value.h:662
SOURCEMETA_FORCEINLINE auto as_real() const -> Real
Definition json_value.h:833
std::allocator< T > Allocator
The allocator used by the JSON document.
Definition json_value.h:50
SOURCEMETA_FORCEINLINE auto at(const typename Array::size_type index) -> JSON &
Definition json_value.h:929
SOURCEMETA_FORCEINLINE auto front() -> JSON &
Definition json_value.h:1121
SOURCEMETA_FORCEINLINE auto defines(const typename Array::size_type index) const -> bool
Definition json_value.h:1609
auto contains(const JSON &element) const -> bool
SOURCEMETA_FORCEINLINE auto try_at(T key, const typename Object::hash_type hash, typename Object::size_type &start) const -> const JSON *
Definition json_value.h:1528
SOURCEMETA_FORCEINLINE auto array_size() const -> std::size_t
Definition json_value.h:1246
SOURCEMETA_FORCEINLINE auto at(const String &key) const -> const JSON &
Definition json_value.h:947
SOURCEMETA_FORCEINLINE auto byte_size() const -> std::size_t
Definition json_value.h:1282
std::function< bool(const String &, const String &)> KeyComparison
Definition json_value.h:110
SOURCEMETA_FORCEINLINE auto is_decimal() const noexcept -> bool
Definition json_value.h:592
SOURCEMETA_FORCEINLINE auto assign_if_nonempty(const StringView key, const StringView value) -> void
Definition json_value.h:2069
SOURCEMETA_FORCEINLINE auto is_integral() const noexcept -> bool
Definition json_value.h:490
SOURCEMETA_FORCEINLINE auto at(const String &key, const typename Object::hash_type hash) const -> const JSON &
Definition json_value.h:981
auto try_assign_before(const String &key, const JSON &value, const String &other) -> void
auto assign_if_nonempty(const StringView key, const std::span< const StringView > values) -> void
Definition json_value.h:2119
SOURCEMETA_FORCEINLINE auto as_array() noexcept -> Array &
Definition json_value.h:763
SOURCEMETA_FORCEINLINE auto is_integer() const noexcept -> bool
Definition json_value.h:461
auto push_back(const JSON &value) -> void
auto assign_assume_new(String &&key, JSON &&value) -> void
auto at_or(const String &key, const JSON &otherwise) const -> const JSON &
auto clear_except(Iterator first, Iterator last) -> void
Definition json_value.h:2285
JSON(Decimal &&value)
A move constructor for the decimal type.
Type
The different types of a JSON instance.
Definition json_value.h:69
@ String
The JSON string type.
Definition json_value.h:79
@ Boolean
The JSON boolean type.
Definition json_value.h:73
@ Array
The JSON array type.
Definition json_value.h:81
@ Object
The JSON object type.
Definition json_value.h:83
@ Real
The JSON real number type.
Definition json_value.h:77
@ Decimal
The JSON decimal type.
Definition json_value.h:85
@ Integer
The JSON integer type.
Definition json_value.h:75
@ Null
The JSON null type.
Definition json_value.h:71
auto push_back_if_unique(const JSON &value) -> std::pair< std::reference_wrapper< const JSON >, bool >
auto assign_if_missing(T key, JSON &&value) -> void
Definition json_value.h:1990
auto is_trimmed() const noexcept -> bool
auto estimated_byte_size() const -> std::uint64_t
JSON(const JSON &)
Misc constructors.
JSON(const Char *const value)
SOURCEMETA_FORCEINLINE auto is_object() const noexcept -> bool
Definition json_value.h:576
auto assign(const String &key, JSON &&value) -> void
SOURCEMETA_FORCEINLINE auto front() const -> const JSON &
Definition json_value.h:1139
JSON(const long value)
This constructor creates a JSON document from an integer type.
Definition json_value.h:149
SOURCEMETA_FORCEINLINE auto as_integer() const -> Integer
Definition json_value.h:856
JSON(const std::size_t value)
auto fast_hash() const -> std::uint64_t
auto merge(const JSON::Object &other) -> void
SOURCEMETA_FORCEINLINE auto at(const String &key) -> JSON &
Definition json_value.h:1011
JSONArray< JSON > Array
The array type used by the JSON document.
Definition json_value.h:56
SOURCEMETA_FORCEINLINE auto is_real() const noexcept -> bool
Definition json_value.h:475
SOURCEMETA_FORCEINLINE auto back() const -> const JSON &
Definition json_value.h:1176
auto erase(typename Array::const_iterator first, typename Array::const_iterator last) -> typename Array::iterator
auto clear_except(std::initializer_list< String > keys) -> void
auto assign_if_nonempty(const StringView key, const typename Object::hash_type hash, const std::span< const StringView > values) -> void
Definition json_value.h:2090
JSONObject< String, JSON, PropertyHashJSON< JSON::String > > Object
The object type used by the JSON document.
Definition json_value.h:58
SOURCEMETA_FORCEINLINE auto at(T key) -> JSON &
This method retrieves an object element by string view key.
Definition json_value.h:1022
auto includes(const String &input) const -> bool
auto unique() const -> bool
static auto make_object() -> JSON
SOURCEMETA_FORCEINLINE auto try_at(const String &key) const -> const JSON *
Definition json_value.h:1379
SOURCEMETA_FORCEINLINE auto defines(const String &key) const -> bool
Definition json_value.h:1548
JSON(const String &value)
SOURCEMETA_FORCEINLINE auto array_member_contains(const StringView key, const StringView value) const -> bool
Definition json_value.h:1713
auto defines_any(Iterator begin, Iterator end) const -> bool
Definition json_value.h:1629
ParsePhase
The parsing phase of a JSON document.
Definition json_value.h:60
auto is_array_of_strings() const -> bool
Definition json_value.h:1729
SOURCEMETA_FORCEINLINE auto is_boolean() const noexcept -> bool
Definition json_value.h:433
JSON(JSON &&) noexcept
A move constructor.
SOURCEMETA_FORCEINLINE auto to_integer() const noexcept -> Integer
Definition json_value.h:644
SOURCEMETA_FORCEINLINE auto empty() const -> bool
Definition json_value.h:1354
std::basic_string_view< Char, CharTraits > StringView
The string view type used by the JSON document.
Definition json_value.h:54
auto to_stringstream() const -> std::basic_istringstream< Char, CharTraits, Allocator< Char > >
auto at_or(const String &key, const typename Object::hash_type hash, const JSON &otherwise) const -> const JSON &
auto into_object() -> void
auto erase_if(const std::function< bool(const JSON &)> &predicate) -> void
JSON(const Object &value)
A copy constructor for the object type.
auto assign(const String &key, const JSON &value) -> void
SOURCEMETA_FORCEINLINE auto assign_if_nonempty(const StringView key, const typename Object::hash_type hash, const StringView value) -> void
Definition json_value.h:2049
SOURCEMETA_FORCEINLINE auto is_string() const noexcept -> bool
Definition json_value.h:546
auto includes(const String::value_type input) const -> bool
auto assign_if_missing(T key, const JSON &value) -> void
Definition json_value.h:1960
auto trim() const -> JSON::String
SOURCEMETA_FORCEINLINE auto object_size() const -> std::size_t
Definition json_value.h:1264
SOURCEMETA_FORCEINLINE auto try_at(T key, const typename Object::hash_type hash) const -> const JSON *
Definition json_value.h:1424
auto erase_keys(std::initializer_list< String > keys) -> void
JSON(const std::int64_t value)
auto at_or(const String &key, JSON &&otherwise) const -> const JSON &=delete
SOURCEMETA_FORCEINLINE auto is_array() const noexcept -> bool
Definition json_value.h:561
JSON(const std::basic_string_view< Char, CharTraits > &value)
SOURCEMETA_FORCEINLINE auto string_size() const -> std::size_t
Definition json_value.h:1228
SOURCEMETA_FORCEINLINE auto try_at(T key) -> JSON *
This method tries to retrieve a mutable object element by string view key.
Definition json_value.h:1454
ParseContext
The context type for parse callbacks.
Definition json_value.h:92
JSON(const Decimal &value)
A copy constructor for the decimal type.
auto assign(T key, JSON &&value) -> void
Definition json_value.h:1913
SOURCEMETA_FORCEINLINE auto defines(T key) const -> bool
Definition json_value.h:1558
SOURCEMETA_FORCEINLINE auto array_member_contains(const StringView key, const typename Object::hash_type hash, const StringView value) const -> bool
Definition json_value.h:1693
SOURCEMETA_FORCEINLINE auto defines(T key, const typename Object::hash_type hash) const -> bool
Definition json_value.h:1591
SOURCEMETA_FORCEINLINE auto is_null() const noexcept -> bool
Definition json_value.h:447
SOURCEMETA_FORCEINLINE auto at(T key, const typename Object::hash_type hash) const -> const JSON &
Definition json_value.h:993
static auto size(const String &value) noexcept -> std::size_t
auto assign_if_missing(const String &key, JSON &&value) -> void
auto erase(typename Array::const_iterator position) -> typename Array::iterator
SOURCEMETA_FORCEINLINE auto at(const typename Array::size_type index) const -> const JSON &
Definition json_value.h:904
auto divisible_by(const JSON &divisor) const -> bool
auto assign_if_missing(const String &key, const JSON &value) -> void
SOURCEMETA_FORCEINLINE auto back() -> JSON &
Definition json_value.h:1158
SOURCEMETA_FORCEINLINE auto to_string() const noexcept -> const String &
Definition json_value.h:702
@ Index
A map of index labels carrying no RDF ranging over an object.
Definition jsonld_materialize.h:116
@ Post
A client_secret in the request body (RFC 6749 Section 2.3.1).
Definition oauth_client_authentication.h:85