limal::ByteBuffer Class Reference

Buffer for storing binary data. More...

#include <ByteBuffer.hpp>

List of all members.

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.
bool empty () const
 Return true if the ByteBuffer is empty (size() == 0).
size_t size () const
 Return the number of bytes in this ByteBuffer.
const char * data () const
 Returns a pointer to the data stored in the ByteBuffer.
char at (size_t pos) const
 Return the byte at position pos.
void append (const char *ptr, size_t len)
 Append new data to this ByteBuffer object.
void append (char c)
 Append a new byte to this ByteBuffer object.
ByteBufferoperator= (const ByteBuffer &buf)
 Assigns buf to this ByteBuffer object.
const char & operator[] (size_t pos) const
 Return the byte at position pos
char & operator[] (size_t pos)
 Return the byte at position pos
ByteBufferoperator+= (const ByteBuffer &buf)
 Appends data from the ByteBuffer object buf.

Private Attributes

BLOCXX_NAMESPACE::COWIntrusiveReference
< 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

limal::ByteBuffer::ByteBuffer (  ) 

Create an empty ByteBuffer object.

limal::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:
str Pointer to a '\0' terminated C string.
Exceptions:
std::bad_alloc 
limal::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:
ptr Pointer to a character array to copy from.
len The length of the character array in ptr.
Exceptions:
std::bad_alloc 
limal::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:
The ByteBuffer object to make a copy of.
limal::ByteBuffer::~ByteBuffer (  ) 

Destroy the ByteBuffer object.


Member Function Documentation

void limal::ByteBuffer::append ( char  c  ) 

Append a new byte to this ByteBuffer object.

Parameters:
c The new byte to append.
Exceptions:
std::bad_alloc 
void limal::ByteBuffer::append ( const char *  ptr,
size_t  len 
)

Append new data to this ByteBuffer object.

Parameters:
ptr Pointer to a character array to copy from.
len The length of the character array in ptr.
Exceptions:
std::bad_alloc 
char limal::ByteBuffer::at ( size_t  pos  )  const

Return the byte at position pos.

Returns:
Return the byte at position pos.
Exceptions:
blocxx::OutOfBoundsException if the position is bigger than the number of bytes in this ByteBuffer.
void limal::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* limal::ByteBuffer::data (  )  const

Returns a pointer to the data stored in the ByteBuffer.

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

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

ByteBuffer& limal::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:
buf The ByteBuffer object to append.
Returns:
A reference to this ByteBuffer object.
Exceptions:
std::bad_alloc 
ByteBuffer& limal::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:
buf The ByteBuffer object to assign
Returns:
A reference to this ByteBuffer object
Exceptions:
std::bad_alloc 
char& limal::ByteBuffer::operator[] ( size_t  pos  ) 

Return the byte at position pos

Parameters:
pos The position of the byte which should be returned.
Returns:
Read-Write reference to the byte at the specified position pos.
Exceptions:
blocxx::OutOfBoundsException if position is bigger than the size of this ByteBuffer.
const char& limal::ByteBuffer::operator[] ( size_t  pos  )  const

Return the byte at position pos

Parameters:
pos The position of the byte which should be returned.
Returns:
Read-Only reference to the byte at the specified position pos.
Exceptions:
blocxx::OutOfBoundsException if position is bigger than the size of this ByteBuffer.
size_t limal::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

BLOCXX_NAMESPACE ::COWIntrusiveReference<ByteBufferImpl> limal::ByteBuffer::m_impl [private]

The documentation for this class was generated from the following file:
Generated on Mon Jul 5 22:00:06 2010 for limal by  doxygen 1.6.3