code::BOOStream Class Reference

Inheritance diagram for code::BOOStream:

code::OutputStream List of all members.

Detailed Description

An output stream that lets you serialize data into a byte-swapped character array suitable for persistent data that will shared between machines of different native byte order.

For this purpose, it's similar to the ByteOrder class. However, BOOStreams are somewhat more flexible in that

Example:

 BOOStream out;
 out << productId() << productNtr() << ch << iVal << lVal;
 Buffer buf = out.getBytes();
 
Author:
: Charles Kerr, Lakshman
Version:
:
Id
code_BOStream.h,v 1.15 2009/06/02 20:17:39 lakshman Exp


Public Member Functions

 BOOStream (bool fileIsLittleEndian=true)
virtual ~BOOStream ()
virtual Buffer createNetworkFormat () const
void clear ()
 erase the contents of the output buffer s.t.
Buffer getBytes () const
 Returns a Buffer array of the bytes written to this stream.
size_t getSize () const
 Returns the size, in bytes, of the data written to this stream since its construction or the last time it was clear()ed.
size_t getPos () const
 Returns an index to the current position in the output stream.
void setPos (size_t pos)
 Reposition the stream s.t.
void setPosEnd ()
 Move the writer position to the end of the stream s.t.
bool isValid (std::string *setme_error_text=0) const
 Returns true if the object passes its internal sanity checks, false otherwise.
virtual BOOStreamoperator<< (char c)
 Write a char to the stream.
virtual BOOStreamoperator<< (unsigned char c)
 Write an unsigned char to the stream.
virtual BOOStreamoperator<< (int16_t i)
 Write a 16-bit signed integer to the stream.
virtual BOOStreamoperator<< (uint16_t i)
 Write a 16-bit unsigned integer to the stream.
virtual BOOStreamoperator<< (int32_t i)
 Write a 32-bit signed integer to the stream.
virtual BOOStreamoperator<< (uint32_t i)
 Write a 32-bit unsigned integer to the stream.
virtual BOOStreamoperator<< (int64_t i)
 Write a 64-bit signed integer to the stream.
virtual BOOStreamoperator<< (uint64_t i)
 Write a 64-bit unsigned integer to the stream.
virtual BOOStreamoperator<< (bool b)
 Write a bool to the stream.
virtual BOOStreamoperator<< (const std::string &)
 Write a string to the stream.
virtual BOOStreamoperator<< (float f)
 Write a float to the OutputStream buffer.
virtual BOOStreamoperator<< (double d)
 Write a double to the OutputStream buffer.

Protected Member Functions

void storeBytes (const char *unswapped_bytes, size_t n)
void storeAsIs (const char *swapped_bytes, size_t n)
template<typename X>
BOOStreamappend (const X &x)

Protected Attributes

const bool _fileOrder
std::vector< char > _buf
size_t _writepos


Constructor & Destructor Documentation

code::BOOStream::BOOStream ( bool  fileIsLittleEndian = true  ) 

virtual code::BOOStream::~BOOStream (  )  [inline, virtual]


Member Function Documentation

template<typename X>
BOOStream& code::BOOStream::append ( const X &  x  )  [inline, protected]

void code::BOOStream::clear (  )  [inline]

erase the contents of the output buffer s.t.

getSize()==0

virtual Buffer code::BOOStream::createNetworkFormat (  )  const [inline, virtual]

Buffer code::BOOStream::getBytes (  )  const [inline]

Returns a Buffer array of the bytes written to this stream.

Returns:
a Buffer array of the bytes written to this stream.

size_t code::BOOStream::getPos (  )  const [inline]

Returns an index to the current position in the output stream.

Returns:
an index to the current position in the output stream

size_t code::BOOStream::getSize (  )  const [inline]

Returns the size, in bytes, of the data written to this stream since its construction or the last time it was clear()ed.

Returns:
the size, in bytes, of the data written to this stream since its construction or the last time it was clear()ed.

bool code::BOOStream::isValid ( std::string *  setme_error_text = 0  )  const

Returns true if the object passes its internal sanity checks, false otherwise.

Returns:
true if the object passes its internal sanity checks, false otherwise.
Parameters:
setme_error_text if not null, and if isValid fails, a description of the failure is placed here. This setup is so that isValid can still be embedded in a throwaway assert (ie, "<code>assert(isValid())</code>") and in a exception check (ie, "<code>string s; if ( !isValid(&s) ) throw s;").

virtual BOOStream& code::BOOStream::operator<< ( double  d  )  [inline, virtual]

Write a double to the OutputStream buffer.

WARNING: doubles are not portable. If you are defining a new data format, please use int/long, multiplying your value by the needed precision. This is for those formats that do use double and can not be helped.

Parameters:
l the long to add.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( float  f  )  [inline, virtual]

Write a float to the OutputStream buffer.

WARNING: floats are not portable. If you are defining a new data format, please use int/long, multiplying your value by the needed precision. This is for those formats that do use float and can not be helped.

Parameters:
l the long to add.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( const std::string &   )  [virtual]

Write a string to the stream.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( bool  b  )  [inline, virtual]

Write a bool to the stream.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( uint64_t  i  )  [inline, virtual]

Write a 64-bit unsigned integer to the stream.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( int64_t  i  )  [inline, virtual]

Write a 64-bit signed integer to the stream.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( uint32_t  i  )  [inline, virtual]

Write a 32-bit unsigned integer to the stream.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( int32_t  i  )  [inline, virtual]

Write a 32-bit signed integer to the stream.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( uint16_t  i  )  [inline, virtual]

Write a 16-bit unsigned integer to the stream.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( int16_t  i  )  [inline, virtual]

Write a 16-bit signed integer to the stream.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( unsigned char  c  )  [inline, virtual]

Write an unsigned char to the stream.

Implements code::OutputStream.

virtual BOOStream& code::BOOStream::operator<< ( char  c  )  [inline, virtual]

Write a char to the stream.

Implements code::OutputStream.

void code::BOOStream::setPos ( size_t  pos  )  [inline]

Reposition the stream s.t.

subsequent &lt&lt data will overwrite data in the specified position.

Parameters:
pos the character index where to write subsequent &lt&lt data

void code::BOOStream::setPosEnd (  )  [inline]

Move the writer position to the end of the stream s.t.

future &lt&lt calls will append to the stream.

void code::BOOStream::storeAsIs ( const char *  swapped_bytes,
size_t  n 
) [protected]

void code::BOOStream::storeBytes ( const char *  unswapped_bytes,
size_t  n 
) [protected]


Member Data Documentation

std::vector<char> code::BOOStream::_buf [protected]

const bool code::BOOStream::_fileOrder [protected]

size_t code::BOOStream::_writepos [protected]


Generated on Fri May 4 13:40:12 2012 for WDSS-IIw2 by  doxygen 1.4.7