libdonut  2.3.2
Application framework for cross-platform game development in C++20
Public Member Functions | Public Attributes | List of all members
donut::json::Reader Struct Reference

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

#include <donut/json.hpp>

Public Member Functions

 Reader (std::istream &stream, const DeserializationOptions &options={})
 Construct a reader with an input stream as input. More...
 
SourceLocation readNull ()
 Read a single JSON value of type Null from the input. More...
 
SourceLocation readBoolean (Boolean &value)
 Read a single JSON value of type Boolean from the input. More...
 
SourceLocation readString (String &value)
 Read a single JSON value of type String from the input. More...
 
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. More...
 
SourceLocation readNumber (Number &value)
 Read a single JSON value of type Number from the input. More...
 
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. More...
 
SourceLocation readObject (Object &value)
 Read a single JSON value of type Object from the input. More...
 
SourceLocation readObject (auto &value)
 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)). More...
 
SourceLocation readArray (Array &value)
 Read a single JSON value of type Array from the input. More...
 
SourceLocation readArray (auto &value)
 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)). More...
 
SourceLocation readValue (Value &value)
 Read a single JSON value from the input. More...
 
template<typename T >
SourceLocation readOptional (T &value)
 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. More...
 
template<typename T >
SourceLocation readAggregate (T &value)
 Read a single JSON value from the input into any value of aggregate type whose fields are deserializable from JSON. More...
 
template<typename T >
void deserialize (T &value)
 Read a JSON value from the input into any value that is deserializable from JSON using its corresponding implementation of Deserializer. More...
 

Public Attributes

DeserializationOptions options
 The current options of the deserialization process. More...
 

Detailed Description

Stateful wrapper object of an input stream for JSON deserialization.

Constructor & Destructor Documentation

◆ Reader()

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

Construct a reader with an input stream as input.

Parameters
streaminput stream to write to.
optionsinput options, see DeserializationOptions.

Member Function Documentation

◆ readNull()

SourceLocation donut::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::bad_allocon allocation failure.
anyexception thrown by the underlying input stream.
See also
Parser::parseNull()
readValue()

◆ readBoolean()

SourceLocation donut::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::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::parseBoolean()

◆ readString() [1/2]

SourceLocation donut::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::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()

◆ readString() [2/2]

SourceLocation donut::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::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
anyexception thrown by the underlying assignment operator or Deserializer implementation of the given value type.

◆ readNumber() [1/2]

SourceLocation donut::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::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()

◆ readNumber() [2/2]

template<typename T >
SourceLocation donut::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::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
anyexception thrown by the underlying conversion or assignment operator of the given value type.

◆ readObject() [1/2]

SourceLocation donut::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::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()

◆ readObject() [2/2]

SourceLocation donut::json::Reader::readObject ( auto &  value)
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.
Returns
the location of the beginning of the parsed object.
Exceptions
json::Erroron invalid input.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
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.

◆ readArray() [1/2]

SourceLocation donut::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::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()

◆ readArray() [2/2]

SourceLocation donut::json::Reader::readArray ( auto &  value)
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.
Returns
the location of the beginning of the parsed array.
Exceptions
json::Erroron invalid input.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
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.

◆ readValue()

SourceLocation donut::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::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()

◆ readOptional()

template<typename T >
SourceLocation donut::json::Reader::readOptional ( T &  value)
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.
Returns
the location of the parsed value.
Exceptions
json::Erroron invalid input.
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.

◆ readAggregate()

template<typename T >
SourceLocation donut::json::Reader::readAggregate ( T &  value)
inline

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

Parameters
valuereference to the output value whose fields to write the parsed results into.
Returns
the location of the beginning of the parsed value.
Exceptions
json::Erroron invalid input.
std::bad_allocon allocation failure.
anyexception thrown by the underlying input iterator.
anyexception thrown by the Deserializer 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.

◆ deserialize()

template<typename T >
void donut::json::Reader::deserialize ( T &  value)
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.
Exceptions
anyexception thrown by the underlying input stream.
anyexception thrown by the Deserializer implementation of T.

Member Data Documentation

◆ options

DeserializationOptions donut::json::Reader::options

The current options of the deserialization process.


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