GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::json::Reader Struct Reference

Stateful wrapper object of an input stream for JSON deserialization. More...

#include <GREM/core/formats/json.hpp>

Public Types

using Token = typename Parser<It>::Token
 Token type of the reader's parser.

Public Member Functions

 Reader (std::istream &stream, const SourceLocation &source={}, const DeserializationOptions &options={})
 Construct a reader with an input stream as input.
SourceLocation readNull ()
 Read a single JSON value of type Null from the input.
bool nextIsNull () const
 Check if the next value of the input is a JSON value of type Null.
SourceLocation readBoolean (Boolean &value)
 Read a single JSON value of type Boolean from the input.
Boolean readBoolean ()
 Read a single JSON value of type Boolean from the input.
bool nextIsBoolean () const
 Check if the next value of the input is a JSON value of type Boolean.
Optional< Boolean > readBooleanOrNull ()
 Read a single nullable JSON value of type Boolean from the input.
SourceLocation readString (String &value)
 Read a single JSON value of type String from the input.
SourceLocation readString (auto &value)
 Read a single JSON value of type String from the input into any value that can be assigned from a standard string or deserialized from JSON.
String readString ()
 Read a single JSON value of type String from the input.
bool nextIsString () const
 Check if the next value of the input is a JSON value of type String.
Optional< String > readStringOrNull ()
 Read a single nullable JSON value of type String from the input.
SourceLocation readNumber (Number &value)
 Read a single JSON value of type Number from the input.
template<typename T>
SourceLocation readNumber (T &value)
 Read a single JSON value of type Number from the input into any value that Number can be explicitly converted to.
Number readNumber ()
 Read a single JSON value of type Number from the input.
bool nextIsNumber () const
 Check if the next value of the input is a JSON value of type Number.
template<typename T>
T readNumber ()
 Read a single JSON value of type Number from the input.
Optional< Number > readNumberOrNull ()
 Read a single nullable JSON value of type Number from the input.
SourceLocation readCustomObject (auto readProperty)
 Read a single JSON object from the input, using a callback function for reading its properties.
SourceLocation readObject (Object &value)
 Read a single JSON value of type Object from the input.
template<typename DeserializerOverride = detail::NoDeserializerOverride>
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 value types are default-constructible and deserializable from JSON, and where the container supports clear() and emplace(std::move(key), std::move(value)).
Object readObject ()
 Read a single JSON value of type Object from the input.
template<typename Object>
Object readObject ()
 Read a single JSON object from the input into any container of key-value pairs where the key and value types are default-constructible and deserializable from JSON, and where the container supports clear() and emplace(std::move(key), std::move(value)).
bool nextIsObject () const
 Check if the next value of the input is a JSON value of type Object.
Optional< Object > readObjectOrNull ()
 Read a single nullable JSON value of type Object from the input.
SourceLocation readCustomArray (auto readItem)
 Read a single JSON array from the input, using a callback function for reading its items.
SourceLocation readArray (Array &value)
 Read a single JSON value of type Array from the input.
template<typename DeserializerOverride = detail::NoDeserializerOverride>
SourceLocation readArray (auto &value, DeserializerOverride deserializerOverride={})
 Read a single JSON array from the input into any container of elements that are default-constructible and deserializable from JSON, where the container supports clear() and push_back(std::move(element)).
Array readArray ()
 Read a single JSON value of type Array from the input.
template<typename Array>
Array readArray ()
 Read a single JSON array from the input into any container of elements that are default-constructible and deserializable from JSON, where the container supports clear() and push_back(std::move(element)).
bool nextIsArray () const
 Check if the next value of the input is a JSON value of type Array.
Optional< Array > readArrayOrNull ()
 Read a single nullable JSON value of type Array from the input.
SourceLocation readValue (Variant &value)
 Read a single JSON value from the input.
SourceLocation readValue (Value &value)
 Read a single JSON value from the input.
Value readValue ()
 Read a single JSON value from the input.
