osgEarth 2.1.1
|
Represents a JSON value. More...
Classes | |
struct | CommentInfo |
class | CZString |
union | ValueHolder |
Public Types | |
typedef std::vector< std::string > | Members |
typedef int | Int |
typedef unsigned int | UInt |
typedef ValueIterator | iterator |
typedef ValueConstIterator | const_iterator |
typedef UInt | ArrayIndex |
typedef std::map< CZString, Value > | ObjectValues |
Public Member Functions | |
Value (ValueType type=nullValue) | |
Create a default Value of the given type. | |
Value (Int value) | |
Value (UInt value) | |
Value (double value) | |
Value (const char *value) | |
Value (const StaticString &value) | |
Constructs a value from a static string. | |
Value (const std::string &value) | |
Value (bool value) | |
Value (const Value &other) | |
~Value () | |
Value & | operator= (const Value &other) |
void | swap (Value &other) |
ValueType | type () const |
bool | operator< (const Value &other) const |
bool | operator<= (const Value &other) const |
bool | operator>= (const Value &other) const |
bool | operator> (const Value &other) const |
bool | operator== (const Value &other) const |
bool | operator!= (const Value &other) const |
int | compare (const Value &other) |
const char * | asCString () const |
std::string | asString () const |
Int | asInt () const |
UInt | asUInt () const |
double | asDouble () const |
bool | asBool () const |
bool | isNull () const |
bool | isBool () const |
bool | isInt () const |
bool | isUInt () const |
bool | isIntegral () const |
bool | isDouble () const |
bool | isNumeric () const |
bool | isString () const |
bool | isArray () const |
bool | isObject () const |
bool | isConvertibleTo (ValueType other) const |
UInt | size () const |
Number of values in array or object. | |
bool | empty () const |
Return true if empty array, empty object, or null; otherwise, false. | |
bool | operator! () const |
Return isNull() | |
void | clear () |
void | resize (UInt size) |
Value & | operator[] (UInt index) |
const Value & | operator[] (UInt index) const |
Value | get (UInt index, const Value &defaultValue) const |
bool | isValidIndex (UInt index) const |
Return true if index < size(). | |
Value & | append (const Value &value) |
Append value to array at the end. | |
Value & | operator[] (const char *key) |
Access an object value by name, create a null member if it does not exist. | |
const Value & | operator[] (const char *key) const |
Access an object value by name, returns null if there is no member with that name. | |
Value & | operator[] (const std::string &key) |
Access an object value by name, create a null member if it does not exist. | |
const Value & | operator[] (const std::string &key) const |
Access an object value by name, returns null if there is no member with that name. | |
Value & | operator[] (const StaticString &key) |
Access an object value by name, create a null member if it does not exist. | |
Value | get (const char *key, const Value &defaultValue) const |
Return the member named key if it exist, defaultValue otherwise. | |
Value | get (const std::string &key, const Value &defaultValue) const |
Return the member named key if it exist, defaultValue otherwise. | |
Value | removeMember (const char *key) |
Remove and return the named member. | |
Value | removeMember (const std::string &key) |
Same as removeMember(const char*) | |
bool | isMember (const char *key) const |
Return true if the object has a member named key. | |
bool | isMember (const std::string &key) const |
Return true if the object has a member named key. | |
Members | getMemberNames () const |
Return a list of the member names. | |
void | setComment (const char *comment, CommentPlacement placement) |
Comments must be //... or /* ... */. | |
void | setComment (const std::string &comment, CommentPlacement placement) |
Comments must be //... or /* ... */. | |
bool | hasComment (CommentPlacement placement) const |
std::string | getComment (CommentPlacement placement) const |
Include delimiters and embedded newlines. | |
std::string | toStyledString () const |
const_iterator | begin () const |
const_iterator | end () const |
iterator | begin () |
iterator | end () |
Static Public Attributes | |
static const Value | null |
static const Int | minInt = Value::Int( ~(Value::UInt(-1)/2) ) |
static const Int | maxInt = Value::Int( Value::UInt(-1)/2 ) |
static const UInt | maxUInt = Value::UInt(-1) |
Private Member Functions | |
Value & | resolveReference (const char *key, bool isStatic) |
Private Attributes | |
union osgEarth::Json::Value::ValueHolder | value_ |
ValueType | type_: 8 |
int | allocated_: 1 |
CommentInfo * | comments_ |
Friends | |
class | ValueIteratorBase |
Represents a JSON value.
This class is a discriminated union wrapper that can represents a:
The type of the held value is represented by a ValueType and can be obtained using type().
values of an objectValue or arrayValue can be accessed using operator[]() methods. Non const methods will automatically create the a nullValue element if it does not exist. The sequence of an arrayValue will be automatically resize and initialized with nullValue. resize() can be used to enlarge or truncate an arrayValue.
The get() methods can be used to obtanis default value in the case the required element does not exist.
It is possible to iterate over the list of a objectValue values using the getMemberNames() method.
typedef int osgEarth::Json::Value::Int |
typedef std::vector<std::string> osgEarth::Json::Value::Members |
typedef std::map<CZString, Value> osgEarth::Json::Value::ObjectValues |
typedef unsigned int osgEarth::Json::Value::UInt |
Value::Value | ( | ValueType | type = nullValue | ) |
Create a default Value of the given type.
This is a very useful constructor. To create an empty array, pass arrayValue. To create an empty object, pass objectValue. Another Value can then be set to this one by assignment. This is useful since clear() and resize() will not alter types.
Examples:
Json::Value null_value; // null Json::Value arr_value(Json::arrayValue); // [] Json::Value obj_value(Json::objectValue); // {}
Default constructor initialization must be equivalent to: memset( this, 0, sizeof(Value) ) This optimization is used in ValueInternalMap fast allocator.
Definition at line 529 of file JsonUtils.cpp.
: type_( type ) , allocated_( 0 ) , comments_( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_( 0 ) #endif { switch ( type ) { case nullValue: break; case intValue: case uintValue: value_.int_ = 0; break; case realValue: value_.real_ = 0.0; break; case stringValue: value_.string_ = 0; break; #ifndef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: case objectValue: value_.map_ = new ObjectValues(); break; #else case arrayValue: value_.array_ = arrayAllocator()->newArray(); break; case objectValue: value_.map_ = mapAllocator()->newMap(); break; #endif case booleanValue: value_.bool_ = false; break; default: JSON_ASSERT_UNREACHABLE; } }
Value::Value | ( | Int | value | ) |
Value::Value | ( | UInt | value | ) |
Value::Value | ( | double | value | ) |
Value::Value | ( | const char * | value | ) |
Definition at line 604 of file JsonUtils.cpp.
: type_( stringValue ) , allocated_( true ) , comments_( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_( 0 ) #endif { value_.string_ = valueAllocator()->duplicateStringValue( value ); }
Value::Value | ( | const StaticString & | value | ) |
Constructs a value from a static string.
Like other value string constructor but do not duplicate the string for internal storage. The given string must remain alive after the call to this constructor. Example of usage:
Json::Value aValue( StaticString("some text") );
Definition at line 628 of file JsonUtils.cpp.
: type_( stringValue ) , allocated_( false ) , comments_( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_( 0 ) #endif { value_.string_ = const_cast<char *>( value.c_str() ); }
Value::Value | ( | const std::string & | value | ) |
Definition at line 615 of file JsonUtils.cpp.
: type_( stringValue ) , allocated_( true ) , comments_( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_( 0 ) #endif { value_.string_ = valueAllocator()->duplicateStringValue( value.c_str(), (unsigned int)value.length() ); }
Value::Value | ( | bool | value | ) |
Definition at line 653 of file JsonUtils.cpp.
: type_( booleanValue ) , comments_( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_( 0 ) #endif { value_.bool_ = value; }
Value::Value | ( | const Value & | other | ) |
Definition at line 664 of file JsonUtils.cpp.
: type_( other.type_ ) , comments_( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_( 0 ) #endif { switch ( type_ ) { case nullValue: case intValue: case uintValue: case realValue: case booleanValue: value_ = other.value_; break; case stringValue: if ( other.value_.string_ ) { value_.string_ = valueAllocator()->duplicateStringValue( other.value_.string_ ); allocated_ = true; } else value_.string_ = 0; break; #ifndef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: case objectValue: value_.map_ = new ObjectValues( *other.value_.map_ ); break; #else case arrayValue: value_.array_ = arrayAllocator()->newArrayCopy( *other.value_.array_ ); break; case objectValue: value_.map_ = mapAllocator()->newMapCopy( *other.value_.map_ ); break; #endif default: JSON_ASSERT_UNREACHABLE; } if ( other.comments_ ) { comments_ = new CommentInfo[numberOfCommentPlacement]; for ( int comment =0; comment < numberOfCommentPlacement; ++comment ) { const CommentInfo &otherComment = other.comments_[comment]; if ( otherComment.comment_ ) comments_[comment].setComment( otherComment.comment_ ); } } }
Value::~Value | ( | ) |
Definition at line 718 of file JsonUtils.cpp.
{ switch ( type_ ) { case nullValue: case intValue: case uintValue: case realValue: case booleanValue: break; case stringValue: if ( allocated_ ) valueAllocator()->releaseStringValue( value_.string_ ); break; #ifndef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: case objectValue: delete value_.map_; break; #else case arrayValue: arrayAllocator()->destructArray( value_.array_ ); break; case objectValue: mapAllocator()->destructMap( value_.map_ ); break; #endif default: JSON_ASSERT_UNREACHABLE; } if ( comments_ ) delete[] comments_; }
Append value to array at the end.
Equivalent to jsonvalue[jsonvalue.size()] = value;
Definition at line 1384 of file JsonUtils.cpp.
{ return (*this)[size()] = value; }
bool Value::asBool | ( | ) | const |
Definition at line 1061 of file JsonUtils.cpp.
{ switch ( type_ ) { case nullValue: return false; case intValue: case uintValue: return value_.int_ != 0; case realValue: return value_.real_ != 0.0; case booleanValue: return value_.bool_; case stringValue: return value_.string_ && value_.string_[0] != 0; case arrayValue: case objectValue: return value_.map_->size() != 0; default: JSON_ASSERT_UNREACHABLE; } return false; // unreachable; }
const char * Value::asCString | ( | ) | const |
Definition at line 923 of file JsonUtils.cpp.
{ JSON_ASSERT( type_ == stringValue ); return value_.string_; }
double Value::asDouble | ( | ) | const |
Definition at line 1036 of file JsonUtils.cpp.
{ switch ( type_ ) { case nullValue: return 0.0; case intValue: return value_.int_; case uintValue: return value_.uint_; case realValue: return value_.real_; case booleanValue: return value_.bool_ ? 1.0 : 0.0; case stringValue: case arrayValue: case objectValue: JSON_ASSERT_MESSAGE( false, "Type is not convertible to double" ); default: JSON_ASSERT_UNREACHABLE; } return 0; // unreachable; }
Value::Int Value::asInt | ( | ) | const |
Definition at line 982 of file JsonUtils.cpp.
{ switch ( type_ ) { case nullValue: return 0; case intValue: return value_.int_; case uintValue: JSON_ASSERT_MESSAGE( value_.uint_ < (unsigned)maxInt, "integer out of signed integer range" ); return value_.uint_; case realValue: JSON_ASSERT_MESSAGE( value_.real_ >= minInt && value_.real_ <= maxInt, "Real out of signed integer range" ); return Int( value_.real_ ); case booleanValue: return value_.bool_ ? 1 : 0; case stringValue: case arrayValue: case objectValue: JSON_ASSERT_MESSAGE( false, "Type is not convertible to int" ); default: JSON_ASSERT_UNREACHABLE; } return 0; // unreachable; }
std::string Value::asString | ( | ) | const |
Definition at line 930 of file JsonUtils.cpp.
{ switch ( type_ ) { case nullValue: return ""; case stringValue: return value_.string_ ? value_.string_ : ""; case booleanValue: return value_.bool_ ? "true" : "false"; case intValue: { std::stringstream buf; buf << value_.int_; std::string bufStr; bufStr = buf.str(); return bufStr; } case uintValue: { std::stringstream buf; buf << value_.uint_; std::string bufStr; bufStr = buf.str(); return bufStr; } case realValue: { std::stringstream buf; buf << value_.real_; std::string bufStr; bufStr = buf.str(); return bufStr; } case arrayValue: case objectValue: JSON_ASSERT_MESSAGE( false, "Type is not convertible to string" ); default: JSON_ASSERT_UNREACHABLE; } return ""; // unreachable }
Value::UInt Value::asUInt | ( | ) | const |
Definition at line 1009 of file JsonUtils.cpp.
{ switch ( type_ ) { case nullValue: return 0; case intValue: JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to unsigned integer" ); return value_.int_; case uintValue: return value_.uint_; case realValue: JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range" ); return UInt( value_.real_ ); case booleanValue: return value_.bool_ ? 1 : 0; case stringValue: case arrayValue: case objectValue: JSON_ASSERT_MESSAGE( false, "Type is not convertible to uint" ); default: JSON_ASSERT_UNREACHABLE; } return 0; // unreachable; }
Value::const_iterator Value::begin | ( | ) | const |
Definition at line 1634 of file JsonUtils.cpp.
{ switch ( type_ ) { #ifdef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: if ( value_.array_ ) { ValueInternalArray::IteratorState it; value_.array_->makeBeginIterator( it ); return const_iterator( it ); } break; case objectValue: if ( value_.map_ ) { ValueInternalMap::IteratorState it; value_.map_->makeBeginIterator( it ); return const_iterator( it ); } break; #else case arrayValue: case objectValue: if ( value_.map_ ) return const_iterator( value_.map_->begin() ); break; #endif default: break; } return const_iterator(); }
Value::iterator Value::begin | ( | ) |
Definition at line 1705 of file JsonUtils.cpp.
{ switch ( type_ ) { #ifdef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: if ( value_.array_ ) { ValueInternalArray::IteratorState it; value_.array_->makeBeginIterator( it ); return iterator( it ); } break; case objectValue: if ( value_.map_ ) { ValueInternalMap::IteratorState it; value_.map_->makeBeginIterator( it ); return iterator( it ); } break; #else case arrayValue: case objectValue: if ( value_.map_ ) return iterator( value_.map_->begin() ); break; #endif default: break; } return iterator(); }
void Value::clear | ( | ) |
Remove all object members and array elements.
Definition at line 1192 of file JsonUtils.cpp.
{ JSON_ASSERT( type_ == nullValue || type_ == arrayValue || type_ == objectValue ); switch ( type_ ) { #ifndef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: case objectValue: value_.map_->clear(); break; #else case arrayValue: value_.array_->clear(); break; case objectValue: value_.map_->clear(); break; #endif default: break; } }
int Value::compare | ( | const Value & | other | ) |
Definition at line 781 of file JsonUtils.cpp.
{ /* int typeDelta = other.type_ - type_; switch ( type_ ) { case nullValue: return other.type_ == type_; case intValue: if ( other.type_.isNumeric() case uintValue: case realValue: case booleanValue: break; case stringValue, break; case arrayValue: delete value_.array_; break; case objectValue: delete value_.map_; default: JSON_ASSERT_UNREACHABLE; } */ return 0; // unreachable }
bool Value::empty | ( | ) | const |
Value::iterator Value::end | ( | ) |
Definition at line 1740 of file JsonUtils.cpp.
{ switch ( type_ ) { #ifdef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: if ( value_.array_ ) { ValueInternalArray::IteratorState it; value_.array_->makeEndIterator( it ); return iterator( it ); } break; case objectValue: if ( value_.map_ ) { ValueInternalMap::IteratorState it; value_.map_->makeEndIterator( it ); return iterator( it ); } break; #else case arrayValue: case objectValue: if ( value_.map_ ) return iterator( value_.map_->end() ); break; #endif default: break; } return iterator(); }
Value::const_iterator Value::end | ( | ) | const |
Definition at line 1669 of file JsonUtils.cpp.
{ switch ( type_ ) { #ifdef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: if ( value_.array_ ) { ValueInternalArray::IteratorState it; value_.array_->makeEndIterator( it ); return const_iterator( it ); } break; case objectValue: if ( value_.map_ ) { ValueInternalMap::IteratorState it; value_.map_->makeEndIterator( it ); return const_iterator( it ); } break; #else case arrayValue: case objectValue: if ( value_.map_ ) return const_iterator( value_.map_->end() ); break; #endif default: break; } return const_iterator(); }
If the array contains at least index+1 elements, returns the element value, otherwise returns defaultValue.
Definition at line 1312 of file JsonUtils.cpp.
Return the member named key if it exist, defaultValue otherwise.
Definition at line 1391 of file JsonUtils.cpp.
Return the member named key if it exist, defaultValue otherwise.
Definition at line 1400 of file JsonUtils.cpp.
{ return get( key.c_str(), defaultValue ); }
std::string Value::getComment | ( | CommentPlacement | placement | ) | const |
Include delimiters and embedded newlines.
Definition at line 1617 of file JsonUtils.cpp.
{ if ( hasComment(placement) ) return comments_[placement].comment_; return ""; }
Value::Members Value::getMemberNames | ( | ) | const |
Return a list of the member names.
If null, return an empty list.
Definition at line 1471 of file JsonUtils.cpp.
{ JSON_ASSERT( type_ == nullValue || type_ == objectValue ); if ( type_ == nullValue ) return Value::Members(); Members members; members.reserve( value_.map_->size() ); #ifndef JSON_VALUE_USE_INTERNAL_MAP ObjectValues::const_iterator it = value_.map_->begin(); ObjectValues::const_iterator itEnd = value_.map_->end(); for ( ; it != itEnd; ++it ) members.push_back( std::string( (*it).first.c_str() ) ); #else ValueInternalMap::IteratorState it; ValueInternalMap::IteratorState itEnd; value_.map_->makeBeginIterator( it ); value_.map_->makeEndIterator( itEnd ); for ( ; !ValueInternalMap::equals( it, itEnd ); ValueInternalMap::increment(it) ) members.push_back( std::string( ValueInternalMap::key( it ) ) ); #endif return members; }
bool Value::hasComment | ( | CommentPlacement | placement | ) | const |
bool Value::isArray | ( | ) | const |
Definition at line 1579 of file JsonUtils.cpp.
{ return type_ == nullValue || type_ == arrayValue; }
bool Value::isBool | ( | ) | const |
Definition at line 1528 of file JsonUtils.cpp.
{ return type_ == booleanValue; }
bool Value::isConvertibleTo | ( | ValueType | other | ) | const |
Definition at line 1087 of file JsonUtils.cpp.
{ switch ( type_ ) { case nullValue: return true; case intValue: return ( other == nullValue && value_.int_ == 0 ) || other == intValue || ( other == uintValue && value_.int_ >= 0 ) || other == realValue || other == stringValue || other == booleanValue; case uintValue: return ( other == nullValue && value_.uint_ == 0 ) || ( other == intValue && value_.uint_ <= (unsigned)maxInt ) || other == uintValue || other == realValue || other == stringValue || other == booleanValue; case realValue: return ( other == nullValue && value_.real_ == 0.0 ) || ( other == intValue && value_.real_ >= minInt && value_.real_ <= maxInt ) || ( other == uintValue && value_.real_ >= 0 && value_.real_ <= maxUInt ) || other == realValue || other == stringValue || other == booleanValue; case booleanValue: return ( other == nullValue && value_.bool_ == false ) || other == intValue || other == uintValue || other == realValue || other == stringValue || other == booleanValue; case stringValue: return other == stringValue || ( other == nullValue && (!value_.string_ || value_.string_[0] == 0) ); case arrayValue: return other == arrayValue || ( other == nullValue && value_.map_->size() == 0 ); case objectValue: return other == objectValue || ( other == nullValue && value_.map_->size() == 0 ); default: JSON_ASSERT_UNREACHABLE; } return false; // unreachable; }
bool Value::isDouble | ( | ) | const |
bool Value::isInt | ( | ) | const |
Definition at line 1535 of file JsonUtils.cpp.
bool Value::isIntegral | ( | ) | const |
bool Value::isMember | ( | const char * | key | ) | const |
Return true if the object has a member named key.
Definition at line 1448 of file JsonUtils.cpp.
bool Value::isMember | ( | const std::string & | key | ) | const |
Return true if the object has a member named key.
Definition at line 1456 of file JsonUtils.cpp.
{ return isMember( key.c_str() ); }
bool Value::isNull | ( | ) | const |
bool Value::isNumeric | ( | ) | const |
Definition at line 1565 of file JsonUtils.cpp.
{ return isIntegral() || isDouble(); }
bool Value::isObject | ( | ) | const |
Definition at line 1586 of file JsonUtils.cpp.
{ return type_ == nullValue || type_ == objectValue; }
bool Value::isString | ( | ) | const |
Definition at line 1572 of file JsonUtils.cpp.
{ return type_ == stringValue; }
bool Value::isUInt | ( | ) | const |
Definition at line 1542 of file JsonUtils.cpp.
bool Value::isValidIndex | ( | UInt | index | ) | const |
Return true if index < size().
Definition at line 1321 of file JsonUtils.cpp.
{ return index < size(); }
bool Value::operator! | ( | ) | const |
Return isNull()
Definition at line 1185 of file JsonUtils.cpp.
{ return isNull(); }
bool Value::operator!= | ( | const Value & | other | ) | const |
Definition at line 917 of file JsonUtils.cpp.
{ return !( *this == other ); }
bool Value::operator< | ( | const Value & | other | ) | const |
Definition at line 811 of file JsonUtils.cpp.
{ int typeDelta = type_ - other.type_; if ( typeDelta ) return typeDelta < 0 ? true : false; switch ( type_ ) { case nullValue: return false; case intValue: return value_.int_ < other.value_.int_; case uintValue: return value_.uint_ < other.value_.uint_; case realValue: return value_.real_ < other.value_.real_; case booleanValue: return value_.bool_ < other.value_.bool_; case stringValue: return ( value_.string_ == 0 && other.value_.string_ ) || ( other.value_.string_ && value_.string_ && strcmp( value_.string_, other.value_.string_ ) < 0 ); #ifndef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: case objectValue: { int delta = int( value_.map_->size() - other.value_.map_->size() ); if ( delta ) return delta < 0; return (*value_.map_) < (*other.value_.map_); } #else case arrayValue: return value_.array_->compare( *(other.value_.array_) ) < 0; case objectValue: return value_.map_->compare( *(other.value_.map_) ) < 0; #endif default: JSON_ASSERT_UNREACHABLE; } return 0; // unreachable }
bool Value::operator<= | ( | const Value & | other | ) | const |
Definition at line 855 of file JsonUtils.cpp.
{ return !(other > *this); }
bool Value::operator== | ( | const Value & | other | ) | const |
Definition at line 873 of file JsonUtils.cpp.
{ //if ( type_ != other.type_ ) // GCC 2.95.3 says: // attempt to take address of bit-field structure member `Json::Value::type_' // Beats me, but a temp solves the problem. int temp = other.type_; if ( type_ != temp ) return false; switch ( type_ ) { case nullValue: return true; case intValue: return value_.int_ == other.value_.int_; case uintValue: return value_.uint_ == other.value_.uint_; case realValue: return value_.real_ == other.value_.real_; case booleanValue: return value_.bool_ == other.value_.bool_; case stringValue: return ( value_.string_ == other.value_.string_ ) || ( other.value_.string_ && value_.string_ && strcmp( value_.string_, other.value_.string_ ) == 0 ); #ifndef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: case objectValue: return value_.map_->size() == other.value_.map_->size() && (*value_.map_) == (*other.value_.map_); #else case arrayValue: return value_.array_->compare( *(other.value_.array_) ) == 0; case objectValue: return value_.map_->compare( *(other.value_.map_) ) == 0; #endif default: JSON_ASSERT_UNREACHABLE; } return 0; // unreachable }
bool Value::operator> | ( | const Value & | other | ) | const |
Definition at line 867 of file JsonUtils.cpp.
{ return other < *this; }
bool Value::operator>= | ( | const Value & | other | ) | const |
Definition at line 861 of file JsonUtils.cpp.
{ return !(*this < other); }
Value & Value::operator[] | ( | const char * | key | ) |
Access an object value by name, create a null member if it does not exist.
Definition at line 1281 of file JsonUtils.cpp.
{ return resolveReference( key, false ); }
Access an array element (zero based index ). If the array contains less than index element, then null value are inserted in the array so that its size is index+1. (You may need to say 'value[0u]' to get your compiler to distinguish this from the operator[] which takes a string.)
Definition at line 1241 of file JsonUtils.cpp.
{ JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); if ( type_ == nullValue ) *this = Value( arrayValue ); #ifndef JSON_VALUE_USE_INTERNAL_MAP CZString key( index ); ObjectValues::iterator it = value_.map_->lower_bound( key ); if ( it != value_.map_->end() && (*it).first == key ) return (*it).second; ObjectValues::value_type defaultValue( key, null ); it = value_.map_->insert( it, defaultValue ); return (*it).second; #else return value_.array_->resolveReference( index ); #endif }
Access an array element (zero based index ) (You may need to say 'value[0u]' to get your compiler to distinguish this from the operator[] which takes a string.)
Definition at line 1262 of file JsonUtils.cpp.
{ JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); if ( type_ == nullValue ) return null; #ifndef JSON_VALUE_USE_INTERNAL_MAP CZString key( index ); ObjectValues::const_iterator it = value_.map_->find( key ); if ( it == value_.map_->end() ) return null; return (*it).second; #else Value *value = value_.array_->find( index ); return value ? *value : null; #endif }
const Value & Value::operator[] | ( | const char * | key | ) | const |
Access an object value by name, returns null if there is no member with that name.
Definition at line 1329 of file JsonUtils.cpp.
{ JSON_ASSERT( type_ == nullValue || type_ == objectValue ); if ( type_ == nullValue ) return null; #ifndef JSON_VALUE_USE_INTERNAL_MAP CZString actualKey( key, CZString::noDuplication ); ObjectValues::const_iterator it = value_.map_->find( actualKey ); if ( it == value_.map_->end() ) return null; return (*it).second; #else const Value *value = value_.map_->find( key ); return value ? *value : null; #endif }
Value & Value::operator[] | ( | const StaticString & | key | ) |
Access an object value by name, create a null member if it does not exist.
If the object as no entry for that name, then the member name used to store the new entry is not duplicated. Example of use:
Json::Value object; static const StaticString code("code"); object[code] = 1234;
Definition at line 1361 of file JsonUtils.cpp.
{ return resolveReference( key, true ); }
Value & Value::operator[] | ( | const std::string & | key | ) |
Access an object value by name, create a null member if it does not exist.
Definition at line 1348 of file JsonUtils.cpp.
{ return (*this)[ key.c_str() ]; }
const Value & Value::operator[] | ( | const std::string & | key | ) | const |
Access an object value by name, returns null if there is no member with that name.
Definition at line 1355 of file JsonUtils.cpp.
{ return (*this)[ key.c_str() ]; }
Value Value::removeMember | ( | const std::string & | key | ) |
Same as removeMember(const char*)
Definition at line 1433 of file JsonUtils.cpp.
{ return removeMember( key.c_str() ); }
Value Value::removeMember | ( | const char * | key | ) |
Remove and return the named member.
Do nothing if it did not exist.
Definition at line 1407 of file JsonUtils.cpp.
{ JSON_ASSERT( type_ == nullValue || type_ == objectValue ); if ( type_ == nullValue ) return null; #ifndef JSON_VALUE_USE_INTERNAL_MAP CZString actualKey( key, CZString::noDuplication ); ObjectValues::iterator it = value_.map_->find( actualKey ); if ( it == value_.map_->end() ) return null; Value old(it->second); value_.map_->erase(it); return old; #else Value *value = value_.map_->find( key ); if (value){ Value old(*value); value_.map_.remove( key ); return old; } else { return null; } #endif }
void Value::resize | ( | UInt | size | ) |
Resize the array to size elements. New elements are initialized to null. May only be called on nullValue or arrayValue.
Definition at line 1217 of file JsonUtils.cpp.
{ JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); if ( type_ == nullValue ) *this = Value( arrayValue ); #ifndef JSON_VALUE_USE_INTERNAL_MAP UInt oldSize = size(); if ( newSize == 0 ) clear(); else if ( newSize > oldSize ) (*this)[ newSize - 1 ]; else { for ( UInt index = newSize; index < oldSize; ++index ) value_.map_->erase( index ); assert( size() == newSize ); } #else value_.array_->resize( newSize ); #endif }
Value & Value::resolveReference | ( | const char * | key, |
bool | isStatic | ||
) | [private] |
Definition at line 1288 of file JsonUtils.cpp.
{ JSON_ASSERT( type_ == nullValue || type_ == objectValue ); if ( type_ == nullValue ) *this = Value( objectValue ); #ifndef JSON_VALUE_USE_INTERNAL_MAP CZString actualKey( key, isStatic ? CZString::noDuplication : CZString::duplicateOnCopy ); ObjectValues::iterator it = value_.map_->lower_bound( actualKey ); if ( it != value_.map_->end() && (*it).first == actualKey ) return (*it).second; ObjectValues::value_type defaultValue( actualKey, null ); it = value_.map_->insert( it, defaultValue ); Value &value = (*it).second; return value; #else return value_.map_->resolveReference( key, isStatic ); #endif }
void Value::setComment | ( | const char * | comment, |
CommentPlacement | placement | ||
) |
Comments must be //... or /* ... */.
Definition at line 1593 of file JsonUtils.cpp.
{ if ( !comments_ ) comments_ = new CommentInfo[numberOfCommentPlacement]; comments_[placement].setComment( comment ); }
void Value::setComment | ( | const std::string & | comment, |
CommentPlacement | placement | ||
) |
Comments must be //... or /* ... */.
Definition at line 1603 of file JsonUtils.cpp.
{ setComment( comment.c_str(), placement ); }
Value::UInt Value::size | ( | ) | const |
Number of values in array or object.
Definition at line 1139 of file JsonUtils.cpp.
{ switch ( type_ ) { case nullValue: case intValue: case uintValue: case realValue: case booleanValue: case stringValue: return 0; #ifndef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: // size of the array is highest index + 1 if ( !value_.map_->empty() ) { ObjectValues::const_iterator itLast = value_.map_->end(); --itLast; return (*itLast).first.index()+1; } return 0; case objectValue: return Int( value_.map_->size() ); #else case arrayValue: return Int( value_.array_->size() ); case objectValue: return Int( value_.map_->size() ); #endif default: JSON_ASSERT_UNREACHABLE; } return 0; // unreachable; }
void Value::swap | ( | Value & | other | ) |
Swap values.
Definition at line 762 of file JsonUtils.cpp.
{ ValueType temp = type_; type_ = other.type_; other.type_ = temp; std::swap( value_, other.value_ ); int temp2 = allocated_; allocated_ = other.allocated_; other.allocated_ = temp2; }
std::string Value::toStyledString | ( | ) | const |
Definition at line 1626 of file JsonUtils.cpp.
{ StyledWriter writer; return writer.write( *this ); }
ValueType Value::type | ( | ) | const |
Definition at line 774 of file JsonUtils.cpp.
{ return type_; }
friend class ValueIteratorBase [friend] |
int osgEarth::Json::Value::allocated_ [private] |
CommentInfo* osgEarth::Json::Value::comments_ [private] |
const Value::Int Value::maxInt = Value::Int( Value::UInt(-1)/2 ) [static] |
const Value::UInt Value::maxUInt = Value::UInt(-1) [static] |
const Value::Int Value::minInt = Value::Int( ~(Value::UInt(-1)/2) ) [static] |
const Value Value::null [static] |
ValueType osgEarth::Json::Value::type_ [private] |
union osgEarth::Json::Value::ValueHolder osgEarth::Json::Value::value_ [private] |