AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::json::WriterContext Class Reference

JSON writer context. More...

#include <writerContext.hpp>

Collaboration diagram for anch::json::WriterContext:

Public Member Functions

 WriterContext ()=delete
 WriterContext (const WriterContext &context)=delete
 WriterContext (WriterContext &&context)=delete
 WriterContext (std::ostream &os, const anch::json::MappingOptions &options) noexcept
virtual ~WriterContext () noexcept
const anch::json::MappingOptions & options () const noexcept
bool writeNull (const std::string &field)
bool writeEmptyArray (const std::string &field)
bool writeEmptyObject (const std::string &field)
void writeField (const std::string &field)
void writeRawField (std::string_view field)
void beginArray ()
void endArray ()
void beginObject ()
void endObject ()
void next ()
void write (char c)
void write (std::string_view str)
template<typename T>
void writeNumber (T value)
void writeString (std::string_view str)
void writeEscaped (std::string_view str)

Public Attributes

std::ostream & output

Detailed Description

JSON writer context.

Context is used to store mapping options and serialization buffers

Author
Vincent Lachenal
Since
0.1

Constructor & Destructor Documentation

◆ WriterContext() [1/4]

anch::json::WriterContext::WriterContext ( )
delete

Forbids WriterContext default constructor

◆ WriterContext() [2/4]

anch::json::WriterContext::WriterContext ( const WriterContext & context)
delete

Forbids WriterContext copy constructor

Parameters
contextthe context not to copy
Here is the call graph for this function:

◆ WriterContext() [3/4]

anch::json::WriterContext::WriterContext ( WriterContext && context)
delete

Forbids WriterContext move constructor

Parameters
contextthe context not to move
Here is the call graph for this function:

◆ WriterContext() [4/4]

anch::json::WriterContext::WriterContext ( std::ostream & os,
const anch::json::MappingOptions & options )
noexcept

WriterContext constructor

Parameters
osthe ouput stream to write in
optionsthe mapping options to use
Here is the call graph for this function:

◆ ~WriterContext()

virtual anch::json::WriterContext::~WriterContext ( )
virtualnoexcept

WriterContext destructor
Delete buffers

Member Function Documentation

◆ beginArray()

void anch::json::WriterContext::beginArray ( )

Write begin array ('[') and push first field in context

Here is the call graph for this function:

◆ beginObject()

void anch::json::WriterContext::beginObject ( )

Write begin array ('{') and push first field in context

Here is the call graph for this function:

◆ endArray()

void anch::json::WriterContext::endArray ( )

Write end array (']') and pop first field from context

Here is the call graph for this function:

◆ endObject()

void anch::json::WriterContext::endObject ( )

Write end array ('}') and pop first field from context

Here is the call graph for this function:

◆ next()

void anch::json::WriterContext::next ( )

Write field/value delimiter (',') according to context (first field or not)

Here is the call graph for this function:

◆ options()

const anch::json::MappingOptions & anch::json::WriterContext::options ( ) const
noexcept

Mapping options getter

Returns
the mapping options
Since
0.2
Here is the call graph for this function:

◆ write() [1/2]

void anch::json::WriterContext::write ( char c)

Write a character in output stream buffer.
Output stream badbit is set when character can not be written.

Parameters
cthe character to write
Here is the call graph for this function:

◆ write() [2/2]

void anch::json::WriterContext::write ( std::string_view str)

Write characters in output stream buffer.
Output stream badbit is set when characters can not be written.

Parameters
strthe characters to write
Here is the call graph for this function:

◆ writeEmptyArray()

bool anch::json::WriterContext::writeEmptyArray ( const std::string & field)

Write empty collection according to options.
When serialize, it will be serialized as '"<field>":[]'

Parameters
fieldthe field name
Here is the call graph for this function:

◆ writeEmptyObject()

bool anch::json::WriterContext::writeEmptyObject ( const std::string & field)

Write empty object (map) according to options.
When serialize, it will be serialized as '"<field>":{}'

Parameters
fieldthe field name
Here is the call graph for this function:

◆ writeEscaped()

void anch::json::WriterContext::writeEscaped ( std::string_view str)

Write characters escaped according to RFC 8259 (without '"' around): '"', '\' and control characters (\b, \f, \n, \r, \t, \u00XX for the others). Other characters (UTF-8 included) are written as is.

Parameters
strthe characters to write
Here is the call graph for this function:

◆ writeField()

void anch::json::WriterContext::writeField ( const std::string & field)

Write field and add ':' into output stream.
Call next() to add ',' or not before field

Parameters
fieldthe field
Here is the call graph for this function:

◆ writeNull()

bool anch::json::WriterContext::writeNull ( const std::string & field)

Write null value or not according to options

Parameters
fieldthe field name
Returns
true when null value has been serialize, false otherwise
Here is the call graph for this function:

◆ writeNumber()

template<typename T>
void anch::json::WriterContext::writeNumber ( T value)

Write number in output stream buffer with std::to_chars .
Floating point numbers are written with the shortest representation which can be read back without precision loss.

Template Parameters
Tthe number type
Parameters
valuethe number to write
Here is the call graph for this function:

◆ writeRawField()

void anch::json::WriterContext::writeRawField ( std::string_view field)

Write field without escaping it and add ':' into output stream.
Field has to be already escaped (it can contain formatting such as console colors).
Call next() to add ',' or not before field

Parameters
fieldthe field
Here is the call graph for this function:

◆ writeString()

void anch::json::WriterContext::writeString ( std::string_view str)

Write JSON string: '"', escaped characters, '"'.
See writeEscaped for escaped characters.

Parameters
strthe characters to write
Here is the call graph for this function:

Member Data Documentation

◆ output

std::ostream& anch::json::WriterContext::output

The input stream to parse


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