00001 #ifndef XANAVERBOSE_H 00002 #define XANAVERBOSE_H 00003 00004 #include <iosfwd> 00005 00006 #include<string> 00007 00008 class XANAVerbose { 00009 00010 public: 00011 enum FilterLevel {DebugLevel=1, TestLevel=5, InfoLevel=8, SilentLevel=9999}; 00012 00013 enum { nFilterLevel=4}; 00014 00015 00016 static const FilterLevel * levels(); 00017 00018 static const std::string * levelNames(); 00019 00020 static const FilterLevel & level(const std::string & name); 00021 00022 static const std::string & levelName(int il); 00023 00024 public: 00025 static std::ostream & out; 00026 00028 explicit XANAVerbose(int il=TestLevel); 00029 00031 XANAVerbose & operator()(int il=TestLevel) { level_=il; return *this;} 00032 00033 XANAVerbose & operator()(const std::string& il) { level_=level(il); return *this;} 00034 00036 operator bool() const { return verbose_ && (level_ >= filter_);} 00037 00039 void verbose(); 00040 00042 void silent(); 00043 00045 void setFilterLevel(int il=TestLevel); 00047 int getFilterLevel() const; 00048 00049 // int level() const { return level_;} 00050 00051 00052 private: 00053 00054 bool verbose_; 00055 int filter_; 00056 int level_; 00057 }; 00058 00059 #include <ostream> 00060 00061 inline std::ostream & operator<<(std::ostream& o, const XANAVerbose& v) { 00062 00063 return v ? o : XANAVerbose::out; 00064 00065 } 00066 00067 /* 00068 namespace Capri { 00069 00070 namespace Streams { 00071 00072 extern std::ostream cout; 00073 extern std::ostream cerr; 00074 extern std::ostream clog; 00075 00076 void redirect(std::streambuf* outbuf, 00077 std::streambuf* errbuf, 00078 std::streambuf* logbuf); 00079 00080 void redirect(std::ostream & iout, 00081 std::ostream & ierr, 00082 std::ostream & ilog); 00083 00084 00085 extern std::ostream infoOut, testOut, debugOut; 00086 00087 class LogStreams { 00088 public: 00089 00090 LogStreams(std::ostream & iinfo, 00091 std::ostream & itest, 00092 std::ostream & idebug); 00093 00094 std::streambuf* rbuf() { return outbuf;} 00095 00096 void set(std::ostream & s, bool yes); 00097 00098 void on(bool info=true, bool test=false, bool debug=false); 00099 00100 void on(const std::string & level); 00101 00102 void on(XANAVerbose::FilterLevel level); 00103 00104 void silent() {on(false,false,false);} 00105 00106 void redirect(std::streambuf* obuf); 00107 00108 private: 00109 std::ostream & infoS; 00110 std::ostream & testS; 00111 std::ostream & debugS; 00112 00113 std::streambuf* outbuf; 00114 }; 00115 00116 00117 class UserLogStreams { 00118 public: 00119 // controlled streams 00120 std::ostream infoOut, testOut, debugOut; 00121 00122 00123 public: 00124 UserLogStreams(); 00125 void redirect(std::streambuf* outbuf); 00126 00127 std::streambuf* rbuf() { return streams().rbuf();} 00128 00129 Capri::Streams::LogStreams & streams() { return streams_;} 00130 00131 00132 private: 00133 LogStreams streams_; 00134 }; 00135 00136 00137 extern LogStreams defaultStreams; 00138 00139 } 00140 } 00141 00142 using Capri::Streams::infoOut; 00143 using Capri::Streams::testOut; 00144 using Capri::Streams::debugOut; 00145 using Capri::Streams::defaultStreams; 00146 00147 #ifndef XANAVerbose_CC 00148 extern XANAVerbose infoV, testV, debugV; 00149 #endif 00150 */ 00151 #endif // XANAVERBOSE_H