JSON writer context.
More...
#include <writerContext.hpp>
JSON writer context.
Context is used to store mapping options and serialization buffers
- Author
- Vincent Lachenal
- Since
- 0.1
◆ WriterContext() [1/4]
| anch::json::WriterContext::WriterContext |
( |
| ) |
|
|
delete |
◆ WriterContext() [2/4]
| anch::json::WriterContext::WriterContext |
( |
const WriterContext & | context | ) |
|
|
delete |
Forbids WriterContext copy constructor
- Parameters
-
| context | the context not to copy |
◆ WriterContext() [3/4]
| anch::json::WriterContext::WriterContext |
( |
WriterContext && | context | ) |
|
|
delete |
Forbids WriterContext move constructor
- Parameters
-
| context | the context not to move |
◆ WriterContext() [4/4]
WriterContext constructor
- Parameters
-
| os | the ouput stream to write in |
| options | the mapping options to use |
◆ ~WriterContext()
| virtual anch::json::WriterContext::~WriterContext |
( |
| ) |
|
|
virtualnoexcept |
◆ beginArray()
| void anch::json::WriterContext::beginArray |
( |
| ) |
|
Write begin array ('[') and push first field in context
◆ beginObject()
| void anch::json::WriterContext::beginObject |
( |
| ) |
|
Write begin array ('{') and push first field in context
◆ endArray()
| void anch::json::WriterContext::endArray |
( |
| ) |
|
Write end array (']') and pop first field from context
◆ endObject()
| void anch::json::WriterContext::endObject |
( |
| ) |
|
Write end array ('}') and pop first field from context
◆ next()
| void anch::json::WriterContext::next |
( |
| ) |
|
Write field/value delimiter (',') according to context (first field or not)
◆ options()
Mapping options getter
- Returns
- the mapping options
- Since
- 0.2
◆ 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
-
◆ 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
-
| str | the characters to write |
◆ 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
-
◆ 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
-
◆ 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
-
| str | the characters to write |
◆ 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
-
◆ writeNull()
| bool anch::json::WriterContext::writeNull |
( |
const std::string & | field | ) |
|
Write null value or not according to options
- Parameters
-
- Returns
true when null value has been serialize, false otherwise
◆ 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
-
- Parameters
-
◆ 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
-
◆ writeString()
| void anch::json::WriterContext::writeString |
( |
std::string_view | str | ) |
|
Write JSON string: '"', escaped characters, '"'.
See writeEscaped for escaped characters.
- Parameters
-
| str | the characters to write |
◆ output
| std::ostream& anch::json::WriterContext::output |
The input stream to parse
The documentation for this class was generated from the following file: