JsonCpp project page JsonCpp home page

Public Member Functions
Json::ValueArrayAllocator Class Reference

Experimental: do not use. More...

#include <json/value.h>

Inherited by Json::DefaultValueArrayAllocator.

List of all members.

Public Member Functions

virtual ~ValueArrayAllocator ()
virtual ValueInternalArraynewArray ()=0
virtual ValueInternalArraynewArrayCopy (const ValueInternalArray &other)=0
virtual void destructArray (ValueInternalArray *array)=0
virtual void reallocateArrayPageIndex (Value **&indexes, ValueInternalArray::PageIndex &indexCount, ValueInternalArray::PageIndex minNewIndexCount)=0
 Reallocate array page index.
virtual void releaseArrayPageIndex (Value **indexes, ValueInternalArray::PageIndex indexCount)=0
virtual ValueallocateArrayPage ()=0
virtual void releaseArrayPage (Value *value)=0

Detailed Description

Experimental: do not use.

Allocator to customize Value internal array. Below is an example of a simple implementation (actual implementation use memory pool).

class DefaultValueArrayAllocator : public ValueArrayAllocator
{
public: // overridden from ValueArrayAllocator
   virtual ~DefaultValueArrayAllocator()
   {
   }

   virtual ValueInternalArray *newArray()
   {
      return new ValueInternalArray();
   }

   virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other )
   {
      return new ValueInternalArray( other );
   }

   virtual void destruct( ValueInternalArray *array )
   {
      delete array;
   }

   virtual void reallocateArrayPageIndex( Value **&indexes, 
                                          ValueInternalArray::PageIndex &indexCount,
                                          ValueInternalArray::PageIndex minNewIndexCount )
   {
      ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1;
      if ( minNewIndexCount > newIndexCount )
         newIndexCount = minNewIndexCount;
      void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount );
      if ( !newIndexes )
         throw std::bad_alloc();
      indexCount = newIndexCount;
      indexes = static_cast<Value **>( newIndexes );
   }
   virtual void releaseArrayPageIndex( Value **indexes, 
                                       ValueInternalArray::PageIndex indexCount )
   {
      if ( indexes )
         free( indexes );
   }

   virtual Value *allocateArrayPage()
   {
      return static_cast<Value *>( malloc( sizeof(Value) * ValueInternalArray::itemsPerPage ) );
   }

   virtual void releaseArrayPage( Value *value )
   {
      if ( value )
         free( value );
   }
};

Definition at line 881 of file value.h.


Constructor & Destructor Documentation

Definition at line 18 of file json_internalarray.inl.


Member Function Documentation

virtual void Json::ValueArrayAllocator::destructArray ( ValueInternalArray array) [pure virtual]

Referenced by Json::Value::~Value().

Referenced by Json::Value::Value().

Referenced by Json::Value::Value().

virtual void Json::ValueArrayAllocator::reallocateArrayPageIndex ( Value **&  indexes,
ValueInternalArray::PageIndex indexCount,
ValueInternalArray::PageIndex  minNewIndexCount 
) [pure virtual]

Reallocate array page index.

Reallocates an array of pointer on each page.

Parameters:
indexes[input] pointer on the current index. May be NULL. [output] pointer on the new index of at least minNewIndexCount pages.
indexCount[input] current number of pages in the index. [output] number of page the reallocated index can handle. MUST be >= minNewIndexCount.
minNewIndexCountMinimum number of page the new index must be able to handle.

Referenced by Json::ValueInternalArray::ValueInternalArray().

virtual void Json::ValueArrayAllocator::releaseArrayPage ( Value value) [pure virtual]
virtual void Json::ValueArrayAllocator::releaseArrayPageIndex ( Value **  indexes,
ValueInternalArray::PageIndex  indexCount 
) [pure virtual]

The documentation for this class was generated from the following files:

SourceForge Logo hosts this site. Send comments to:
Json-cpp Developers