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::StaticBuffer Class Reference

A memory buffer of static size. More...

#include <StaticBuffer.h>

Public Member Functions

 StaticBuffer ()
 Constructor. More...
 
 StaticBuffer (size_t len, size_t alignment=0)
 Constructor. More...
 
 StaticBuffer (void *data, uint32_t len, bool take_ownership=true)
 Constructor; assigns an existing buffer and can take ownership of that buffer. More...
 
 StaticBuffer (DynamicBuffer &dbuf)
 Constructor; takes ownership from a DynamicBuffer. More...
 
 ~StaticBuffer ()
 Destructor; if "own" is true then the buffer will be delete[]d. More...
 
 StaticBuffer (StaticBuffer &other)
 Copy constructor. More...
 
StaticBufferoperator= (StaticBuffer &other)
 Assignment operator. More...
 
StaticBufferoperator= (DynamicBuffer &dbuf)
 Assignment operator for DynamicBuffer. More...
 
void set (uint8_t *data, uint32_t len, bool take_ownership=true)
 Sets data pointer; the existing buffer is discarded and deleted. More...
 
void free ()
 Clears the data; if this object is owner of the data then the allocated buffer is delete[]d. More...
 
size_t aligned_size ()
 

Public Attributes

uint8_t * base
 
size_t alignment
 
uint32_t size
 
bool own
 

Detailed Description

A memory buffer of static size.

The actual buffer can be allocated or assigned by the caller. If the StaticBuffer "owns" the pointer then it will be released when going out of scope.

Definition at line 45 of file StaticBuffer.h.

Constructor & Destructor Documentation

Hypertable::StaticBuffer::StaticBuffer ( )
inline

Constructor.

Creates an empty buffer

Definition at line 48 of file StaticBuffer.h.

Hypertable::StaticBuffer::StaticBuffer ( size_t  len,
size_t  alignment = 0 
)
inlineexplicit

Constructor.

Allocates a new buffer of size len. If alignment is non-zero, then the posix_memalign() function will be called to obtain memory and alignment is set to alignment. Memory will be released when going out of scope.

Parameters
lenThe size of the new buffer, in bytes
alignmentBuffer alignment

Definition at line 61 of file StaticBuffer.h.

Hypertable::StaticBuffer::StaticBuffer ( void *  data,
uint32_t  len,
bool  take_ownership = true 
)
inline

Constructor; assigns an existing buffer and can take ownership of that buffer.

Parameters
dataPointer to the existing buffer
lenSize of the existing buffer
take_ownershipIf yes, will "own" the existing buffer and delete[] the memory when going out of scope. Make sure that the buffer was allocated with new[]!

Definition at line 83 of file StaticBuffer.h.

Hypertable::StaticBuffer::StaticBuffer ( DynamicBuffer dbuf)
inline

Constructor; takes ownership from a DynamicBuffer.

Definition at line 88 of file StaticBuffer.h.

Hypertable::StaticBuffer::~StaticBuffer ( )
inline

Destructor; if "own" is true then the buffer will be delete[]d.

Definition at line 100 of file StaticBuffer.h.

Hypertable::StaticBuffer::StaticBuffer ( StaticBuffer other)
inline

Copy constructor.

WARNING: This assignment operator will cause the ownership of the buffer to transfer to the lvalue buffer if the own flag is set to 'true' in the buffer being copied. The buffer being copied will be modified to have it's 'own' flag set to false and the 'base' pointer will be set to NULL. In other words, the buffer being copied is no longer usable after the assignment.

Parameters
otherReference to the original instance

Definition at line 116 of file StaticBuffer.h.

Member Function Documentation

size_t Hypertable::StaticBuffer::aligned_size ( )
inline

Definition at line 196 of file StaticBuffer.h.

void Hypertable::StaticBuffer::free ( )
inline

Clears the data; if this object is owner of the data then the allocated buffer is delete[]d.

Definition at line 185 of file StaticBuffer.h.

StaticBuffer& Hypertable::StaticBuffer::operator= ( StaticBuffer other)
inline

Assignment operator.

WARNING: This assignment operator will cause the ownership of the buffer to transfer to the lvalue buffer if the own flag is set to 'true' in the buffer being copied. The buffer being copied will be modified to have it's 'own' flag set to false and the 'base' pointer will be set to NULL. In other words, the buffer being copied is no longer usable after the assignment.

Parameters
otherReference to the original instance

Definition at line 139 of file StaticBuffer.h.

StaticBuffer& Hypertable::StaticBuffer::operator= ( DynamicBuffer dbuf)
inline

Assignment operator for DynamicBuffer.

Parameters
dbufReference to the original DynamicBuffer instance

Definition at line 155 of file StaticBuffer.h.

void Hypertable::StaticBuffer::set ( uint8_t *  data,
uint32_t  len,
bool  take_ownership = true 
)
inline

Sets data pointer; the existing buffer is discarded and deleted.

Parameters
dataPointer to the existing buffer
lenSize of the existing buffer
take_ownershipIf yes, will "own" the existing buffer and delete[] the memory when going out of scope. Make sure that the buffer was allocated with new[]!

Definition at line 175 of file StaticBuffer.h.

Member Data Documentation

size_t Hypertable::StaticBuffer::alignment

Definition at line 203 of file StaticBuffer.h.

uint8_t* Hypertable::StaticBuffer::base

Definition at line 202 of file StaticBuffer.h.

bool Hypertable::StaticBuffer::own

Definition at line 205 of file StaticBuffer.h.

uint32_t Hypertable::StaticBuffer::size

Definition at line 204 of file StaticBuffer.h.


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