TBTK
Need a break? Support the development by playing Polarity Puzzles
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 
67 class Streams{
68 public:
70  static std::ostream out;
71 
73  static std::ostream log;
74 
76  static std::ostream err;
77 
79  static void setStdMuteOut();
80 
82  static void setStdMuteErr();
83 
87  static void openLog(std::string filename = "TBTKLog");
88 
90  static void closeLog();
91 
93  static bool logIsOpen();
94 private:
96  static class NullBuffer : public std::streambuf{
97  public:
98  int overflow(int c);
99  } nullBuffer;
100 
102  class ForkBuffer : public std::streambuf{
103  public:
105  ForkBuffer(
106  std::basic_ostream<char, std::char_traits<char>> *ostream1,
107  std::basic_ostream<char, std::char_traits<char>> *ostream2
108  );
109 
111  void mute(int n, bool isMute);
112  private:
114  std::basic_ostream<char, std::char_traits<char>> *ostreams[2];
115 
117  bool isMute[2];
118 
121  int overflow(int c);
122  };
123 
125  class LogBuffer : public std::streambuf{
126  public:
128  LogBuffer();
129 
131  ~LogBuffer();
132 
134  void open(std::string fileName);
135 
137  void close();
138 
140  bool isOpen();
141  private:
143  std::ofstream fout;
144 
147  int overflow(int c);
148  };
149 
151  static std::ostream null;
152 
154  static ForkBuffer stdOutBuffer;
155 
157  static LogBuffer stdLogBuffer;
158 
160  static ForkBuffer stdErrBuffer;
161 
163  static std::ofstream logFile;
164 };
165 
166 }; //End of namespace TBTK
167 
168 #endif
169 
static bool logIsOpen()
static void setStdMuteErr()
static void setStdMuteOut()
Definition: Streams.h:67
static void closeLog()
static std::ostream out
Definition: Streams.h:70
static std::ostream log
Definition: Streams.h:73
static void openLog(std::string filename="TBTKLog")
Definition: Boolean.h:32
static std::ostream err
Definition: Streams.h:76