cx::DataInputStream Class Reference

Class that provides formated input. More...

#include <DataInputStream.hpp>

Inheritance diagram for cx::DataInputStream:
cx::Stream cx::NonCopyable cx::FileInputStream

List of all members.

Public Types

enum  Mode {
  singleThreaded,
  multiThreaded
}
 

Operation mode.

More...

Public Member Functions

 DataInputStream (Producer &producer, Mode mode=singleThreaded)
 Constructor by producer.
 DataInputStream (Producer &producer, Filter &f1, Mode mode=singleThreaded)
 Constructor with one filter.
 DataInputStream (Producer &producer, Filter &f1, Filter &f2, Mode mode=singleThreaded)
 Constructor with two filters.
 DataInputStream (Producer &producer, const std::vector< Filter * > &filters, Mode mode=singleThreaded)
 Constructor with a vector of filters.
virtual ~DataInputStream ()
 Virtual Destructor.
virtual void close ()
 Close the input.
void read (void *data, std::size_t sizeInBytes)
 Read a generic bunch of data.
bool readBool ()
 Read a boolean value.
Int8 readInt8 ()
 Read a 1 byte integer.
Uint8 readUint8 ()
 Read a 1 byte unsigned integer.
Int16 readInt16 ()
 Read a 2 bytes integer.
Uint16 readUint16 ()
 Read a 2 bytes unsigned integer.
Int32 readInt32 ()
 Read a 4 bytes integer.
Uint32 readUint32 ()
 Read a 4 bytes unsigned integer.
float readFloat ()
 Read a float value.
double readDouble ()
 Read a double value.
void read (char *data)
 Read a '' terminated char array.
void read (std::string &data)
 Read a string.
void read (wchar_t *data)
 Read a '' terminated wide char array.
void read (std::wstring &data)
 Read a wide string.
void read (Resource &resource)
 Read a resource object.
DataInputStreamoperator>> (bool &data)
 Read a boolean value.
DataInputStreamoperator>> (Int8 &data)
 Read a 1 byte integer.
DataInputStreamoperator>> (Uint8 &data)
 Read a 1 byte unsigned integer.
DataInputStreamoperator>> (Int16 &data)
 Read a 2 bytes integer.
DataInputStreamoperator>> (Uint16 &data)
 Read a 2 bytes unsigned integer.
DataInputStreamoperator>> (Int32 &data)
 Read a 4 bytes integer.
DataInputStreamoperator>> (Uint32 &data)
 Read a 4 bytes unsigned integer.
DataInputStreamoperator>> (float &data)
 Read a float value.
DataInputStreamoperator>> (double &data)
 Read a double value.
DataInputStreamoperator>> (char *data)
 Read a '' terminated char array.
DataInputStreamoperator>> (std::string &data)
 Read a string.
DataInputStreamoperator>> (wchar_t *data)
 Read a '' terminated wide char array.
DataInputStreamoperator>> (std::wstring &data)
 Read a wide string.
DataInputStreamoperator>> (Resource &resource)
 Read a resource object.
void wait ()
 Wait for stream termination.

Protected Member Functions

 DataInputStream (Mode mode)
 Protected constructor.
void init (Producer &producer)
 Initialization by producer.
void init (Producer &producer, Filter &filter1)
 Initialization with one filter.
void init (Producer &producer, Filter &filter1, Filter &filter2)
 Constructor with two filters.
void init (Producer &producer, const std::vector< Filter * > &filters)
 Constructor with a vector of filters.
void safeWait ()
 Safelly wait for stream termination.
void init (Producer &producer, const std::vector< Filter * > &filters, Consumer &consumer, Mode mode)
 Initialize the stream.
void singleThreadRun (Producer &producer, const std::vector< Filter * > &filters, Consumer &consumer)
 Do the full streaming in singleTreaded mode.
void multiThreadLaunch (Producer &producer, const std::vector< Filter * > &filters, Consumer &consumer)
 Launch the streaming process in multiTreaded mode.
bool singleProcessProducer (Producer &producer, Chunk &chunk)
 Do a producer step in singleTreaded mode.
void singleProcessFilters (const std::vector< Filter * > &filters, Chunk &chunk, bool hasMore)
 Process all filters in singleTreaded mode.
bool singleProcessConsumer (Consumer &consumer, Chunk &chunk, bool hasMore)
 Do a consumer step in singleTreaded mode.

Protected Attributes

std::vector< PipeNode * > pipe
 The pipeline threads (multiTreaded mode only).
bool waited
 True if stream already waited for it's threads (multiTreaded mode only).

Friends

class ChunkReceiver

Detailed Description

Class that provides formated input.

This is the base class for streams based on reading structured information.

It can be used like the standard std::istream to stream native types, strings and resource objects (objects of classes derived from cx::Resource). However, for basic types it is recomended that you use the equivalent reading functions instead of the operator >>. This is because the size of basic types is differen between platforms.

