Project stdui: "Simple Type Dialog User-Interface"

|
Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cdebug.hxx

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Serge Lussier                                   *
00003  *   serge.lussier@videotron.ca                                            *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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 //#include <pthread.h>
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 }// namespace debug
00118 
00119 #endif

API Documentation Generated by:  doxygen 1.4.0
About the author | Site started with trial version of DreamWeaver MX 2004 | Finalizing with  | Contact | ©2005, Serge Lussier ( Bretzel )