template<typename T, typename DeserializerOverride = detail::NoDeserializerOverride>
SourceLocation readOptional (T &value, DeserializerOverride deserializerOverride={})
 Read a single nullable JSON value from the input into any value that is default-constructible, move-assignable and dereferencable, and where the dereferenced value type is default-constructible, deserializable from JSON and can be move-assigned into the value.
template<typename Aggregate, typename DeserializerOverride = detail::NoDeserializerOverride>
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 whose fields are deserializable from JSON.
template<typename Aggregate, typename DeserializerOverride = detail::NoDeserializerOverride>
SourceLocation readAggregateObject (Aggregate &value, DeserializerOverride deserializerOverride={})
 Read a single JSON value from the input into any value of aggregate type whose fields are deserializable from JSON.
template<typename Aggregate, typename DeserializerOverride = detail::NoDeserializerOverride>
Aggregate readAggregateObject (DeserializerOverride deserializerOverride={})
 Read a single JSON value from the input into any value of aggregate type whose fields are deserializable from JSON.
template<typename Aggregate, typename DeserializerOverride = detail::NoDeserializerOverride>
SourceLocation readAggregateArray (Aggregate &value, DeserializerOverride deserializerOverride={})
 Read a single JSON value from the input into any value of aggregate type whose fields are deserializable from JSON.
template<typename Aggregate, typename DeserializerOverride = detail::NoDeserializerOverride>
Aggregate readAggregateArray (DeserializerOverride deserializerOverride={})
 Read a single JSON value from the input into any value of aggregate type whose fields are deserializable from JSON.
template<typename T, typename DeserializerOverride = detail::NoDeserializerOverride>
void deserialize (T &value, DeserializerOverride deserializerOverride={})
 Read a JSON value from the input into any value that is deserializable from JSON using its corresponding implementation of Deserializer.
template<typename T, typename DeserializerOverride = detail::NoDeserializerOverride>
T deserialize (DeserializerOverride deserializerOverride={})
 Read a JSON value from the input into any value that is deserializable from JSON using its corresponding implementation of Deserializer.

Public Attributes

DeserializationOptions options
 The current options of the deserialization process.

Detailed Description

Stateful wrapper object of an input stream for JSON deserialization.

Member Typedef Documentation

◆ Token

using grem::json::Reader::Token = typename Parser<It>::Token

Token type of the reader's parser.

Constructor & Destructor Documentation

◆ Reader()

grem::json::Reader::Reader ( std::istream & stream,
const SourceLocation & source = {},
const DeserializationOptions & options = {} )
inlineexplicit

Construct a reader with an input stream as input.

Parameters
streaminput stream to write to.
sourcesource location corresponding to the start of the given stream.
optionsinput options, see DeserializationOptions.

Member Function Documentation

◆ readNull()

SourceLocation grem::json::Reader::readNull ( )
inline

Read a single JSON value of type Null from the input.

Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::parseNull()
readValue()

◆ nextIsNull()

bool grem::json::Reader::nextIsNull ( ) const
inlinenodiscard

Check if the next value of the input is a JSON value of type Null.

Returns
true if the next value is of type Null, false otherwise.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::peekIsNull()
readNull()

◆ readBoolean() [1/2]

SourceLocation grem::json::Reader::readBoolean ( Boolean & value)
inline

Read a single JSON value of type Boolean from the input.

Parameters
valuereference to the output value to write the parsed result to.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
Note
If any exception is thrown, the output value is left unmodified.
See also
Parser::readBoolean()
readValue()

◆ readBoolean() [2/2]

Boolean grem::json::Reader::readBoolean ( )
inlinenodiscard

Read a single JSON value of type Boolean from the input.

Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::readBoolean()
readValue()

◆ nextIsBoolean()

bool grem::json::Reader::nextIsBoolean ( ) const
inlinenodiscard

Check if the next value of the input is a JSON value of type Boolean.

Returns
true if the next value is a of type Boolean, false otherwise.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::peekIsBoolean()
readBoolean()

◆ readBooleanOrNull()

Optional< Boolean > grem::json::Reader::readBooleanOrNull ( )
inlinenodiscard

Read a single nullable JSON value of type Boolean from the input.

Returns
the read value, or an empty optional if the value was null.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.

◆ readString() [1/3]