So, instead of this:

 int myInteger
 stream >> myInteger;

You should do:

 int myInteger
 stream.readInt32(myInteger); // this will read an integer of exactly 4 bytes

Alternativelly, use the Codex basic types instead:

 cx::Uint32 myInteger
 stream >> myInteger; // this will read an integer of exactly 4 bytes

Usage example:

 MyProducerClass producer; // MyProducerClass derives from cx::Producer
 cx::DataInputStream stream(producer); // we will read data from the producer
 // read some data from the producer
 unsigned int myInt;
 bool myFlag;
 std::string myString;
 cx::MyResource myRsc; // MyResource derives from cx::Resource
 stream.readUint16(myInt); // read an unsigned int of 2 bytes (16 bits).
 stream >> myFlag >> myString >> myRsc;
 ...
 stream.close();

Note: Remember to catch eventual exceptions when using pipeline components (Stream, filters, producers and consumers).

See also:
cx::DataOutputStream
cx::FileInputStream
cx::FileOutputStream
cx::Stream
cx::Producer

Definition at line 45 of file DataInputStream.hpp.


Member Enumeration Documentation

enum cx::Stream::Mode [inherited]

Operation mode.

Enumerator:
singleThreaded 

Do not create threads.

multiThreaded 

Use a thread per pipeline node.

Definition at line 55 of file Stream.hpp.


Constructor & Destructor Documentation

cx::DataInputStream::DataInputStream ( Producer producer,
Mode  mode = singleThreaded 
) [explicit]

Constructor by producer.

Parameters:
producer The data producer.
mode Operation mode (singleThreaded by default).
cx::DataInputStream::DataInputStream ( Producer producer,
Filter f1,
Mode  mode = singleThreaded 
)

Constructor with one filter.

Parameters:
producer The stream data producer.
f1 A filter to process data from the producer.
mode Operation mode (singleThreaded by default).
cx::DataInputStream::DataInputStream ( Producer producer,
Filter f1,
Filter f2,
Mode  mode = singleThreaded 
)

Constructor with two filters.

Parameters:
producer The stream data producer.
f1 A filter to process data from the producer.
f2 A filter to process data after the first filter f1.
mode Operation mode (singleThreaded by default).
cx::DataInputStream::DataInputStream ( Producer producer,
const std::vector< Filter * > &  filters,
Mode  mode = singleThreaded 
)

Constructor with a vector of filters.

Parameters:
producer The stream data producer.
filters Filters to be used abter the producer.
mode Operation mode (singleThreaded by default).
virtual cx::DataInputStream::~DataInputStream (  )  [virtual]

Virtual Destructor.

Cleanup the input state. If being used on a stream, it waits for the stream to end.

cx::DataInputStream::DataInputStream ( Mode  mode  )  [protected]

Protected constructor.

Parameters:
mode Operation mode.

Member Function Documentation

virtual void cx::DataInputStream::close (  )  [virtual]

Close the input.

If being used on a stream, it waits for the stream to end. After closed it can't be reopened (create a new one instead).

Reimplemented in cx::FileInputStream.

void cx::Stream::init ( Producer producer,
const std::vector< Filter * > &  filters,
Consumer consumer,
Mode  mode 
) [protected, inherited]

Initialize the stream.

Parameters:
producer The stream data producer.
filters Filters to be used between the producer and the consumer.
consumer The stream data consumer.
mode Operation mode (singleThreaded by default).
void cx::DataInputStream::init ( Producer producer,
const std::vector< Filter * > &  filters 
) [protected]

Constructor with a vector of filters.

Parameters:
producer The stream data producer.
filters Filters to be used abter the producer.
void cx::DataInputStream::init ( Producer producer,
Filter filter1,
Filter filter2 
) [protected]

Constructor with two filters.

Parameters:
producer The stream data producer.
f1 A filter to process data from the producer.
f2 A filter to process data after the first filter f1.
void cx::DataInputStream::init ( Producer producer,
Filter filter1 
) [protected]

Initialization with one filter.

Parameters:
producer The stream data producer.
f1 A filter to process data from the producer.
void cx::DataInputStream::init ( Producer producer  )  [protected]

Initialization by producer.

Parameters:
producer The data producer.
void cx::Stream::multiThreadLaunch ( Producer producer,
const std::vector< Filter * > &  filters,
Consumer consumer 
) [protected, inherited]

Launch the streaming process in multiTreaded mode.

Parameters:
producer The stream data producer.
filters Filters to be used between the producer and the consumer.
consumer The stream data consumer.
DataInputStream& cx::DataInputStream::operator>> ( Resource resource  ) 

Read a resource object.

DataInputStream& cx::DataInputStream::operator>> ( std::wstring &  data  ) 

Read a wide string.

