This class provides an interface to writing json values directly to a stream.
More...
#include <json.h>
|
enum class | Style { Compact
, Pretty
} |
|
|
JS_API | JsWriter (std::ostream &ostr, Style style=Style::Compact) |
| Constructor.
|
|
JS_API | ~JsWriter () |
| Destructor.
|
|
| JsWriter (const JsWriter &)=delete |
| Disable copies.
|
|
JsWriter & | operator= (const JsWriter &)=delete |
|
JS_API bool | WriteValue (std::nullptr_t) |
| Write a null value.
|
|
JS_API bool | WriteValue (bool b) |
| Write a boolean value.
|
|
JS_API bool | WriteValue (int i) |
| Write an integer value.
|
|
JS_API bool | WriteValue (unsigned u) |
| Write an unsigned integer value.
|
|
JS_API bool | WriteValue (int64_t i) |
| Write a 64-bit integer value.
|
|
JS_API bool | WriteValue (uint64_t u) |
| Write a 64-bit unsigned integer value.
|
|
JS_API bool | WriteValue (double d) |
| Write a double value.
|
|
JS_API bool | WriteValue (const std::string &s) |
| Write a string value.
|
|
JS_API bool | WriteValue (const char *s) |
| Write a string value.
|
|
template<size_t N> |
bool | WriteValue (const char(&s)[N]) |
| Write a string value.
|
|
JS_API bool | BeginObject () |
| Write the start of an object.
|
|
JS_API bool | WriteKey (const std::string &) |
| Write an object key.
|
|
JS_API bool | WriteKey (const char *) |
| Write an object key.
|
|
template<size_t N> |
bool | WriteKey (const char(&s)[N]) |
| Write a string literal object key.
|
|
template<class K , class V > |
void | WriteKeyValue (K &&k, V &&v) |
| Convenience function to write an object key and value.
|
|
JS_API bool | EndObject () |
| Write the end of an object.
|
|
JS_API bool | BeginArray () |
| Write the start of an array.
|
|
JS_API bool | EndArray () |
| Write the end of an array.
|
|
template<class Container > |
void | WriteArray (const Container &c) |
| Convenience function to write an array of values.
|
|
template<class Container , class ItemWriteFn > |
void | WriteArray (const Container &c, const ItemWriteFn &f) |
| Convenience function to write an array of values by calling the given functor for each item in the container.
|
|
template<class Iterator , class ItemWriteFn > |
void | WriteArray (const Iterator &begin, const Iterator &end, const ItemWriteFn &f) |
| Convenience function to write an array of values given two iterators by calling the given functor for each item in the container.
|
|
template<class ... T> |
void | WriteObject (T &&... f) |
| Convenience function to write an object given key value pair arguments.
|
|
This class provides an interface to writing json values directly to a stream.
This can be much more efficient than constructing a JsValue instance and using JsWriteToStream if the data size is significant.
Definition at line 76 of file json.h.
◆ Style
◆ JsWriter() [1/2]
JS_API JsWriter |
( |
std::ostream & |
ostr, |
|
|
Style |
style = Style::Compact |
|
) |
| |
Constructor.
The lifetime of the /p ostr parameter is assumed to be longer than the JsWriter instance.
◆ ~JsWriter()
◆ JsWriter() [2/2]
◆ BeginArray()
JS_API bool BeginArray |
( |
| ) |
|
Write the start of an array.
◆ BeginObject()
JS_API bool BeginObject |
( |
| ) |
|
Write the start of an object.
◆ EndArray()
Write the end of an array.
◆ EndObject()
JS_API bool EndObject |
( |
| ) |
|
Write the end of an object.
◆ WriteArray() [1/3]
void WriteArray |
( |
const Container & |
c | ) |
|
|
inline |
Convenience function to write an array of values.
Definition at line 155 of file json.h.
◆ WriteArray() [2/3]
void WriteArray |
( |
const Container & |
c, |
|
|
const ItemWriteFn & |
f |
|
) |
| |
|
inline |
Convenience function to write an array of values by calling the given functor for each item in the container.
Definition at line 166 of file json.h.
◆ WriteArray() [3/3]
void WriteArray |
( |
const Iterator & |
begin, |
|
|
const Iterator & |
end, |
|
|
const ItemWriteFn & |
f |
|
) |
| |
|
inline |
Convenience function to write an array of values given two iterators by calling the given functor for each item in the container.
Definition at line 177 of file json.h.
◆ WriteKey() [1/3]
JS_API bool WriteKey |
( |
const char * |
| ) |
|
◆ WriteKey() [2/3]
bool WriteKey |
( |
const char(&) |
s[N] | ) |
|
|
inline |
Write a string literal object key.
Definition at line 136 of file json.h.
◆ WriteKey() [3/3]
JS_API bool WriteKey |
( |
const std::string & |
| ) |
|
◆ WriteKeyValue()
void WriteKeyValue |
( |
K && |
k, |
|
|
V && |
v |
|
) |
| |
|
inline |
Convenience function to write an object key and value.
Definition at line 140 of file json.h.
◆ WriteObject()
void WriteObject |
( |
T &&... |
f | ) |
|
|
inline |
Convenience function to write an object given key value pair arguments.
key arguments must be convertable to strings, value argruments must be either a writable type, or a callablable type taking a JsWriter&.
Definition at line 190 of file json.h.
◆ WriteValue() [1/10]
JS_API bool WriteValue |
( |
bool |
b | ) |
|
◆ WriteValue() [2/10]
JS_API bool WriteValue |
( |
const char * |
s | ) |
|
◆ WriteValue() [3/10]
bool WriteValue |
( |
const char(&) |
s[N] | ) |
|
|
inline |
Write a string value.
Definition at line 123 of file json.h.
◆ WriteValue() [4/10]
JS_API bool WriteValue |
( |
const std::string & |
s | ) |
|
◆ WriteValue() [5/10]
JS_API bool WriteValue |
( |
double |
d | ) |
|
◆ WriteValue() [6/10]
JS_API bool WriteValue |
( |
int |
i | ) |
|
◆ WriteValue() [7/10]
JS_API bool WriteValue |
( |
int64_t |
i | ) |
|
Write a 64-bit integer value.
◆ WriteValue() [8/10]
JS_API bool WriteValue |
( |
std::nullptr_t |
| ) |
|
◆ WriteValue() [9/10]
JS_API bool WriteValue |
( |
uint64_t |
u | ) |
|
Write a 64-bit unsigned integer value.
◆ WriteValue() [10/10]
JS_API bool WriteValue |
( |
unsigned |
u | ) |
|
Write an unsigned integer value.
The documentation for this class was generated from the following file: