remove some unnecessary checks
This commit is contained in:
parent
d77c2e3fb0
commit
8d5d2a93d5
34
janssonxx.h
34
janssonxx.h
@ -90,18 +90,13 @@ public:
|
|||||||
unsigned int size() const {
|
unsigned int size() const {
|
||||||
if (is_object())
|
if (is_object())
|
||||||
return json_object_size(_value);
|
return json_object_size(_value);
|
||||||
else if (is_array())
|
|
||||||
return json_array_size(_value);
|
|
||||||
else
|
else
|
||||||
return 0;
|
return json_array_size(_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get value at array index (const version)
|
// get value at array index (const version)
|
||||||
const Value at(unsigned int index) const {
|
const Value at(unsigned int index) const {
|
||||||
if (is_array())
|
return Value(json_array_get(_value, index));
|
||||||
return Value(json_array_get(_value, index));
|
|
||||||
else
|
|
||||||
return Value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value operator[](signed int index) const { return at(index); }
|
const Value operator[](signed int index) const { return at(index); }
|
||||||
@ -113,10 +108,7 @@ public:
|
|||||||
|
|
||||||
// get value at array index (non-const version)
|
// get value at array index (non-const version)
|
||||||
Value at(unsigned int index) {
|
Value at(unsigned int index) {
|
||||||
if (is_array())
|
return Value(json_array_get(_value, index));
|
||||||
return Value(json_array_get(_value, index));
|
|
||||||
else
|
|
||||||
return Value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value operator[](signed int index) { return at(index); }
|
Value operator[](signed int index) { return at(index); }
|
||||||
@ -128,10 +120,7 @@ public:
|
|||||||
|
|
||||||
// get object property
|
// get object property
|
||||||
const Value get(const char* key) const {
|
const Value get(const char* key) const {
|
||||||
if (is_object())
|
return Value(json_object_get(_value, key));
|
||||||
return Value(json_object_get(_value, key));
|
|
||||||
else
|
|
||||||
return Value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value get(const std::string& key) const { return get(key.c_str()); }
|
const Value get(const std::string& key) const { return get(key.c_str()); }
|
||||||
@ -142,7 +131,7 @@ public:
|
|||||||
void clear() {
|
void clear() {
|
||||||
if (is_object())
|
if (is_object())
|
||||||
json_object_clear(_value);
|
json_object_clear(_value);
|
||||||
else if (is_array())
|
else
|
||||||
json_array_clear(_value);
|
json_array_clear(_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,8 +194,7 @@ public:
|
|||||||
|
|
||||||
// increment iterator
|
// increment iterator
|
||||||
void next() {
|
void next() {
|
||||||
if (_iter != 0)
|
_iter = json_object_iter_next(_object.as_json_t(), _iter);
|
||||||
_iter = json_object_iter_next(_object.as_json_t(), _iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator& operator++() { next(); return *this; }
|
Iterator& operator++() { next(); return *this; }
|
||||||
@ -217,20 +205,14 @@ public:
|
|||||||
|
|
||||||
// get key
|
// get key
|
||||||
const char* ckey() const {
|
const char* ckey() const {
|
||||||
if (_iter != 0)
|
return json_object_iter_key(_iter);
|
||||||
return json_object_iter_key(_iter);
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string key() const { return ckey(); }
|
std::string key() const { return ckey(); }
|
||||||
|
|
||||||
// get value
|
// get value
|
||||||
const Value value() const {
|
const Value value() const {
|
||||||
if (_iter != 0)
|
return Value(json_object_iter_value(_iter));
|
||||||
return Value(json_object_iter_value(_iter));
|
|
||||||
else
|
|
||||||
return Value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dereference value
|
// dereference value
|
||||||
|
Loading…
Reference in New Issue
Block a user