Provides a central class to register globally used output streams. Currently supported streams are. More...
#include <OpenMS/CONCEPT/StreamHandler.h>
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, StreamType > | name_to_type_map_ |
| Maps all registered stream names to the corresponding StreamHandler::StreamType. | |
| map< String, Size > | name_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 StreamHandler & | operator= (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. | |
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
| enum StreamType |
| StreamHandler | ( | ) |
Default constructor.
| virtual ~StreamHandler | ( | ) | [virtual] |
destructor
| StreamHandler | ( | const StreamHandler & | source | ) | [private] |
copy constructor
| ostream* createStream_ | ( | const StreamType | type, | |
| const String & | stream_name | |||
| ) | [protected] |
Creates a stream with the given type and the given name.
| type | Type of the stream (e.g. FILE) | |
| stream_name | Name of the stream (e.g. the file name for a file 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.
| type | Type of the stream (e.g. FILE) | |
| stream_name | Name of the stream (e.g. the file name for a file stream). |
| ElementNotFoundException |
| bool hasStream | ( | const StreamType | type, | |
| const String & | stream_name | |||
| ) |
Returns true if the stream stream_name with type type is registered.
| type | Type of the stream (e.g. FILE) | |
| stream_name | Name of the stream (e.g. the file name for a file stream). |
| 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.
| type | Type of the stream (e.g. FILE) | |
| stream_name | Name of the stream (e.g. the file name for a file stream). |
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.
| type | Type of the stream (e.g. FILE) | |
| stream_name | Name of the stream (e.g. the file name for a file stream). |
| 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.
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 |