|
JSON Voorhees
Killer JSON for C++
|
An encoder that outputs to an std::ostream.
More...
#include <jsonv/encode.hpp>
Inheritance diagram for jsonv::ostream_encoder:
Collaboration diagram for jsonv::ostream_encoder:Public Member Functions | |
| ostream_encoder (std::ostream &output) | |
| Create an instance which places text into output. | |
| void | ensure_ascii (bool value) |
| If set to true (the default), then all non-ASCII characters in strings will be replaced with their numeric encodings. | |
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 |
| Write the key for an object, including the separator. | |
| virtual void | write_object_delimiter () override |
| Write the delimiter between two entries in an object. | |
| 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 |
| Write the delimiter between two entries in an array. | |
| virtual void | write_string (std::string_view value) override |
| Write a string value. | |
| virtual void | write_integer (std::int64_t value) override |
| Write an integer value. | |
| virtual void | write_decimal (double value) override |
When a special value is given, this will output null. | |
| virtual void | write_boolean (bool value) override |
| Write a boolean value. | |
| std::ostream & | output () |
| The stream text goes into. | |
Protected Member Functions inherited from jsonv::encoder | |
| virtual void | write_tree (jsonv::value &&source) |
| Write source and everything under it as one value, taking it over. | |
| virtual void | write_tree (const jsonv::value &source) |
| Write source and everything under it as one value. | |
An encoder that outputs to an std::ostream.
This implementation is used for operator<< on a value.
Text goes into the stream unformatted, so the stream's format flags, width, fill and locale have no say in the JSON written, and are left as the caller set them. A width set before os << some_value applies to whatever is inserted after it, not to the document.
Definition at line 180 of file encode.hpp.
| void jsonv::ostream_encoder::ensure_ascii | ( | bool | value | ) |
If set to true (the default), then all non-ASCII characters in strings will be replaced with their numeric encodings.
Since JSON allows for encoded text to be contained in a document, this is inefficient if you have many non-ASCII characters. If you know that your decoding side can properly handle UTF-8 encoding, then you should turn this off, and well-formed UTF-8 will be written out as it is. An ostream_pretty_encoder follows this setting too.
|
protected |
The stream text goes into.
Write to it unformatted, with put and write, as this class does. A formatted insertion would let the stream's state into the JSON, and would use up a width the caller left pending.
|
overrideprotectedvirtual |
Write the opening of an array value.
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.
|
overrideprotectedvirtual |
Write the delimiter between two entries in an array.
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.
|
overrideprotectedvirtual |
Write the closing of an array value.
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.
|
overrideprotectedvirtual |
Write a boolean value.
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.
|
overrideprotectedvirtual |
When a special value is given, this will output null.
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.
|
overrideprotectedvirtual |
Write an integer value.
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
Write the opening of an object value.
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.
|
overrideprotectedvirtual |
Write the delimiter between two entries in an object.
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.
|
overrideprotectedvirtual |
Write the closing of an object value.
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.
|
overrideprotectedvirtual |
Write the key for an object, including the separator.
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.
|
overrideprotectedvirtual |
Write a string value.
| value | is the string to write. It will hopefully be encoded as valid UTF-8. It is the implementation's choice of how to deal with malformed string values. Two common options are to replace malformed sequences with ?s or to simply output these encodings and let the receiver deal with them. |
Implements jsonv::encoder.
Reimplemented in jsonv::ostream_pretty_encoder.