The Micro C++ Library
|
A simple generic Buffer that could dynamically grow or shrink. More...
#include <micxx.hxx>
Inherits micxx::traits::ToString.
Inherited by micxx::Datagram.
Public Member Functions | |
Buffer (std::size_t size=0) | |
Create a new Buffer with initial size and initial capacity set to size. | |
Buffer (const Buffer &right) | |
Create a copy of Buffer right. | |
virtual | ~Buffer () |
Delete the internal pointer to the dynamically allocated storage. | |
virtual void | append (const void *address, std::size_t size) |
Appends the address range starting at address to the end of this buffer. | |
virtual void * | getAddress () |
The address of (or pointer to) the dynamically allocated storage. | |
virtual const void * | getAddress () const |
virtual std::size_t | getCapacity () const |
The actual size of the dynamically allocated storage. | |
virtual std::size_t | getSize () const |
The currently used size of the available capacity. | |
virtual unsigned char * | operator+ (std::size_t offset) |
The Address of the offset offset into the dynamically allocated storage. | |
virtual const unsigned char * | operator+ (std::size_t offset) const |
virtual unsigned char & | operator[] (std::size_t offset) |
The byte at offset offset from the dynamically allocated storage. | |
virtual const unsigned char & | operator[] (std::size_t offset) const |
virtual Buffer & | operator= (const Buffer &right) |
Make this a copy of Buffer right . | |
virtual std::size_t | operator== (const Buffer &right) |
Compare the content from this buffer with right. | |
template<typename Writer > | |
Writer & | operator>> (Writer &writer) const |
Write the current buffer data (const void*)(*this) with size getSize() / sizeof(Writer::char_type) to the output Writer writer. | |
template<typename Reader > | |
Buffer & | operator<< (Reader &reader) |
Reads up to getCapacity() / sizeof(Reader::char_type) into this buffer. | |
virtual | operator void * () |
virtual | operator const void * () const |
virtual void | setCapacity (std::size_t capacity) |
Sets the new capacity to capacity. | |
virtual void | setSize (std::size_t size) |
Sets the currently used size to size. | |
virtual std::string | toString () const |
A string representation describing this Buffer. | |
Protected Attributes | |
void * | address |
The pointer (or address) to the dynamically allocated storage. | |
std::size_t | size |
The current used size of the available capacity. | |
std::size_t | capacity |
The actually available size of the dynamically allocated storage. |
A simple generic Buffer that could dynamically grow or shrink.
A Buffer has
micxx::Buffer::Buffer | ( | std::size_t | size = 0 | ) | [explicit] |
Create a new Buffer with initial size and initial capacity set to size.
size | The initial size and capacity. |
micxx::Buffer::Buffer | ( | const Buffer & | right | ) |
virtual micxx::Buffer::~Buffer | ( | ) | [virtual] |
Delete the internal pointer to the dynamically allocated storage.
virtual void micxx::Buffer::append | ( | const void * | address, |
std::size_t | size | ||
) | [virtual] |
Appends the address range starting at address to the end of this buffer.
The size of this buffer is incremented by size before.
virtual void* micxx::Buffer::getAddress | ( | ) | [inline, virtual] |
The address of (or pointer to) the dynamically allocated storage.
{ return address; }
virtual const void* micxx::Buffer::getAddress | ( | ) | const [inline, virtual] |
The const version of getAddress().
{ return address; }
virtual std::size_t micxx::Buffer::getCapacity | ( | ) | const [inline, virtual] |
virtual std::size_t micxx::Buffer::getSize | ( | ) | const [inline, virtual] |
virtual micxx::Buffer::operator const void * | ( | ) | const [inline, virtual] |
Same as getAddress() const.
{ return address; }
virtual micxx::Buffer::operator void * | ( | ) | [inline, virtual] |
Same as getAddress().
{ return address; }
virtual unsigned char* micxx::Buffer::operator+ | ( | std::size_t | offset | ) | [virtual] |
The Address of the offset offset into the dynamically allocated storage.
offset | The offset into the dynamically allocated storage |
((unsigned char *)
getAddress()) +
offset. virtual const unsigned char* micxx::Buffer::operator+ | ( | std::size_t | offset | ) | const [virtual] |
The const version of operator+(std::size_t offset).
Buffer & micxx::Buffer::operator<< | ( | Reader & | reader | ) |
Reads up to getCapacity() / sizeof(Reader::char_type)
into this buffer.
setCapacity()
should be called before calling this operator. Use getSize()
afterwards to get the number of bytes read from the Reader reader. { __MICXXTRY__ setSize(0); std::streamsize num = getCapacity() / sizeof(Reader::char_type); if (num) { std::size_t bytesRead = reader.read(address, num); setSize(bytesRead); } return *this; __MICXXEND__ }
virtual std::size_t micxx::Buffer::operator== | ( | const Buffer & | right | ) | [virtual] |
Compare the content from this buffer with right.
0
, if both buffers are equal, orWriter & micxx::Buffer::operator>> | ( | Writer & | writer | ) | const |
Write the current buffer data (const void*)(*this)
with size getSize() / sizeof(Writer::char_type)
to the output Writer writer.
{ __MICXXTRY__ std::streamsize num = getSize() / sizeof(typename Writer::char_type); if (num) { writer.write(static_cast<const typename Writer::char_type*>(address), num); } return writer; __MICXXEND__ }
virtual unsigned char& micxx::Buffer::operator[] | ( | std::size_t | offset | ) | [virtual] |
The byte at offset offset from the dynamically allocated storage.
offset | The offset of the desired byte from the dynamically allocated storage |
((unsigned char *)
getAddress())[
offset ]
. virtual const unsigned char& micxx::Buffer::operator[] | ( | std::size_t | offset | ) | const [virtual] |
The const
version of operator[](std::size_t offset).
virtual void micxx::Buffer::setCapacity | ( | std::size_t | capacity | ) | [virtual] |
virtual void micxx::Buffer::setSize | ( | std::size_t | size | ) | [virtual] |
Sets the currently used size to size.
If size >
getCapacity(), then setCapacity(std::size_t) is called with size before, causing the Buffer to grow dynamically.
size | The new currently used size. |
virtual std::string micxx::Buffer::toString | ( | ) | const [virtual] |
A string representation describing this Buffer.
Reimplemented from micxx::traits::ToString.
Reimplemented in micxx::Datagram.
void* micxx::Buffer::address [protected] |
The pointer (or address) to the dynamically allocated storage.
std::size_t micxx::Buffer::capacity [protected] |
The actually available size of the dynamically allocated storage.
std::size_t micxx::Buffer::size [protected] |
The current used size of the available capacity.