Medial Code Documentation
Loading...
Searching...
No Matches
Data Structures | Public Member Functions
dmlc::JSONObjectReadHelper Class Reference

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

#include <json.h>

Public Member Functions

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

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);
}
};
Lightweight JSON Reader to read any STL compositions and structs. The user need to know the schema of...
Definition json.h:44
Definition parameter_test.cc:4

Member Function Documentation

◆ DeclareField()

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.

◆ DeclareOptionalField()

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.

◆ ReadAllFields()

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: