mxnet
Public Member Functions | List of all members
dmlc::JSONWriter Class Reference

Lightweight json to write any STL compositions. More...

#include <json.h>

Collaboration diagram for dmlc::JSONWriter:
Collaboration graph

Public Member Functions

 JSONWriter (std::ostream *os)
 Constructor. More...
 
void WriteNoEscape (const std::string &s)
 Write a string that do not contain escape characters. More...
 
void WriteString (const std::string &s)
 Write a string that can contain escape characters. More...
 
template<typename ValueType >
void WriteNumber (const ValueType &v)
 Write a string that can contain escape characters. More...
 
void BeginArray (bool multi_line=true)
 Start beginning of array. More...
 
void EndArray ()
 Finish writing an array. More...
 
void BeginObject (bool multi_line=true)
 Start beginning of array. More...
 
void EndObject ()
 Finish writing object. More...
 
template<typename ValueType >
void WriteObjectKeyValue (const std::string &key, const ValueType &value)
 Write key value pair in the object. More...
 
void WriteArraySeperator ()
 Write seperator of array, before writing next element. User can proceed to call writer->Write to write next item. More...
 
template<typename ValueType >
void WriteArrayItem (const ValueType &value)
 Write value into array. More...
 
template<typename ValueType >
void Write (const ValueType &value)
 Write value to json. More...
 

Detailed Description

Lightweight json to write any STL compositions.

Constructor & Destructor Documentation

dmlc::JSONWriter::JSONWriter ( std::ostream *  os)
inlineexplicit

Constructor.

Parameters
osthe output reciever.

Member Function Documentation

void dmlc::JSONWriter::BeginArray ( bool  multi_line = true)
inline

Start beginning of array.

Parameters
multi_linewhether to start an multi_line array.
writer->BeginArray();
for (auto& v : vdata) {
writer->WriteArrayItem(v);
}
writer->EndArray();
void dmlc::JSONWriter::BeginObject ( bool  multi_line = true)
inline

Start beginning of array.

Parameters
multi_linewhether to start an multi_line array.
writer->BeginObject();
for (auto& kv : vmap) {
writer->WriteObjectKeyValue(kv.first, kv.second);
}
writer->EndObject();
void dmlc::JSONWriter::EndArray ( )
inline

Finish writing an array.

void dmlc::JSONWriter::EndObject ( )
inline

Finish writing object.

template<typename ValueType >
void dmlc::JSONWriter::Write ( const ValueType &  value)
inline

Write value to json.

Parameters
valueany STL or json readable that can be written.
Template Parameters
ValueTypethe data type to be write.
template<typename ValueType >
void dmlc::JSONWriter::WriteArrayItem ( const ValueType &  value)
inline

Write value into array.

Parameters
valueThe value of to be written.
Template Parameters
ValueTypeThe value type to be written.
void dmlc::JSONWriter::WriteArraySeperator ( )
inline

Write seperator of array, before writing next element. User can proceed to call writer->Write to write next item.

void dmlc::JSONWriter::WriteNoEscape ( const std::string &  s)
inline

Write a string that do not contain escape characters.

Parameters
sthe string to be written.
template<typename ValueType >
void dmlc::JSONWriter::WriteNumber ( const ValueType &  v)
inline

Write a string that can contain escape characters.

Parameters
vthe value to be written.
Template Parameters
ValueTypeThe value type to be written.
template<typename ValueType >
void dmlc::JSONWriter::WriteObjectKeyValue ( const std::string &  key,
const ValueType &  value 
)
inline

Write key value pair in the object.

Parameters
keythe key of the object.
valuethe value of to be written.
Template Parameters
ValueTypeThe value type to be written.
void dmlc::JSONWriter::WriteString ( const std::string &  s)
inline

Write a string that can contain escape characters.

Parameters
sthe string to be written.

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