Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Friends

StreamHandler Class Reference
[Concept]

Provides a central class to register globally used output streams. Currently supported streams are. More...

#include <OpenMS/CONCEPT/StreamHandler.h>

List of all members.

Public Types

enum  StreamType { FILE, STRING }
 

Defines the type of the stream that should be handled.

More...

Public Member Functions

 StreamHandler ()
 Default constructor.
virtual ~StreamHandler ()
 destructor
Int registerStream (StreamType const type, const String &stream_name)
 Creates a stream of type type and with name stream_name.
void unregisterStream (StreamType const type, const String &stream_name)
 Deregisters a stream of type type and with name stream_name from the handler.
ostream & getStream (StreamType const type, const String &stream_name)
 Returns a reference to the stream of type type and with name stream_name.
bool hasStream (const StreamType type, const String &stream_name)
 Returns true if the stream stream_name with type type is registered.

Protected Member Functions

ostream * createStream_ (const StreamType type, const String &stream_name)
 Creates a stream with the given type and the given name.

Protected Attributes

map< String, ostream * > name_to_stream_map_
 Maps all registered stream names to the corresponding std::ostream.
map< String, StreamTypename_to_type_map_
 Maps all registered stream names to the corresponding StreamHandler::StreamType.
map< String, Sizename_to_counter_map_
 Maps all registered stream names to the number of times it was registered. If the counter goes to zero, the stream will be closed and removed.

Private Member Functions

 StreamHandler (const StreamHandler &source)
 copy constructor
virtual StreamHandleroperator= (const StreamHandler &source)
 assignment operator

Friends

std::ostream & operator<< (std::ostream &os, StreamHandler const &stream_handler)
 Overload for the insertion operator (operator<<) to have a formated output of the StreamHandler.

Detailed Description

Provides a central class to register globally used output streams. Currently supported streams are.

You can simply request a stream from StreamHandler and it will manage the process of construction and destruction (if the stream is not needed any more).

A normal scenario would be

STREAM_HANDLER.registerStream(StreamHandler::FILE, "name_of_the_output_file");
STREAM_HANDLER.getStream(StreamHandler::FILE, "name_of_the_output_file") << "This will be send to the file" << std::endl;
// ...

// you do not need the file any more
STREAM_HANDLER.unregisterStream(StreamHandler::FILE, "name_of_the_output_file");
// StreamHandler will close the file stream if no other part of your program requested the same stream


Member Enumeration Documentation

enum StreamType

Defines the type of the stream that should be handled.

Enumerator:
FILE 
STRING 

Constructor & Destructor Documentation

StreamHandler (  ) 

Default constructor.

virtual ~StreamHandler (  )  [virtual]

destructor

StreamHandler ( const StreamHandler source  )  [private]

copy constructor


Member Function Documentation

ostream* createStream_ ( const StreamType  type,
const String stream_name 
) [protected]

Creates a stream with the given type and the given name.

Parameters:
type Type of the stream (e.g. FILE)
stream_name Name of the stream (e.g. the file name for a file stream).
Returns:
A pointer to the created stream.
ostream& getStream ( StreamType const   type,
const String stream_name 
)

Returns a reference to the stream of type type and with name stream_name.

If the stream was not registered before an ElementNotFoundException will be thrown.

Parameters:
type Type of the stream (e.g. FILE)
stream_name Name of the stream (e.g. the file name for a file stream).
Exceptions:
ElementNotFoundException 
Returns:
A reference to the requested stream.
bool hasStream ( const StreamType  type,
const String stream_name 
)

Returns true if the stream stream_name with type type is registered.

Parameters:
type Type of the stream (e.g. FILE)
stream_name Name of the stream (e.g. the file name for a file stream).
Returns:
bool indication if the stream is known.
virtual StreamHandler& operator= ( const StreamHandler source  )  [private, virtual]

assignment operator

Int registerStream ( StreamType const   type,
const String stream_name 
)

Creates a stream of type type and with name stream_name.

If the stream is already registered the reference counter is increased.

Note:
The stream name must be unique. You cannot register the same stream name with two different types.
Parameters:
type Type of the stream (e.g. FILE)
stream_name Name of the stream (e.g. the file name for a file stream).
Returns:
An integer indicating if the operation was completed succesfully (value != 1 means a failure occured).
void unregisterStream ( StreamType const   type,
const String stream_name 
)

Deregisters a stream of type type and with name stream_name from the handler.

It also decreases the reference counter for the named stream. If the counter reaches 0. The stream will be closed.

Parameters:
type Type of the stream (e.g. FILE)
stream_name Name of the stream (e.g. the file name for a file stream).

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
StreamHandler const &  stream_handler 
) [friend]

Overload for the insertion operator (operator<<) to have a formated output of the StreamHandler.


Member Data Documentation

map<String, Size> name_to_counter_map_ [protected]

Maps all registered stream names to the number of times it was registered. If the counter goes to zero, the stream will be closed and removed.

map<String, ostream *> name_to_stream_map_ [protected]

Maps all registered stream names to the corresponding std::ostream.

map<String, StreamType> name_to_type_map_ [protected]

Maps all registered stream names to the corresponding StreamHandler::StreamType.


OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:51 using doxygen 1.7.1