SourceLocation grem::json::Reader::readString ( String & value)
inline

Read a single JSON value of type String from the input.

Parameters
valuereference to the output value to write the parsed result to.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
Note
If any exception is thrown, the output value is left unmodified.
See also
Parser::parseString()
readValue()

◆ readString() [2/3]

SourceLocation grem::json::Reader::readString ( auto & value)
inline

Read a single JSON value of type String from the input into any value that can be assigned from a standard string or deserialized from JSON.

Parameters
valuereference to the output value to write the parsed result to.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
anyexception thrown by the underlying assignment operator or Deserializer implementation of the given value type.

◆ readString() [3/3]

String grem::json::Reader::readString ( )
inlinenodiscard

Read a single JSON value of type String from the input.

Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::parseString()
readValue()

◆ nextIsString()

bool grem::json::Reader::nextIsString ( ) const
inlinenodiscard

Check if the next value of the input is a JSON value of type String.

Returns
true if the next value is of type String, false otherwise.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::peekIsString()
readString()

◆ readStringOrNull()

Optional< String > grem::json::Reader::readStringOrNull ( )
inlinenodiscard

Read a single nullable JSON value of type String from the input.

Returns
the read value, or an empty optional if the value was null.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.

◆ readNumber() [1/4]

SourceLocation grem::json::Reader::readNumber ( Number & value)
inline

Read a single JSON value of type Number from the input.

Parameters
valuereference to the output value to write the parsed result to.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
Note
If any exception is thrown, the output value is left unmodified.
See also
Parser::parseNumber()
readValue()

◆ readNumber() [2/4]

template<typename T>
SourceLocation grem::json::Reader::readNumber ( T & value)
inline

Read a single JSON value of type Number from the input into any value that Number can be explicitly converted to.

Parameters
valuereference to the output value to write the parsed result to.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
anyexception thrown by the underlying conversion or assignment operator of the given value type.

◆ readNumber() [3/4]

Number grem::json::Reader::readNumber ( )
inlinenodiscard

Read a single JSON value of type Number from the input.

Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::parseNumber()
readValue()

◆ nextIsNumber()

bool grem::json::Reader::nextIsNumber ( ) const
inlinenodiscard

Check if the next value of the input is a JSON value of type Number.

Returns
true if the next value is of type Number, false otherwise.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::peekIsNumber()
readNumber()

◆ readNumber() [4/4]

template<typename T>
T grem::json::Reader::readNumber ( )
inlinenodiscard

Read a single JSON value of type Number from the input.

Template Parameters
Tnumber type to read.
Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::parseNumber()
readValue()

◆ readNumberOrNull()

Optional< Number > grem::json::Reader::readNumberOrNull ( )
inlinenodiscard

Read a single nullable JSON value of type Number from the input.

Returns
the read value, or an empty optional if the value was null.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.

◆ readCustomObject()

SourceLocation grem::json::Reader::readCustomObject ( auto readProperty)
inline

Read a single JSON object from the input, using a callback function for reading its properties.

Parameters
readPropertyfunction object for reading each property of the object, which should return void and accept the following parameters:
  • const SourceLocation& source: source location of the upcoming value to be read.
  • json::String&& key: the key of the read property. The function should read the value of the property using this reader. If the function does nothing, the property value will be skipped automatically.
Returns
the location of the beginning of the parsed object.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
anyexception thrown by the callback functions.

◆ readObject() [1/4]

SourceLocation grem::json::Reader::readObject ( Object & value)
inline

Read a single JSON value of type Object from the input.

Parameters
valuereference to the output value to write the parsed result to.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
Note
If any exception is thrown, the output value is left unmodified.
See also
Parser::parseObject()
readValue()

◆ readObject() [2/4]

template<typename DeserializerOverride = detail::NoDeserializerOverride>
SourceLocation grem::json::Reader::readObject ( auto & value,
DeserializerOverride deserializerOverride = {} )
inline

Read a single JSON object from the input into any container of key-value pairs where the key and value types are default-constructible and deserializable from JSON, and where the container supports clear() and emplace(std::move(key), std::move(value)).

Parameters
valuereference to the output container to write the parsed results into.
deserializerOverrideoverloaded function object that overrides the default deserialization behavior for nested values whenever a call to deserializerOverride(reader, value) yields a valid matching overload.
Returns
the location of the beginning of the parsed object.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
anyexception thrown by the default constructors of the given key/value types.
anyexception thrown by the Deserializer implementations of the given key/value types.
anyexception thrown by clear() or emplace(std::move(key), std::move(value)).
Warning
If an exception is thrown, the output value may be left empty or with some successfully parsed properties added to it, since they are not removed automatically if a later operation fails.

◆ readObject() [3/4]

Object grem::json::Reader::readObject ( )
inlinenodiscard

Read a single JSON value of type Object from the input.

Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::parseObject()
readValue()

◆ readObject() [4/4]

template<typename Object>
Object grem::json::Reader::readObject ( )
inlinenodiscard

Read a single JSON object from the input into any container of key-value pairs where the key and value types are default-constructible and deserializable from JSON, and where the container supports clear() and emplace(std::move(key), std::move(value)).

Template Parameters
Objectobject type to read.
Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
anyexception thrown by the default constructors of the given key/value types.
anyexception thrown by the Deserializer implementations of the given key/value types.
anyexception thrown by clear() or emplace(std::move(key), std::move(value)).
See also
Parser::parseObject()
readValue()

◆ nextIsObject()

bool grem::json::Reader::nextIsObject ( ) const
inlinenodiscard

Check if the next value of the input is a JSON value of type Object.

Returns
true if the next value is of type Object, false otherwise.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::peekIsObject()
readObject()

◆ readObjectOrNull()

Optional< Object > grem::json::Reader::readObjectOrNull ( )
inlinenodiscard

Read a single nullable JSON value of type Object from the input.

Returns
the read value, or an empty optional if the value was null.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.

◆ readCustomArray()

SourceLocation grem::json::Reader::readCustomArray ( auto readItem)
inline

Read a single JSON array from the input, using a callback function for reading its items.

Parameters
readItemfunction object for reading each item of the array, which should return void and accept the following parameter:
  • const SourceLocation& source: source location of the upcoming value to be read. The function should read the value of the item using this reader. If the function does nothing, the item value will be skipped automatically.
Returns
the location of the beginning of the parsed array.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
anyexception thrown by the callback functions.

◆ readArray() [1/4]

SourceLocation grem::json::Reader::readArray ( Array & value)
inline

Read a single JSON value of type Array from the input.

Parameters
valuereference to the output value to write the parsed result to.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
Note
If any exception is thrown, the output value is left unmodified.
See also
Parser::parseArray()
readValue()

◆ readArray() [2/4]

template<typename DeserializerOverride = detail::NoDeserializerOverride>
SourceLocation grem::json::Reader::readArray ( auto & value,
DeserializerOverride deserializerOverride = {} )
inline

Read a single JSON array from the input into any container of elements that are default-constructible and deserializable from JSON, where the container supports clear() and push_back(std::move(element)).

Parameters
valuereference to the output container to write the parsed results into.
deserializerOverrideoverloaded function object that overrides the default deserialization behavior for nested items whenever a call to deserializerOverride(reader, value) yields a valid matching overload.
Returns
the location of the beginning of the parsed array.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
anyexception thrown by the default constructor of the given element type.
anyexception thrown by the Deserializer implementation of the given element type.
anyexception thrown by clear() or push_back(std::move(element)).
Warning
If an exception is thrown, the output value may be left empty or with some successfully parsed items added to it, since they are not removed automatically if a later operation fails.

◆ readArray() [3/4]

Array grem::json::Reader::readArray ( )
inlinenodiscard

Read a single JSON value of type Array from the input.

Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::parseArray()
readValue()

◆ readArray() [4/4]

template<typename Array>
Array grem::json::Reader::readArray ( )
inlinenodiscard

Read a single JSON array from the input into any container of elements that are default-constructible and deserializable from JSON, where the container supports clear() and push_back(std::move(element)).

