29 #include "nomlib/json/Value.hpp"
34 Value::Value (
void ) :
38 Value::~Value (
void ) {}
40 Value::Value (
const Value& copy )
43 this->key_ = copy.
key_;
48 this->object_ = other;
57 uint32 Value::size (
void )
const
59 return this->object_.
size();
62 JSONValueType Value::type (
void )
const
64 return this->object_.type();
67 JSONValueType Value::type (
int index )
const
69 return this->object_[index].type();
72 JSONValueType Value::type (
const std::string& key,
int index )
const
74 return this->object_[index][key].type();
77 JSONMemberType Value::members (
int index )
const
79 return this->object_[index].getMemberNames();
82 int Value::get_int (
int index )
84 return this->object_[index].asInt();
87 std::vector<int> Value::get_ints (
const std::string& key,
int index )
89 std::vector<int> members;
90 for ( uint i = 0; i < this->object_[index][key].size(); ++i )
92 members.push_back ( this->object_[index][key][i].asInt() );
97 int Value::get_int (
const std::string& key,
int index )
99 return this->object_[index][key].asInt();
102 uint Value::get_uint (
int index )
104 return this->object_[index].asUInt();
107 std::vector<uint> Value::get_uints (
int index )
109 std::vector<uint> members;
110 for ( uint i = 0; i < this->object_[i].size(); ++i )
112 members.push_back ( this->object_[index][i].asUInt() );
117 uint Value::get_uint (
const std::string& key )
119 return this->object_[key].asUInt();
122 const char* Value::c_str (
int index )
124 return this->object_[index].asCString();
127 std::string Value::get_string (
int index )
129 return this->object_[index].asString();
132 std::vector<std::string> Value::get_strings (
int index )
134 std::vector<std::string> members;
135 for ( uint i = 0; i < this->object_[i].size(); ++i )
137 members.push_back ( this->object_[index][i].asString() );
142 const char* Value::c_str (
const std::string& key )
144 return this->object_[key].asCString();
147 std::string Value::get_string (
const std::string& key,
int index )
149 return this->object_[index][key].asString();
152 bool Value::get_bool (
int index )
154 return this->object_[index].asBool();
157 std::vector<bool> Value::get_bools (
int index )
159 std::vector<bool> members;
160 for ( uint i = 0; i < this->object_[i].size(); ++i )
162 members.push_back ( this->object_[index][i].asBool() );
167 bool Value::get_bool (
const std::string& key )
169 return this->object_[key].asBool();
172 ValueType Value::value (
int index )
174 return this->object_[index];
177 std::vector<ValueType> Value::values (
int index )
179 std::vector<ValueType> members;
180 for ( uint i = 0; i < this->object_[i].size(); ++i )
182 members.push_back ( this->object_[index][i] );
187 ValueType Value::value (
const std::string& key )
189 return this->object_[key];
192 void Value::insert (
const std::string& key,
int index )
197 void Value::insert (
const std::string& key,
int value,
int index )
202 void Value::insert (
const std::string& key, std::vector<int> values )
204 for (
auto member = values.begin(); member != values.end(); ++member )
206 this->object_[key].append ( * member );
210 void Value::insert (
const std::string& key, uint value,
int index )
215 void Value::insert (
const std::string& key,
const std::vector<uint>& values )
217 for (
auto member = values.begin(); member != values.end(); ++member )
219 this->object_[key].append ( * member );
223 void Value::insert (
const std::string& key,
double value,
int index )
228 void Value::insert (
const std::string& key,
float value,
int index )
233 void Value::insert (
const std::string& key,
const char* value,
int index )
238 void Value::insert (
const std::string& key,
const std::string& value,
244 void Value::insert (
const std::string& key,
245 const std::vector<std::string>& values )
247 for (
auto member = values.begin(); member != values.end(); ++member )
249 this->object_[key].append ( * member );
253 void Value::insert (
const std::string& key,
bool value,
int index )
258 void Value::insert (
const std::string& key,
259 const std::vector<ValueType>& values )
261 for (
auto member = values.begin(); member != values.end(); ++member )
263 this->object_[key].append ( *member );
Interface class for JSON data types.
std::string key_
Identifying access string for an object node.
ArrayIndex size() const
Number of values in array or object.
ValueType
Type of the value held by a Value object.