xvr2::Buffer Class Reference

#include <Buffer.h>

Inheritance diagram for xvr2::Buffer:

Inheritance graph
[legend]

List of all members.


Detailed Description

Represents a data block and as such it holds a data store and a means to account the amount of stored data.

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 Bufferappend (UInt8 v)
 Appends (inserts at the end) the value of v to the data store.
const Bufferappend (const void *__data, UInt32 __size)
 Appends (inserts at the end) the datablock pointed by __data with size __size to the data store.
const Bufferappend (const Buffer &b)
 Appends (inserts at the end) the Buffer b to the data store.
const Bufferappend (const String &s)
 Appends (inserts at the end) the String s to the data store.
const Bufferoperator<< (UInt8 v)
 Appends (inserts at the end) the value of v to the data store.
const Bufferoperator<< (const Buffer &b)
 Appends (inserts at the end) the Buffer b to the data store.
const Bufferoperator<< (const String &s)
 Appends (inserts at the end) the String s to the data store.
const Bufferinsert (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 Bufferinsert (UInt32 pos, const void *__data, UInt32 __size)
const Bufferinsert (UInt32 pos, const Buffer &b)
const Bufferinsert (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 Buffercopy (const Buffer &b)
 Copies the contents of b.
const Buffercopy (const void *__data, UInt32 __size)
const Buffercopy (UInt8 v)
const Buffercopy (const String &s)
const Bufferassign (const Buffer &b)
const Bufferassign (const void *__data, UInt32 __size)
const Bufferassign (UInt8 v)
const Bufferassign (const String &s)
Buffer ref ()
 Returns a reference to this object.
const BufferrefTo (const Buffer &b)
 Converts this buffer in a reference of Buffer b.
const BufferrefTo (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)

Constructor & Destructor Documentation

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).


Member Function Documentation

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.

const Buffer& xvr2::Buffer::append ( UInt8  v  ) 

Appends (inserts at the end) the value of v to the data store.

const Buffer& xvr2::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& xvr2::Buffer::append ( const Buffer b  ) 

Appends (inserts at the end) the Buffer b to the data store.

const Buffer& xvr2::Buffer::append ( const String s  ) 

Appends (inserts at the end) the String s to the data store.

const Buffer& xvr2::Buffer::operator<< ( UInt8  v  ) 

Appends (inserts at the end) the value of v to the data store.

const Buffer& xvr2::Buffer::operator<< ( const Buffer b  ) 

Appends (inserts at the end) the Buffer b to the data store.

const Buffer& xvr2::Buffer::operator<< ( const String s  ) 

Appends (inserts at the end) the String s to the data store.

const Buffer& xvr2::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& xvr2::Buffer::insert ( UInt32  pos,
const void *  __data,
UInt32  __size 
)

const Buffer& xvr2::Buffer::insert ( UInt32  pos,
const Buffer b 
)

const Buffer& xvr2::Buffer::insert ( UInt32  pos,
const String s 
)

Buffer xvr2::Buffer::cloneMe (  ) 

Clones the current Buffer object into a new one which will be an exact copy of the former.

static Buffer xvr2::Buffer::clone ( const Buffer b  )  [static]

Clones b by creating an exact copy of it into a new Buffer instance.

const Buffer& xvr2::Buffer::copy ( const Buffer b  ) 

Copies the contents of b.

This basically means the contents of this object will be replaced by the contents of b.

const Buffer& xvr2::Buffer::copy ( const void *  __data,
UInt32  __size 
)

const Buffer& xvr2::Buffer::copy ( UInt8  v  ) 

const Buffer& xvr2::Buffer::copy ( const String s  ) 

const Buffer& xvr2::Buffer::assign ( const Buffer b  ) 

const Buffer& xvr2::Buffer::assign ( const void *  __data,
UInt32  __size 
)

const Buffer& xvr2::Buffer::assign ( UInt8  v  ) 

const Buffer& xvr2::Buffer::assign ( const String s  ) 

Buffer xvr2::Buffer::ref (  ) 

Returns a reference to this object.

const Buffer& xvr2::Buffer::refTo ( const Buffer b  ) 

Converts this buffer in a reference of Buffer b.

const Buffer& xvr2::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.

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]


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  stream,
const Object s 
) [friend, inherited]


Member Data Documentation

bool xvr2::Buffer::freeme [private]

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.

Definition at line 43 of file Buffer.h.

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.

Definition at line 50 of file Buffer.h.

Holds the amount of data bytes stored in _data.

Definition at line 52 of file Buffer.h.

std::string xvr2::Object::__cls_name [protected, inherited]

Definition at line 30 of file Object.h.


The documentation for this class was generated from the following file:

Generated on Fri Jun 20 22:55:50 2008 for X-VR2 SDK by  doxygen 1.5.5