DebugStream.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef DEBUGSTREAM_H
00015 #define DEBUGSTREAM_H
00016
00017
00018
00019
00020
00021 #include <iostream>
00022 #include <string>
00023
00024 #ifdef TEST_DEBUGSTREAM
00025 #include <string>
00026 struct Debug {
00027 enum type {
00028 NONE = 0,
00029 INFO = (1 << 0),
00030 WARN = (1 << 1),
00031 CRIT = (1 << 2)
00032 };
00033 static const type ANY = type(INFO | WARN | CRIT);
00034 static Debug::type value(std::string const & val) {
00035 if (val == "NONE") return Debug::NONE;
00036 if (val == "INFO") return Debug::INFO;
00037 if (val == "WARN") return Debug::WARN;
00038 if (val == "CRIT") return Debug::CRIT;
00039 return Debug::NONE;
00040 }
00041 };
00042 #endif
00043
00081 class DebugStream : public std::ostream
00082 {
00083 public:
00085 explicit DebugStream(Debug::type t = Debug::NONE);
00086
00088 explicit
00089 DebugStream(char const * f, Debug::type t = Debug::NONE);
00090
00092 ~DebugStream();
00093
00095 void level(Debug::type t) {
00096 dt = Debug::type(t & Debug::ANY);
00097 }
00098
00100 Debug::type level() const {
00101 return dt;
00102 }
00103
00105 void addLevel(Debug::type t) {
00106 dt = Debug::type(dt | t);
00107 }
00108
00110 void delLevel(Debug::type t) {
00111 dt = Debug::type(dt & ~t);
00112 }
00113
00115 void logFile(const std::string f);
00116
00117 inline std::string getLogFile(){ return fname; }
00118
00120 bool debugging(Debug::type t = Debug::ANY) const
00121 {
00122 if (dt & t) return true;
00123 return false;
00124 }
00125
00126
00131 std::ostream & debug(Debug::type t = Debug::ANY);
00132
00133
00134
00135
00136
00141 std::ostream & operator[](Debug::type t) {
00142 return debug(t);
00143 }
00144
00148 inline std::ostream& to_end(Debug::type t)
00149 {
00150 return this->operator()(t);
00151 }
00152
00156 std::ostream& operator()(Debug::type t);
00157
00158
00159 inline void showDateTime(bool s)
00160 {
00161 show_datetime = s;
00162 }
00163
00164
00165 std::ostream& print_date(Debug::type t, char brk='/');
00166 std::ostream& print_time(Debug::type t, char brk=':');
00167 std::ostream& print_datetime(Debug::type t);
00168
00169
00170 std::ostream& pos(int x, int y);
00171
00172 const DebugStream &operator=(const DebugStream& r);
00173
00174 private:
00176 Debug::type dt;
00178 std::ostream nullstream;
00180 struct debugstream_internal;
00182 debugstream_internal * internal;
00183 bool show_datetime;
00184 std::string fname;
00185
00186 };
00187
00188 #endif