7 #ifndef ZEROBUF_ALLOCATOR_H
8 #define ZEROBUF_ALLOCATOR_H
10 #include <zerobuf/Types.h>
26 virtual uint8_t* getData() = 0;
27 virtual const uint8_t* getData()
const = 0;
28 virtual size_t getSize()
const = 0;
29 virtual void copyBuffer(
const void* data,
size_t size ) = 0;
38 template<
class T > T* getItemPtr(
const size_t offset )
39 {
return reinterpret_cast< T*
>( getData() + offset ); }
41 template<
class T >
const T* getItemPtr(
const size_t offset )
const
42 {
return reinterpret_cast< const T*
>( getData() + offset ); }
44 template<
class T > T& getItem(
const size_t offset )
45 {
return *getItemPtr< T >( offset ); }
47 template<
class T > T getItem(
const size_t offset )
const
48 {
return *getItemPtr< T >( offset ); }
50 template<
class T > T* getDynamic(
const size_t index )
51 {
return reinterpret_cast< T*
>( getData() + _getOffset( index )); }
53 template<
class T >
const T* getDynamic(
const size_t index )
const
54 {
return reinterpret_cast< const T*
>( getData() + _getOffset(index)); }
56 size_t getDynamicSize(
const size_t index )
const
57 {
return _getSize( index ); }
60 uint64_t& _getOffset(
const size_t i )
61 {
return getItem< uint64_t >( 4 + i * 16 ); }
62 uint64_t _getOffset(
const size_t i )
const
63 {
return getItem< uint64_t >( 4 + i * 16 ); }
64 uint64_t& _getSize(
const size_t i )
65 {
return getItem< uint64_t >( 4 + 8 + i * 16 ); }
66 uint64_t _getSize(
const size_t i )
const
67 {
return getItem< uint64_t >( 4 + 8 + i * 16 ); }
Allocator base class and interface.
virtual uint8_t * updateAllocation(size_t index, size_t newSize)=0
Update allocation of the dynamic elem.