OpenMS
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 #include <map>
13 #include <iosfwd>
14 
15 namespace OpenMS
16 {
42  class OPENMS_DLLAPI StreamHandler
43  {
44 public:
49  {
51  STRING
52  };
53 
56 
58  virtual ~StreamHandler();
59 
72  Int registerStream(StreamType const type, const String & stream_name);
73 
84  void unregisterStream(StreamType const type, const String & stream_name);
85 
98  std::ostream & getStream(StreamType const type, const String & stream_name);
99 
109  bool hasStream(const StreamType type, const String & stream_name);
110 
111 protected:
112 
113  std::map<String, std::ostream *> name_to_stream_map_;
114  std::map<String, StreamType> name_to_type_map_;
115  std::map<String, Size> name_to_counter_map_;
116 
125  std::ostream * createStream_(const StreamType type, const String & stream_name);
126 
127 private:
128  // copy constructor and assignment operator are hidden to avoid
129  // creating multiple pointers to a single filestream instance
130 
132  StreamHandler(const StreamHandler & source);
133 
135  virtual StreamHandler & operator=(const StreamHandler & source);
136 
137  friend OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, StreamHandler const & stream_handler);
138  };
139 
141  OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, StreamHandler const & stream_handler);
142 
144  OPENMS_DLLAPI extern StreamHandler STREAM_HANDLER;
145 } // end namespace OpenMS
146 
Provides a central class to register globally used output streams. Currently supported streams are.
Definition: StreamHandler.h:43
StreamHandler()
Default constructor.
Int registerStream(StreamType const type, const String &stream_name)
Creates a stream of type type and with name stream_name.
std::ostream & getStream(StreamType const type, const String &stream_name)
Returns a reference to the stream of type type and with name stream_name.
std::ostream * createStream_(const StreamType type, const String &stream_name)
Creates a stream with the given type and the given name.
void unregisterStream(StreamType const type, const String &stream_name)
De-registers a stream of type type and with name stream_name from the handler.
std::map< String, StreamType > name_to_type_map_
Maps all registered stream names to the corresponding StreamHandler::StreamType.
Definition: StreamHandler.h:114
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 zer...
Definition: StreamHandler.h:115
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.
virtual StreamHandler & operator=(const StreamHandler &source)
assignment operator
StreamHandler(const StreamHandler &source)
copy constructor
std::map< String, std::ostream * > name_to_stream_map_
Maps all registered stream names to the corresponding std::ostream.
Definition: StreamHandler.h:113
StreamType
Defines the type of the stream that should be handled.
Definition: StreamHandler.h:49
@ FILE
Definition: StreamHandler.h:50
bool hasStream(const StreamType type, const String &stream_name)
Returns true if the stream stream_name with type type is registered.
virtual ~StreamHandler()
destructor
A more convenient string class.
Definition: String.h:34
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.