|
JSON Voorhees
Killer JSON for C++
|
An encoder which builds a value from the tokens it is given: the sink for a document which is produced token by token through a writer but is wanted as a tree.
More...
#include <jsonv/encode.hpp>
Inheritance diagram for jsonv::value_encoder:
Collaboration diagram for jsonv::value_encoder:Public Member Functions | |
| value_encoder () | |
| Create an instance holding nothing. | |
| value_encoder (const value_encoder &)=delete | |
| value_encoder & | operator= (const value_encoder &)=delete |
| value_encoder (value_encoder &&)=delete | |
| value_encoder & | operator= (value_encoder &&)=delete |
| value | take () && |
| Hand out the document written so far. | |
Public Member Functions inherited from jsonv::encoder | |
| void | encode (const jsonv::value &source) |
Encode some source value into this encoder, through write_tree. | |
Protected Member Functions | |
| virtual void | write_null () override |
| Write the null value. | |
| virtual void | write_object_begin () override |
| Write the opening of an object value. | |
| virtual void | write_object_end () override |
| Write the closing of an object value. | |
| virtual void | write_object_key (std::string_view key) override |
| Keep key for the member whose value comes next. | |
| virtual void | write_object_delimiter () override |
| Does nothing: a tree has no punctuation. | |
| virtual void | write_array_begin () override |
| Write the opening of an array value. | |
| virtual void | write_array_end () override |
| Write the closing of an array value. | |
| virtual void | write_array_delimiter () override |
| Does nothing: a tree has no punctuation. | |
| virtual void | write_string (std::string_view value) override |
| The string is copied into the tree as it is, valid UTF-8 or not. | |
| virtual void | write_integer (std::int64_t value) override |
| Write an integer value. | |
| virtual void | write_decimal (double value) override |
Kept as given: a value can hold a NaN or an infinity, so nothing is substituted for one. | |
| virtual void | write_boolean (bool value) override |
| Write a boolean value. | |
| virtual void | write_tree (jsonv::value &&source) override |
| Takes source as it is. | |
| virtual void | write_tree (const jsonv::value &source) override |
| Copies source in whole. | |
An encoder which builds a value from the tokens it is given: the sink for a document which is produced token by token through a writer but is wanted as a tree.
It is the mirror of reader::from_value, which hands a tree out as tokens.
An object is built as a value keeps one, so a key which repeats within it keeps the value written last, as parse keeps it by default; a document built from tokens and the same document parsed from text select the same data. The encoder holds one document at a time: a second root value written before take replaces the first, as a repeated key does.
Definition at line 308 of file encode.hpp.
| value jsonv::value_encoder::take | ( | ) | && |
Hand out the document written so far.
This instance is left holding nothing, as it was constructed, so another document may follow.
| std::logic_error | if an object or array is still open, or if nothing has been written at all. A JSON document is never empty, so a writer which has produced nothing has not produced null. |
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
Does nothing: a tree has no punctuation.
Implements jsonv::encoder.
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
Kept as given: a value can hold a NaN or an infinity, so nothing is substituted for one.
Implements jsonv::encoder.
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
Does nothing: a tree has no punctuation.
Implements jsonv::encoder.
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
Keep key for the member whose value comes next.
Implements jsonv::encoder.
|
overrideprotectedvirtual |
The string is copied into the tree as it is, valid UTF-8 or not.
Implements jsonv::encoder.
|
overrideprotectedvirtual |
Copies source in whole.
A tree written as an lvalue – to_json of a value, or of anything holding one – costs what copying it does rather than a rebuild through the hooks above, which inserts each member and grows each array one element at a time.
Reimplemented from jsonv::encoder.
|
overrideprotectedvirtual |
Takes source as it is.
A tree handed over whole is placed where the next value goes without being rebuilt, which is what keeps a serializer on the value bridge linear in the depth of what it serializes.
Reimplemented from jsonv::encoder.