xentara-utils v2.0.4
The Xentara Utility Library
|
An accessor used for reading the members of a JSON object. More...
#include <xentara/utils/json/decoder/Object.hpp>
Classes | |
class | Iterator |
An iterator to iterator to iterate over the members. More... | |
struct | Member |
A member of an object. More... | |
Public Member Functions | |
Object ()=delete | |
This type is not user-constructible. | |
internal auto | begin () -> Iterator |
Returns an object that can be used to iterate over the members. | |
constexpr auto | end () noexcept -> std::default_sentinel_t |
Returns an sentinel that can be used to determine if an iterator is exhausted. | |
auto | document () const -> std::reference_wrapper< const Document > |
Gets the JSON document that the object belongs to. | |
auto | lineNumber () const -> std::uint_least32_t |
Gets the line number in the JSON document that the object is on. | |
auto | location () const -> Location |
Gets the location of the object within the JSON document. | |
template<typename Filter > requires std::is_invocable_r_v<bool, std::decay_t<Filter>, const Name &, Value &> | |
auto | filter (Filter &&filter) &-> Object & |
Adds a filter to filter out selected members. | |
template<typename Filter > requires std::is_invocable_r_v<bool, std::decay_t<Filter>, const Name &, Value &> | |
auto | filter (Filter &&filter) &&-> Object && |
Adds a filter to filter out selected members. | |
An accessor used for reading the members of a JSON object.
Objects of this class can be moved, but not copied.
|
delete |
This type is not user-constructible.
auto xentara::utils::json::decoder::Object::begin | ( | ) | -> Iterator |
Returns an object that can be used to iterate over the members.
std::runtime_error | An error occured reading the first member from the stream |
auto xentara::utils::json::decoder::Object::document | ( | ) | const -> std::reference_wrapper<const Document> |
Gets the JSON document that the object belongs to.
|
constexprnoexcept |
Returns an sentinel that can be used to determine if an iterator is exhausted.
auto xentara::utils::json::decoder::Object::filter | ( | Filter && | filter | ) | && -> Object && |
Adds a filter to filter out selected members.
Filters can be used to filter out selected members when iterating over the object. The members can either be skipped entirely, or they can be read and handled by the filter function.
The filter is called with the name and value of each member of the object. The name and the type of the value can be examined to determine whether the member should be filtered out. If the member is filtered out, then the value must either be skipped using Value::skip(), or read using one of the read functions, like Value::asString(), Value::asNumber(), or Value::asObject(), or a conversion function like Value::toUuid() or Value::toDateTime(). The filter function can discard the value, or use it to perform some sort of processing.
If the member is filtered out, the filter function must return true. If the member is to be handled normally by the iterators, the filter function must return false. If the filter function returns false, the value of the object must not be read.
Here is an example of a filter function that skips all members named "$comment":
Here is an example of a filter object that filters out the "$schema" member, and stores the schema URL in a variable:
filter | The filter to use to filter out the objects. The return value of the filter must be convertible to bool. |
auto xentara::utils::json::decoder::Object::filter | ( | Filter && | filter | ) | & -> Object & |
Adds a filter to filter out selected members.
Filters can be used to filter out selected members when iterating over the object. The members can either be skipped entirely, or they can be read and handled by the filter function.
The filter is called with the name and value of each member of the object. The name and the type of the value can be examined to determine whether the member should be filtered out. If the member is filtered out, then the value must either be skipped using Value::skip(), or read using one of the read functions, like Value::asString(), Value::asNumber(), or Value::asObject(), or a conversion function like Value::toUuid() or Value::toDateTime(). The filter function can discard the value, or use it to perform some sort of processing.
If the member is filtered out, the filter function must return true. If the member is to be handled normally by the iterators, the filter function must return false. If the filter function returns false, the value of the object must not be read.
Here is an example of a filter function that skips all members named "$comment":
Here is an example of a filter object that filters out the "$schema" member, and stores the schema URL in a variable:
filter | The filter to use to filter out the objects. The return value of the filter must be convertible to bool. |
auto xentara::utils::json::decoder::Object::lineNumber | ( | ) | const -> std::uint_least32_t |
Gets the line number in the JSON document that the object is on.
auto xentara::utils::json::decoder::Object::location | ( | ) | const -> Location |
Gets the location of the object within the JSON document.