OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JsonAccessors.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 #ifndef QUERYENGINE_JSONACCESSORS_H
26 #define QUERYENGINE_JSONACCESSORS_H
27 
28 #include <rapidjson/document.h>
29 #include "Logger/Logger.h"
30 
31 inline const rapidjson::Value& field(const rapidjson::Value& obj,
32  const char field[]) noexcept {
33  CHECK(obj.IsObject());
34  const auto field_it = obj.FindMember(field);
35  CHECK(field_it != obj.MemberEnd());
36  return field_it->value;
37 }
38 
39 inline const int64_t json_i64(const rapidjson::Value& obj) noexcept {
40  CHECK(obj.IsInt64());
41  return obj.GetInt64();
42 }
43 
44 inline const std::string json_str(const rapidjson::Value& obj) noexcept {
45  CHECK(obj.IsString());
46  return obj.GetString();
47 }
48 
49 inline const bool json_bool(const rapidjson::Value& obj) noexcept {
50  CHECK(obj.IsBool());
51  return obj.GetBool();
52 }
53 
54 inline const double json_double(const rapidjson::Value& obj) noexcept {
55  CHECK(obj.IsDouble());
56  return obj.GetDouble();
57 }
58 
59 #endif // QUERYENGINE_JSONACCESSORS_H
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:49
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
const int64_t json_i64(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:39
const double json_double(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:54
#define CHECK(condition)
Definition: Logger.h:291