libcamgm
Public Member Functions | Private Attributes | Friends | List of all members
ca_mgm::ByteBuffer Class Reference

Buffer for storing binary data. More...

#include <ByteBuffer.hpp>

Public Member Functions

 ByteBuffer ()
 
 ByteBuffer (const char *str)
 
 ByteBuffer (const char *ptr, size_t len)
 
 ByteBuffer (const ByteBuffer &buf)
 
 ~ByteBuffer ()
 
void clear ()
 Remove all data from the ByteBuffer. More...
 
bool empty () const
 Return true if the ByteBuffer is empty (size() == 0) More...
 
size_t size () const
 Return the number of bytes in this ByteBuffer. More...
 
const char * data () const
 Returns a pointer to the data stored in the ByteBuffer. More...
 
char at (size_t pos) const
 Return the byte at position pos. More...
 
void append (const char *ptr, size_t len)
 Append new data to this ByteBuffer object. More...
 
void append (char c)
 Append a new byte to this ByteBuffer object. More...
 
ByteBufferoperator= (const ByteBuffer &buf)
 Assigns buf to this ByteBuffer object. More...
 
const char & operator[] (size_t pos) const
 Return the byte at position pos More...
 
char & operator[] (size_t pos)
 Return the byte at position pos More...
 
ByteBufferoperator+= (const ByteBuffer &buf)
 Appends data from the ByteBuffer object buf. More...
 

Private Attributes

ca_mgm::RWCOW_pointer< ByteBufferImpl > m_impl
 

Friends

std::ostream & operator<< (std::ostream &out, const ByteBuffer &buf)
 
bool operator== (const ByteBuffer &l, const ByteBuffer &r)
 
bool operator!= (const ByteBuffer &l, const ByteBuffer &r)
 
bool operator< (const ByteBuffer &l, const ByteBuffer &r)
 
bool operator> (const ByteBuffer &l, const ByteBuffer &r)
 
bool operator<= (const ByteBuffer &l, const ByteBuffer &r)
 
bool operator>= (const ByteBuffer &l, const ByteBuffer &r)
 
ByteBuffer operator+ (const ByteBuffer &b1, const ByteBuffer &b2)
 

Detailed Description

Buffer for storing binary data.

The class implements a byte buffer useful for manipulating memory areas with custom data.

It is reference counted and supports copy on write functionality.

Constructor & Destructor Documentation

ca_mgm::ByteBuffer::ByteBuffer ( )

Create an empty ByteBuffer object.

ca_mgm::ByteBuffer::ByteBuffer ( const char *  str)

Create a ByteBuffer object and initialize it with the C string provided in str. The size is determined using the ::strlen(str) function.

Parameters
strPointer to a '\0' terminated C string.
Exceptions
std::bad_alloc
ca_mgm::ByteBuffer::ByteBuffer ( const char *  ptr,
size_t  len 
)

Create a ByteBuffer object that will contain a copy of the given character array ptr and its size given in len.

Parameters
ptrPointer to a character array to copy from.
lenThe length of the character array in ptr.
Exceptions
std::bad_alloc
ca_mgm::ByteBuffer::ByteBuffer ( const ByteBuffer buf)

Create a new ByteBuffer object that is a shared copy of an another ByteBuffer object.

Upon return, both objects will point to the same underlying byte buffer. This state will remain until one of the objects is modified (copy on write).

Parameters
TheByteBuffer object to make a copy of.
ca_mgm::ByteBuffer::~ByteBuffer ( )

Destroy the ByteBuffer object.

Member Function Documentation

void ca_mgm::ByteBuffer::append ( const char *  ptr,
size_t  len 
)

Append new data to this ByteBuffer object.

Parameters
ptrPointer to a character array to copy from.
lenThe length of the character array in ptr.
Exceptions
std::bad_alloc
void ca_mgm::ByteBuffer::append ( char  c)

Append a new byte to this ByteBuffer object.

Parameters
cThe new byte to append.
Exceptions
std::bad_alloc
char ca_mgm::ByteBuffer::at ( size_t  pos) const

