const Value & Value::operator[]( const char *key ) const { 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 }
// @param key is not null-terminated. Value& Value::resolveReference(char const* key, char const* end) { JSON_ASSERT_MESSAGE( type() == nullValue || type() == objectValue, "in Json::Value::resolveReference(key, end): requires objectValue"); if (type() == nullValue) *this = Value(objectValue); CZString actualKey(key, static_cast<unsigned>(end - key), CZString::duplicateOnCopy); auto it = value_.map_->lower_bound(actualKey); if (it != value_.map_->end() && (*it).first == actualKey) return (*it).second; ObjectValues::value_type defaultValue(actualKey, nullSingleton()); it = value_.map_->insert(it, defaultValue); Value& value = (*it).second; return value; }
// Access an object value by name, create a null member if it does not exist. // @pre Type of '*this' is object or null. // @param key is null-terminated. Value& Value::resolveReference(const char* key) { JSON_ASSERT_MESSAGE( type_ == nullValue || type_ == objectValue, "in Json::Value::resolveReference(): requires objectValue"); if (type_ == nullValue) *this = Value(objectValue); CZString actualKey( key, static_cast<unsigned>(strlen(key)), CZString::noDuplication); // NOTE! ObjectValues::iterator it = value_.map_->lower_bound(actualKey); if (it != value_.map_->end() && (*it).first == actualKey) return (*it).second; ObjectValues::value_type defaultValue(actualKey, nullSingleton()); it = value_.map_->insert(it, defaultValue); Value& value = (*it).second; return value; }
Value &Value::resolveReference(const char *key, bool isStatic) { 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 }
bool Value::removeMember(const char* begin, const char* end, Value* removed) { if (type_ != objectValue) { return false; } CZString actualKey(begin, static_cast<unsigned>(end - begin), CZString::noDuplication); ObjectValues::iterator it = value_.map_->find(actualKey); if (it == value_.map_->end()) return false; if (removed) #if JSON_HAS_RVALUE_REFERENCES *removed = std::move(it->second); #else *removed = it->second; #endif value_.map_->erase(it); return true; }
Value Value::removeMember(const char *key) { 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 }