vpr::BufferObjectWriter Class Reference

Object writer for data buffers. More...

#include <vpr/IO/BufferObjectWriter.h>

Inheritance diagram for vpr::BufferObjectWriter:

Inheritance graph
[legend]
Collaboration diagram for vpr::BufferObjectWriter:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 BufferObjectWriter ()
 BufferObjectWriter (std::vector< vpr::Uint8 > *data, const unsigned int curPos=0)
void setCurPos (unsigned int val)
unsigned int getCurPos ()
std::vector< vpr::Uint8 > * getData ()
virtual vpr::ReturnStatus writeUint8 (vpr::Uint8 val)
 Writes out the single byte.
virtual vpr::ReturnStatus writeUint16 (vpr::Uint16 val)
virtual vpr::ReturnStatus writeUint32 (vpr::Uint32 val)
virtual vpr::ReturnStatus writeUint64 (vpr::Uint64 val)
virtual vpr::ReturnStatus writeFloat (float val)
virtual vpr::ReturnStatus writeDouble (double val)
virtual vpr::ReturnStatus writeString (std::string val)
virtual vpr::ReturnStatus writeBool (bool val)
vpr::ReturnStatus writeRaw (vpr::Uint8 *data, const unsigned int len=1)
Tag and attribute handling
virtual vpr::ReturnStatus beginTag (const std::string &tagName)
 Starts a new section/element of name tagName.
virtual vpr::ReturnStatus endTag ()
 Ends the most recently named tag.
virtual vpr::ReturnStatus beginAttribute (const std::string &attributeName)
 Starts an attribute of the name attributeName.
virtual vpr::ReturnStatus endAttribute ()
 Ends the most recently named attribute.

Public Attributes

std::vector< vpr::Uint8 > * mData
unsigned int mCurHeadPos

Static Public Attributes

static const unsigned int STRING_LENGTH_SIZE
 Number of bytes used to store the size of the string.

Detailed Description

Object writer for data buffers.

Writes directly to a data buffer.

Todo:
Add smart buffering for type sizes.

Definition at line 62 of file BufferObjectWriter.h.


Constructor & Destructor Documentation

vpr::BufferObjectWriter::BufferObjectWriter (  ) 

Definition at line 52 of file BufferObjectWriter.cpp.

References vpr::ObjectWriter::mIsBinary.

00053    : mData(new std::vector<vpr::Uint8>)
00054    , mCurHeadPos(0)
00055 {
00056    mIsBinary = true;
00057 }

vpr::BufferObjectWriter::BufferObjectWriter ( std::vector< vpr::Uint8 > *  data,
const unsigned int  curPos = 0 
)

Definition at line 59 of file BufferObjectWriter.cpp.

References vpr::ObjectWriter::mIsBinary.

00061    : mData(data)
00062    , mCurHeadPos(curPos)
00063 {
00064    mIsBinary = true;
00065 }


Member Function Documentation

void vpr::BufferObjectWriter::setCurPos ( unsigned int  val  )  [inline]

Definition at line 77 of file BufferObjectWriter.h.

00078    {
00079       mCurHeadPos = val;
00080    }

unsigned int vpr::BufferObjectWriter::getCurPos (  )  [inline]

Definition at line 82 of file BufferObjectWriter.h.

00083    {
00084       return mCurHeadPos;
00085    }

std::vector<vpr::Uint8>* vpr::BufferObjectWriter::getData (  )  [inline]

Definition at line 87 of file BufferObjectWriter.h.

00088    {
00089       return mData;
00090    }

virtual vpr::ReturnStatus vpr::BufferObjectWriter::beginTag ( const std::string &  tagName  )  [inline, virtual]

Starts a new section/element of name tagName.

Implements vpr::ObjectWriter.

Definition at line 95 of file BufferObjectWriter.h.

References vpr::ReturnStatus::Succeed.

00096    {
00097       boost::ignore_unused_variable_warning(tagName);
00098       return vpr::ReturnStatus::Succeed;
00099    }

virtual vpr::ReturnStatus vpr::BufferObjectWriter::endTag (  )  [inline, virtual]

Ends the most recently named tag.

Implements vpr::ObjectWriter.

Definition at line 102 of file BufferObjectWriter.h.

References vpr::ReturnStatus::Succeed.

00103    {
00104       return vpr::ReturnStatus::Succeed;
00105    }

virtual vpr::ReturnStatus vpr::BufferObjectWriter::beginAttribute ( const std::string &  attributeName  )  [inline, virtual]

Starts an attribute of the name attributeName.

Implements vpr::ObjectWriter.

Definition at line 108 of file BufferObjectWriter.h.

References vpr::ReturnStatus::Succeed.

00109    {
00110       boost::ignore_unused_variable_warning(attributeName);
00111       return vpr::ReturnStatus::Succeed;
00112    }

virtual vpr::ReturnStatus vpr::BufferObjectWriter::endAttribute (  )  [inline, virtual]

Ends the most recently named attribute.

Implements vpr::ObjectWriter.

Definition at line 115 of file BufferObjectWriter.h.

References vpr::ReturnStatus::Succeed.

00116    {
00117       return vpr::ReturnStatus::Succeed;
00118    }

vpr::ReturnStatus vpr::BufferObjectWriter::writeUint8 ( vpr::Uint8  val  )  [inline, virtual]

Writes out the single byte.

Postcondition:
data = old(data)+val, mCurHeadPos advaced 1

Implements vpr::ObjectWriter.

