void Value::CommentInfo::setComment(const char *text) { if (comment_) valueAllocator()->releaseStringValue(comment_); JSON_ASSERT(text); JSON_ASSERT_MESSAGE(text[0] == '\0' || text[0] == '/', "Comments must start with /"); // It seems that /**/ style comments are acceptable as well. comment_ = valueAllocator()->duplicateStringValue(text); }
Value::Value ( const Value& other ) : type_ ( other.type_ ) { 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; case arrayValue: case objectValue: value_.map_ = new ObjectValues ( *other.value_.map_ ); break; default: JSON_ASSERT_UNREACHABLE; } }
Value::~Value() { 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_; }
Value::~Value () { switch ( type_ ) { case nullValue: case intValue: case uintValue: case realValue: case booleanValue: break; case stringValue: if ( allocated_ ) valueAllocator ()->releaseStringValue ( value_.string_ ); break; case arrayValue: case objectValue: delete value_.map_; break; default: JSON_ASSERT_UNREACHABLE; } }
Value::Value ( std::string const& value ) : type_ ( stringValue ) , allocated_ ( true ) { value_.string_ = valueAllocator ()->duplicateStringValue ( value.c_str (), (unsigned int)value.length () ); }
Value::Value ( const char* beginValue, const char* endValue ) : type_ ( stringValue ) , allocated_ ( true ) { value_.string_ = valueAllocator ()->duplicateStringValue ( beginValue, UInt (endValue - beginValue) ); }
Value::Value (beast::String const& beastString) : type_ ( stringValue ) , allocated_ ( true ) { value_.string_ = valueAllocator ()->duplicateStringValue ( beastString.toStdString ().c_str (), (unsigned int)beastString.length () ); }
Value::CZString::CZString( const CZString &other ) : cstr_( other.index_ != noDuplication && other.cstr_ != 0 ? valueAllocator()->makeMemberName( other.cstr_ ) : other.cstr_ ) , index_( other.cstr_ ? (other.index_ == noDuplication ? noDuplication : duplicate) : other.index_ ) { }
Value::Value( const CppTL::ConstString &value ) : type_( stringValue ) , allocated_( true ) , comments_( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_( 0 ) #endif { value_.string_ = valueAllocator()->duplicateStringValue( value, value.length() ); }
Value::Value( const char *value ) : type_( stringValue ) , allocated_( true ) , comments_( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_( 0 ) #endif { value_.string_ = valueAllocator()->duplicateStringValue( value ); }
Value::Value(const std::string &value) : type_(stringValue), allocated_(true), comments_(nullptr) #ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_(0) #endif { value_.string_ = valueAllocator()->duplicateStringValue(value.c_str(), (unsigned int)value.length()); }
Value::Value(const char *beginValue, const char *endValue) : type_(stringValue), allocated_(true), comments_(nullptr) #ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_(0) #endif { value_.string_ = valueAllocator()->duplicateStringValue(beginValue, UInt(endValue - beginValue)); }
Value::Value( const Value &other ) : 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 int64Value: case uint64Value: 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( const Datacratic::Utf8String &value ) : type_( stringValue ) , allocated_( true ) , comments_( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_( 0 ) #endif { value_.string_ = valueAllocator()->duplicateStringValue( value.rawData(), (unsigned int)value.rawLength() ); }
Value::Value (beast::String const& beastString) : type_ ( stringValue ) , allocated_ ( true ) , comments_ ( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_ ( 0 ) #endif { value_.string_ = valueAllocator ()->duplicateStringValue ( beastString.toStdString ().c_str (), (unsigned int)beastString.length () ); }
Value::CZString::~CZString() { if (cstr_ && index_ == duplicate) valueAllocator()->releaseMemberName(const_cast<char *>(cstr_)); }
Value::CZString::CZString(const char *cstr, DuplicationPolicy allocate) : cstr_(allocate == duplicate ? valueAllocator()->makeMemberName(cstr) : cstr), index_(allocate) {}
Value::CommentInfo::~CommentInfo() { if (comment_) valueAllocator()->releaseStringValue(comment_); }
Value::Value ( const char* value ) : type_ ( stringValue ) , allocated_ ( true ) { value_.string_ = valueAllocator ()->duplicateStringValue ( value ); }
DummyValueAllocatorInitializer() { valueAllocator(); // ensure valueAllocator() statics are initialized before main(). }
DummyValueAllocatorInitializer() { // ensure value allocator statics are initialized before main valueAllocator(); }