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. More... | |
virtual | ~StreamHandler () |
destructor More... | |
Int | registerStream (StreamType const type, const String &stream_name) |
Creates a stream of type type and with name stream_name . More... | |
void | unregisterStream (StreamType const type, const String &stream_name) |
De-registers a stream of type type and with name stream_name from the handler. More... | |
std::ostream & | getStream (StreamType const type, const String &stream_name) |
Returns a reference to the stream of type type and with name stream_name . More... | |
bool | hasStream (const StreamType type, const String &stream_name) |
Returns true if the stream stream_name with type type is registered. More... | |
Protected Member Functions | |
std::ostream * | createStream_ (const StreamType type, const String &stream_name) |
Creates a stream with the given type and the given name. More... | |
Protected Attributes | |
std::map< String, std::ostream * > | name_to_stream_map_ |
Maps all registered stream names to the corresponding std::ostream. More... | |
std::map< String, StreamType > | name_to_type_map_ |
Maps all registered stream names to the corresponding StreamHandler::StreamType. More... | |
std::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. More... | |
Private Member Functions | |
StreamHandler (const StreamHandler &source) | |
copy constructor More... | |
virtual StreamHandler & | operator= (const StreamHandler &source) |
assignment operator More... | |
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. More... | |
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.
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& 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). |
|
privatevirtual |
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 occurred). void unregisterStream | ( | StreamType const | type, |
const 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.
type | Type of the stream (e.g. FILE) |
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.
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.