cx::DataOutputStream Class Reference

Class that provides formated output. More...

#include <DataOutputStream.hpp>

Inheritance diagram for cx::DataOutputStream:
cx::Stream cx::NonCopyable cx::FileOutputStream

List of all members.

Public Types

enum  Mode {
  singleThreaded,
  multiThreaded
}
 

Operation mode.

More...

Public Member Functions

 DataOutputStream (Consumer &consumer, Mode mode=singleThreaded, unsigned int chunkSize=DEFAULT_CHUNK_SIZE)
 Constructor by consumer.
 DataOutputStream (Filter &f1, Consumer &consumer, Mode mode=singleThreaded, unsigned int chunkSize=DEFAULT_CHUNK_SIZE)
 Constructor with one filter.
 DataOutputStream (Filter &f1, Filter &f2, Consumer &consumer, Mode mode=singleThreaded, unsigned int chunkSize=DEFAULT_CHUNK_SIZE)
 Constructor with two filters.
 DataOutputStream (const std::vector< Filter * > &filters, Consumer &consumer, Mode mode=singleThreaded, unsigned int chunkSize=DEFAULT_CHUNK_SIZE)
 Constructor with a vector of filters.
virtual ~DataOutputStream ()
 Destructor.
virtual void close ()
 Close the output.
void write (const void *data, std::size_t sizeInBytes)
 Write a generic bunch of data.
void writeBool (bool data)
 Write a boolean value.
void writeInt8 (Int8 data)
 Write a 1 byte integer.
void writeUint8 (Uint8 data)
 Write a 1 byte unsigned integer.
void writeInt16 (Int16 data)
 Write a 2 bytes integer.
void writeUint16 (Uint16 data)
 Write a 2 bytes unsigned integer.
void writeInt32 (Int32 data)
 Write a 4 bytes integer.
void writeUint32 (Uint32 data)
 Write a 4 bytes unsigned integer.
void writeFloat (float data)
 Write a float value.
void writeDouble (double data)
 Write a double value.
void write (const char *data)
 Write a '' terminated char array.
void write (const std::string &data)
 Write a string.
void write (const wchar_t *data)
 Write a '' terminated wide char array.
void write (const std::wstring &data)
 Write a wide string.
void write (const Resource &resource)
 Write a resource object.
DataOutputStreamoperator<< (bool data)
 Write a boolean value.
DataOutputStreamoperator<< (Int8 data)
 Write a 1 byte integer.
DataOutputStreamoperator<< (Uint8 data)
 Write a 1 byte unsigned integer.
DataOutputStreamoperator<< (Int16 data)
 Write a 2 bytes integer.
DataOutputStreamoperator<< (Uint16 data)
 Write a 2 bytes unsigned integer.
DataOutputStreamoperator<< (Int32 data)
 Write a 4 bytes integer.
DataOutputStreamoperator<< (Uint32 data)
 Write a 4 bytes unsigned integer.
DataOutputStreamoperator<< (float data)
 Write a float value.
DataOutputStreamoperator<< (double data)
 Write a double value.
DataOutputStreamoperator<< (const char *data)
 Write a '' terminated char array.
DataOutputStreamoperator<< (const std::string &data)
 Write a string.
DataOutputStreamoperator<< (const wchar_t *data)
 Write a '' terminated wide char array.
DataOutputStreamoperator<< (const std::wstring &data)
 Write a wide string.
DataOutputStreamoperator<< (const Resource &resource)
 Write a resource object.
void wait ()
 Wait for stream termination.

Static Public Attributes

static const std::size_t DEFAULT_CHUNK_SIZE
 Default buffer size.

Protected Member Functions

 DataOutputStream (Mode mode, unsigned int chunkSize)
 Protected constructor.
void init (Consumer &consumer)
 Initialization by consumer.
void init (Filter &filter1, Consumer &consumer)
 Initialization with one filter.
void init (Filter &filter1, Filter &filter2, Consumer &consumer)
 Initialization with two filters.
void init (const std::vector< Filter * > &filters, Consumer &consumer)
 Initialization 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 ChunkSender

Detailed Description

Class that provides formated output.

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

It can be used like the standard std::ostream 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 writing 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.writeInt32(myInteger); // this will write an integer of exactly 4 bytes

Alternativelly, use the Codex basic types instead:

 cx::Uint32 myInteger
 stream << myInteger; // this will write an integer of exactly 4 bytes

Usage example:

 MyConsumerClass consumer; // MyConsumerClass derives from cx::Consumer
 cx::DataoutputStream stream(consumer); // We will write data to the consumer
 // write some data
 bool myFlag;
 std::string myString;
 cx::MyResource myRsc; // MyResource derives from cx::Resource
 stream.writeUint16(568); // write 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::DataInputStream
cx::FileInputStream
cx::FileOutputStream
cx::Stream
cx::Consumer

Definition at line 45 of file DataOutputStream.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::DataOutputStream::DataOutputStream ( Consumer consumer,
Mode  mode = singleThreaded,
unsigned int  chunkSize = DEFAULT_CHUNK_SIZE 
) [explicit]

Constructor by consumer.

Parameters:
consumer The data consumer.
mode Operation mode (singleThreaded by default).
chunkSize Size of the internal buffer.
cx::DataOutputStream::DataOutputStream ( Filter f1,
Consumer consumer,
Mode  mode = singleThreaded,
unsigned int  chunkSize = DEFAULT_CHUNK_SIZE 
)

Constructor with one filter.

