libcamgm
|
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... | |
ByteBuffer & | operator= (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... | |
ByteBuffer & | operator+= (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) |
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.
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.
str | Pointer to a '\0' terminated C string. |
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.
ptr | Pointer to a character array to copy from. |
len | The length of the character array in ptr. |
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).
The | ByteBuffer object to make a copy of. |
ca_mgm::ByteBuffer::~ByteBuffer | ( | ) |
Destroy the ByteBuffer object.
void ca_mgm::ByteBuffer::append | ( | const char * | ptr, |
size_t | len | ||
) |
Append new data to this ByteBuffer object.
ptr | Pointer to a character array to copy from. |
len | The length of the character array in ptr. |
std::bad_alloc |
void ca_mgm::ByteBuffer::append | ( | char | c | ) |
Append a new byte to this ByteBuffer object.
c | The new byte to append. |
std::bad_alloc |
char ca_mgm::ByteBuffer::at | ( | size_t | pos | ) | const |
Return the byte at position pos.
ca_mgm::OutOfBoundsException | if 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.
std::bad_alloc |
const char* ca_mgm::ByteBuffer::data | ( | ) | const |
Returns a pointer to the data stored in the ByteBuffer.
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.
buf | The ByteBuffer object to append. |
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.
buf | The ByteBuffer object to assign |
std::bad_alloc |
const char& ca_mgm::ByteBuffer::operator[] | ( | size_t | pos | ) | const |
Return the byte at position pos
pos | The position of the byte which should be returned. |
ca_mgm::OutOfBoundsException | if position is bigger than the size of this ByteBuffer. |
char& ca_mgm::ByteBuffer::operator[] | ( | size_t | pos | ) |
Return the byte at position pos
pos | The position of the byte which should be returned. |
ca_mgm::OutOfBoundsException | if position is bigger than the size of this ByteBuffer. |
size_t ca_mgm::ByteBuffer::size | ( | ) | const |
Return the number of bytes in this ByteBuffer.
|
friend |
|
friend |
std::bad_alloc |
|
friend |
|
friend |
A stream output operator for debugging purposes.
|
friend |
|
friend |
|
friend |
|
friend |
|
private |