StreamDataWriter Class Reference

A DataWriter which writes data to a Stream. More...

#include <StreamDataWriter.h++>

Inheritance diagram for StreamDataWriter:

Inheritance graph
[legend]
Collaboration diagram for StreamDataWriter:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 StreamDataWriter (Stream &stream, size_t bufferSize=BUFFER_SIZE)
 Construct a new StreamDataWriter for the given Stream.
 ~StreamDataWriter () throw ()
 Destructor.
void skip (size_t count) throw (IOException)
 Skip past the given number of bytes in the data stream.
void skip (size_t count, byte_t fillByte) throw (IOException)
 Skip past the given number of bytes, filling the bytes with the given value.
void flush () throw (IOException)
 Flush any buffered but not yet written data to the output destination.
void setOffset (int64_t offset) throw (IOException)
 Set the current reading/writing offset.
DataWriteroperator<< (bool v) throw (IOException)
 Write operator.
DataWriteroperator<< (byte_t v) throw (IOException)
 Write operator.
DataWriteroperator<< (const byte_t *v) throw (IOException)
 Write operator.
DataWriteroperator<< (char v) throw (IOException)
 Write operator.
DataWriteroperator<< (const char *v) throw (IOException)
 Write operator.
DataWriteroperator<< (int16_t v) throw (IOException)
 Write operator.
DataWriteroperator<< (const int16_t *v) throw (IOException)
 Write operator.
DataWriteroperator<< (uint16_t v) throw (IOException)
 Write operator.
DataWriteroperator<< (const uint16_t *v) throw (IOException)
 Write operator.
DataWriteroperator<< (int32_t v) throw (IOException)
 Write operator.
DataWriteroperator<< (const int32_t *v) throw (IOException)
 Write operator.
DataWriteroperator<< (uint32_t v) throw (IOException)
 Write operator.
DataWriteroperator<< (const uint32_t *v) throw (IOException)
 Write operator.
DataWriteroperator<< (const int64_t &v) throw (IOException)
 Write operator.
DataWriteroperator<< (const int64_t *v) throw (IOException)
 Write operator.
DataWriteroperator<< (const uint64_t &v) throw (IOException)
 Write operator.
DataWriteroperator<< (const uint64_t *v) throw (IOException)
 Write operator.
DataWriteroperator<< (float v) throw (IOException)
 Write operator.
DataWriteroperator<< (const float *v) throw (IOException)
 Write operator.
DataWriteroperator<< (const double &v) throw (IOException)
 Write operator.
DataWriteroperator<< (const double *v) throw (IOException)
 Write operator.
DataWriteroperator<< (const Blob &v) throw (IOException)
 Write operator.
DataWriteroperator<< (const String &v) throw (IOException)
 Write operator.
DataWriteroperator<< (const Manipulator &manip) throw (IOException)
 Write operator.
virtual void reset () throw (IOException)
 Reset the encoder.
void pushContext ()
 Push a new encoder context.
void popContext ()
 Pop the active encoder context.
bool isTopContext () const throw ()
 Determine if the active context is the topmost (and only) context.
uint_t getContextDepth () const throw ()
 Get the current context depth.
void setEndianness (Endianness endianness) throw ()
 Specify the byte-endianness for reading/writing primitive integer types in the active context.
Endianness getEndianness () const throw ()
 Get the byte-endianness in the active context.
void setLength (size_t length) throw ()
 Specify the length of String, Blob, and array values for subsequent reading/writing in the active context.
size_t getLength () const throw ()
 Get the current length for string values.
void setLimit (int64_t limit) throw (IOException)
 Specify the maximum number of bytes that can be read/written in the active context.
int64_t getLimit () const throw ()
 Get the current limit.
void setStringPadding (bool stringPadding) throw ()
 Enables or disable string padding in the active context.
bool getStringPadding () const throw ()
 Get the current string padding status.
int64_t getOffset () const throw ()
 Get the current encoding/decoding offset.
int64_t getCumulativeOffset () const throw ()
 Get the cumulative reading/writing offset.
int64_t getRemaining () const throw ()
 Get the number of bytes between the current offset and the limit, i.e., the number of bytes remaining to be read or written.
void align (size_t size) throw (IOException)
 Skip past enough bytes to re-align the data stream at a specified boundary.

Static Public Attributes

static const size_t BUFFER_SIZE = 4096

Protected Member Functions

size_t write (const byte_t *buf, size_t count) throw (IOException)
 Write raw data to the output destination.
bool isSameEndianness () const throw ()
 Test if the endianness of the encoder is the same as the endianness of the host system.
ContextcurrentContext ()
 Get a reference to the current context.
const ContextcurrentContext () const
 Get a reference to the current context.
void checkRemaining (const Context &ctx, size_t count) const throw (IOException)
 Check if at least the given number of bytes are available to be read or written.

Protected Attributes

ContextStack * _contexts
int64_t _maxOffset


Detailed Description

A DataWriter which writes data to a Stream.

Author:
Mark Lindner

Constructor & Destructor Documentation

StreamDataWriter ( Stream stream,
size_t  bufferSize = BUFFER_SIZE 
)

Construct a new StreamDataWriter for the given Stream.

Parameters:
stream The Stream to write data to.
bufferSize The stream buffer size.