Parameters:
f1 A filter to process data before consuming it.
consumer The data consumer.
mode Operation mode (singleThreaded by default).
chunkSize Size of the internal buffer.
cx::DataOutputStream::DataOutputStream ( Filter f1,
Filter f2,
Consumer consumer,
Mode  mode = singleThreaded,
unsigned int  chunkSize = DEFAULT_CHUNK_SIZE 
)

Constructor with two filters.

Parameters:
f1 A filter to process the source data.
f2 A filter to process data after f1, before consumption.
consumer The data consumer.
mode Operation mode (singleThreaded by default).
chunkSize Size of the internal buffer.
cx::DataOutputStream::DataOutputStream ( const std::vector< Filter * > &  filters,
Consumer consumer,
Mode  mode = singleThreaded,
unsigned int  chunkSize = DEFAULT_CHUNK_SIZE 
)

Constructor with a vector of filters.

Parameters:
filters Filters to be used before consumption.
consumer The data consumer.
mode Operation mode (singleThreaded by default).
chunkSize Size of the internal buffer.
virtual cx::DataOutputStream::~DataOutputStream (  )  [virtual]

Destructor.

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

cx::DataOutputStream::DataOutputStream ( Mode  mode,
unsigned int  chunkSize 
) [protected]

Protected constructor.

Parameters:
mode Operation mode.
chunkSize Size of the internal buffer.

Member Function Documentation

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

Close the output.

Close the output and flush the internal buffer into the stream. 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::FileOutputStream.

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::DataOutputStream::init ( const std::vector< Filter * > &  filters,
Consumer consumer 
) [protected]

Initialization with a vector of filters.

Parameters:
filters Filters to be used before consumption.
consumer The data consumer.
void cx::DataOutputStream::init ( Filter filter1,
Filter filter2,
Consumer consumer 
) [protected]

Initialization with two filters.

Parameters:
f1 A filter to process the source data.
f2 A filter to process data after f1, before consumption.
consumer The data consumer.
void cx::DataOutputStream::init ( Filter filter1,
Consumer consumer 
) [protected]

Initialization with one filter.

Parameters:
f1 A filter to process data before consumption.
consumer The data consumer.
void cx::DataOutputStream::init ( Consumer consumer  )  [protected]

Initialization by consumer.

Parameters:
consumer The data consumer.
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.
DataOutputStream& cx::DataOutputStream::operator<< ( const Resource resource  ) 

Write a resource object.

DataOutputStream& cx::DataOutputStream::operator<< ( const std::wstring &  data  ) 

Write a wide string.

DataOutputStream& cx::DataOutputStream::operator<< ( const wchar_t *  data  ) 

Write a '' terminated wide char array.

DataOutputStream& cx::DataOutputStream::operator<< ( const std::string &  data  ) 

Write a string.

DataOutputStream& cx::DataOutputStream::operator<< ( const char *  data  ) 

Write a '' terminated char array.

DataOutputStream& cx::DataOutputStream::operator<< ( double  data  ) 

Write a double value.

DataOutputStream& cx::DataOutputStream::operator<< ( float  data  ) 

Write a float value.

DataOutputStream& cx::DataOutputStream::operator<< ( Uint32  data  ) 

Write a 4 bytes unsigned integer.

DataOutputStream& cx::DataOutputStream::operator<< ( Int32  data  ) 

Write a 4 bytes integer.

DataOutputStream& cx::DataOutputStream::operator<< ( Uint16  data  ) 

Write a 2 bytes unsigned integer.

DataOutputStream& cx::DataOutputStream::operator<< ( Int16  data  ) 

Write a 2 bytes integer.

DataOutputStream& cx::DataOutputStream::operator<< ( Uint8  data  ) 

Write a 1 byte unsigned integer.

DataOutputStream& cx::DataOutputStream::operator<< ( Int8  data  ) 

Write a 1 byte integer.

DataOutputStream& cx::DataOutputStream::operator<< ( bool  data  ) 

Write a boolean value.

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.

void cx::DataOutputStream::write ( const Resource resource  ) 

Write a resource object.

void cx::DataOutputStream::write ( const std::wstring &  data  ) 

Write a wide string.

void cx::DataOutputStream::write ( const wchar_t *  data  ) 

Write a '' terminated wide char array.

void cx::DataOutputStream::write ( const std::string &  data  ) 

Write a string.

void cx::DataOutputStream::write ( const char *  data  ) 

Write a '' terminated char array.

void cx::DataOutputStream::write ( const void *  data,
std::size_t  sizeInBytes 
)

Write a generic bunch of data.

Parameters:
data A pointer to the object to be written.
sizeInBytes Size of the object in bytes.
void cx::DataOutputStream::writeBool ( bool  data  ) 

Write a boolean value.

void cx::DataOutputStream::writeDouble ( double  data  ) 

Write a double value.

void cx::DataOutputStream::writeFloat ( float  data  ) 

Write a float value.

void cx::DataOutputStream::writeInt16 ( Int16  data  ) 

Write a 2 bytes integer.

void cx::DataOutputStream::writeInt32 ( Int32  data  ) 

Write a 4 bytes integer.

void cx::DataOutputStream::writeInt8 ( Int8  data  ) 

Write a 1 byte integer.

void cx::DataOutputStream::writeUint16 ( Uint16  data  ) 

Write a 2 bytes unsigned integer.

void cx::DataOutputStream::writeUint32 ( Uint32  data  ) 

Write a 4 bytes unsigned integer.

void cx::DataOutputStream::writeUint8 ( Uint8  data  ) 

Write a 1 byte unsigned integer.


Member Data Documentation

const std::size_t cx::DataOutputStream::DEFAULT_CHUNK_SIZE [static]

Default buffer size.

Definition at line 248 of file DataOutputStream.hpp.

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: