Value.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_JSON_VALUE_HPP
30 #define NOMLIB_JSON_VALUE_HPP
31 
32 #include <iostream>
33 #include <string>
34 #include <vector>
35 
36 #include "json.h" // JSONCPP
37 
38 #include "nomlib/config.hpp"
39 #include "nomlib/json/config_json.hpp"
40 
41 namespace nom {
42 namespace JSON {
43 
45 class Value
46 {
47  public:
48  Value ( void );
49  ~Value ( void );
50 
52  Value ( const Value& copy );
53 
55  Value& operator = ( const ValueType& other );
56 
58  ValueType& get ( void ) const;
59 
60  uint32 size ( void ) const;
61 
62  JSONValueType type ( void ) const;
63  JSONValueType type ( int index ) const;
64  JSONValueType type ( const std::string& key, int index ) const;
65 
66  JSONMemberType members ( int index ) const;
67 
68  int get_int ( int index );
70  std::vector<int> get_ints ( const std::string& key, int index );
71  int get_int ( const std::string& key, int index );
72 
73  uint get_uint ( int index );
75  std::vector<uint> get_uints ( int index );
76  uint get_uint ( const std::string& key );
77 
78  //double get_double ( int index );
79 
80  const char* c_str ( int index );
81  std::string get_string ( int index );
83  std::vector<std::string> get_strings ( int index );
84  const char* c_str ( const std::string& key );
85  std::string get_string ( const std::string& key, int index );
86 
87  bool get_bool ( int index );
89  std::vector<bool> get_bools ( int index );
90  bool get_bool ( const std::string& key );
91 
92  ValueType value ( int index );
93  std::vector<ValueType> values ( int index );
94 
95  ValueType value ( const std::string& key );
96 
100  void insert ( const std::string& key, int index );
101 
105  void insert ( const std::string& key, int value, int index );
106  void insert ( const std::string& key, std::vector<int> values );
107 
111  void insert ( const std::string& key, uint value, int index );
112  void insert ( const std::string& key, const std::vector<uint>& values );
113 
117  void insert ( const std::string& key, double value, int index );
118 
122  void insert ( const std::string& key, float value, int index );
123 
127  void insert ( const std::string& key, const char* value, int index );
128 
132  void insert ( const std::string& key, const std::string& value, int index );
133  void insert ( const std::string& key, const std::vector<std::string>& values );
134 
138  void insert ( const std::string& key, bool value, int index );
139 
143  void insert ( const std::string& key, const std::vector<ValueType>& values );
144 
145  private:
150 
152  std::string key_;
153 };
154 
155 } // namespace JSON
156 } // namespace nom
157 
158 #endif // include guard defined
159 
std::vector< bool > get_bools(int index)
Get bool array values by index.
Definition: Value.cpp:157
void insert(const std::string &key, int index)
Definition: Value.cpp:192
std::vector< int > get_ints(const std::string &key, int index)
Get signed integer array values by key, index.
Definition: Value.cpp:87
std::vector< uint > get_uints(int index)
Get unsigned integer array values by index.
Definition: Value.cpp:107
std::vector< std::string > get_strings(int index)
Get C++ string array values by index.
Definition: Value.cpp:132
Interface class for JSON data types.
Definition: Value.hpp:45
ValueType object_
Definition: Value.hpp:149
Value & operator=(const ValueType &other)
Copy assignment operator.
Definition: Value.cpp:46
std::string key_
Identifying access string for an object node.
Definition: Value.hpp:152
Represents a JSON value.
Definition: json.h:433
ValueType
Type of the value held by a Value object.
Definition: json.h:345