DataInputStream& cx::DataInputStream::operator>> ( wchar_t *  data  ) 

Read a '' terminated wide char array.

DataInputStream& cx::DataInputStream::operator>> ( std::string &  data  ) 

Read a string.

DataInputStream& cx::DataInputStream::operator>> ( char *  data  ) 

Read a '' terminated char array.

DataInputStream& cx::DataInputStream::operator>> ( double &  data  ) 

Read a double value.

DataInputStream& cx::DataInputStream::operator>> ( float &  data  ) 

Read a float value.

DataInputStream& cx::DataInputStream::operator>> ( Uint32 &  data  ) 

Read a 4 bytes unsigned integer.

DataInputStream& cx::DataInputStream::operator>> ( Int32 &  data  ) 

Read a 4 bytes integer.

DataInputStream& cx::DataInputStream::operator>> ( Uint16 &  data  ) 

Read a 2 bytes unsigned integer.

DataInputStream& cx::DataInputStream::operator>> ( Int16 &  data  ) 

Read a 2 bytes integer.

DataInputStream& cx::DataInputStream::operator>> ( Uint8 &  data  ) 

Read a 1 byte unsigned integer.

DataInputStream& cx::DataInputStream::operator>> ( Int8 &  data  ) 

Read a 1 byte integer.

DataInputStream& cx::DataInputStream::operator>> ( bool &  data  ) 

Read a boolean value.

void cx::DataInputStream::read ( Resource resource  ) 

Read a resource object.

void cx::DataInputStream::read ( std::wstring &  data  ) 

Read a wide string.

void cx::DataInputStream::read ( wchar_t *  data  ) 

Read a '' terminated wide char array.

void cx::DataInputStream::read ( std::string &  data  ) 

Read a string.

void cx::DataInputStream::read ( char *  data  ) 

Read a '' terminated char array.

void cx::DataInputStream::read ( void *  data,
std::size_t  sizeInBytes 
)

Read a generic bunch of data.

Parameters:
data A pointer to the object to be read.
sizeInBytes Size of the object in bytes.
bool cx::DataInputStream::readBool (  ) 

Read a boolean value.

double cx::DataInputStream::readDouble (  ) 

Read a double value.

float cx::DataInputStream::readFloat (  ) 

Read a float value.

Int16 cx::DataInputStream::readInt16 (  ) 

Read a 2 bytes integer.

Int32 cx::DataInputStream::readInt32 (  ) 

Read a 4 bytes integer.

Int8 cx::DataInputStream::readInt8 (  ) 

Read a 1 byte integer.

Uint16 cx::DataInputStream::readUint16 (  ) 

Read a 2 bytes unsigned integer.

Uint32 cx::DataInputStream::readUint32 (  ) 

Read a 4 bytes unsigned integer.

Uint8 cx::DataInputStream::readUint8 (  ) 

Read a 1 byte unsigned integer.

void cx::Stream::safeWait (  )  [protected, inherited]

Safelly wait for stream termination.

Any exception caught is written on std::cerr.

bool cx::Stream::singleProcessConsumer ( Consumer consumer,
Chunk chunk,
bool  hasMore 
) [protected, inherited]

Do a consumer step in singleTreaded mode.

Parameters:
Consumer The consumer being processed.
chunk The chunk of data to be consumed.
hasMore Flag telling if the producer has more data (i.e., this isn't the last chunk).
Returns:
true if the consumer can acept more data.
void cx::Stream::singleProcessFilters ( const std::vector< Filter * > &  filters,
Chunk chunk,
bool  hasMore 
) [protected, inherited]

Process all filters in singleTreaded mode.

Parameters:
filters The filters that will process the data chunk.
chunk The chunk of data to be filtered.
hasMore Flag telling if the producer has more data (i.e., this isn't the last chunk).
bool cx::Stream::singleProcessProducer ( Producer producer,
Chunk chunk 
) [protected, inherited]

Do a producer step in singleTreaded mode.

Parameters:
producer The data producer being processed.
[out] chunk The produced data.
Returns:
true if the producer has more data to produce.
void cx::Stream::singleThreadRun ( Producer producer,
const std::vector< Filter * > &  filters,
Consumer consumer 
) [protected, inherited]

Do the full streaming in singleTreaded mode.

Parameters:
producer The stream data producer.
filters Filters to be used between the producer and the consumer.
consumer The stream data consumer.
void cx::Stream::wait (  )  [inherited]

Wait for stream termination.

Only applycable when the stream is running in multiThreaded mode.


Member Data Documentation

std::vector<PipeNode*> cx::Stream::pipe [protected, inherited]

The pipeline threads (multiTreaded mode only).

Definition at line 222 of file Stream.hpp.

bool cx::Stream::waited [protected, inherited]

True if stream already waited for it's threads (multiTreaded mode only).

Definition at line 223 of file Stream.hpp.


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