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 
25 #include <boost/filesystem/path.hpp>
26 
27 struct cJSON;
28 
29 namespace Json {
30 
31  class JsonObject {
32  public:
33  explicit JsonObject(const boost::filesystem::path& jsonFile );
34  explicit JsonObject(const std::string& inline_json);
35  explicit JsonObject(const char * inline_json);
36  explicit JsonObject(cJSON * root);
37  ~JsonObject();
38 
39  bool has_item(const std::string& key) const;
40  JsonObject get_array_item( size_t index ) const;
41  JsonObject get_item(const std::string& key) const;
42 
43  std::string to_string() const;
44  std::string get_string(const std::string& key) const;
45  std::string as_string() const;
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 
Definition: cJSON.h:45
JsonObject get_array_item(size_t index) const
std::string to_string() const
bool is_number() const
double get_double(const std::string &key) const
bool is_object() const
Definition: JsonObject.hpp:29
bool is_array() const
double as_double() const
Definition: JsonObject.hpp:31
int get_int(const std::string &key) const
JsonObject get_item(const std::string &key) const
size_t size() const
bool has_item(const std::string &key) const
std::string as_string() const
bool is_string() const
int as_int() const
std::string get_string(const std::string &key) const
JsonObject(const boost::filesystem::path &jsonFile)