TBTK
Streams.h
Go to the documentation of this file.
1 /* Copyright 2016 Kristofer Bj√∂rnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_STREAMS
24 #define COM_DAFER45_TBTK_STREAMS
25 
26 #include <ostream>
27 #include <fstream>
28 #include <string>
29 #include <vector>
30 
31 namespace TBTK{
32 
33 class Streams{
34 public:
36  static std::ostream out;
37 
39  static std::ostream log;
40 
42  static std::ostream err;
43 
45  static void setStdMuteOut();
46 
48  static void setStdMuteErr();
49 
51  static void openLog(std::string filename = "TBTKLog");
52 
54  static void closeLog();
55 
57  static bool logIsOpen();
58 private:
60  static class NullBuffer : public std::streambuf{
61  public:
62  int overflow(int c);
63  } nullBuffer;
64 
66  class ForkBuffer : public std::streambuf{
67  public:
69  ForkBuffer(
70  std::basic_ostream<char, std::char_traits<char>> *ostream1,
71  std::basic_ostream<char, std::char_traits<char>> *ostream2
72  );
73 
75  void mute(int n, bool isMute);
76  private:
78  std::basic_ostream<char, std::char_traits<char>> *ostreams[2];
79 
81  bool isMute[2];
82 
85  int overflow(int c);
86  };
87 
89  class LogBuffer : public std::streambuf{
90  public:
92  LogBuffer();
93 
95  ~LogBuffer();
96 
98  void open(std::string fileName);
99 
101  void close();
102 
104  bool isOpen();
105  private:
107  std::ofstream fout;
108 
111  int overflow(int c);
112  };
113 
115  static std::ostream null;
116 
118  static ForkBuffer stdOutBuffer;
119 
121  static LogBuffer stdLogBuffer;
122 
124  static ForkBuffer stdErrBuffer;
125 
127  static std::ofstream logFile;
128 };
129 
130 }; //End of namespace TBTK
131 
132 #endif
133 
static bool logIsOpen()
static void setStdMuteErr()
static void setStdMuteOut()
Definition: Streams.h:33
static void closeLog()
static std::ostream out
Definition: Streams.h:36
static std::ostream log
Definition: Streams.h:39
static void openLog(std::string filename="TBTKLog")
Definition: ModelFactory.h:35
static std::ostream err
Definition: Streams.h:42