![]() |
OpenMS
|
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 std::string &stream_name) |
Creates a stream of type type and with name stream_name. | |
| void | unregisterStream (StreamType const type, const std::string &stream_name) |
De-registers a stream of type type and with name stream_name from the handler. | |
| std::ostream & | getStream (StreamType const type, const std::string &stream_name) |
Returns a reference to the stream of type type and with name stream_name. | |
| bool | hasStream (const StreamType type, const std::string &stream_name) |
Returns true if the stream stream_name with type type is registered. | |
Protected Member Functions | |
| std::ostream * | createStream_ (const StreamType type, const std::string &stream_name) |
| Creates a stream with the given type and the given name. | |
Protected Attributes | |
| std::map< std::string, std::ostream * > | name_to_stream_map_ |
| Maps all registered stream names to the corresponding std::ostream. | |
| std::map< std::string, StreamType > | name_to_type_map_ |
| Maps all registered stream names to the corresponding StreamHandler::StreamType. | |
| std::map< std::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 formatted 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 |
destructor
|
private |
copy constructor
|
protected |
Creates a stream with the given type and the given name.
| [in] | type | Type of the stream (e.g. FILE) |
| [in] | stream_name | Name of the stream (e.g. the file name for a file stream). |
| std::ostream & getStream | ( | StreamType const | type, |
| const std::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.
| [in] | type | Type of the stream (e.g. FILE) |
| [in] | stream_name | Name of the stream (e.g. the file name for a file stream). |
| ElementNotFoundException |
| bool hasStream | ( | const StreamType | type, |
| const std::string & | stream_name | ||
| ) |
Returns true if the stream stream_name with type type is registered.
| [in] | type | Type of the stream (e.g. FILE) |
| [in] | stream_name | Name of the stream (e.g. the file name for a file stream). |
|
privatevirtual |
assignment operator
| Int registerStream | ( | StreamType const | type, |
| const std::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.
| [in] | type | Type of the stream (e.g. FILE) |
| [in] | stream_name | Name of the stream (e.g. the file name for a file stream). |
value != 1 means a failure occurred). | void unregisterStream | ( | StreamType const | type, |
| const std::string & | stream_name | ||
| ) |
De-registers 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.
| [in] | type | Type of the stream (e.g. FILE) |
| [in] | stream_name | Name of the stream (e.g. the file name for a file stream). |
|
friend |
Overload for the insertion operator (operator<<) to have a formatted output of the StreamHandler.
|
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.
|
protected |
Maps all registered stream names to the corresponding std::ostream.
|
protected |
Maps all registered stream names to the corresponding StreamHandler::StreamType.