#include <ByteBuffer.h>
Public Member Functions | |
virtual void | alloc (size_t n) |
make sure that at least n bytes are allocated. | |
void | assign_copy (const void *data, size_t len) |
copy a memory range into the buffer | |
void | assign_keep (void *data, size_t len) |
associate this object with a new memory buffer. | |
size_t | buffsize () const |
return the number of available bytes in the buffer | |
ByteBuffer (const ByteBuffer &o) | |
copy constructor: create a new duplicate object. | |
ByteBuffer (size_t n) | |
create a object with n bytes preallocated | |
ByteBuffer () | |
create an empty object | |
void | clear () |
clears the memory contents. does not deallocate the memory | |
char * | data () |
return a pointer to the currently kept memory | |
const char * | data () const |
return a const pointer to the currently kept memory | |
void | dealloc () |
deallocates the kept memory space (we use dealloc() instead of free() as a name, because sometimes "free" is replaced by the preprocessor) | |
const char * | detach () |
detach the memory from the object. returns the memory pointer | |
std::pair< const char *, size_t > | detach_pair () |
detach the memory from the object, returning a std::pair containing memory pointer and size. | |
bool | empty () const |
returns true if the buffer is empty | |
virtual void | grow (size_t n) |
make sure that at least n bytes are allocated. | |
operator std::string () const | |
automatic conversion cast to std::string (copies memory) | |
ByteBuffer & | operator= (const ByteBuffer &o) |
assignment: copy memory | |
void | set_size (size_t s) |
set the currently used data | |
size_t | size () const |
return the currently used length in bytes | |
std::string | toString () const |
explicit conversion to std::string | |
virtual | ~ByteBuffer () |
destroys the memory space | |
Protected Attributes | |
size_t | _buff |
allocated bytes at _data | |
char * | _data |
pointer to the allocated memory buffer | |
size_t | _size |
used bytes within the buffer |
The class has two virtual functions, which can be used to implement ByteBuffer derivations, which use other alloc() and free() functions.
Definition at line 18 of file ByteBuffer.h.
VGServer::ByteBuffer::ByteBuffer | ( | ) | [inline, explicit] |
VGServer::ByteBuffer::ByteBuffer | ( | size_t | n | ) | [inline, explicit] |
VGServer::ByteBuffer::ByteBuffer | ( | const ByteBuffer & | o | ) | [inline, explicit] |
copy constructor: create a new duplicate object.
Definition at line 45 of file ByteBuffer.h.
References _buff, _data, _size, assign_copy(), data(), and size().
virtual VGServer::ByteBuffer::~ByteBuffer | ( | ) | [inline, virtual] |
virtual void VGServer::ByteBuffer::alloc | ( | size_t | n | ) | [inline, virtual] |
make sure that at least n bytes are allocated.
if less than n bytes are available, then enlarge the buffer to exactly n bytes, or the next possible size.
Definition at line 101 of file ByteBuffer.h.
Referenced by ByteBuffer().
void VGServer::ByteBuffer::assign_copy | ( | const void * | data, | |
size_t | len | |||
) | [inline] |
copy a memory range into the buffer
Definition at line 165 of file ByteBuffer.h.
Referenced by ByteBuffer(), VGServer::ByteInBuffer::fetchBytes(), and operator=().
void VGServer::ByteBuffer::assign_keep | ( | void * | data, | |
size_t | len | |||
) | [inline] |
associate this object with a new memory buffer.
It will be deallocated with dealloc()!
Definition at line 157 of file ByteBuffer.h.
size_t VGServer::ByteBuffer::buffsize | ( | ) | const [inline] |
return the number of available bytes in the buffer
Definition at line 75 of file ByteBuffer.h.
References _buff.
Referenced by VGServer::ByteOutBuffer::append(), and VGServer::ByteOutBuffer::appendBytes().
void VGServer::ByteBuffer::clear | ( | ) | [inline] |
clears the memory contents. does not deallocate the memory
Definition at line 95 of file ByteBuffer.h.
char* VGServer::ByteBuffer::data | ( | ) | [inline] |
return a pointer to the currently kept memory
Definition at line 67 of file ByteBuffer.h.
References _data.
const char* VGServer::ByteBuffer::data | ( | ) | const [inline] |
return a const pointer to the currently kept memory
Definition at line 63 of file ByteBuffer.h.
References _data.
Referenced by VGServer::ByteOutBuffer::append(), VGServer::ByteOutBuffer::appendByteBuffer(), VGServer::ByteOutBuffer::appendBytes(), ByteBuffer(), VGServer::ByteInBuffer::fetch(), VGServer::ByteInBuffer::fetchBytes(), VGServer::ByteInBuffer::fetchLongString(), VGServer::ByteInBuffer::fetchString(), VGServer::GraphData::loadSnapshot(), operator=(), and VGServer::GraphData::saveSnapshot().
void VGServer::ByteBuffer::dealloc | ( | ) | [inline] |
deallocates the kept memory space (we use dealloc() instead of free() as a name, because sometimes "free" is replaced by the preprocessor)
Definition at line 130 of file ByteBuffer.h.
Referenced by ~ByteBuffer().
const char* VGServer::ByteBuffer::detach | ( | ) | [inline] |
detach the memory from the object. returns the memory pointer
Definition at line 138 of file ByteBuffer.h.
std::pair<const char*, size_t> VGServer::ByteBuffer::detach_pair | ( | ) | [inline] |
detach the memory from the object, returning a std::pair containing memory pointer and size.
Definition at line 147 of file ByteBuffer.h.
bool VGServer::ByteBuffer::empty | ( | ) | const [inline] |
virtual void VGServer::ByteBuffer::grow | ( | size_t | n | ) | [inline, virtual] |
make sure that at least n bytes are allocated.
if less than n bytes are available, enlarge the buffer. this function may choose to allocate considerably more than n bytes in expectance of more memory need.
Definition at line 113 of file ByteBuffer.h.
Referenced by VGServer::ByteOutBuffer::append(), and VGServer::ByteOutBuffer::appendBytes().
VGServer::ByteBuffer::operator std::string | ( | ) | const [inline] |
automatic conversion cast to std::string (copies memory)
Definition at line 87 of file ByteBuffer.h.
ByteBuffer& VGServer::ByteBuffer::operator= | ( | const ByteBuffer & | o | ) | [inline] |
assignment: copy memory
Definition at line 52 of file ByteBuffer.h.
References assign_copy(), data(), and size().
void VGServer::ByteBuffer::set_size | ( | size_t | s | ) | [inline] |
set the currently used data
Definition at line 83 of file ByteBuffer.h.
Referenced by VGServer::ByteOutBuffer::append(), and VGServer::ByteOutBuffer::appendBytes().
size_t VGServer::ByteBuffer::size | ( | ) | const [inline] |
return the currently used length in bytes
Definition at line 71 of file ByteBuffer.h.
References _size.
Referenced by VGServer::ByteOutBuffer::append(), VGServer::ByteOutBuffer::appendByteBuffer(), VGServer::ByteOutBuffer::appendBytes(), ByteBuffer(), VGServer::ByteInBuffer::cursor_available(), empty(), VGServer::GraphContainer::getArea(), VGServer::GraphData::loadSnapshot(), operator=(), VGServer::ByteInBuffer::remaining(), and VGServer::GraphData::saveSnapshot().
std::string VGServer::ByteBuffer::toString | ( | ) | const [inline] |
size_t VGServer::ByteBuffer::_buff [protected] |
allocated bytes at _data
Definition at line 28 of file ByteBuffer.h.
Referenced by buffsize(), ByteBuffer(), and set_size().
char* VGServer::ByteBuffer::_data [protected] |
pointer to the allocated memory buffer
Definition at line 22 of file ByteBuffer.h.
Referenced by ByteBuffer(), data(), and operator std::string().
size_t VGServer::ByteBuffer::_size [protected] |
used bytes within the buffer
Definition at line 25 of file ByteBuffer.h.
Referenced by ByteBuffer(), operator std::string(), set_size(), and size().