JsonCpp project page JsonCpp home page

Public Member Functions | List of all members
Json::ValueArrayAllocator Class Referenceabstract

Experimental: do not use. More...

#include <json/value.h>

Inherited by Json::DefaultValueArrayAllocator.

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. More...
 
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 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,
{
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

Json::ValueArrayAllocator::~ValueArrayAllocator ( )
virtual

Definition at line 18 of file json_internalarray.inl.

Member Function Documentation

virtual Value* Json::ValueArrayAllocator::allocateArrayPage ( )
pure virtual
virtual void Json::ValueArrayAllocator::destructArray ( ValueInternalArray array)
pure virtual

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

virtual ValueInternalArray* Json::ValueArrayAllocator::newArray ( )
pure virtual

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

virtual ValueInternalArray* Json::ValueArrayAllocator::newArrayCopy ( const ValueInternalArray other)
pure virtual

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