JsonCpp project page | JsonCpp home page |
#include <json/value.h>
Inherited by Json::DefaultValueArrayAllocator.
Public Member Functions | |
virtual | ~ValueArrayAllocator () |
virtual ValueInternalArray * | newArray ()=0 |
virtual ValueInternalArray * | newArrayCopy (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 Value * | allocateArrayPage ()=0 |
virtual void | releaseArrayPage (Value *value)=0 |
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.
Json::ValueArrayAllocator::~ValueArrayAllocator | ( | ) | [virtual] |
Definition at line 18 of file json_internalarray.inl.
virtual Value* Json::ValueArrayAllocator::allocateArrayPage | ( | ) | [pure virtual] |
Referenced by Json::ValueInternalArray::ValueInternalArray().
virtual void Json::ValueArrayAllocator::destructArray | ( | ValueInternalArray * | array | ) | [pure virtual] |
virtual ValueInternalArray* Json::ValueArrayAllocator::newArray | ( | ) | [pure virtual] |
virtual ValueInternalArray* Json::ValueArrayAllocator::newArrayCopy | ( | const ValueInternalArray & | other | ) | [pure virtual] |
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.
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. | |
minNewIndexCount | Minimum 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] |
Referenced by Json::ValueInternalArray::resize(), and Json::ValueInternalArray::~ValueInternalArray().
virtual void Json::ValueArrayAllocator::releaseArrayPageIndex | ( | Value ** | indexes, | |
ValueInternalArray::PageIndex | indexCount | |||
) | [pure virtual] |
Referenced by Json::ValueInternalArray::~ValueInternalArray().
hosts this site. |
Send comments to: Json-cpp Developers |