Definition at line 143 of file BufferObjectWriter.h.

References writeRaw().

00144 {
00145    return writeRaw(&val, 1);
00146 }

vpr::ReturnStatus vpr::BufferObjectWriter::writeUint16 ( vpr::Uint16  val  )  [inline, virtual]

Implements vpr::ObjectWriter.

Definition at line 148 of file BufferObjectWriter.h.

References vpr::SystemPosix::Htons(), and writeRaw().

00149 {
00150    vpr::Uint16 nw_val = vpr::System::Htons(val);
00151 
00152    return writeRaw((vpr::Uint8*) &nw_val, 2);
00153 }

vpr::ReturnStatus vpr::BufferObjectWriter::writeUint32 ( vpr::Uint32  val  )  [inline, virtual]

Implements vpr::ObjectWriter.

Definition at line 155 of file BufferObjectWriter.h.

References vpr::SystemPosix::Htonl(), and writeRaw().

Referenced by writeString().

00156 {
00157    vpr::Uint32 nw_val = vpr::System::Htonl(val);
00158 
00159    return writeRaw((vpr::Uint8*) &nw_val, 4);
00160 }

vpr::ReturnStatus vpr::BufferObjectWriter::writeUint64 ( vpr::Uint64  val  )  [inline, virtual]

Implements vpr::ObjectWriter.

Definition at line 162 of file BufferObjectWriter.h.

References vpr::SystemPosix::Htonll(), and writeRaw().

00163 {
00164    vpr::Uint64 nw_val = vpr::System::Htonll(val);
00165 
00166    return writeRaw((vpr::Uint8*) &nw_val, 8);
00167 }

vpr::ReturnStatus vpr::BufferObjectWriter::writeFloat ( float  val  )  [inline, virtual]

Implements vpr::ObjectWriter.

Definition at line 169 of file BufferObjectWriter.h.

References vpr::SystemPosix::Htonl(), and writeRaw().

00170 {
00171    // We are writing the float as a 4 byte value
00172    BOOST_STATIC_ASSERT(sizeof(float) == 4);
00173    vpr::Uint32 nw_val = vpr::System::Htonl(*((vpr::Uint32*) &val));
00174 
00175    return writeRaw((vpr::Uint8*) &nw_val, 4);
00176 }

vpr::ReturnStatus vpr::BufferObjectWriter::writeDouble ( double  val  )  [inline, virtual]

Implements vpr::ObjectWriter.

Definition at line 178 of file BufferObjectWriter.h.

References vpr::SystemPosix::Htonll(), and writeRaw().

00179 {
00180    // We are writing the double as a 8 byte value
00181    BOOST_STATIC_ASSERT(sizeof(double) == 8);
00182    vpr::Uint64 nw_val = vpr::System::Htonll(*((vpr::Uint64*) &val));
00183 
00184    return writeRaw((vpr::Uint8*) &nw_val, 8);
00185 }

vpr::ReturnStatus vpr::BufferObjectWriter::writeString ( std::string  val  )  [inline, virtual]

Implements vpr::ObjectWriter.

Definition at line 187 of file BufferObjectWriter.h.

References vpr::ReturnStatus::Succeed, writeRaw(), and writeUint32().

00188 {
00189    // Note: If you change this, you need to change STRING_LENGTH_SIZE
00190    writeUint32(val.size());
00191 
00192    for ( vpr::Uint32 i = 0; i < val.length(); ++i )
00193    {
00194       writeRaw((vpr::Uint8*) &val[i], 1);
00195    }
00196 
00197    return vpr::ReturnStatus::Succeed;
00198 }

vpr::ReturnStatus vpr::BufferObjectWriter::writeBool ( bool  val  )  [inline, virtual]

Implements vpr::ObjectWriter.

Definition at line 200 of file BufferObjectWriter.h.

References writeRaw().

00201 {
00202    // Darwin uses four bytes (!) for bools.
00203 #ifdef VPR_OS_Darwin
00204    vpr::Uint8 temp = (vpr::Uint8) val;
00205    return writeRaw((vpr::Uint8*) &temp, 1);
00206 #else
00207    return writeRaw((vpr::Uint8*) &val, 1);
00208 #endif
00209 }

vpr::ReturnStatus vpr::BufferObjectWriter::writeRaw ( vpr::Uint8 data,
const unsigned int  len = 1 
) [inline]

Definition at line 211 of file BufferObjectWriter.h.

References mCurHeadPos, mData, and vpr::ReturnStatus::Succeed.

Referenced by writeBool(), writeDouble(), writeFloat(), writeString(), writeUint16(), writeUint32(), writeUint64(), and writeUint8().

00213 {
00214    for ( unsigned int i = 0; i < len; ++i )
00215    {
00216       mData->push_back(data[i]);
00217    }
00218 
00219    mCurHeadPos += len;
00220    return vpr::ReturnStatus::Succeed;
00221 }


Member Data Documentation

const unsigned int vpr::BufferObjectWriter::STRING_LENGTH_SIZE [static]

Number of bytes used to store the size of the string.

Since:
1.0.2

Definition at line 70 of file BufferObjectWriter.h.

std::vector<vpr::Uint8>* vpr::BufferObjectWriter::mData

Definition at line 139 of file BufferObjectWriter.h.

Referenced by writeRaw().

unsigned int vpr::BufferObjectWriter::mCurHeadPos

Definition at line 140 of file BufferObjectWriter.h.

Referenced by writeRaw().


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:55:06 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1