OpenMS
Loading...
Searching...
No Matches
StreamHandler.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg$
6// $Authors: Stephan Aiche$
7// --------------------------------------------------------------------------
8
9#pragma once
10
12
13#include <map>
14#include <iosfwd>
15#include <string>
16
17namespace OpenMS
18{
44 class OPENMS_DLLAPI StreamHandler
45 {
46public:
51 {
53 STRING
54 };
55
58
60 virtual ~StreamHandler();
61
74 Int registerStream(StreamType const type, const std::string & stream_name);
75
86 void unregisterStream(StreamType const type, const std::string & stream_name);
87
100 std::ostream & getStream(StreamType const type, const std::string & stream_name);
101
111 bool hasStream(const StreamType type, const std::string & stream_name);
112
113protected:
114
115 std::map<std::string, std::ostream *> name_to_stream_map_;
116 std::map<std::string, StreamType> name_to_type_map_;
117 std::map<std::string, Size> name_to_counter_map_;
118
127 std::ostream * createStream_(const StreamType type, const std::string & stream_name);
128
129private:
130 // copy constructor and assignment operator are hidden to avoid
131 // creating multiple pointers to a single filestream instance
132
135
137 virtual StreamHandler & operator=(const StreamHandler & source);
138
139 friend OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, StreamHandler const & stream_handler);
140 };
141
143 OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, StreamHandler const & stream_handler);
144
146 OPENMS_DLLAPI extern StreamHandler STREAM_HANDLER;
147} // end namespace OpenMS
148
Provides a central class to register globally used output streams. Currently supported streams are.
Definition StreamHandler.h:45
std::map< std::string, std::ostream * > name_to_stream_map_
Maps all registered stream names to the corresponding std::ostream.
Definition StreamHandler.h:115
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.
std::ostream * createStream_(const StreamType type, const std::string &stream_name)
Creates a stream with the given type and the given name.
StreamHandler()
Default constructor.
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::map< std::string, StreamType > name_to_type_map_
Maps all registered stream names to the corresponding StreamHandler::StreamType.
Definition StreamHandler.h:116
bool hasStream(const StreamType type, const std::string &stream_name)
Returns true if the stream stream_name with type type is registered.
friend std::ostream & operator<<(std::ostream &os, StreamHandler const &stream_handler)
Overload for the insertion operator (operator<<) to have a formatted output of the StreamHandler.
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 zer...
Definition StreamHandler.h:117
StreamHandler(const StreamHandler &source)
copy constructor
StreamType
Defines the type of the stream that should be handled.
Definition StreamHandler.h:51
@ FILE
Definition StreamHandler.h:52
Int registerStream(StreamType const type, const std::string &stream_name)
Creates a stream of type type and with name stream_name.
virtual ~StreamHandler()
destructor
virtual StreamHandler & operator=(const StreamHandler &source)
assignment operator
int Int
Signed integer type.
Definition Types.h:72
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
StreamHandler STREAM_HANDLER
Global StreamHandler instance.