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

Lightweight JSON Reader to read any STL compositions and structs. The user need to know the schema of the. More...

#include <json.h>

Collaboration diagram for dmlc::JSONReader:
Collaboration graph

Public Member Functions

 JSONReader (std::istream *is)
 Constructor. More...
 
void ReadString (std::string *out_str)
 Parse next JSON string. More...
 
template<typename ValueType >
void ReadNumber (ValueType *out_value)
 Read Number. More...
 
void BeginObject ()
 Begin parsing an object. More...
 
void BeginArray ()
 Begin parsing an array. More...
 
bool NextObjectItem (std::string *out_key)
 Try to move to next object item. If this call is successful, user can proceed to call reader->Read to read in the value. More...
 
bool NextArrayItem ()
 Try to read the next element in the array. If this call is successful, user can proceed to call reader->Read to read in the value. More...
 
template<typename ValueType >
void Read (ValueType *out_value)
 Read next ValueType. More...
 
std::string line_info () const
 

Detailed Description

Lightweight JSON Reader to read any STL compositions and structs. The user need to know the schema of the.

Constructor & Destructor Documentation

dmlc::JSONReader::JSONReader ( std::istream *  is)
inlineexplicit

Constructor.

Parameters
isthe input source.

Member Function Documentation

void dmlc::JSONReader::BeginArray ( )
inline

Begin parsing an array.

// value can be any type that is json serializable.
std::string value;
reader->BeginArray();
while (reader->NextArrayItem(&value)) {
// do somthing to value
}
void dmlc::JSONReader::BeginObject ( )
inline

Begin parsing an object.

std::string key;
// value can be any type that is json serializable.
std::string value;
reader->BeginObject();
while (reader->NextObjectItem(&key)) {
// do somthing to key value
reader->Read(&value);
}
std::string dmlc::JSONReader::line_info ( ) const
inline
Returns
current line count
bool dmlc::JSONReader::NextArrayItem ( )
inline

Try to read the next element in the array. If this call is successful, user can proceed to call reader->Read to read in the value.

Returns
true if the read is successful, false if we are at end of the array.
bool dmlc::JSONReader::NextObjectItem ( std::string *  out_key)
inline

Try to move to next object item. If this call is successful, user can proceed to call reader->Read to read in the value.

Parameters
out_keythe key to the next object.
Returns
true if the read is successful, false if we are at end of the object.
template<typename ValueType >
void dmlc::JSONReader::Read ( ValueType *  out_value)
inline

Read next ValueType.

Parameters
out_valueany STL or json readable type to be read
Exceptions
dmlc::Errorwhen the read of ValueType is not successful.
Template Parameters
ValueTypethe data type to be read.
template<typename ValueType >
void dmlc::JSONReader::ReadNumber ( ValueType *  out_value)
inline

Read Number.

Parameters
out_valueoutput value;
Exceptions
dmlc::Errorwhen next token is not number of ValueType.
Template Parameters
ValueTypetype of the number
void dmlc::JSONReader::ReadString ( std::string *  out_str)
inline

Parse next JSON string.

Parameters
out_strthe output string.
Exceptions
dmlc::Errorwhen next token is not string

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