Template Parameters
Arrayarray type to read.
Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
anyexception thrown by the default constructor of the given element type.
anyexception thrown by the Deserializer implementation of the given element type.
anyexception thrown by clear() or push_back(std::move(element)).
See also
Parser::parseArray()
readValue()

◆ nextIsArray()

bool grem::json::Reader::nextIsArray ( ) const
inlinenodiscard

Check if the next value of the input is a JSON value of type Array.

Returns
true if the next value is of type Array, false otherwise.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::peekIsArray()
readArray()

◆ readArrayOrNull()

Optional< Array > grem::json::Reader::readArrayOrNull ( )
inlinenodiscard

Read a single nullable JSON value of type Array from the input.

Returns
the read value, or an empty optional if the value was null.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.

◆ readValue() [1/3]

SourceLocation grem::json::Reader::readValue ( Variant & value)
inline

Read a single JSON value from the input.

Parameters
valuereference to the output value to write the parsed result to.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
Note
If any exception is thrown, the output value is left unmodified.
See also
Parser::parseValue()

◆ readValue() [2/3]

SourceLocation grem::json::Reader::readValue ( Value & value)
inline

Read a single JSON value from the input.

Parameters
valuereference to the output value to write the parsed result to.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
Note
If any exception is thrown, the output value is left unmodified.
See also
Parser::parseValue()

◆ readValue() [3/3]

Value grem::json::Reader::readValue ( )
inlinenodiscard

Read a single JSON value from the input.

Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::readValue()

◆ readOptional()

template<typename T, typename DeserializerOverride = detail::NoDeserializerOverride>
SourceLocation grem::json::Reader::readOptional ( T & value,
DeserializerOverride deserializerOverride = {} )
inline

Read a single nullable JSON value from the input into any value that is default-constructible, move-assignable and dereferencable, and where the dereferenced value type is default-constructible, deserializable from JSON and can be move-assigned into the value.

If a null value is read, the output is assigned a default-constructed value of its own type.

Parameters
valuereference to the output value to write the result to.
deserializerOverrideoverloaded function object that overrides the default deserialization behavior for the nested value whenever a call to deserializerOverride(reader, value) yields a valid matching overload.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
anyexception thrown by the default constructor of the given value type or its dereferenced type.
anyexception thrown by the Deserializer implementation of the given value's dereferenced type.
anyexception thrown by the assignment operator of the given value type.

◆ readAggregateField()

template<typename Aggregate, typename DeserializerOverride = detail::NoDeserializerOverride>
Optional< SourceLocation > grem::json::Reader::readAggregateField ( StringView fieldName,
Aggregate & aggregate,
DeserializerOverride deserializerOverride = {} )
inline

Read a single JSON value from the input into any value into a specific named field of an aggregate whose fields are deserializable from JSON.

Parameters
fieldNamename of the field to read a value for.
aggregatereference to the output aggregate whose field to write the parsed result into.
deserializerOverrideoverloaded function object that overrides the default deserialization behavior for nested fields whenever a call to deserializerOverride(reader, value) yields a valid matching overload.
Returns
the location of the beginning of the parsed value, or an empty optional if a field with the given name could not be found.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
anyexception thrown by the Deserializer/DeserializerOverride implementations of the given field types.
Note
If any exception is thrown, the output value is left unmodified.

◆ readAggregateObject() [1/2]

template<typename Aggregate, typename DeserializerOverride = detail::NoDeserializerOverride>
SourceLocation grem::json::Reader::readAggregateObject ( Aggregate & value,
DeserializerOverride deserializerOverride = {} )
inline

Read a single JSON value from the input into any value of aggregate type whose fields are deserializable from JSON.

The expected JSON format is an object with properties whose keys match the field names of the aggregate. Properties whose keys don't match any field name are ignored. Fields without a corresponding property are left unmodified.

Parameters
valuereference to the output value whose fields to write the parsed results into.
deserializerOverrideoverloaded function object that overrides the default deserialization behavior for nested fields whenever a call to deserializerOverride(reader, value) yields a valid matching overload.
Returns
the location of the beginning of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
anyexception thrown by the Deserializer/DeserializerOverride implementations of the given field types.
Warning
If an exception is thrown, the output value may be left with some successfully parsed fields, since they are not reset automatically if a later operation fails.