Return the byte at position pos.

Returns
Return the byte at position pos.
Exceptions
ca_mgm::OutOfBoundsExceptionif the position is bigger than the number of bytes in this ByteBuffer.
void ca_mgm::ByteBuffer::clear ( )

Remove all data from the ByteBuffer.

The size() of the ByteBuffer should be zero after calling this method.

Exceptions
std::bad_alloc
const char* ca_mgm::ByteBuffer::data ( ) const

Returns a pointer to the data stored in the ByteBuffer.

Returns
Returns a pointer to the data.
bool ca_mgm::ByteBuffer::empty ( ) const

Return true if the ByteBuffer is empty (size() == 0)

ByteBuffer& ca_mgm::ByteBuffer::operator+= ( const ByteBuffer buf)

Appends data from the ByteBuffer object buf.

Appends data from the specified ByteBuffer object buf to the end of this ByteBuffer object and returns a reference to this ByteBuffer object.

Parameters
bufThe ByteBuffer object to append.
Returns
A reference to this ByteBuffer object.
Exceptions
std::bad_alloc
ByteBuffer& ca_mgm::ByteBuffer::operator= ( const ByteBuffer buf)

Assigns buf to this ByteBuffer object.

Assigns buf to this ByteBuffer object and returns a reference to this ByteBuffer object.

Parameters
bufThe ByteBuffer object to assign
Returns
A reference to this ByteBuffer object
Exceptions
std::bad_alloc
const char& ca_mgm::ByteBuffer::operator[] ( size_t  pos) const

Return the byte at position pos

Parameters
posThe position of the byte which should be returned.
Returns
Read-Only reference to the byte at the specified position pos.
Exceptions
ca_mgm::OutOfBoundsExceptionif position is bigger than the size of this ByteBuffer.
char& ca_mgm::ByteBuffer::operator[] ( size_t  pos)

Return the byte at position pos

Parameters
posThe position of the byte which should be returned.
Returns
Read-Write reference to the byte at the specified position pos.
Exceptions
ca_mgm::OutOfBoundsExceptionif position is bigger than the size of this ByteBuffer.
size_t ca_mgm::ByteBuffer::size ( ) const

Return the number of bytes in this ByteBuffer.

Returns
The number of bytes in this ByteBuffer.

Friends And Related Function Documentation

bool operator!= ( const ByteBuffer l,
const ByteBuffer r 
)
friend
Returns
True if the ByteBuffer object l is not equal to the ByteBuffer object r; otherwise false.
ByteBuffer operator+ ( const ByteBuffer b1,
const ByteBuffer b2 
)
friend
Returns
A ByteBuffer object that is the result of concatenating the ByteBuffer object b1 and the ByteBuffer object b2.
Exceptions
std::bad_alloc
bool operator< ( const ByteBuffer l,
const ByteBuffer r 
)
friend
Returns
True if the ByteBuffer object l is less than the ByteBuffer object r; otherwise false.
std::ostream& operator<< ( std::ostream &  out,
const ByteBuffer buf 
)
friend

A stream output operator for debugging purposes.

bool operator<= ( const ByteBuffer l,
const ByteBuffer r 
)
friend
Returns
True if the ByteBuffer object l is less than or equal to the ByteBuffer object r; otherwise false.
bool operator== ( const ByteBuffer l,
const ByteBuffer r 
)
friend
Returns
True if the ByteBuffer object l is equal to the ByteBuffer object r; otherwise false.
bool operator> ( const ByteBuffer l,
const ByteBuffer r 
)
friend
Returns
True if the ByteBuffer object l is greater than the ByteBuffer object r; otherwise false.
bool operator>= ( const ByteBuffer l,
const ByteBuffer r 
)
friend
Returns
True if the ByteBuffer object l is greater then or equal to the ByteBuffer object r; otherwise false.

Member Data Documentation

ca_mgm::RWCOW_pointer<ByteBufferImpl> ca_mgm::ByteBuffer::m_impl
private

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