LayerBuf

The class LayerBuf provides resizable arrays of arbitrary type. It is derived from the abstract base class LBBase. It is implemented as std::vector of arrays of T. When more space is needed, new layers are added to the vector.

../../images/LayerBuf_full.png
Code:

Public Methods

constructor

LayerBuf(uint iLayerSize, int iStrategy=MB_DESTROY_DELAY1);

Creates a LayerBuf object with layer size iLayerSize and garbage specified garbage strategy.

iLayerSize

Size of the layers.

iStrategy

Deletion strategy for empty layers. Possible values are:

MB_DESTROY_EAGER

immediately delete empty layers

MB_DESTROY_DELAY

keep at most one empty layer

MB_DESTROY_DELAY1

keep at most two empty layers

MB_DESTROY_LAZY

keep at most 128 empty layers

constructor

LayerBuf();

Empty constructor.

destructor

~LayerBuf();

The destructor deletes all layers.

init

void init(uint iLayerSize, int iStrategy=MB_DESTROY_DELAY1);

Initializes the layers.

iLayerSize

Size of the layers.

iStrategy

see above.

operator[]

template<typename T>
T &operator[](uint i) const;

Transparent element access over all layers.

i

Index of element to get.

size

size_t size();

Returns total capacity of all layers.

freeLayer

void freeLayer(uint iIndex);

Mark the layer as unused ot delete it if the strategy requires it.

iIndex

Index of the layer to be freed.

freeAllLayers

void freeAllLayers();

Frees all layers and deletes them if necessary.

showUsedLayers

showUsedLayers();

Display the pointers to all used layers (debugging)

showFreeLayers

void showFreeLayers();

Display the pointers to all free layers (debugging)

createLayer

void createLayer();

Create a new layer or reuse an existing free one.

getNumLayers

uint getNumLayers() const;

Returns number of free layers.

getLayerSize

uint getLayerSize() const;

Returns layer size.

elementShift

void elementShift(uint iTo, uint iFrom);

Moves an element to a different location.

iTo

Destination index.

iFrom

Original index of element.

moveElements

void moveElements(uint iToLayer, uint iToIndex, uint iFromLayer, uint iFromIndex, uint iNum);

Move iNum elements to a different location.

iToLayer

Index of destination layer.

iToIndex

Destination index in destination layer.

iFromLayer

Index of orignal layer.

iFromIndex

Original index of first element in original layer,

iNum

Number of elements to move.

getNumUsedLayers

size_t getNumUsedLayers() const;

Returns number of used layers.

copyBlock

template<typename T>
virtual int copyBlock(uint iStart, T *pBlock, uint iSize);

Copy an array of iSize elements to specified position. It is the callers responsibility to avoid overwriting.

iStart

Target index.

pBlock

Array of elements.

iSize

Size of arrays.

copyBlock

template<typename T>
virtual int copyBlock(uint iDest, LayerBuf<T> *pBuf, uint iOrig, uint iSize);

Copies parts from a different LayerBuf to a destination in this LayerBuf.

iDest

Destination index in this LayerBuf.

pBuf

Pointer to other LayerBuf.

iOrig

Start index to copy from.

iSize

Number of elements to copy.

getLayer

const T *getLayer(uint i);

Returns pointer tp specified layer.

i

Index of layer in vector.

copyLayer

int copyLayer(int iDestLayer, const T *pData);

Copy the contents of pData to the specified layer.

iDestLayer

Index of destination layer in vector.

pData

Array of elements. We expect pData to contain at least m_iLayerSize elements.