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

Helper class to read JSON into a class or struct object. More...

#include <json.h>

Collaboration diagram for dmlc::JSONObjectReadHelper:
Collaboration graph

Public Member Functions

template<typename T >
void DeclareField (const std::string &key, T *addr)
 Declare field of type T. More...
 
template<typename T >
void DeclareOptionalField (const std::string &key, T *addr)
 Declare optional field of type T. More...
 
void ReadAllFields (JSONReader *reader)
 Read in all the declared fields. More...
 

Detailed Description

Helper class to read JSON into a class or struct object.

struct Param {
std::string name;
int value;
// define load function from JSON
inline void Load(dmlc::JSONReader *reader) {
dmlc::JSONStructReadHelper helper;
helper.DeclareField("name", &name);
helper.DeclareField("value", &value);
helper.ReadAllFields(reader);
}
};

Member Function Documentation

template<typename T >
void dmlc::JSONObjectReadHelper::DeclareField ( const std::string &  key,
T *  addr 
)
inline

Declare field of type T.

Parameters
keythe key of the of field.
addraddress of the data type.
Template Parameters
Tthe data type to be read, must be STL composition of JSON serializable.
template<typename T >
void dmlc::JSONObjectReadHelper::DeclareOptionalField ( const std::string &  key,
T *  addr 
)
inline

Declare optional field of type T.

Parameters
keythe key of the of field.
addraddress of the data type.
Template Parameters
Tthe data type to be read, must be STL composition of JSON serializable.
void dmlc::JSONObjectReadHelper::ReadAllFields ( JSONReader reader)
inline

Read in all the declared fields.

Parameters
readerthe JSONReader to read the json.

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