libcommonc++  0.7
DataReader Class Referenceabstract

An abstract base class for data readers. More...

#include <DataReader.h++>

Inheritance diagram for DataReader:
Collaboration diagram for DataReader:

Public Member Functions

virtual ~DataReader ()
 Destructor. More...
 
DataReaderoperator>> (bool &v)
 Read operator. More...
 
DataReaderoperator>> (byte_t &v)
 Read operator. More...
 
DataReaderoperator>> (byte_t *v)
 Read operator. More...
 
DataReaderoperator>> (char &v)
 Read operator. More...
 
DataReaderoperator>> (char *v)
 Read operator. More...
 
DataReaderoperator>> (int16_t &v)
 Read operator. More...
 
DataReaderoperator>> (int16_t *v)
 Read operator. More...
 
DataReaderoperator>> (uint16_t &v)
 Read operator. More...
 
DataReaderoperator>> (uint16_t *v)
 Read operator. More...
 
DataReaderoperator>> (int32_t &v)
 Read operator. More...
 
DataReaderoperator>> (int32_t *v)
 Read operator. More...
 
DataReaderoperator>> (uint32_t &v)
 Read operator. More...
 
DataReaderoperator>> (uint32_t *v)
 Read operator. More...
 
DataReaderoperator>> (int64_t &v)
 Read operator. More...
 
DataReaderoperator>> (int64_t *v)
 Read operator. More...
 
DataReaderoperator>> (uint64_t &v)
 Read operator. More...
 
DataReaderoperator>> (uint64_t *v)
 Read operator. More...
 
DataReaderoperator>> (float &v)
 Read operator. More...
 
DataReaderoperator>> (float *v)
 Read operator. More...
 
DataReaderoperator>> (double &v)
 Read operator. More...
 
DataReaderoperator>> (double *v)
 Read operator. More...
 
DataReaderoperator>> (Blob &v)
 Read operator. More...
 
DataReaderoperator>> (String &v)
 Read operator. More...
 
DataReaderoperator>> (const Manipulator &manip)
 Read operator. More...
 
size_t readBytes (byte_t *buf, size_t len)
 Read raw bytes. More...
 
void readFully (byte_t *buf, size_t len)
 Read raw bytes, throwing an EOFException if the exact number of bytes requested could not be read. More...
 
virtual void reset ()
 Reset the encoder. More...
 
void pushContext ()
 Push a new encoder context. More...
 
void popContext ()
 Pop the active encoder context. More...
 
bool isTopContext () const
 Determine if the active context is the topmost (and only) context. More...
 
uint_t getContextDepth () const
 Get the current context depth. More...
 
void setEndianness (Endianness endianness)
 Specify the byte-endianness for reading/writing primitive integer types in the active context. More...
 
Endianness getEndianness () const
 Get the byte-endianness in the active context. More...
 
void setLength (size_t length)
 Specify the length of String, Blob, and array values for subsequent reading/writing in the active context. More...
 
size_t getLength () const
 Get the current length for string values. More...
 
void setLimit (int64_t limit)
 Specify the maximum number of bytes that can be read/written in the active context. More...
 
int64_t getLimit () const
 Get the current limit. More...
 
int64_t getOffset () const
 Get the current encoding/decoding offset. More...
 
virtual void setOffset (int64_t offset)=0
 Set the current reading/writing offset. More...
 
int64_t getCumulativeOffset () const
 Get the cumulative reading/writing offset. More...
 
int64_t getRemaining () const
 Get the number of bytes between the current offset and the limit, i.e., the number of bytes remaining to be read or written. More...
 
void align (size_t size)
 Skip past enough bytes to re-align the data stream at a specified boundary. More...
 
virtual void skip (size_t count)=0
 Skip past the given number of bytes in the data stream. More...
 

Protected Member Functions

 DataReader ()
 Constructor. More...
 
virtual size_t read (byte_t *buf, size_t count)=0
 Read raw data from the input source. More...
 
virtual void readString (String &v, uint32_t length)
 Read a string from the input source. More...
 
bool isSameEndianness () const
 Test if the endianness of the encoder is the same as the endianness of the host system. More...
 
ContextcurrentContext ()
 Get a reference to the current context. More...
 
const ContextcurrentContext () const
 Get a reference to the current context. More...
 
void checkRemaining (const Context &ctx, size_t count) const
 Check if at least the given number of bytes are available to be read or written. More...
 

Detailed Description

An abstract base class for data readers.

A data reader reads raw bytes from an input source and converts them to primitive values such as integers and strings.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ ~DataReader()

~DataReader ( )
virtual

Destructor.

◆ DataReader()

DataReader ( )
protected

Constructor.

Member Function Documentation

◆ align()

void align ( size_t  size)
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
sizeThe alignment size. Typical values include 2, 4, or 8. Other values are allowed but are of limited usefulness.
Exceptions
IOExceptionIf an I/O error occurs.

◆ checkRemaining()

void checkRemaining ( const Context ctx,
size_t  count 
) const
protectedinherited

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

Parameters
ctxThe context to check.
countThe number of bytes.
Exceptions
IOExceptionIf there are not enough bytes remaining.