~StreamDataWriter (  )  throw ()

Destructor.


Member Function Documentation

void align ( size_t  size  )  throw (IOException) [inherited]

Skip past enough bytes to re-align the data stream at a specified boundary.

When reading, the bytes are simply skipped over; when writing, the bytes are filled with NULs.

Parameters:
size The alignment size. Typical values include 2, 4, or 8. Other values are allowed but are of limited usefulness.
Exceptions:
IOException If an I/O error occurs.

void checkRemaining ( const Context ctx,
size_t  count 
) const throw (IOException) [protected, inherited]

Check if at least the given number of bytes are available to be read or written.

Parameters:
ctx The context to check.
count The number of bytes.
Exceptions:
IOException If there are not enough bytes remaining.

const DataEncoder::Context & currentContext (  )  const [protected, inherited]

Get a reference to the current context.

DataEncoder::Context & currentContext (  )  [protected, inherited]

Get a reference to the current context.

void flush (  )  throw (IOException) [virtual]

Flush any buffered but not yet written data to the output destination.

Implements DataWriter.

uint_t getContextDepth (  )  const throw () [inherited]

Get the current context depth.

int64_t getCumulativeOffset (  )  const throw () [inherited]

Get the cumulative reading/writing offset.

This is a sum of the offsets across all contexts.

Endianness getEndianness (  )  const throw () [inherited]

Get the byte-endianness in the active context.

size_t getLength (  )  const throw () [inherited]

Get the current length for string values.

int64_t getLimit (  )  const throw () [inherited]

Get the current limit.

int64_t getOffset (  )  const throw () [inherited]

Get the current encoding/decoding offset.

int64_t getRemaining (  )  const throw () [inherited]

Get the number of bytes between the current offset and the limit, i.e., the number of bytes remaining to be read or written.

bool getStringPadding (  )  const throw () [inherited]

Get the current string padding status.

bool isSameEndianness (  )  const throw () [protected, inherited]

Test if the endianness of the encoder is the same as the endianness of the host system.

bool isTopContext (  )  const throw () [inherited]

Determine if the active context is the topmost (and only) context.

DataWriter & operator<< ( const Manipulator manip  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const String v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const Blob v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const double *  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const double &  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const float *  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( float  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const uint64_t *  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const uint64_t &  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const int64_t *  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const int64_t &  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const uint32_t *  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( uint32_t  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const int32_t *  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( int32_t  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const uint16_t *  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( uint16_t  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const int16_t *  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( int16_t  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const char *  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( char  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( const byte_t v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( byte_t  v  )  throw (IOException) [inherited]

Write operator.

DataWriter & operator<< ( bool  v  )  throw (IOException) [inherited]

Write operator.

void popContext (  )  [inherited]

Pop the active encoder context.

The previous context becomes the active context, and the offset in the current context is incremented by the offset of the popped context.

void pushContext (  )  [inherited]

Push a new encoder context.

void reset (  )  throw (IOException) [virtual, inherited]

Reset the encoder.

Discards all but the topmost context, and resets the topmost context to default values.

Reimplemented in ByteArrayDataReader, ByteArrayDataWriter, ByteBufferDataReader, ByteBufferDataWriter, and StreamDataReader.

void setEndianness ( Endianness  endianness  )  throw () [inherited]

Specify the byte-endianness for reading/writing primitive integer types in the active context.

void setLength ( size_t  length  )  throw () [inherited]

Specify the length of String, Blob, and array values for subsequent reading/writing in the active context.

Depending on whether string padding is enabled or disabled, written strings will be padded with either space characters or NUL bytes, respectively.

void setLimit ( int64_t  limit  )  throw (IOException) [inherited]

Specify the maximum number of bytes that can be read/written in the active context.

Attempts to read/write past this limit will raise an IOException.

void setOffset ( int64_t  offset  )  throw (IOException) [virtual]

Set the current reading/writing offset.

Implements DataEncoder.

void setStringPadding ( bool  stringPadding  )  throw () [inherited]

Enables or disable string padding in the active context.

When enabled, strings are padded with spaces during writing; otherwise they are padded with NUL bytes.

Parameters:
stringPadding A flag indicating the type of padding; true for spaces, false for NUL bytes.

void skip ( size_t  count,
byte_t  fillByte 
) throw (IOException) [virtual]

Skip past the given number of bytes, filling the bytes with the given value.

Parameters:
count The number of bytes to skip.
fillByte The value to write to all the skipped bytes.
Exceptions:
IOException If an I/O error occurs.

Implements DataWriter.

void skip ( size_t  count  )  throw (IOException) [virtual]

Skip past the given number of bytes in the data stream.

When reading, the bytes are simply skipped over; when writing, the bytes are filled with NULs.

Parameters:
count The number of bytes to skip.
Exceptions:
IOException If an I/O error occurs.

Implements DataWriter.

size_t write ( const byte_t buf,
size_t  count 
) throw (IOException) [protected, virtual]

Write raw data to the output destination.

Implements DataWriter.


Member Data Documentation

ContextStack* _contexts [protected, inherited]

int64_t _maxOffset [protected, inherited]

const size_t BUFFER_SIZE = 4096 [static]


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

Generated on Sat Apr 17 23:03:10 2010 for libcommonc++ by  doxygen 1.5.9