0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Public Attributes | List of all members
Hypertable::DynamicBuffer Class Reference

A dynamic, resizable and reference counted memory buffer. More...

#include <DynamicBuffer.h>

Public Member Functions

 DynamicBuffer (size_t initial_size=0, bool own_buffer=true)
 Constructor. More...
 
 ~DynamicBuffer ()
 Destructor; releases the buffer if it "owns" it. More...
 
size_t remaining () const
 Returns the size of the unused portion. More...
 
size_t fill () const
 Returns the size of the used portion. More...
 
bool empty () const
 Returns true if the buffer is empty. More...
 
void ensure (size_t len)
 Ensure space for additional data Will grow the space to 1.5 of the needed space with existing data unchanged. More...
 
void reserve (size_t len, bool nocopy=false)
 Reserve space for additional data Will grow the space to exactly what's needed. More...
 
uint8_t * add_unchecked (const void *data, size_t len)
 Adds additional data without boundary checks. More...
 
uint8_t * add (const void *data, size_t len)
 Adds more data WITH boundary checks; if required the buffer is resized and existing data is preserved. More...
 
void set (const void *data, size_t len)
 Overwrites the existing data. More...
 
void clear ()
 Clears the buffer. More...
 
void set_mark ()
 Sets the mark; the mark can be used by the caller just like a bookmark. More...
 
void free ()
 Frees resources. More...
 
uint8_t * release (size_t *lenp=0)
 Moves ownership of the buffer to the caller. More...
 
void grow (size_t new_size, bool nocopy=false)
 Grows the buffer and copies the data unless nocopy is true. More...
 

Public Attributes

uint8_t * base
 Pointer to the allocated memory buffer. More...
 
uint8_t * ptr
 Pointer to the end of the used part of the buffer. More...
 
uint8_t * mark
 A "bookmark", can be set by the caller. More...
 
uint32_t size
 The size of the allocated memory buffer (base) More...
 
bool own
 If true then the buffer (base) will be released when going out of scope; if false then the caller has to release it. More...
 

Detailed Description

A dynamic, resizable and reference counted memory buffer.

Definition at line 42 of file DynamicBuffer.h.

Constructor & Destructor Documentation

Hypertable::DynamicBuffer::DynamicBuffer ( size_t  initial_size = 0,
bool  own_buffer = true 
)
inlineexplicit

Constructor.

Parameters
initial_sizeInitial size of the buffer
own_bufferIf true, then this object takes ownership of the buffer and releases it when going out of scope

Definition at line 52 of file DynamicBuffer.h.

Hypertable::DynamicBuffer::~DynamicBuffer ( )
inline

Destructor; releases the buffer if it "owns" it.

Definition at line 61 of file DynamicBuffer.h.

Member Function Documentation

uint8_t* Hypertable::DynamicBuffer::add ( const void *  data,
size_t  len 
)
inline

Adds more data WITH boundary checks; if required the buffer is resized and existing data is preserved.

Parameters
dataA pointer to the new data
lenThe size of the new data
Returns
A pointer to the added data

Definition at line 122 of file DynamicBuffer.h.

uint8_t* Hypertable::DynamicBuffer::add_unchecked ( const void *  data,
size_t  len 
)
inline

Adds additional data without boundary checks.

Parameters
dataA pointer to the new data
lenThe size of the new data
Returns
A pointer to the added data

Definition at line 106 of file DynamicBuffer.h.

void Hypertable::DynamicBuffer::clear ( )
inline

Clears the buffer.

Definition at line 139 of file DynamicBuffer.h.

bool Hypertable::DynamicBuffer::empty ( ) const
inline

Returns true if the buffer is empty.

Definition at line 73 of file DynamicBuffer.h.

void Hypertable::DynamicBuffer::ensure ( size_t  len)
inline

Ensure space for additional data Will grow the space to 1.5 of the needed space with existing data unchanged.

Parameters
lenAdditional bytes to grow

Definition at line 82 of file DynamicBuffer.h.

size_t Hypertable::DynamicBuffer::fill ( ) const
inline

Returns the size of the used portion.

Definition at line 70 of file DynamicBuffer.h.

void Hypertable::DynamicBuffer::free ( )
inline

Frees resources.

Definition at line 150 of file DynamicBuffer.h.

void Hypertable::DynamicBuffer::grow ( size_t  new_size,
bool  nocopy = false 
)
inline

Grows the buffer and copies the data unless nocopy is true.

Parameters
new_sizeThe new buffer size
nocopyIf true then the data will not be preserved

Definition at line 176 of file DynamicBuffer.h.

uint8_t* Hypertable::DynamicBuffer::release ( size_t *  lenp = 0)
inline

Moves ownership of the buffer to the caller.

Parameters
lenpIf not null then the length of the buffer is stored
Returns
A pointer to the data

Definition at line 162 of file DynamicBuffer.h.

size_t Hypertable::DynamicBuffer::remaining ( ) const
inline

Returns the size of the unused portion.

Definition at line 67 of file DynamicBuffer.h.

void Hypertable::DynamicBuffer::reserve ( size_t  len,
bool  nocopy = false 
)
inline

Reserve space for additional data Will grow the space to exactly what's needed.

Existing data is NOT preserved by default

Parameters
lenSize of the reserved space
nocopyIf true then the existing data is not preserved

Definition at line 95 of file DynamicBuffer.h.

void Hypertable::DynamicBuffer::set ( const void *  data,
size_t  len 
)
inline

Overwrites the existing data.

Parameters
dataA pointer to the new data
lenThe size of the new data

Definition at line 132 of file DynamicBuffer.h.

void Hypertable::DynamicBuffer::set_mark ( )
inline

Sets the mark; the mark can be used by the caller just like a bookmark.

Definition at line 145 of file DynamicBuffer.h.

Member Data Documentation

uint8_t* Hypertable::DynamicBuffer::base

Pointer to the allocated memory buffer.

Definition at line 191 of file DynamicBuffer.h.

uint8_t* Hypertable::DynamicBuffer::mark

A "bookmark", can be set by the caller.

Definition at line 197 of file DynamicBuffer.h.

bool Hypertable::DynamicBuffer::own

If true then the buffer (base) will be released when going out of scope; if false then the caller has to release it.

Definition at line 204 of file DynamicBuffer.h.

uint8_t* Hypertable::DynamicBuffer::ptr

Pointer to the end of the used part of the buffer.

Definition at line 194 of file DynamicBuffer.h.

uint32_t Hypertable::DynamicBuffer::size

The size of the allocated memory buffer (base)

Definition at line 200 of file DynamicBuffer.h.


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