◆ currentContext() [1/2]

DataEncoder::Context & currentContext ( )
protectedinherited

Get a reference to the current context.

◆ currentContext() [2/2]

const DataEncoder::Context & currentContext ( ) const
protectedinherited

Get a reference to the current context.

◆ getContextDepth()

uint_t getContextDepth ( ) const
inherited

Get the current context depth.

◆ getCumulativeOffset()

int64_t getCumulativeOffset ( ) const
inherited

Get the cumulative reading/writing offset.

This is a sum of the offsets across all contexts.

◆ getEndianness()

Endianness getEndianness ( ) const
inherited

Get the byte-endianness in the active context.

◆ getLength()

size_t getLength ( ) const
inherited

Get the current length for string values.

◆ getLimit()

int64_t getLimit ( ) const
inherited

Get the current limit.

◆ getOffset()

int64_t getOffset ( ) const
inherited

Get the current encoding/decoding offset.

◆ getRemaining()

int64_t getRemaining ( ) const
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.

◆ isSameEndianness()

bool isSameEndianness ( ) const
protectedinherited

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

◆ isTopContext()

bool isTopContext ( ) const
inherited

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

◆ operator>>() [1/24]

DataReader & operator>> ( bool &  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [2/24]

DataReader & operator>> ( byte_t v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [3/24]

DataReader & operator>> ( byte_t v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [4/24]

DataReader & operator>> ( char &  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [5/24]

DataReader & operator>> ( char *  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [6/24]

DataReader & operator>> ( int16_t &  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [7/24]

DataReader & operator>> ( int16_t *  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [8/24]

DataReader & operator>> ( uint16_t &  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [9/24]

DataReader & operator>> ( uint16_t *  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [10/24]

DataReader & operator>> ( int32_t &  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [11/24]

DataReader & operator>> ( int32_t *  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [12/24]

DataReader & operator>> ( uint32_t &  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [13/24]

DataReader & operator>> ( uint32_t *  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [14/24]

DataReader & operator>> ( int64_t &  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [15/24]

DataReader & operator>> ( int64_t *  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [16/24]

DataReader & operator>> ( uint64_t &  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [17/24]

DataReader & operator>> ( uint64_t *  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [18/24]

DataReader & operator>> ( float &  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [19/24]

DataReader & operator>> ( float *  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [20/24]

DataReader & operator>> ( double &  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [21/24]

DataReader & operator>> ( double *  v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [22/24]

DataReader & operator>> ( Blob v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [23/24]

DataReader & operator>> ( String v)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [24/24]

DataReader & operator>> ( const Manipulator manip)

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ popContext()

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.

◆ pushContext()

void pushContext ( )
inherited

Push a new encoder context.

◆ read()

virtual size_t read ( byte_t buf,
size_t  count 
)
protectedpure virtual

Read raw data from the input source.

Parameters
bufThe buffer to read into.
countThe number of bytes to read.
Returns
The number of bytes actually read.
Exceptions
IOExceptionIf an I/O error occurs.

Implemented in StreamDataReader, CircularByteBufferDataReader, ByteArrayDataReader, and ByteBufferDataReader.

◆ readBytes()

size_t readBytes ( byte_t buf,
size_t  len 
)

Read raw bytes.

The number of bytes read may be less than the number requested, if an end-of-file condition occurs.

Parameters
bufThe buffer in which to place the bytes.
lenThe maximum number of bytes to read.
Returns
The number of bytes actually read.
Exceptions
IOExceptionIf an I/O error occurs.

◆ readFully()

void readFully ( byte_t buf,
size_t  len 
)

Read raw bytes, throwing an EOFException if the exact number of bytes requested could not be read.

Parameters
bufThe buffer in which to place the bytes.
lenThe exact number of bytes to read.
Exceptions
IOExceptionIf an I/O error occurs.

◆ readString()

void readString ( String v,
uint32_t  length 
)
protectedvirtual

Read a string from the input source.

Parameters
vThe String to read into.
lengthThe length of the string to read, or 0 to read a String that is preceded by a 32-bit length.
Exceptions
IOExceptionIf an I/O error occurs.

Reimplemented in CircularByteBufferDataReader.

◆ reset()

void reset ( )
virtualinherited

Reset the encoder.

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

Exceptions
IOExceptionIf an I/O error occurs.

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

◆ setEndianness()

void setEndianness ( Endianness  endianness)
inherited

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

◆ setLength()

void setLength ( size_t  length)
inherited

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

◆ setLimit()

void setLimit ( int64_t  limit)
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.

Exceptions
IOExceptionIf an I/O error occurs.

◆ setOffset()

virtual void setOffset ( int64_t  offset)
pure virtualinherited

◆ skip()

virtual void skip ( size_t  count)
pure virtualinherited

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
countThe number of bytes to skip.
Exceptions
IOExceptionIf an I/O error occurs.

Implemented in StreamDataWriter, ByteArrayDataWriter, CircularByteBufferDataReader, StreamDataReader, ByteArrayDataReader, ByteBufferDataReader, ByteBufferDataWriter, and DataWriter.


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