cdebug.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NCXXNDEBUGSTREAM_H
00021 #define NCXXNDEBUGSTREAM_H
00022 #include <iostream>
00023 #include <fstream>
00024 #include <sstream>
00025 #include <string>
00026 #include <cxstring.hxx>
00027
00028 #include <map>
00029
00030
00031 using std::ofstream;
00032 using std::ostringstream;
00033
00034 namespace debug {
00035
00036
00037 struct dbch{
00038 typedef std::map<unsigned int, dbch> dictionary;
00039 typedef dictionary::iterator iterator;
00040 int _indent;
00041 unsigned int id;
00042 dbch(unsigned int ch): id(ch), _active(false), _indent(0){}
00043 dbch(): id(-1), _active(false), _indent(0){}
00044 void operator --(){ -- _indent ; }
00045 void operator ++(){ ++ _indent; }
00046 bool _active;
00047
00048 };
00057 class cdebug{
00058
00059 static dbch::dictionary _channels;
00060 static std::ofstream Os;
00061 static bool started;
00062 static std::string _appname;
00063 static int indentation;
00064 static bool __enabled;
00065 static std::string function;
00066 static int line;
00067
00068 public:
00069 cdebug();
00070 cdebug(int ichan, const char* filename, const char* func, int line);
00071 static bool init(const string& app_name="debug");
00072 static const std::string &appname(){
00073 return _appname;
00074 }
00075 template<typename t> std::ofstream& operator << (t& _arg);
00076
00077 void end(){
00078 cdebug::os.flush();
00079 cdebug::os.close();
00080 }
00081 ~cdebug();
00082
00086 static void disable(int c=-1) { cdebug::__enabled = false; }
00087
00091 static void enable() { cdebug::__enabled = true; }
00092
00093 string getfilename();
00094
00095 private:
00096 static string filename;
00097 unsigned int _ch;
00098
00099 };
00100
00101
00102 template<typename T> ofstream& cdebug::operator << (T& _arg){
00103
00104 dbch::iterator it = cdebug::_channels.find(_ch);
00105 if(it == cdebug::_channels.end() ) return cdebug::Os;
00106 if( !(*it)._active || !cdebug::__enabled ) return cdebug::Os;
00107 string f = getFilename() + ':';
00108 string i((*it)._indent*4, ' ');
00109 cdebug::Os << (*it).id <<':' << f << cdebug::function << ':' << cdebug::line << ':' << i << _arg;
00110 return cdebug::Os;
00111 }
00112
00113 #define _HERE_ __PRETTY_FUNCTION__
00114 #define _debug(x) cdebug( (x), __FILE__, __FUNCTION__, __LINE__ )
00115
00116
00117 }
00118
00119 #endif
API Documentation Generated by:
1.4.0
About the author |

Site started with trial version of DreamWeaver MX 2004 |
Finalizing with

|
Contact | ©2005, Serge Lussier ( Bretzel )