libdonut
2.3.2
Application framework for cross-platform game development in C++20
|
Stateful wrapper object of an output stream for JSON serialization. More...
#include <donut/json.hpp>
Public Member Functions | |
Writer (std::ostream &stream, const SerializationOptions &options={}) | |
Construct a writer with an output stream as output. More... | |
void | write (char byte) |
Write a single raw byte to the output without any extra formatting. More... | |
void | write (std::string_view bytes) |
Write a raw sequence of bytes to the output without any extra formatting. More... | |
void | writeIndentation () |
Write a sequence of indentation characters to the output. More... | |
void | writeNewline () |
Write a newline sequence to the output. More... | |
void | writeNull () |
Write a single JSON value of type Null to the output. More... | |
void | writeBoolean (Boolean value) |
Write a single JSON value of type Boolean to the output. More... | |
void | writeString (std::string_view bytes) |
Write a single JSON value of type String to the output from a raw byte string. More... | |
template<typename CharT , typename Traits > | |
void | writeString (std::basic_string_view< CharT, Traits > value) requires(!std |
Write a single JSON value of type String to the output from a raw string, interpreted as raw bytes. More... | |
void | writeString (const auto &value) |
Write a single JSON value of type String to the output from any string-view-like or JSON-serializable value. More... | |
void | writeNumber (Number value) |
Write a single JSON value of type Number to the output. More... | |
template<typename PropertyFilter = detail::AlwaysTrue, typename GetKey = detail::GetFirst, typename GetValue = detail::GetSecond> | |
void | writeObject (const auto &value, PropertyFilter propertyFilter={}, GetKey getKey={}, GetValue getValue={}) |
Write a single JSON object to the output from any range of JSON-serializable key-value pairs. More... | |
template<typename ItemFilter = detail::AlwaysTrue, typename GetValue = detail::Get> | |
void | writeArray (const auto &value, ItemFilter itemFilter={}, GetValue getValue={}) |
Write a single JSON array to the output from any range of JSON-serializable values. More... | |
void | writeOptional (const auto &value) |
Write a single JSON value to the output from any value that supports conversion to bool and the dereference operator. More... | |
template<typename T > | |
void | writeAggregate (const T &value) |
Write a single JSON value to the output from any value of aggregate type. More... | |
template<typename T > | |
void | serialize (const T &value) |
Write any JSON-serializable value to the output using its corresponding implementation of Serializer. More... | |
Public Attributes | |
SerializationOptions | options |
The current options of the serialization process. More... | |
Stateful wrapper object of an output stream for JSON serialization.
|
inlineexplicit |
Construct a writer with an output stream as output.
stream | output stream to write to. |
options | output options, see SerializationOptions. |
|
inline |
Write a single raw byte to the output without any extra formatting.
byte | value to write. |
any | exception thrown by the underlying output stream. |
|
inline |
Write a raw sequence of bytes to the output without any extra formatting.
bytes | values to write. |
any | exception thrown by the underlying output stream. |
|
inline |
Write a sequence of indentation characters to the output.
The length of the sequence matches the current indentation level specified in the options.
any | exception thrown by the underlying output stream. |
|
inline |
Write a newline sequence to the output.
any | exception thrown by the underlying output stream. |
|
inline |
Write a single JSON value of type Null to the output.
any | exception thrown by the underlying output stream. |
|
inline |
Write a single JSON value of type Boolean to the output.
value | value to write. |
any | exception thrown by the underlying output stream. |
|
inline |
Write a single JSON value of type String to the output from a raw byte string.
bytes | raw string value to write. |
any | exception thrown by the underlying output stream. |
|
inline |
Write a single JSON value of type String to the output from a raw string, interpreted as raw bytes.
value | raw string value whose bytes to write. |
any | exception thrown by the underlying output stream. |
|
inline |
Write a single JSON value of type String to the output from any string-view-like or JSON-serializable value.
value | value to write. |
any | exception thrown by the underlying output stream. |
any | exception thrown by the underlying string view conversion or Serializer implementation of the given value type. |
|
inline |
Write a single JSON value of type Number to the output.
value | value to write. |
any | exception thrown by the underlying output stream. |
|
inline |
Write a single JSON object to the output from any range of JSON-serializable key-value pairs.
value | range to write as an object. |
propertyFilter | predicate that each key-value pair from the range must pass in order to be included in the output. Defaults to always pass. |
getKey | function for getting the key from each key-value pair. Defaults to returning pair.first. |
getValue | function for getting the value from each key-value pair. Defaults to returning pair.second. |
any | exception thrown by the underlying output stream. |
any | exception thrown by the Serializer implementations of the given key/value types. |
|
inline |
Write a single JSON array to the output from any range of JSON-serializable values.
value | range to write as an array. |
itemFilter | predicate that each value from the range must pass in order to be included in the output. Defaults to always pass. |
getValue | function for getting the value from each value of the range. Defaults to returning each value without modification. |
any | exception thrown by the underlying output stream. |
any | exception thrown by the Serializer implementation of the element type of the given value type. |
|
inline |
Write a single JSON value to the output from any value that supports conversion to bool and the dereference operator.
If the value evaluates to true when converted to bool, the value is dereferenced and serialized normally. Otherwise, null is written.
value | value to write. |
any | exception thrown by the underlying output stream. |
any | exception thrown by the Serializer implementation of the dereferenced type of the given value type. |
|
inline |
Write a single JSON value to the output from any value of aggregate type.
value | aggregate whose fields to write. |
any | exception thrown by the underlying output stream. |
any | exception thrown by the Serializer implementations of the given field types. |
|
inline |
Write any JSON-serializable value to the output using its corresponding implementation of Serializer.
value | value to write. |
any | exception thrown by the underlying output stream. |
any | exception thrown by the Serializer implementation of T. |
SerializationOptions donut::json::Writer::options |
The current options of the serialization process.