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_error.h>
10#include <sourcemeta/core/json_hash.h>
11#include <sourcemeta/core/json_object.h>
13#include <sourcemeta/core/numeric.h>
14#include <sourcemeta/core/preprocessor.h>
24#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<Object::pair_value_type> values);
262 auto operator=(
const JSON &other) ->
JSON &;
263 auto operator=(
JSON &&other)
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
auto is_boolean() const noexcept
447 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto is_null() const noexcept ->
bool {
460 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto is_integer() const noexcept
474 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto is_real() const noexcept ->
bool {
488 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto is_integral() const noexcept
490 switch (this->
type()) {
494 Real integral_part = 0.0;
495 return std::modf(this->
to_real(), &integral_part) == 0.0;
516 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto is_number() const noexcept ->
bool {
540 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto is_double() const noexcept ->
bool {
569 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto is_float() const noexcept ->
bool {
603 [[nodiscard]] SOURCEMETA_FORCEINLINE auto
is_string() const noexcept ->
bool {
617 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto is_array() const noexcept ->
bool {
631 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto is_object() const noexcept ->
bool {
646 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto is_decimal() const noexcept
660 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto type() const noexcept ->
Type {
661 return this->current_type_;
679 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto to_boolean() const noexcept
682 return this->data_boolean;
697 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto to_integer() const noexcept
700 return this->data_integer;
715 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto to_real() const noexcept ->
Real {
717 assert(!std::isinf(this->data_real));
718 assert(!std::isnan(this->data_real));
719 return this->data_real;
734 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto to_decimal() const noexcept
737 assert(this->data_decimal.is_finite());
738 assert(!this->data_decimal.is_nan());
739 return this->data_decimal;
754 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto to_string() const noexcept
757 return this->data_string;
797 [[nodiscard]] SOURCEMETA_FORCEINLINE auto
as_array() const noexcept
800 return this->data_array;
817 return this->data_array;
844 return this->data_object;
865 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto as_object() const noexcept
868 return this->data_object;
884 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto as_real() const ->
Real {
913 const auto truncated{std::trunc(this->
to_real())};
914 if (truncated <
static_cast<Real>(std::numeric_limits<Integer>::min()) ||
915 truncated >=
static_cast<Real>(std::numeric_limits<Integer>::max())) {
917 "The real number does not fit in a 64-bit integer"};
920 return static_cast<Integer>(truncated);
922 const auto integral{this->
to_decimal().to_integral()};
923 if (!integral.is_int64()) {
925 "The decimal number does not fit in a 64-bit integer"};
928 return integral.to_int64();
953 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
954 at(
const Array::size_type index)
const ->
const JSON & {
956 assert(index < this->
size());
957 return this->data_array.data_[index];
978 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto at(
const Array::size_type index)
981 assert(index < this->
size());
982 return this->data_array.data_[index];
997 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto at(
const String &key)
const
1001 const auto &
object{this->data_object};
1002 return object.at(key,
object.hash(key));
1006 template <
typename T>
1007 requires std::same_as<std::remove_cvref_t<T>, StringView>
1008 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto at(T key)
const ->
const JSON & {
1011 const auto &
object{this->data_object};
1012 return object.at(key,
object.hash(key));
1029 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1030 at(
const String &key,
const Object::hash_type hash)
const ->
const JSON & {
1033 return this->data_object.at(key, hash);
1038 template <
typename T>
1039 requires std::same_as<std::remove_cvref_t<T>, StringView>
1040 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1041 at(T key,
const Object::hash_type hash)
const ->
const JSON & {
1044 return this->data_object.at(key, hash);
1059 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto at(
const String &key) ->
JSON & {
1062 auto &
object{this->data_object};
1063 return object.at(key,
object.hash(key));
1067 template <
typename T>
1068 requires std::same_as<std::remove_cvref_t<T>, StringView>
1069 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto at(T key) ->
JSON & {
1072 auto &
object{this->data_object};
1073 return object.at(key,
object.hash(key));
1090 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto at(
const String &key,
1091 const Object::hash_type hash)
1095 return this->data_object.at(key, hash);
1100 template <
typename T>
1101 requires std::same_as<std::remove_cvref_t<T>, StringView>
1102 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto at(T key,
1103 const Object::hash_type hash)
1107 return this->data_object.at(key, hash);
1130 ->
const JSON & =
delete;
1148 [[nodiscard]]
auto at_or(
const String &key,
const Object::hash_type &hash,
1149 const JSON &otherwise)
const ->
const JSON &;
1153 [[nodiscard]]
auto at_or(
const String &key,
const Object::hash_type &hash,
1154 JSON &&otherwise)
const ->
const JSON & =
delete;
1168 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto front() ->
JSON & {
1170 assert(!this->
empty());
1171 return this->data_array.data_.front();
1186 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto front() const -> const
JSON & {
1188 assert(!this->
empty());
1189 return this->data_array.data_.front();
1204 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto back() ->
JSON & {
1206 assert(!this->
empty());
1207 return this->data_array.data_.back();
1222 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto back() const -> const
JSON & {
1224 assert(!this->
empty());
1225 return this->data_array.data_.back();
1252 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto size() const -> std::
size_t {
1273 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto string_size() const -> std::
size_t {
1290 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto array_size() const -> std::
size_t {
1292 return this->data_array.data_.size();
1307 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto object_size() const -> std::
size_t {
1309 return this->data_object.size();
1324 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto byte_size() const -> std::
size_t {
1326 return this->data_string.size();
1395 [[nodiscard]] SOURCEMETA_FORCEINLINE auto
empty() const ->
bool {
1397 return this->data_object.empty();
1400 return this->data_array.data_.empty();
1402 return this->data_string.empty();
1422 const auto &
object{this->data_object};
1423 return object.try_at(key,
object.hash(key));
1427 template <
typename T>
1428 requires std::same_as<std::remove_cvref_t<T>, StringView>
1429 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto try_at(T key)
const
1432 const auto &
object{this->data_object};
1433 return object.try_at(key,
object.hash(key));
1452 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1456 const auto &
object{this->data_object};
1457 return object.try_at(key, hash);
1462 template <
typename T>
1463 requires std::same_as<std::remove_cvref_t<T>, StringView>
1464 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1465 try_at(T key,
const Object::hash_type hash)
const ->
const JSON * {
1467 const auto &
object{this->data_object};
1468 return object.try_at(key, hash);
1488 auto &
object{this->data_object};
1489 return object.try_at(key,
object.hash(key));
1493 template <
typename T>
1494 requires std::same_as<std::remove_cvref_t<T>, StringView>
1495 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto try_at(T key) ->
JSON * {
1497 auto &
object{this->data_object};
1498 return object.try_at(key,
object.hash(key));
1517 const Object::hash_type hash)
1520 return this->data_object.try_at(key, hash);
1525 template <
typename T>
1526 requires std::same_as<std::remove_cvref_t<T>, StringView>
1527 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto try_at(T key,
1528 const Object::hash_type hash)
1531 return this->data_object.try_at(key, hash);
1558 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1560 Object::size_type &start)
const ->
const JSON * {
1562 const auto &
object{this->data_object};
1563 return object.try_at(key, hash, start);
1568 template <
typename T>
1569 requires std::same_as<std::remove_cvref_t<T>, StringView>
1570 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1571 try_at(T key,
const Object::hash_type hash, Object::size_type &start)
const
1574 const auto &
object{this->data_object};
1575 return object.try_at(key, hash, start);
1593 const auto &
object{this->data_object};
1594 return object.defines(key,
object.hash(key));
1599 template <
typename T>
1600 requires std::same_as<std::remove_cvref_t<T>, StringView>
1601 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto defines(T key)
const ->
bool {
1603 const auto &
object{this->data_object};
1604 return object.defines(key,
object.hash(key));
1621 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1624 return this->data_object.defines(key, hash);
1629 template <
typename T>
1630 requires std::same_as<std::remove_cvref_t<T>, StringView>
1631 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1632 defines(T key,
const Object::hash_type hash)
const ->
bool {
1634 return this->data_object.defines(key, hash);
1649 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1650 defines(
const Array::size_type index)
const ->
bool {
1651 return this->
defines(std::to_string(index));
1669 template <
typename Iterator>
1670 [[nodiscard]]
auto defines_any(Iterator begin, Iterator end)
const ->
bool {
1672 return std::any_of(begin, end, [
this](
const auto &key) ->
auto {
1689 [[nodiscard]]
auto defines_any(std::initializer_list<String> keys)
const
1733 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1737 const auto *member{this->
try_at(key, hash)};
1738 return member !=
nullptr && member->is_array() && member->contains(value);
1752 [[nodiscard]] SOURCEMETA_FORCEINLINE
auto
1774 for (
const auto &element : this->
as_array()) {
1775 if (!element.is_string()) {
1807 [[nodiscard]]
auto includes(
const String::value_type input)
const -> bool;
1887 -> std::pair<std::reference_wrapper<const
JSON>,
bool>;
1907 -> std::pair<std::reference_wrapper<const
JSON>,
bool>;
1927 template <typename T>
1928 requires std::same_as<std::remove_cvref_t<T>,
StringView>
1931 this->data_object.emplace(
String{key}, value);
1951 template <
typename T>
1952 requires std::same_as<std::remove_cvref_t<T>,
StringView>
1955 this->data_object.emplace(
String{key}, std::move(value));
1972 const String &other) -> void;
1998 template <
typename T>
1999 requires std::same_as<std::remove_cvref_t<T>,
StringView>
2003 this->
assign(key, value);
2028 template <
typename T>
2029 requires std::same_as<std::remove_cvref_t<T>,
StringView>
2033 this->
assign(key, std::move(value));
2073 const Object::hash_type &hash) ->
JSON &;
2089 const Object::hash_type hash,
2092 if (!value.empty()) {
2131 const std::span<const StringView> values) ->
void {
2132 if (values.empty()) {
2137 for (
const auto value : values) {
2138 array.push_back(
JSON{value});
2159 const std::span<const StringView> values) ->
void {
2177 template <
typename T>
2178 requires std::same_as<std::remove_cvref_t<T>,
StringView>
2179 auto erase(T key) -> Object::size_type {
2181 return this->data_object.erase(key);
2197 const Object::hash_type hash)
2198 -> Object::size_type {
2200 return this->data_object.erase(key, hash);
2205 template <
typename T>
2206 requires std::same_as<std::remove_cvref_t<T>, StringView>
2207 SOURCEMETA_FORCEINLINE
auto erase(T key,
const Object::hash_type hash)
2208 -> Object::size_type {
2210 return this->data_object.erase(key, hash);
2234 template <
typename Iterator>
2237 for (
auto iterator = first; iterator != last; ++iterator) {
2238 this->data_object.erase(*iterator);
2276 auto erase(Array::const_iterator position) -> Array::iterator;
2291 auto erase(Array::const_iterator first, Array::const_iterator last)
2351 template <
typename Iterator>
2355 for (
auto iterator = first; iterator != last; ++iterator) {
2356 whitelist.insert(*iterator);
2360 for (
const auto &pair : this->
as_object()) {
2361 if (!whitelist.contains(pair.first)) {
2362 blacklist.insert(pair.first);
2366 this->
erase_keys(blacklist.cbegin(), blacklist.cend());
2571#if defined(_MSC_VER)
2572#pragma warning(push)
2573#pragma warning(disable : 4251)
2587 static_assert(
sizeof(
Decimal) <=
sizeof(String));
2588#if defined(_MSC_VER)
2591 auto maybe_destruct_union() -> void;
static constexpr auto hash(const String &key) noexcept -> hash_type
Definition json_object.h:190
SOURCEMETA_FORCEINLINE auto is_number() const noexcept -> bool
Definition json_value.h:516
JSON(const JSON &other)
Misc constructors.
SOURCEMETA_FORCEINLINE auto type() const noexcept -> Type
Definition json_value.h:660
SOURCEMETA_FORCEINLINE auto try_at(const String &key) -> JSON *
Definition json_value.h:1485
SOURCEMETA_FORCEINLINE auto defines(const Array::size_type index) const -> bool
Definition json_value.h:1650
JSON(const Array &value)
A copy constructor for the array type.
JSON(const std::nullptr_t)
double Real
The real type used by the JSON document.
Definition json_value.h:48
char Char
The character type used by the JSON document.
Definition json_value.h:42
SOURCEMETA_FORCEINLINE auto try_at(const String &key, const Object::hash_type hash) const -> const JSON *
Definition json_value.h:1453
auto assign_assume_new(const String &key, JSON &&value) -> void
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 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
SOURCEMETA_FORCEINLINE auto at(const String &key, const Object::hash_type hash) const -> const JSON &
Definition json_value.h:1030
SOURCEMETA_FORCEINLINE auto to_decimal() const noexcept -> const Decimal &
Definition json_value.h:734
SOURCEMETA_FORCEINLINE auto at(const Array::size_type index) -> JSON &
Definition json_value.h:978
SOURCEMETA_FORCEINLINE auto as_array() const noexcept -> const Array &
Definition json_value.h:797
auto assign_if_missing(T key, JSON &&value) -> void
Definition json_value.h:2030
SOURCEMETA_FORCEINLINE auto to_boolean() const noexcept -> bool
Definition json_value.h:679
SOURCEMETA_FORCEINLINE auto as_object() noexcept -> Object &
Definition json_value.h:842
SOURCEMETA_FORCEINLINE auto at(T key) const -> const JSON &
This method retrieves an object element by string view key.
Definition json_value.h:1008
SOURCEMETA_FORCEINLINE auto as_object() const noexcept -> const Object &
Definition json_value.h:865
std::char_traits< Char > CharTraits
The character traits used by the JSON document.
Definition json_value.h:44
auto unique_keys() const -> bool
static auto make_array() -> JSON
auto assign_assume_new(String &&key, JSON &&value, const Object::hash_type &hash) -> JSON &
SOURCEMETA_FORCEINLINE auto size() const -> std::size_t
Definition json_value.h:1252
SOURCEMETA_FORCEINLINE auto defines(T key) const -> bool
Definition json_value.h:1601
auto erase_keys(Iterator first, Iterator last) -> void
Definition json_value.h:2235
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:1429
auto reorder(const KeyComparison &compare) -> void
auto into_array() -> void
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
std::bitset< 8 > TypeSet
A set of types.
Definition json_value.h:89
auto is_positive() const noexcept -> bool
SOURCEMETA_FORCEINLINE auto at(const String &key, const Object::hash_type hash) -> JSON &
Definition json_value.h:1090
SOURCEMETA_FORCEINLINE auto to_real() const noexcept -> Real
Definition json_value.h:715
SOURCEMETA_FORCEINLINE auto as_real() const -> Real
Definition json_value.h:884
std::allocator< T > Allocator
The allocator used by the JSON document.
Definition json_value.h:50
SOURCEMETA_FORCEINLINE auto defines(T key, const Object::hash_type hash) const -> bool
Definition json_value.h:1632
JSON(std::initializer_list< Object::pair_value_type > values)
SOURCEMETA_FORCEINLINE auto try_at(T key, const Object::hash_type hash, Object::size_type &start) const -> const JSON *
Definition json_value.h:1571
SOURCEMETA_FORCEINLINE auto front() -> JSON &
Definition json_value.h:1168
auto contains(const JSON &element) const -> bool
SOURCEMETA_FORCEINLINE auto is_float() const noexcept -> bool
Definition json_value.h:569
SOURCEMETA_FORCEINLINE auto array_size() const -> std::size_t
Definition json_value.h:1290
SOURCEMETA_FORCEINLINE auto at(const String &key) const -> const JSON &
Definition json_value.h:997
SOURCEMETA_FORCEINLINE auto byte_size() const -> std::size_t
Definition json_value.h:1324
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:646
SOURCEMETA_FORCEINLINE auto assign_if_nonempty(const StringView key, const StringView value) -> void
Definition json_value.h:2109
SOURCEMETA_FORCEINLINE auto is_integral() const noexcept -> bool
Definition json_value.h:488
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:2158
SOURCEMETA_FORCEINLINE auto as_array() noexcept -> Array &
Definition json_value.h:815
SOURCEMETA_FORCEINLINE auto is_integer() const noexcept -> bool
Definition json_value.h:460
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 &
static auto make_array(std::initializer_list< JSON > values) -> JSON
auto clear_except(Iterator first, Iterator last) -> void
Definition json_value.h:2352
JSON(Decimal &&value)
A move constructor for the decimal type.
SOURCEMETA_FORCEINLINE auto try_at(const String &key, const Object::hash_type hash) -> JSON *
Definition json_value.h:1516
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 >
SOURCEMETA_FORCEINLINE auto erase(T key, const Object::hash_type hash) -> Object::size_type
Definition json_value.h:2207
auto is_trimmed() const noexcept -> bool
auto estimated_byte_size() const -> std::uint64_t
JSON(const Char *const value)
SOURCEMETA_FORCEINLINE auto is_object() const noexcept -> bool
Definition json_value.h:631
auto assign(const String &key, JSON &&value) -> void
auto assign_if_nonempty(const StringView key, const Object::hash_type hash, const std::span< const StringView > values) -> void
Definition json_value.h:2130
SOURCEMETA_FORCEINLINE auto front() const -> const JSON &
Definition json_value.h:1186
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:907
JSON(const std::size_t value)
SOURCEMETA_FORCEINLINE auto erase(const String &key, const Object::hash_type hash) -> Object::size_type
Definition json_value.h:2196
SOURCEMETA_FORCEINLINE auto defines(const String &key, const Object::hash_type hash) const -> bool
Definition json_value.h:1622
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:1059
JSONArray< JSON > Array
The array type used by the JSON document.
Definition json_value.h:56
auto rename(const JSON::String &key, JSON::String &&target) -> void
auto assign(T key, JSON &&value) -> void
Definition json_value.h:1953
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:1495
SOURCEMETA_FORCEINLINE auto at(const Array::size_type index) const -> const JSON &
Definition json_value.h:954
SOURCEMETA_FORCEINLINE auto is_real() const noexcept -> bool
Definition json_value.h:474
SOURCEMETA_FORCEINLINE auto at(T key) -> JSON &
This method retrieves an object element by string view key.
Definition json_value.h:1069
SOURCEMETA_FORCEINLINE auto back() const -> const JSON &
Definition json_value.h:1222
auto clear_except(std::initializer_list< String > keys) -> void
JSONObject< String, JSON, PropertyHashJSON< JSON::String > > Object
The object type used by the JSON document.
Definition json_value.h:58
auto includes(const String &input) const -> bool
auto unique() const -> bool
static auto make_object() -> JSON
auto at_or(const String &key, const Object::hash_type &hash, const JSON &otherwise) const -> const JSON &
SOURCEMETA_FORCEINLINE auto try_at(const String &key) const -> const JSON *
Definition json_value.h:1419
SOURCEMETA_FORCEINLINE auto defines(const String &key) const -> bool
Definition json_value.h:1590
auto erase(const String &key) -> Object::size_type
JSON(const String &value)
SOURCEMETA_FORCEINLINE auto array_member_contains(const StringView key, const StringView value) const -> bool
Definition json_value.h:1753
auto defines_any(Iterator begin, Iterator end) const -> bool
Definition json_value.h:1670
ParsePhase
The parsing phase of a JSON document.
Definition json_value.h:60
auto is_array_of_strings() const -> bool
Definition json_value.h:1769
SOURCEMETA_FORCEINLINE auto is_boolean() const noexcept -> bool
Definition json_value.h:433
SOURCEMETA_FORCEINLINE auto to_integer() const noexcept -> Integer
Definition json_value.h:697
SOURCEMETA_FORCEINLINE auto empty() const -> bool
Definition json_value.h:1395
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 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_if_missing(T key, const JSON &value) -> void
Definition json_value.h:2000
auto at_or(const String &key, const Object::hash_type &hash, JSON &&otherwise) const -> const JSON &=delete
auto assign(const String &key, const JSON &value) -> void
SOURCEMETA_FORCEINLINE auto is_string() const noexcept -> bool
Definition json_value.h:603
auto includes(const String::value_type input) const -> bool
SOURCEMETA_FORCEINLINE auto try_at(T key, const Object::hash_type hash) const -> const JSON *
Definition json_value.h:1465
auto trim() const -> JSON::String
SOURCEMETA_FORCEINLINE auto object_size() const -> std::size_t
Definition json_value.h:1307
auto erase_keys(std::initializer_list< String > keys) -> void
SOURCEMETA_FORCEINLINE auto at(T key, const Object::hash_type hash) -> JSON &
Definition json_value.h:1102
SOURCEMETA_FORCEINLINE auto assign_if_nonempty(const StringView key, const Object::hash_type hash, const StringView value) -> void
Definition json_value.h:2088
SOURCEMETA_FORCEINLINE auto array_member_contains(const StringView key, const Object::hash_type hash, const StringView value) const -> bool
Definition json_value.h:1734
JSON(const std::int64_t value)
SOURCEMETA_FORCEINLINE auto try_at(T key, const Object::hash_type hash) -> JSON *
Definition json_value.h:1527
auto at_or(const String &key, JSON &&otherwise) const -> const JSON &=delete
SOURCEMETA_FORCEINLINE auto is_array() const noexcept -> bool
Definition json_value.h:617
JSON(const std::basic_string_view< Char, CharTraits > &value)
SOURCEMETA_FORCEINLINE auto string_size() const -> std::size_t
Definition json_value.h:1273
auto erase(Array::const_iterator position) -> Array::iterator
ParseContext
The context type for parse callbacks.
Definition json_value.h:92
JSON(const Decimal &value)
A copy constructor for the decimal type.
auto erase(T key) -> Object::size_type
This method deletes an object key by string view.
Definition json_value.h:2179
auto erase(Array::const_iterator first, Array::const_iterator last) -> Array::iterator
SOURCEMETA_FORCEINLINE auto is_null() const noexcept -> bool
Definition json_value.h:447
SOURCEMETA_FORCEINLINE auto at(T key, const Object::hash_type hash) const -> const JSON &
Definition json_value.h:1041
static auto size(const String &value) noexcept -> std::size_t
auto assign_if_missing(const String &key, JSON &&value) -> void
SOURCEMETA_FORCEINLINE auto is_double() const noexcept -> bool
Definition json_value.h:540
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:1204
JSON(JSON &&other) noexcept
A move constructor.
SOURCEMETA_FORCEINLINE auto to_string() const noexcept -> const String &
Definition json_value.h:754
SOURCEMETA_FORCEINLINE auto try_at(const String &key, const Object::hash_type hash, Object::size_type &start) const -> const JSON *
Definition json_value.h:1559
@ Index
A map of index labels carrying no RDF ranging over an object.
Definition jsonld_materialize.h:116
constexpr auto is_representable_as(const Integer value) -> bool
Definition numeric_util.h:419
@ Post
A client_secret in the request body (RFC 6749 Section 2.3.1).
Definition oauth_client_authentication.h:85