![]() |
Thoth
A functional, expressive, asynchronous C++26 webdev library
|
#include <Json.hpp>
Public Types | |
| using | Value = std::variant< Null, String, Number, Bool, Object, Array > |
| using | PredicatePointer = bool(*)(const Json &) |
Public Member Functions | |
| Json () | |
| Json (const JsonObject &child) | |
| Json (JsonObject &&child) | |
| Json (const Array &child) | |
| Json (Array &&child) | |
| Json (Value &&newValue) noexcept | |
| Json (const Value &newValue) | |
| Json (Json &&other) noexcept | |
| Json (const Json &other) | |
| Json (bool other) | |
| template<class T > requires std::floating_point<T> || std::integral<T> && (!std::same_as<T, bool>) | |
| Json (T other) | |
| template<class T > requires std::constructible_from<std::string, T> | |
| Json (T &&other) | |
| Json & | operator= (const JsonObject &other) |
| Json & | operator= (JsonObject &&other) |
| Json & | operator= (const Array &child) |
| Json & | operator= (Array &&child) |
| Json & | operator= (Value &&newValue) noexcept |
| Json & | operator= (const Value &newValue) |
| Json & | operator= (Json &&other) noexcept |
| Json & | operator= (const Json &other) |
| Json & | operator= (bool other) |
| template<class T > requires std::floating_point<T> || std::integral<T> && (!std::same_as<T, bool>) | |
| Json & | operator= (T other) |
| template<class T > requires std::constructible_from<std::string, T> | |
| Json & | operator= (T &&other) |
| operator Value & () | |
| operator const Value & () const | |
| template<class T > | |
| bool | IsOf () const |
| template<class T > | |
| T & | As () |
| template<class T > | |
| const T & | As () const |
| template<class T > | |
| T & | AsMut () |
| template<class T > | |
| T | AsMov () && |
| template<class T > | |
| const T & | AsRef () const |
| template<class T > | |
| std::optional< T * > | Ensure () |
| template<class T > | |
| std::optional< T * > | Ensure () const |
| template<class T > | |
| std::optional< T * > | EnsureMut () |
| template<class T > | |
| std::optional< T > | EnsureMov () && |
| template<class T > | |
| std::optional< const T * > | EnsureRef () const |
| template<class T > | |
| std::expected< T *, Http::RequestError > | EnsureOrError () |
| template<class T > | |
| std::expected< T *, Http::RequestError > | EnsureOrError () const |
| template<class T > | |
| std::expected< T *, Http::RequestError > | EnsureMutOrError () |
| template<class T > | |
| std::expected< T, Http::RequestError > | EnsureMovOrError () && |
| template<class T > | |
| std::expected< const T *, Http::RequestError > | EnsureRefOrError () const |
| bool | operator== (const Json &other) const |
| template<class Callable > | |
| constexpr decltype(auto) | Visit (Callable &&callable) |
| convenient call to std::visit() on _value. | |
| template<class Callable > | |
| constexpr decltype(auto) | Visit (Callable &&callable) const |
| convenient call to std::visit() on _value. | |
Get Functions | |
Will get the direct child of this element with a given key/index. | |
| OptRefValWrapper | Get (Key key) |
| Return a ref of the element with this index/key if this is an Object or Array, std::nullopt otherwise. | |
| OptCRefValWrapper | Get (Key key) const |
| Return a ref of the element with this index/key if this is an Object or Array, std::nullopt otherwise. | |
| OptValWrapper | GetCopy (Key key) const |
| Return a copy of the element with this index/key if this is an Object or Array, std::nullopt otherwise. | |
| OptValWrapper | GetAndMove (Key key) && |
| Return (with move) the element with this index/key if this is an Object or Array, std::nullopt otherwise. | |
| ValWrapper | GetCopyOrNull (Key key) const |
| Return a copy of the element with this index/key if this is an Object or Array, null otherwise. | |
| ValWrapper | GetAndMoveOrNull (Key key) && |
| Move the element with this index/key if this is an Object or Array, null otherwise. | |
| ExpRefValWrapper | GetOrError (Key key) |
| Return a ref of the element with this index/key if this is an Object or Array, RequestError otherwise. | |
| ExpCRefValWrapper | GetOrError (Key key) const |
| Return a ref of the element with this index/key if this is an Object or Array, RequestError otherwise. | |
| ExpValWrapper | GetCopyOrError (Key key) const |
| Return a copy of the element with this index/key if this is an Object or Array, RequestError otherwise. | |
| ExpValWrapper | GetAndMoveOrError (Key key) && |
| Move the element with this index/key if this is an Object or Array. Return RequestError otherwise. | |
Find Functions | |
Will find a nested child in the tree. Something like | |
| OptRefValWrapper | Find (Keys keys) |
| Same as successive calls to Get, std::nullopt at the first fail. | |
| OptCRefValWrapper | Find (Keys keys) const |
| Same as successive calls to Get, std::nullopt at the first fail. | |
| OptValWrapper | FindCopy (Keys keys) const |
| Same as successive calls to GetCopy, std::nullopt at the first fail. | |
| OptValWrapper | FindAndMove (Keys keys) && |
| Same as successive calls to GetAndMove, std::nullopt at the first fail. | |
| ValWrapper | FindCopyOrNull (Keys keys) const |
| Same as successive calls to GetCopy. Return null at the first fail. | |
| ValWrapper | FindAndMoveOrNull (Keys keys) && |
| Same as successive calls to GetAndMove. Return null at the first fail. | |
| ExpRefValWrapper | FindOrError (Keys keys) |
| Same as successive calls to Get. Return RequestError at the first fail. | |
| ExpCRefValWrapper | FindOrError (Keys keys) const |
| Same as successive calls to Get. Return RequestError at the first fail. | |
| ExpValWrapper | FindCopyOrError (Keys keys) const |
| Same as successive calls to GetCopy. Return RequestError at the first fail. | |
| ExpValWrapper | FindAndMoveOrError (Keys keys) && |
| Same as successive calls to Find. Return RequestError at the first fail. | |
Search Functions | |
Will pick the fist element that satisfies the given predicate. | |
| template<class Pred = PredicatePointer> requires std::predicate<Pred, Json> | |
| OptRefValWrapper | Search (Pred &&pred) |
| Will search the childs for the first element that matches the predicate and return it, or std::nullopt if no matches. | |
| template<class Pred = PredicatePointer> requires std::predicate<Pred, Json> | |
| OptCRefValWrapper | Search (Pred &&pred) const |
| Will search the childs for the first element that matches the predicate and return it, or std::nullopt if no matches. | |
| template<class Pred = PredicatePointer> requires std::predicate<Pred, Json> | |
| OptValWrapper | SearchCopy (Pred &&pred) const |
| Will search the childs for the first element that matches the predicate and clone it, or std::nullopt if no matches. | |
| template<class Pred = PredicatePointer> requires std::predicate<Pred, Json> | |
| OptValWrapper | SearchAndMove (Pred &&pred) && |
| Will search the childs for the first element that matches the predicate and move it, or std::nullopt if no matches. | |
| template<class Pred = PredicatePointer> requires std::predicate<Pred, Json> | |
| ValWrapper | SearchCopyOrNull (Pred &&pred) const |
| Will search the childs for the first element that matches the predicate and clone it, or RequestError if no matches. | |
| template<class Pred = PredicatePointer> requires std::predicate<Pred, Json> | |
| ValWrapper | SearchAndMoveOrNull (Pred &&pred) |
| Will search the childs for the first element that matches the predicate and move it, or RequestError if no matches. | |
| template<class Pred = PredicatePointer> requires std::predicate<Pred, Json> | |
| ExpRefValWrapper | SearchOrError (Pred &&pred) |
| Will search the childs for the first element that matches the predicate and return it, or std::nullopt if no matches. | |
| template<class Pred = PredicatePointer> requires std::predicate<Pred, Json> | |
| ExpCRefValWrapper | SearchOrError (Pred &&pred) const |
| Will search the childs for the first element that matches the predicate and return it, or std::nullopt if no matches. | |
| template<class Pred = PredicatePointer> requires std::predicate<Pred, Json> | |
| ExpValWrapper | SearchCopyOrError (Pred &&pred) const |
| Will search the childs for the first element that matches the predicate and clone it, or std::nullopt if no matches. | |
| template<class Pred = PredicatePointer> requires std::predicate<Pred, Json> | |
| ExpValWrapper | SearchAndMoveOrError (Pred &&pred) && |
| Will search the childs for the first element that matches the predicate and move it, or std::nullopt if no matches. | |
Static Public Member Functions | |
| template<class T > | |
| static bool | IsOfType (const Json &val) |
| template<class T > | |
| static T & | AsType (Json &val) |
| static std::expected< Json, Http::RequestError > | Parse (std::string_view input) |
| Tries to parse the Json from a string. | |
| static std::expected< Json, Http::RequestError > | ParseText (std::string_view input, bool copyData=true, bool checkFinal=true) |
| Tries to parse the Json from a string. | |
| using Thoth::NJson::Json::PredicatePointer = bool(*)(const Json&) |
| Thoth::NJson::Json::Json | ( | ) |
| Thoth::NJson::Json::Json | ( | const JsonObject & | child | ) |
| Thoth::NJson::Json::Json | ( | JsonObject && | child | ) |
| Thoth::NJson::Json::Json | ( | const Array & | child | ) |
| Thoth::NJson::Json::Json | ( | Array && | child | ) |
|
noexcept |
| Thoth::NJson::Json::Json | ( | const Value & | newValue | ) |
|
noexcept |
| Thoth::NJson::Json::Json | ( | const Json & | other | ) |
| Thoth::NJson::Json::Json | ( | bool | other | ) |
| Thoth::NJson::Json::Json | ( | T | other | ) |
| Thoth::NJson::Json::Json | ( | T && | other | ) |
| T & Thoth::NJson::Json::As | ( | ) |
| const T & Thoth::NJson::Json::As | ( | ) | const |
| T Thoth::NJson::Json::AsMov | ( | ) | && |
| T & Thoth::NJson::Json::AsMut | ( | ) |
| const T & Thoth::NJson::Json::AsRef | ( | ) | const |
|
static |
| std::optional< T * > Thoth::NJson::Json::Ensure | ( | ) |
| std::optional< T * > Thoth::NJson::Json::Ensure | ( | ) | const |
| std::optional< T > Thoth::NJson::Json::EnsureMov | ( | ) | && |
| std::expected< T, Http::RequestError > Thoth::NJson::Json::EnsureMovOrError | ( | ) | && |
| std::optional< T * > Thoth::NJson::Json::EnsureMut | ( | ) |
| std::expected< T *, Http::RequestError > Thoth::NJson::Json::EnsureMutOrError | ( | ) |
| std::expected< T *, Http::RequestError > Thoth::NJson::Json::EnsureOrError | ( | ) |
| std::expected< T *, Http::RequestError > Thoth::NJson::Json::EnsureOrError | ( | ) | const |
| std::optional< const T * > Thoth::NJson::Json::EnsureRef | ( | ) | const |
| std::expected< const T *, Http::RequestError > Thoth::NJson::Json::EnsureRefOrError | ( | ) | const |
| OptRefValWrapper Thoth::NJson::Json::Find | ( | Keys | keys | ) |
Same as successive calls to Get, std::nullopt at the first fail.
| OptCRefValWrapper Thoth::NJson::Json::Find | ( | Keys | keys | ) | const |
Same as successive calls to Get, std::nullopt at the first fail.
| OptValWrapper Thoth::NJson::Json::FindAndMove | ( | Keys | keys | ) | && |
Same as successive calls to GetAndMove, std::nullopt at the first fail.
| ExpValWrapper Thoth::NJson::Json::FindAndMoveOrError | ( | Keys | keys | ) | && |
Same as successive calls to Find. Return RequestError at the first fail.
| ValWrapper Thoth::NJson::Json::FindAndMoveOrNull | ( | Keys | keys | ) | && |
Same as successive calls to GetAndMove. Return null at the first fail.
| OptValWrapper Thoth::NJson::Json::FindCopy | ( | Keys | keys | ) | const |
Same as successive calls to GetCopy, std::nullopt at the first fail.
| ExpValWrapper Thoth::NJson::Json::FindCopyOrError | ( | Keys | keys | ) | const |
Same as successive calls to GetCopy. Return RequestError at the first fail.
| ValWrapper Thoth::NJson::Json::FindCopyOrNull | ( | Keys | keys | ) | const |
Same as successive calls to GetCopy. Return null at the first fail.
| ExpRefValWrapper Thoth::NJson::Json::FindOrError | ( | Keys | keys | ) |
Same as successive calls to Get. Return RequestError at the first fail.
| ExpCRefValWrapper Thoth::NJson::Json::FindOrError | ( | Keys | keys | ) | const |
Same as successive calls to Get. Return RequestError at the first fail.
| OptRefValWrapper Thoth::NJson::Json::Get | ( | Key | key | ) |
Return a ref of the element with this index/key if this is an Object or Array, std::nullopt otherwise.
| OptCRefValWrapper Thoth::NJson::Json::Get | ( | Key | key | ) | const |
Return a ref of the element with this index/key if this is an Object or Array, std::nullopt otherwise.
| OptValWrapper Thoth::NJson::Json::GetAndMove | ( | Key | key | ) | && |
Return (with move) the element with this index/key if this is an Object or Array, std::nullopt otherwise.
| ExpValWrapper Thoth::NJson::Json::GetAndMoveOrError | ( | Key | key | ) | && |
Move the element with this index/key if this is an Object or Array. Return RequestError otherwise.
| ValWrapper Thoth::NJson::Json::GetAndMoveOrNull | ( | Key | key | ) | && |
Move the element with this index/key if this is an Object or Array, null otherwise.
| OptValWrapper Thoth::NJson::Json::GetCopy | ( | Key | key | ) | const |
Return a copy of the element with this index/key if this is an Object or Array, std::nullopt otherwise.
| ExpValWrapper Thoth::NJson::Json::GetCopyOrError | ( | Key | key | ) | const |
Return a copy of the element with this index/key if this is an Object or Array, RequestError otherwise.
| ValWrapper Thoth::NJson::Json::GetCopyOrNull | ( | Key | key | ) | const |
Return a copy of the element with this index/key if this is an Object or Array, null otherwise.
| ExpRefValWrapper Thoth::NJson::Json::GetOrError | ( | Key | key | ) |
Return a ref of the element with this index/key if this is an Object or Array, RequestError otherwise.
| ExpCRefValWrapper Thoth::NJson::Json::GetOrError | ( | Key | key | ) | const |
Return a ref of the element with this index/key if this is an Object or Array, RequestError otherwise.
| bool Thoth::NJson::Json::IsOf | ( | ) | const |
|
static |
| Thoth::NJson::Json::operator const Value & | ( | ) | const |
| Thoth::NJson::Json::operator Value & | ( | ) |
| Json & Thoth::NJson::Json::operator= | ( | bool | other | ) |
| Json & Thoth::NJson::Json::operator= | ( | const JsonObject & | other | ) |
| Json & Thoth::NJson::Json::operator= | ( | JsonObject && | other | ) |
| Json & Thoth::NJson::Json::operator= | ( | T && | other | ) |
| Json & Thoth::NJson::Json::operator= | ( | T | other | ) |
| bool Thoth::NJson::Json::operator== | ( | const Json & | other | ) | const |
|
static |
|
static |
| OptRefValWrapper Thoth::NJson::Json::Search | ( | Pred && | pred | ) |
Will search the childs for the first element that matches the predicate and return it, or std::nullopt if no matches.
| OptCRefValWrapper Thoth::NJson::Json::Search | ( | Pred && | pred | ) | const |
Will search the childs for the first element that matches the predicate and return it, or std::nullopt if no matches.
| OptValWrapper Thoth::NJson::Json::SearchAndMove | ( | Pred && | pred | ) | && |
Will search the childs for the first element that matches the predicate and move it, or std::nullopt if no matches.
| ExpValWrapper Thoth::NJson::Json::SearchAndMoveOrError | ( | Pred && | pred | ) | && |
Will search the childs for the first element that matches the predicate and move it, or std::nullopt if no matches.
| ValWrapper Thoth::NJson::Json::SearchAndMoveOrNull | ( | Pred && | pred | ) |
Will search the childs for the first element that matches the predicate and move it, or RequestError if no matches.
| OptValWrapper Thoth::NJson::Json::SearchCopy | ( | Pred && | pred | ) | const |
Will search the childs for the first element that matches the predicate and clone it, or std::nullopt if no matches.
| ExpValWrapper Thoth::NJson::Json::SearchCopyOrError | ( | Pred && | pred | ) | const |
Will search the childs for the first element that matches the predicate and clone it, or std::nullopt if no matches.
| ValWrapper Thoth::NJson::Json::SearchCopyOrNull | ( | Pred && | pred | ) | const |
Will search the childs for the first element that matches the predicate and clone it, or RequestError if no matches.
| ExpRefValWrapper Thoth::NJson::Json::SearchOrError | ( | Pred && | pred | ) |
Will search the childs for the first element that matches the predicate and return it, or std::nullopt if no matches.
| ExpCRefValWrapper Thoth::NJson::Json::SearchOrError | ( | Pred && | pred | ) | const |
Will search the childs for the first element that matches the predicate and return it, or std::nullopt if no matches.
|
constexpr |
convenient call to std::visit() on _value.
|
constexpr |
convenient call to std::visit() on _value.