Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
DynBlock Class Reference

#include <elm/alloc/DynBlock.h>

Public Member Functions

 DynBlock (int capacity=256, int increment=64)
 
 ~DynBlock (void)
 
void put (const char *block, int size)
 
void get (char *block, int size, int pos)
 
char * alloc (int size)
 
int size (void) const
 
int capacity (void) const
 
int increment (void) const
 
void setSize (int new_size)
 
void reset (void)
 
const char * base (void) const
 
char * detach (void)
 

Detailed Description

This class implements an exyensible block of memory.

Constructor & Destructor Documentation

◆ DynBlock()

DynBlock ( int  capacity = 256,
int  increment = 64 
)
inline

Build a new dynamic block.

Parameters
capacityInitial capacity of allocated buffer.
incrementIncrement for enlarging the buffer.

◆ ~DynBlock()

~DynBlock ( void  )
inline

Delete the buffer.

Member Function Documentation

◆ alloc()

char * alloc ( int  size)

Allocate a block of memory that may be initialized by caller application.

Parameters
sizeSize of block to allocate.
Returns
Allocated block that may initialized by application.

References DynBlock::size().

◆ base()

const char * base ( void  ) const
inline

Get the buffer base of the block.

Returns
Block buffer base.

Referenced by BlockOutStream::block(), and BlockOutStream::toString().

◆ capacity()

int capacity ( void  ) const
inline

Get the capacity of the block.

Returns
Block capacity.

◆ detach()

char * detach ( void  )
inline

Detach the block from this dynamic manager. The dynamic block must no more be used after this call.

Returns
Block buffer that must be fried using "delete []".

Referenced by BlockOutStream::detach().

◆ get()

void get ( char *  block,
int  size,
int  pos 
)

Get a part from the dynamic block. It is an error to pass a size too big, or a position out of range.

Parameters
blockBlock to put bytes in.
sizeSize of the block.
posPosition to get bytes from.

References DynBlock::size().

◆ increment()

int increment ( void  ) const
inline

Get the incrementation value.

Returns
Incrementation value.

◆ put()

void put ( const char *  block,
int  size 
)

Put a new data piece in the current block. Enlarge the block if required.

Parameters
blockBlock to put in.
sizeSize of the block.

References DynBlock::size().

Referenced by BlockOutStream::write().

◆ reset()

void reset ( void  )
inline

Reset the block to a size of 0.

Referenced by BlockOutStream::clear().

◆ setSize()

void setSize ( int  new_size)
inline

Set the size of the block. Must be less or equal to the current block size.

Parameters
new_sizeNew size of the block.

Referenced by BlockOutStream::setSize().

◆ size()

int size ( void  ) const
inline

Get the ize of the block.

Returns
Block size.

Referenced by DynBlock::alloc(), DynBlock::get(), DynBlock::put(), BlockOutStream::size(), and BlockOutStream::toString().


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