#include <json.h>
|
| JSON (std::shared_ptr< rapidjson::Document > doc, rapidjson::Value *vptr, rapidjson::Document::AllocatorType &allo, const std::string &name) |
|
|
std::shared_ptr
< rapidjson::Document > | doc_ |
|
rapidjson::Value * | vptr_ |
|
rapidjson::Document::AllocatorType & | allo_ |
|
const std::string | name_ |
|
Definition at line 65 of file json.h.
Definition at line 73 of file json.h.
Referenced by operator[]().
74 :
doc_(std::make_shared<rapidjson::Document>())
std::shared_ptr< rapidjson::Document > doc_
rapidjson::Document::AllocatorType & allo_
heavyai::JSON::JSON |
( |
const JSON & |
peer | ) |
|
|
inline |
Definition at line 80 of file json.h.
References allo_, and vptr_.
rapidjson::Document::AllocatorType & allo_
heavyai::JSON::JSON |
( |
JSON && |
| ) |
|
|
default |
heavyai::JSON::JSON |
( |
const std::string & |
json | ) |
|
|
inline |
Definition at line 86 of file json.h.
References parse().
void parse(const std::string &json)
heavyai::JSON::JSON |
( |
const char * |
json | ) |
|
|
inline |
Definition at line 89 of file json.h.
References parse().
void parse(const std::string &json)
heavyai::JSON::JSON |
( |
const char * |
json, |
|
|
size_t |
len |
|
) |
| |
|
inline |
Definition at line 93 of file json.h.
References parse().
void parse(const std::string &json)
heavyai::JSON::JSON |
( |
std::shared_ptr< rapidjson::Document > |
doc, |
|
|
rapidjson::Value * |
vptr, |
|
|
rapidjson::Document::AllocatorType & |
allo, |
|
|
const std::string & |
name |
|
) |
| |
|
inlineprivate |
Definition at line 301 of file json.h.
std::shared_ptr< rapidjson::Document > doc_
rapidjson::Document::AllocatorType & allo_
std::string heavyai::JSON::getType |
( |
| ) |
const |
|
inline |
bool heavyai::JSON::hasMember |
( |
const std::string & |
name | ) |
const |
|
inline |
bool heavyai::JSON::isArray |
( |
| ) |
const |
|
inline |
bool heavyai::JSON::isBoolean |
( |
| ) |
const |
|
inline |
bool heavyai::JSON::isNull |
( |
| ) |
const |
|
inline |
bool heavyai::JSON::isNumber |
( |
| ) |
const |
|
inline |
bool heavyai::JSON::isObject |
( |
| ) |
const |
|
inline |
bool heavyai::JSON::isString |
( |
| ) |
const |
|
inline |
heavyai::JSON::operator bool |
( |
| ) |
const |
|
inline |
Definition at line 140 of file json.h.
References kTypeNames, name_, and vptr_.
141 if (!
vptr_->IsBool()) {
142 throw std::runtime_error(
"expected JSON field '" +
name_ +
143 "' to be Boolean but got [" +
146 return vptr_->GetBool();
static std::string kTypeNames[]
heavyai::JSON::operator std::string |
( |
| ) |
const |
|
inline |
Definition at line 131 of file json.h.
References kTypeNames, name_, and vptr_.
132 if (!
vptr_->IsString()) {
133 throw std::runtime_error(
"expected JSON field '" +
name_ +
137 return std::string{
vptr_->GetString(),
vptr_->GetStringLength()};
static std::string kTypeNames[]
template<typename T >
heavyai::JSON::operator T |
( |
| ) |
const |
|
inline |
Definition at line 150 of file json.h.
References kTypeNames, name_, heavydb.dtypes::T, and vptr_.
151 static_assert((std::is_integral_v<T> && !std::is_same_v<
bool, std::remove_cv_t<T>>) ||
152 (std::is_floating_point_v<T>));
153 if constexpr (std::is_integral_v<T>) {
154 if constexpr (std::numeric_limits<T>::is_signed) {
155 if constexpr (
sizeof(
T) < 8) {
156 if (!
vptr_->IsInt()) {
157 throw std::runtime_error(
"can't convert JSON field '" +
name_ +
158 "' to be signed integer from [" +
161 return vptr_->GetInt();
163 if (!
vptr_->IsInt64()) {
164 throw std::runtime_error(
"can't convert JSON field '" +
name_ +
165 "' to be signed 64-bit integer from [" +
168 return vptr_->GetInt64();
171 if constexpr (
sizeof(
T) < 8) {
172 if (!
vptr_->IsUint()) {
173 throw std::runtime_error(
"can't convert JSON field '" +
name_ +
174 "' to be unsigned integer from [" +
177 return vptr_->GetUint();
179 if (!
vptr_->IsUint64()) {
180 throw std::runtime_error(
"can't convert JSON field '" +
name_ +
181 "' to be unsigned 64-bit integer from [" +
184 return vptr_->GetUint64();
187 }
else if constexpr (std::is_floating_point_v<T>) {
188 if (!
vptr_->IsDouble()) {
189 throw std::runtime_error(
"can't convert JSON field '" +
name_ +
190 "' to be floating point number from [" +
193 return vptr_->GetDouble();
static std::string kTypeNames[]
JSON& heavyai::JSON::operator= |
( |
const JSON & |
peer | ) |
|
|
inline |
Definition at line 197 of file json.h.
References allo_, and vptr_.
rapidjson::Document::AllocatorType & allo_
JSON& heavyai::JSON::operator= |
( |
const std::string & |
item | ) |
|
|
inline |
Definition at line 202 of file json.h.
References allo_, and vptr_.
203 *
vptr_ = rapidjson::Value().SetString(item,
allo_);
rapidjson::Document::AllocatorType & allo_
JSON& heavyai::JSON::operator= |
( |
const char * |
item | ) |
|
|
inline |
Definition at line 207 of file json.h.
References allo_, and vptr_.
208 *
vptr_ = rapidjson::Value().SetString(item,
allo_);
rapidjson::Document::AllocatorType & allo_
JSON& heavyai::JSON::operator= |
( |
bool |
item | ) |
|
|
inline |
JSON& heavyai::JSON::operator= |
( |
int32_t |
item | ) |
|
|
inline |
JSON& heavyai::JSON::operator= |
( |
int64_t |
item | ) |
|
|
inline |
JSON& heavyai::JSON::operator= |
( |
uint32_t |
item | ) |
|
|
inline |
JSON& heavyai::JSON::operator= |
( |
uint64_t |
item | ) |
|
|
inline |
JSON heavyai::JSON::operator[] |
( |
const std::string & |
name | ) |
|
|
inline |
JSON heavyai::JSON::operator[] |
( |
const char * |
name | ) |
|
|
inline |
JSON heavyai::JSON::operator[] |
( |
const std::string & |
name | ) |
const |
|
inline |
Definition at line 253 of file json.h.
253 {
return (*
this)[
name.c_str()]; }
JSON heavyai::JSON::operator[] |
( |
const char * |
name | ) |
const |
|
inline |
Definition at line 254 of file json.h.
References allo_, doc_, JSON(), kTypeNames, name_, and vptr_.
255 if (!
vptr_->IsObject()) {
256 throw std::runtime_error(
"JSON " +
kTypeNames[
vptr_->GetType()] +
" field '" +
257 name_ +
"' can't use operator []");
260 throw std::runtime_error(
"JSON field '" + std::string(
name) +
"' not found");
std::shared_ptr< rapidjson::Document > doc_
rapidjson::Document::AllocatorType & allo_
static std::string kTypeNames[]
template<typename T >
JSON heavyai::JSON::operator[] |
( |
T |
index | ) |
|
|
inline |
Definition at line 266 of file json.h.
References operator[]().
267 return operator[](static_cast<size_t>(index));
JSON operator[](const std::string &name)
JSON heavyai::JSON::operator[] |
( |
size_t |
index | ) |
|
|
inline |
template<typename T >
JSON heavyai::JSON::operator[] |
( |
T |
index | ) |
const |
|
inline |
Definition at line 281 of file json.h.
References operator[]().
282 return operator[](static_cast<size_t>(index));
JSON operator[](const std::string &name)
JSON heavyai::JSON::operator[] |
( |
size_t |
index | ) |
const |
|
inline |
void heavyai::JSON::parse |
( |
const std::string & |
json | ) |
|
|
inline |
Definition at line 95 of file json.h.
References doc_.
Referenced by JSON().
96 if (
doc_->Parse(json).HasParseError()) {
97 throw std::runtime_error(
"failed to parse json");
std::shared_ptr< rapidjson::Document > doc_
void heavyai::JSON::parse |
( |
const char * |
json | ) |
|
|
inline |
Definition at line 101 of file json.h.
References doc_.
102 if (
doc_->Parse(json).HasParseError()) {
103 throw std::runtime_error(
"failed to parse json");
std::shared_ptr< rapidjson::Document > doc_
void heavyai::JSON::parse |
( |
const char * |
json, |
|
|
size_t |
len |
|
) |
| |
|
inline |
Definition at line 107 of file json.h.
References doc_.
108 if (
doc_->Parse(json, len).HasParseError()) {
109 throw std::runtime_error(
"failed to parse json");
std::shared_ptr< rapidjson::Document > doc_
std::string heavyai::JSON::stringify |
( |
| ) |
const |
|
inline |
Definition at line 113 of file json.h.
References vptr_.
114 rapidjson::StringBuffer buf;
115 rapidjson::Writer<rapidjson::StringBuffer> wr(buf);
117 return buf.GetString();
bool operator!= |
( |
const JSON & |
json1, |
|
|
const JSON & |
json2 |
|
) |
| |
|
friend |
Definition at line 327 of file json.h.
328 return (*json1.vptr_ != *json2.vptr_);
template<typename T >
bool operator!= |
( |
const JSON & |
json, |
|
|
const T & |
value |
|
) |
| |
|
friend |
Definition at line 343 of file json.h.
344 return (*json.vptr_ != value);
template<typename T >
bool operator!= |
( |
const T & |
value, |
|
|
const JSON & |
json |
|
) |
| |
|
friend |
Definition at line 347 of file json.h.
348 return (json != value);
bool operator== |
( |
const JSON & |
json1, |
|
|
const JSON & |
json2 |
|
) |
| |
|
friend |
Definition at line 323 of file json.h.
324 return (*json1.vptr_ == *json2.vptr_);
template<typename T >
bool operator== |
( |
const JSON & |
json, |
|
|
const T & |
value |
|
) |
| |
|
friend |
Definition at line 334 of file json.h.
335 return (*json.vptr_ == value);
template<typename T >
bool operator== |
( |
const T & |
value, |
|
|
const JSON & |
json |
|
) |
| |
|
friend |
Definition at line 338 of file json.h.
339 return (json == value);
rapidjson::Document::AllocatorType& heavyai::JSON::allo_ |
|
private |
std::shared_ptr<rapidjson::Document> heavyai::JSON::doc_ |
|
private |
std::string heavyai::JSON::kTypeNames[] |
|
inlinestaticprivate |
Initial value:=
{"Null", "False", "True", "Object", "Array", "String", "Number"}
Definition at line 297 of file json.h.
Referenced by getType(), operator bool(), operator std::string(), operator T(), and operator[]().
const std::string heavyai::JSON::name_ |
|
private |
rapidjson::Value* heavyai::JSON::vptr_ |
|
private |
Definition at line 67 of file json.h.
Referenced by getType(), hasMember(), isArray(), isBoolean(), isNull(), isNumber(), isObject(), isString(), JSON(), operator bool(), operator std::string(), operator T(), heavyai::operator!=(), operator=(), heavyai::operator==(), operator[](), and stringify().
The documentation for this class was generated from the following file:
- /home/jenkins-slave/workspace/core-os-doxygen/Shared/json.h