OmniSciDB  a5dc49c757
 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 <iostream>
29 
30 #include <rapidjson/document.h>
31 #include "Logger/Logger.h"
32 
33 inline const rapidjson::Value& field(const rapidjson::Value& obj,
34  const char field[]) noexcept {
35  CHECK(obj.IsObject());
36  const auto field_it = obj.FindMember(field);
37  CHECK(field_it != obj.MemberEnd());
38  return field_it->value;
39 }
40 
41 inline const int64_t json_i64(const rapidjson::Value& obj) noexcept {
42  CHECK(obj.IsInt64());
43  return obj.GetInt64();
44 }
45 
46 inline const std::string json_str(const rapidjson::Value& obj) noexcept {
47  CHECK(obj.IsString());
48  return obj.GetString();
49 }
50 
51 inline const bool json_bool(const rapidjson::Value& obj) noexcept {
52  CHECK(obj.IsBool());
53  return obj.GetBool();
54 }
55 
56 inline const double json_double(const rapidjson::Value& obj) noexcept {
57  CHECK(obj.IsDouble());
58  return obj.GetDouble();
59 }
60 
61 #endif // QUERYENGINE_JSONACCESSORS_H
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:51
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
const int64_t json_i64(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:41
const double json_double(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:56
#define CHECK(condition)
Definition: Logger.h:291