JsonObject.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Statoil ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef JSON_OBJECT_HPP
21#define JSON_OBJECT_HPP
22
23#include <string>
24
26
27struct cJSON;
28
29namespace Json {
30
31 class JsonObject {
32 public:
33 explicit JsonObject(const Opm::filesystem::path& jsonFile );
34 explicit JsonObject(const std::string& inline_json);
35 explicit JsonObject(const char * inline_json);
36 explicit JsonObject(cJSON * root);
38
39 bool has_item(const std::string& key) const;
41 JsonObject get_item(const std::string& key) const;
42
46 bool is_string( ) const;
47
48 bool is_number( ) const;
49 int get_int(const std::string& key) const;
50 int as_int() const;
51 double get_double(const std::string& key) const;
52 double as_double() const;
53
54 bool is_array( ) const;
55 bool is_object( ) const;
56
57 size_t size() const;
58 private:
59 JsonObject get_scalar_object(const std::string& key) const;
60 void initialize(const std::string& inline_json);
61 cJSON * root;
62 bool owner;
63 };
64}
65
66
67
68#endif
69
70
int index
Definition: cJSON.h:168
const char *const string
Definition: cJSON.h:170
Definition: JsonObject.hpp:31
bool is_array() const
bool is_object() const
bool is_string() const
std::string as_string() const
std::string to_string() const
size_t size() const
JsonObject(const std::string &inline_json)
bool is_number() const
bool has_item(const std::string &key) const
JsonObject(cJSON *root)
JsonObject(const char *inline_json)
int get_int(const std::string &key) const
JsonObject get_array_item(size_t index) const
int as_int() const
double get_double(const std::string &key) const
JsonObject get_item(const std::string &key) const
std::string get_string(const std::string &key) const
JsonObject(const Opm::filesystem::path &jsonFile)
double as_double() const
Definition: JsonObject.hpp:29
Definition: cJSON.h:104