Debug.h

00001 # ifndef Conjecture_Debug_h
00002 # define Conjecture_Debug_h Conjecture_Debug_h
00003 
00004 #include "Root.h"
00005 #include <iostream>
00006 #include <sstream>
00007 
00008 namespace Conjecture {
00009 
00013     class Debug : public Root {
00014         public:
00015 
00019             typedef enum {
00020                 DEBUG_LEVEL_NONE          = 0x00,   
00021                 DEBUG_LEVEL_ERROR         = 0x01,   
00022                 DEBUG_LEVEL_WARNING       = 0x02,   
00023                 DEBUG_LEVEL_INFO          = 0x04,   
00024                         DEBUG_LEVEL_IMAGES_BASIC  = 0x40,   
00025                 DEBUG_LEVEL_IMAGES_FULL   = 0x80,   
00026                 DEBUG_LEVEL_ALL           = 0xFF    
00027             } verboseLevel;
00028 
00034             static Debug &getHandle(void) {
00035                 static Debug *singleton = new Debug();
00036                 return *singleton;
00037             }
00038 
00044             inline void setLogStream(std::ostream &s) {
00045                 this->_outStream = &s;
00046             }
00047 
00053             inline void toggleLevel(verboseLevel l) {
00054                 this->_level = static_cast<verboseLevel>(l | this->_level);
00055             }
00056 
00062             inline void untoggleLevel(verboseLevel l) {
00063                 this->_level = static_cast<verboseLevel>((~l) & this->_level);
00064             }
00065 
00071             inline void setLevel(verboseLevel l) {
00072                 this->_level = l;
00073             }
00074 
00080             inline bool isInLevel(verboseLevel l) {
00081                 if ((l & this->_level) != 0) {
00082                     return true;
00083                 }
00084                 return false;
00085             }
00086 
00092             virtual void header(verboseLevel l);
00093 
00100                     virtual Debug & operator<< (const std::string &str);
00101 
00108                     virtual Debug & operator<< (const char *str);
00109 
00110         protected:
00111             verboseLevel            _level;           
00117             inline std::ostream* outStream() { return this->_outStream; }
00118 
00124             inline const char *levelToString(verboseLevel l) const {
00125                 switch (l) {
00126                   case DEBUG_LEVEL_ERROR:
00127                     return (const char *)"ERROR:: ";
00128                   case DEBUG_LEVEL_WARNING:
00129                     return (const char *)"WARNING: ";
00130                   case DEBUG_LEVEL_INFO:
00131                     return (const char *)"Info: ";
00132                   case DEBUG_LEVEL_IMAGES_BASIC:
00133                     return (const char *)"Image (basic): ";
00134                   case DEBUG_LEVEL_IMAGES_FULL:
00135                     return (const char *)"Image (full): ";
00136                   default:
00137                     return (const char *)"Unknown: ";
00138                 }
00139                 // should never happen
00140                 return NULL;
00141             }
00142 
00143             virtual ~Debug();
00144 
00145       private:
00146             std::ostream            *_outStream;      
00151             Debug();
00152 
00156             void operator=(Debug &);
00157 
00161             Debug(const Debug &);
00162     };
00163 
00164 #ifdef ENABLE_LOG
00165  #define LOG(level, message) \
00166     if (Debug::getHandle().isInLevel(Conjecture::Debug::level)) { \
00167             Debug::getHandle().header(libglass::Log::level); \
00168             std::stringstream ___s; \
00169             ___s << message; \
00170             l << ___s.str(); \
00171         } \
00172     }
00173 #else
00174  #define LOG(l, level, message)
00175 #endif
00176 
00177 
00178 } // namespace
00179 
00180 #endif

Generated on Wed Jun 14 15:08:02 2006 for Conjecture by  doxygen 1.4.6