◆ readAggregateObject() [2/2]

template<typename Aggregate, typename DeserializerOverride = detail::NoDeserializerOverride>
Aggregate grem::json::Reader::readAggregateObject ( DeserializerOverride deserializerOverride = {})
inlinenodiscard

Read a single JSON value from the input into any value of aggregate type whose fields are deserializable from JSON.

The expected JSON format is an object with properties whose keys match the field names of the aggregate. Properties whose keys don't match any field name are ignored. Fields without a corresponding property are left default-initialized.

Template Parameters
Aggregateaggregate type to read.
Parameters
deserializerOverrideoverloaded function object that overrides the default deserialization behavior for nested fields whenever a call to deserializerOverride(reader, value) yields a valid matching overload.
Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
anyexception thrown by the Deserializer/DeserializerOverride implementations of the given field types.

◆ readAggregateArray() [1/2]

template<typename Aggregate, typename DeserializerOverride = detail::NoDeserializerOverride>
SourceLocation grem::json::Reader::readAggregateArray ( Aggregate & value,
DeserializerOverride deserializerOverride = {} )
inline

Read a single JSON value from the input into any value of aggregate type whose fields are deserializable from JSON.

The expected JSON format is an array with the same number of items as the number of fields in the aggregate.

Parameters
valuereference to the output value whose fields to write the parsed results into.
deserializerOverrideoverloaded function object that overrides the default deserialization behavior for nested fields whenever a call to deserializerOverride(reader, value) yields a valid matching overload.
Returns
the location of the beginning of the parsed value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
anyexception thrown by the Deserializer/DeserializerOverride implementations of the given field types.
Warning
If an exception is thrown, the output value may be left with some successfully parsed fields, since they are not reset automatically if a later operation fails.

◆ readAggregateArray() [2/2]

template<typename Aggregate, typename DeserializerOverride = detail::NoDeserializerOverride>
Aggregate grem::json::Reader::readAggregateArray ( DeserializerOverride deserializerOverride = {})
inlinenodiscard

Read a single JSON value from the input into any value of aggregate type whose fields are deserializable from JSON.

The expected JSON format is an array with the same number of items as the number of fields in the aggregate.

Template Parameters
Aggregateaggregate type to read.
Parameters
deserializerOverrideoverloaded function object that overrides the default deserialization behavior for nested fields whenever a call to deserializerOverride(reader, value) yields a valid matching overload.
Returns
the read value.
Exceptions
json::Erroron invalid input.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
anyexception thrown by the Deserializer/DeserializerOverride implementations of the given field types.

◆ deserialize() [1/2]

template<typename T, typename DeserializerOverride>
void grem::json::Reader::deserialize ( T & value,
DeserializerOverride deserializerOverride = {} )
inline

Read a JSON value from the input into any value that is deserializable from JSON using its corresponding implementation of Deserializer.

Parameters
valuereference to the output value to write the parsed result to.
deserializerOverrideoverloaded function object that overrides the default deserialization behavior for the value or its nested elements/fields whenever a call to deserializerOverride(reader, value) yields a valid matching overload.
Exceptions
anyexception thrown by the underlying input stream.
anyexception thrown by the Deserializer/DeserializerOverride implementation of T.

◆ deserialize() [2/2]

template<typename T, typename DeserializerOverride = detail::NoDeserializerOverride>
T grem::json::Reader::deserialize ( DeserializerOverride deserializerOverride = {})
inlinenodiscard

Read a JSON value from the input into any value that is deserializable from JSON using its corresponding implementation of Deserializer.

Template Parameters
Tvalue type to read.
Parameters
deserializerOverrideoverloaded function object that overrides the default deserialization behavior for the value or its nested elements/fields whenever a call to deserializerOverride(reader, value) yields a valid matching overload.
Returns
the read value.
Exceptions
anyexception thrown by the underlying input stream.
anyexception thrown by the Deserializer implementation of T.

Member Data Documentation

◆ options

DeserializationOptions grem::json::Reader::options

The current options of the deserialization process.


The documentation for this struct was generated from the following file: