HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JsWriter Class Reference

#include <json.h>

Public Types

enum  Style { Style::Compact, Style::Pretty }
 

Public Member Functions

JS_API JsWriter (std::ostream &ostr, Style style=Style::Compact)
 
JS_API ~JsWriter ()
 Destructor. More...
 
 JsWriter (const JsWriter &)=delete
 Disable copies. More...
 
JsWriteroperator= (const JsWriter &)=delete
 
JS_API bool WriteValue (std::nullptr_t)
 Write a null value. More...
 
JS_API bool WriteValue (bool b)
 Write a boolean value. More...
 
JS_API bool WriteValue (int i)
 Write an integer value. More...
 
JS_API bool WriteValue (unsigned u)
 Write an unsigned integer value. More...
 
JS_API bool WriteValue (int64_t i)
 Write a 64-bit integer value. More...
 
JS_API bool WriteValue (uint64_t u)
 Write a 64-bit unsigned integer value. More...
 
JS_API bool WriteValue (double d)
 Write a double value. More...
 
JS_API bool WriteValue (const std::string &s)
 Write a string value. More...
 
JS_API bool WriteValue (const char *s)
 Write a string value. More...
 
template<size_t N>
bool WriteValue (const char(&s)[N])
 Write a string value. More...
 
JS_API bool BeginObject ()
 Write the start of an object. More...
 
JS_API bool WriteKey (const std::string &)
 Write an object key. More...
 
JS_API bool WriteKey (const char *)
 Write an object key. More...
 
template<size_t N>
bool WriteKey (const char(&s)[N])
 Write a string literal object key. More...
 
template<class K , class V >
void WriteKeyValue (K &&k, V &&v)
 Convenience function to write an object key and value. More...
 
JS_API bool EndObject ()
 Write the end of an object. More...
 
JS_API bool BeginArray ()
 Write the start of an array. More...
 
JS_API bool EndArray ()
 Write the end of an array. More...
 
template<class Container >
void WriteArray (const Container &c)
 Convenience function to write an array of values. More...
 
template<class Container , class ItemWriteFn >
void WriteArray (const Container &c, const ItemWriteFn &f)
 
template<class Iterator , class ItemWriteFn >
void WriteArray (const Iterator &begin, const Iterator &end, const ItemWriteFn &f)
 
template<class... T>
void WriteObject (T &&...f)
 

Detailed Description

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.

Member Enumeration Documentation

enum JsWriter::Style
strong
Enumerator
Compact 
Pretty 

Definition at line 78 of file json.h.

Constructor & Destructor Documentation

JS_API JsWriter::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.

JS_API JsWriter::~JsWriter ( )

Destructor.

JsWriter::JsWriter ( const JsWriter )
delete

Disable copies.

Member Function Documentation

JS_API bool JsWriter::BeginArray ( )

Write the start of an array.

JS_API bool JsWriter::BeginObject ( )

Write the start of an object.

JS_API bool JsWriter::EndArray ( )

Write the end of an array.

JS_API bool JsWriter::EndObject ( )

Write the end of an object.

JsWriter& JsWriter::operator= ( const JsWriter )
delete
template<class Container >
void JsWriter::WriteArray ( const Container &  c)
inline

Convenience function to write an array of values.

Definition at line 155 of file json.h.

template<class Container , class ItemWriteFn >
void JsWriter::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.

template<class Iterator , class ItemWriteFn >
void JsWriter::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.

JS_API bool JsWriter::WriteKey ( const std::string )

Write an object key.

JS_API bool JsWriter::WriteKey ( const char *  )

Write an object key.

template<size_t N>
bool JsWriter::WriteKey ( const char(&)  s[N])
inline

Write a string literal object key.

Definition at line 136 of file json.h.

template<class K , class V >
void JsWriter::WriteKeyValue ( K &&  k,
V &&  v 
)
inline

Convenience function to write an object key and value.

Definition at line 140 of file json.h.

template<class... T>
void JsWriter::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.

JS_API bool JsWriter::WriteValue ( std::nullptr_t  )

Write a null value.

JS_API bool JsWriter::WriteValue ( bool  b)

Write a boolean value.

JS_API bool JsWriter::WriteValue ( int  i)

Write an integer value.

JS_API bool JsWriter::WriteValue ( unsigned  u)

Write an unsigned integer value.

JS_API bool JsWriter::WriteValue ( int64_t  i)

Write a 64-bit integer value.

JS_API bool JsWriter::WriteValue ( uint64_t  u)

Write a 64-bit unsigned integer value.

JS_API bool JsWriter::WriteValue ( double  d)

Write a double value.

JS_API bool JsWriter::WriteValue ( const std::string s)

Write a string value.

JS_API bool JsWriter::WriteValue ( const char *  s)

Write a string value.

template<size_t N>
bool JsWriter::WriteValue ( const char(&)  s[N])
inline

Write a string value.

Definition at line 123 of file json.h.


The documentation for this class was generated from the following file: