Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
Json::ValueArrayAllocator Class Referenceabstract

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

#include <json.h>

Public Member Functions

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. Reallocates an array of pointer on each page. 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 &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 );
}
};

Member Function Documentation

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.

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