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_;
}
Beispiel #2
0
Value::Value( const Value &other )
   : type_( other.type_ )
   , allocated_( false )
# ifdef JSON_VALUE_USE_INTERNAL_MAP
   , itemIsUsed_( 0 )
#endif
   , comments_( 0 )
{
   switch ( type_ )
   {
   case nullValue:
   case intValue:
   case uintValue:
   case realValue:
   case booleanValue:
      value_ = other.value_;
      break;
   case stringValue:
      if ( other.value_.string_ )
      {
         value_.string_ = duplicateStringValue( other.value_.string_ );
         allocated_ = true;
      }
      else
      {
         value_.string_ = 0;
         allocated_ = false;
      }
      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_ );
      }
   }
}
Beispiel #3
0
/*! \internal Default constructor initialization must be equivalent to:
 * memset( this, 0, sizeof(Value) )
 * This optimization is used in ValueInternalMap fast allocator.
 */
Value::Value ( ValueType type )
    : 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;
    }
}
Beispiel #4
0
Value::Value( const std::initializer_list<Json::Value> & vals )
   : type_( arrayValue )
   , allocated_( 0 )
   , comments_( 0 )
# ifdef JSON_VALUE_USE_INTERNAL_MAP
   , itemIsUsed_( 0 )
#endif
{
#ifndef JSON_VALUE_USE_INTERNAL_MAP
    value_.map_ = new ObjectValues();
#else
    value_.array_ = arrayAllocator()->newArray();
#endif

    for (auto & v: vals)
        append(v);
}