#include <Buffer.h>
Buffers has two operation modes: 1. They can be references to another Buffers in the same way a pointer points to an already defined data block. 2. They can be copies of existing data blocks. In case #2 during the object destruction the contents of the data store will be properly freed from memory, however for case #1 they won't since they are "pointing" to a data block defined externally to them, so it is responsability of the other end to properly release the data block after it is used, in either case you must take care that if the external data block is released your Buffer will be pointing to that old memory address just like standard pointers do, you have been warned.
Definition at line 37 of file Buffer.h.
Public Member Functions | |
Buffer () | |
Default constructor, initializes _data and _size to 0 and sets freeme to false. | |
Buffer (void *__data, UInt32 __size, bool _freeme=true) | |
If freeme is true, then it will construct a Buffer which its data store will be a copy of __data, however if freeme is false then if will be just a reference to __data so the contents of _data will not be delete[] during the destruction stage. | |
Buffer (const void *__data, UInt32 __size, bool _freeme=false) | |
If freeme is true, then it will construct a Buffer which its data store will be a copy of __data, however if freeme is false then if will be just a reference to __data so the contents of _data will not be delete[] during the destruction stage. | |
Buffer (const Buffer &b) | |
Creates a reference buffer whose _data will point to b._data and its datastore won't be freed during the object's destruction. | |
virtual | ~Buffer () |
The destructor will attept to free the data store only if freeme has been set to true, the idea behind this is that only copied buffers need to delete its datastore (because they're copies) and references will not (because their data store is not actually theirs). | |
UInt32 | size () |
Returns the amount of bytes stored in the data store. | |
UInt32 | size () const |
Returns the amount of bytes stored in the data store. | |
const void * | data () |
Returns a pointer to the data store. | |
const void * | data () const |
Returns a pointer to the data store. | |
const UInt8 | operator[] (int pos) |
Returns the value of the byte stored at position pos. | |
const UInt8 | operator[] (int pos) const |
Returns the value of the byte stored at position pos. | |
const UInt8 | get (int pos) |
Returns the value of the byte stored at position pos. | |
const UInt8 | get (int pos) const |
Returns the value of the byte stored at position pos. | |
const void * | getBuf (int pos) |
Returns a pointer to position pos within the data store. | |
const void * | getBuf (int pos) const |
Returns a pointer to position pos within the data store. | |
virtual std::string | toString () |
const Buffer & | append (UInt8 v) |
Appends (inserts at the end) the value of v to the data store. | |
const Buffer & | append (const void *__data, UInt32 __size) |
Appends (inserts at the end) the datablock pointed by __data with size __size to the data store. | |
const Buffer & | append (const Buffer &b) |
Appends (inserts at the end) the Buffer b to the data store. | |
const Buffer & | append (const String &s) |
Appends (inserts at the end) the String s to the data store. | |
const Buffer & | operator<< (UInt8 v) |
Appends (inserts at the end) the value of v to the data store. | |
const Buffer & | operator<< (const Buffer &b) |
Appends (inserts at the end) the Buffer b to the data store. | |
const Buffer & | operator<< (const String &s) |
Appends (inserts at the end) the String s to the data store. | |
const Buffer & | insert (UInt32 pos, UInt8 v) |
Inserts a byte (v) of data at position pos, given that pos is a position from the begining of the buffer. | |
const Buffer & | insert (UInt32 pos, const void *__data, UInt32 __size) |
const Buffer & | insert (UInt32 pos, const Buffer &b) |
const Buffer & | insert (UInt32 pos, const String &s) |
Buffer | cloneMe () |
Clones the current Buffer object into a new one which will be an exact copy of the former. | |
const Buffer & | copy (const Buffer &b) |
Copies the contents of b. | |
const Buffer & | copy (const void *__data, UInt32 __size) |
const Buffer & | copy (UInt8 v) |
const Buffer & | copy (const String &s) |
const Buffer & | assign (const Buffer &b) |
const Buffer & | assign (const void *__data, UInt32 __size) |
const Buffer & | assign (UInt8 v) |
const Buffer & | assign (const String &s) |
Buffer | ref () |
Returns a reference to this object. | |
const Buffer & | refTo (const Buffer &b) |
Converts this buffer in a reference of Buffer b. | |
const Buffer & | refTo (void *_buf, UInt32 _siz, bool __f=false) |
Transform this Buffer object in a pointer to __buf, given that it is holding _siz bytes. | |
void | empty () |
Clears the buffer contents. | |
void | clear () |
virtual const char * | getClassName () |
Returns the name of the current class. | |
Static Public Member Functions | |
static Buffer | clone (const Buffer &b) |
Clones b by creating an exact copy of it into a new Buffer instance. | |
static void | debugmsg (Object *obj, const char *msg, int linenumber=__LINE__, const char *srcfile=__FILE__) |
Will print a debug message to the screen. | |
static void | debugmsgln (Object *obj, const char *msg, int linenumber=__LINE__, const char *srcfile=__FILE__) |
Protected Attributes | |
UInt8 * | _data |
The buffer's data store itself, this might point to another datastore or just be a copy of another datastore, if it is a copy then freeme will be set to true, however if it is a pointer to an external datastore then freeme will be false. | |
UInt32 | _size |
Holds the amount of data bytes stored in _data. | |
std::string | __cls_name |
Private Attributes | |
bool | freeme |
Tells whether the data store is a reference or copy of an exiting buffer, if it is copy its value will be true, so the destructor can delete[] _data, however if it is false no such operation takes place. | |
Friends | |
std::ostream & | operator<< (std::ostream &stream, const Object &s) |
xvr2::Buffer::Buffer | ( | ) |
Default constructor, initializes _data and _size to 0 and sets freeme to false.
(A reference to NULL)
xvr2::Buffer::Buffer | ( | void * | __data, | |
UInt32 | __size, | |||
bool | _freeme = true | |||
) |
If freeme is true, then it will construct a Buffer which its data store will be a copy of __data, however if freeme is false then if will be just a reference to __data so the contents of _data will not be delete[] during the destruction stage.
(By default it will create a copy buffer)
xvr2::Buffer::Buffer | ( | const void * | __data, | |
UInt32 | __size, | |||
bool | _freeme = false | |||
) |
If freeme is true, then it will construct a Buffer which its data store will be a copy of __data, however if freeme is false then if will be just a reference to __data so the contents of _data will not be delete[] during the destruction stage.
(By default it will create a reference buffer)
xvr2::Buffer::Buffer | ( | const Buffer & | b | ) |
Creates a reference buffer whose _data will point to b._data and its datastore won't be freed during the object's destruction.
virtual xvr2::Buffer::~Buffer | ( | ) | [virtual] |
The destructor will attept to free the data store only if freeme has been set to true, the idea behind this is that only copied buffers need to delete its datastore (because they're copies) and references will not (because their data store is not actually theirs).
UInt32 xvr2::Buffer::size | ( | ) |
Returns the amount of bytes stored in the data store.
UInt32 xvr2::Buffer::size | ( | ) | const |
Returns the amount of bytes stored in the data store.
const void* xvr2::Buffer::data | ( | ) |
Returns a pointer to the data store.
const void* xvr2::Buffer::data | ( | ) | const |
Returns a pointer to the data store.
const UInt8 xvr2::Buffer::operator[] | ( | int | pos | ) |
Returns the value of the byte stored at position pos.
const UInt8 xvr2::Buffer::operator[] | ( | int | pos | ) | const |
Returns the value of the byte stored at position pos.
const UInt8 xvr2::Buffer::get | ( | int | pos | ) |
Returns the value of the byte stored at position pos.
const UInt8 xvr2::Buffer::get | ( | int | pos | ) | const |
Returns the value of the byte stored at position pos.
const void* xvr2::Buffer::getBuf | ( | int | pos | ) |
Returns a pointer to position pos within the data store.
const void* xvr2::Buffer::getBuf | ( | int | pos | ) | const |
Returns a pointer to position pos within the data store.
virtual std::string xvr2::Buffer::toString | ( | ) | [virtual] |
Reimplemented from xvr2::Object.
Appends (inserts at the end) the value of v to the data store.
Appends (inserts at the end) the datablock pointed by __data with size __size to the data store.
Appends (inserts at the end) the Buffer b to the data store.
Appends (inserts at the end) the String s to the data store.
Appends (inserts at the end) the value of v to the data store.
Appends (inserts at the end) the Buffer b to the data store.
Appends (inserts at the end) the String s to the data store.
Inserts a byte (v) of data at position pos, given that pos is a position from the begining of the buffer.
Buffer xvr2::Buffer::cloneMe | ( | ) |
Clones the current Buffer object into a new one which will be an exact copy of the former.
Clones b by creating an exact copy of it into a new Buffer instance.
Copies the contents of b.
This basically means the contents of this object will be replaced by the contents of b.
Buffer xvr2::Buffer::ref | ( | ) |
Returns a reference to this object.
Converts this buffer in a reference of Buffer b.
Transform this Buffer object in a pointer to __buf, given that it is holding _siz bytes.
If the __f parameter is true then by the time this object is destroid the inner reference to _buf will also be freed
void xvr2::Buffer::empty | ( | ) |
Clears the buffer contents.
void xvr2::Buffer::clear | ( | ) |
virtual const char* xvr2::Object::getClassName | ( | ) | [virtual, inherited] |
Returns the name of the current class.
static void xvr2::Object::debugmsg | ( | Object * | obj, | |
const char * | msg, | |||
int | linenumber = __LINE__ , |
|||
const char * | srcfile = __FILE__ | |||
) | [static, inherited] |
Will print a debug message to the screen.
static void xvr2::Object::debugmsgln | ( | Object * | obj, | |
const char * | msg, | |||
int | linenumber = __LINE__ , |
|||
const char * | srcfile = __FILE__ | |||
) | [static, inherited] |
std::ostream& operator<< | ( | std::ostream & | stream, | |
const Object & | s | |||
) | [friend, inherited] |
bool xvr2::Buffer::freeme [private] |
UInt8* xvr2::Buffer::_data [protected] |
The buffer's data store itself, this might point to another datastore or just be a copy of another datastore, if it is a copy then freeme will be set to true, however if it is a pointer to an external datastore then freeme will be false.
This variable is also commonly called as data store.
UInt32 xvr2::Buffer::_size [protected] |
std::string xvr2::Object::__cls_name [protected, inherited] |