JSON writer context. More...
#include <writerContext.hpp>
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 |
JSON writer context.
Context is used to store mapping options and serialization buffers
|
delete |
Forbids WriterContext default constructor
|
delete |
Forbids WriterContext copy constructor
| context | the context not to copy |
|
delete |
Forbids WriterContext move constructor
| context | the context not to move |
|
noexcept |
WriterContext constructor
| os | the ouput stream to write in |
| options | the mapping options to use |
|
virtualnoexcept |
WriterContext destructor
Delete buffers
Write begin array ('[') and push first field in context
Write begin array ('{') and push first field in context
| void anch::json::WriterContext::endArray | ( | ) |
Write end array (']') and pop first field from context
| void anch::json::WriterContext::endObject | ( | ) |
Write end array ('}') and pop first field from context
| void anch::json::WriterContext::next | ( | ) |
Write field/value delimiter (',') according to context (first field or not)
|
noexcept |
Mapping options getter
| 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.
| c | the character to write |
| 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.
| str | the characters to write |
| bool anch::json::WriterContext::writeEmptyArray | ( | const std::string & | field | ) |
Write empty collection according to options.
When serialize, it will be serialized as '"<field>":[]'
| field | the field name |
| bool anch::json::WriterContext::writeEmptyObject | ( | const std::string & | field | ) |
Write empty object (map) according to options.
When serialize, it will be serialized as '"<field>":{}'
| field | the field name |
| 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.
| str | the characters to write |
| void anch::json::WriterContext::writeField | ( | const std::string & | field | ) |
Write field and add ':' into output stream.
Call next() to add ',' or not before field
| field | the field |
| bool anch::json::WriterContext::writeNull | ( | const std::string & | field | ) |
Write null value or not according to options
| field | the field name |
true when null value has been serialize, false otherwise | 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.
| T | the number type |
| value | the number to write |
| 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
| field | the field |
| void anch::json::WriterContext::writeString | ( | std::string_view | str | ) |
Write JSON string: '"', escaped characters, '"'.
See writeEscaped for escaped characters.
| str | the characters to write |
| std::ostream& anch::json::WriterContext::output |
The input stream to parse