class QPanda::RJson

Overview

a wrapper class of rapidjson. More…

#include <RJson.h>

class RJson
{
public:
    // methods

    static int GetValue(
        const rapidjson::Value** value,
        const char* name,
        const rapidjson::Value* parent
        );

    static int GetValue(
        const rapidjson::Value** value,
        const size_t idx,
        const rapidjson::Value* parent
        );

    template <typename T>
    static int GetObject(
        const rapidjson::Value** value,
        T tag,
        const rapidjson::Value* parent
        );

    template <typename T>
    static int GetArray(
        const rapidjson::Value** value,
        T tag,
        const rapidjson::Value* parent
        );

    template <typename T>
    static int GetStr(
        std::string& str,
        T tag,
        const rapidjson::Value* parent
        );

    template <typename T>
    static int GetBool(
        bool& n,
        T tag,
        const rapidjson::Value* parent
        );

    template <typename T>
    static int GetInt(int& n, T tag, const rapidjson::Value* parent);

    template <typename T>
    static int GetDouble(
        double& n,
        T tag,
        const rapidjson::Value* parent
        );

    template <typename T1, typename T2>
    static int GetValue(
        const rapidjson::Value** value,
        T1 t1,
        T2 t2,
        const rapidjson::Value* parent
        );

    template <typename T1, typename T2>
    static int GetObject(
        const rapidjson::Value** value,
        T1 t1,
        T2 t2,
        const rapidjson::Value* parent
        );

    template <typename T1, typename T2>
    static int GetArray(
        const rapidjson::Value** value,
        T1 t1,
        T2 t2,
        const rapidjson::Value* parent
        );

    template <typename T1, typename T2>
    static int GetStr(
        std::string& str,
        T1 t1,
        T2 t2,
        const rapidjson::Value* parent
        );

    template <typename T1, typename T2>
    static int GetBool(
        bool& n,
        T1 t1,
        T2 t2,
        const rapidjson::Value* parent
        );

    template <typename T1, typename T2>
    static int GetInt(
        int& n,
        T1 t1,
        T2 t2,
        const rapidjson::Value* parent
        );

    template <typename T1, typename T2>
    static int GetDouble(
        double& n,
        T1 t1,
        T2 t2,
        const rapidjson::Value* parent
        );

    static int ToString(std::string& str, const rapidjson::Value* node);
    static std::string ToString(const rapidjson::Value* node);
    static bool parse(const std::string& filename, rapidjson::Document& doc);

    static bool validate(
        const std::string& filename,
        const std::string& config_schema,
        rapidjson::Document& doc
        );
};

Detailed Documentation

a wrapper class of rapidjson.

Methods

static int GetValue(
    const rapidjson::Value** value,
    const char* name,
    const rapidjson::Value* parent
    )

get the val by the name of a key

Parameters:

rapidjson::Value**

Pointer of a pointer, pointer to the storage Memory address.

char*

the name of key

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

static int GetValue(
    const rapidjson::Value** value,
    const size_t idx,
    const rapidjson::Value* parent
    )

get the val by index

Parameters:

rapidjson::Value**

Pointer of a pointer, pointer to the storage Memory address.

size_t

the target index

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T>
static int GetObject(
    const rapidjson::Value** value,
    T tag,
    const rapidjson::Value* parent
    )

get the object by tag

Parameters:

rapidjson::Value**

Pointer of a pointer, pointer to the storage Memory address.

T

tag

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T>
static int GetArray(
    const rapidjson::Value** value,
    T tag,
    const rapidjson::Value* parent
    )

get the array by tag

Parameters:

rapidjson::Value**

Pointer of a pointer, pointer to the storage Memory address.

T

tag

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T>
static int GetStr(
    std::string& str,
    T tag,
    const rapidjson::Value* parent
    )

get the string of tag

Parameters:

std::string&

the string of tag

T

tag

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T>
static int GetBool(
    bool& n,
    T tag,
    const rapidjson::Value* parent
    )

get the bool val of tag

Parameters:

bool&

the bool val

T

tag

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T>
static int GetInt(
    int& n,
    T tag,
    const rapidjson::Value* parent
    )

get the int val of tag

Parameters:

int&

the int val

T

tag

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T>
static int GetDouble(
    double& n,
    T tag,
    const rapidjson::Value* parent
    )

get the double val of tag

Parameters:

double&

the double val

T

tag

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T1, typename T2>
static int GetValue(
    const rapidjson::Value** value,
    T1 t1,
    T2 t2,
    const rapidjson::Value* parent
    )

get the val of t1.t2

Parameters:

rapidjson::Value**

Pointer of a pointer, pointer to the storage Memory address.

T1

t1

T2

t2

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T1, typename T2>
static int GetObject(
    const rapidjson::Value** value,
    T1 t1,
    T2 t2,
    const rapidjson::Value* parent
    )

get the object pointer of t1.t2

Parameters:

rapidjson::Value**

Pointer of a pointer, pointer to the storage Memory address.

T1

t1

T2

t2

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T1, typename T2>
static int GetArray(
    const rapidjson::Value** value,
    T1 t1,
    T2 t2,
    const rapidjson::Value* parent
    )

get the Array pointer of t1.t2

Parameters:

rapidjson::Value**

Pointer of a pointer, pointer to the storage Memory address.

T1

t1

T2

t2

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T1, typename T2>
static int GetStr(
    std::string& str,
    T1 t1,
    T2 t2,
    const rapidjson::Value* parent
    )

get the string of t1.t2

Parameters:

std::string&

the target string

T1

t1

T2

t2

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T1, typename T2>
static int GetBool(
    bool& n,
    T1 t1,
    T2 t2,
    const rapidjson::Value* parent
    )

get the bool val of t1.t2

Parameters:

bool&

the target bool val

T1

t1

T2

t2

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T1, typename T2>
static int GetInt(
    int& n,
    T1 t1,
    T2 t2,
    const rapidjson::Value* parent
    )

get the int val of t1.t2

Parameters:

int&

the target int val

T1

t1

T2

t2

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

template <typename T1, typename T2>
static int GetDouble(
    double& n,
    T1 t1,
    T2 t2,
    const rapidjson::Value* parent
    )

get the double val of t1.t2

Parameters:

double&

the target double val

T1

t1

T2

t2

rapidjson::Value*

parent node pointer

Returns:

int 0: on success, -1: others

static int ToString(std::string& str, const rapidjson::Value* node)

node data to string

Parameters:

std::string&

the string of node data

rapidjson::Value*

the target node

Returns:

int 0: on success, -1: others

static std::string ToString(const rapidjson::Value* node)

node data to string

Parameters:

rapidjson::Value*

the target node

Returns:

std::string the string of node data. if any error occurred, the returned string is empty.

static bool parse(const std::string& filename, rapidjson::Document& doc)

parse a faile

Parameters:

std::string&

the target file name

rapidjson::Document&

JSON file parser

Returns:

bool return true on success, or else false on any error occurred

static bool validate(
    const std::string& filename,
    const std::string& config_schema,
    rapidjson::Document& doc
    )

judge the file whether valid or not.

Parameters:

std::string&

the target file name

std::string&

the config schema

rapidjson::Document&

JSON file parser

Returns:

bool if file is valid return true, or else return false