Debug.h

00001 # ifndef Conjecture_Debug_h
00002 # define Conjecture_Debug_h Conjecture_Debug_h
00003 
00004 // Insert SVN header substitution variable here
00005 // Class Champion: Unassigned
00006 
00007 #include "Root.h"
00008 #include <iostream>
00009 #include <sstream>
00010 
00011 namespace Conjecture {
00012 
00016     class Debug : public Root {
00017         public:
00018 
00022             typedef enum {
00023                 DEBUG_LEVEL_NONE          = 0x00,   
00024                 DEBUG_LEVEL_ERROR         = 0x01,   
00025                 DEBUG_LEVEL_WARNING       = 0x02,   
00026                 DEBUG_LEVEL_INFO          = 0x04,   
00027                 DEBUG_LEVEL_IMAGES_BASIC  = 0x40,   
00028                 DEBUG_LEVEL_IMAGES_FULL   = 0x80,   
00029                 DEBUG_LEVEL_ALL           = 0xFF    
00030             } verboseLevel;
00031 
00037             static Debug &getHandle(void) {
00038                 static Debug *singleton = new Debug();
00039                 return *singleton;
00040             }
00041 
00047             inline void setLogStream(std::ostream &s) {
00048                 this->_outStream = &s;
00049             }
00050 
00056             inline void toggleLevel(verboseLevel l) {
00057                 this->_level = static_cast<verboseLevel>(l | this->_level);
00058             }
00059 
00065             inline void untoggleLevel(verboseLevel l) {
00066                 this->_level = static_cast<verboseLevel>((~l) & this->_level);
00067             }
00068 
00074             inline void setLevel(verboseLevel l) {
00075                 this->_level = l;
00076             }
00077 
00083             inline bool isInLevel(verboseLevel l) {
00084                 if ((l & this->_level) != 0) {
00085                     return true;
00086                 }
00087                 return false;
00088             }
00089 
00095             virtual void header(verboseLevel l);
00096 
00103             virtual Debug & operator<< (const std::string &str);
00104             
00111             virtual Debug & operator<< (const char *str);
00112 
00113         protected:
00114             verboseLevel            _level;           
00120             inline std::ostream* outStream() { return this->_outStream; }
00121 
00127             inline const char *levelToString(verboseLevel l) const {
00128                 switch (l) {
00129                   case DEBUG_LEVEL_ERROR:
00130                     return (const char *)"ERROR:: ";
00131                   case DEBUG_LEVEL_WARNING:
00132                     return (const char *)"WARNING: ";
00133                   case DEBUG_LEVEL_INFO:
00134                     return (const char *)"Info: ";
00135                   case DEBUG_LEVEL_IMAGES_BASIC:
00136                     return (const char *)"Image (basic): ";
00137                   case DEBUG_LEVEL_IMAGES_FULL:
00138                     return (const char *)"Image (full): ";
00139                   default:
00140                     return (const char *)"Unknown: ";
00141                 }
00142                 // should never happen
00143                 return NULL;
00144             }
00145 
00146             virtual ~Debug();
00147 
00148       private:
00149             std::ostream            *_outStream;      
00154             Debug();
00155 
00159             void operator=(Debug &);
00160 
00164             Debug(const Debug &);
00165     };
00166 
00167 #ifdef ENABLE_LOG
00168  #define LOG(level, message) \
00169     if (Debug::getHandle().isInLevel(Conjecture::Debug::level)) { \
00170             Debug::getHandle().header(libglass::Log::level); \
00171             std::stringstream ___s; \
00172             ___s << message; \
00173             l << ___s.str(); \
00174         } \
00175     }
00176 #else
00177  #define LOG(l, level, message)
00178 #endif
00179 
00180 
00181 } // namespace
00182 
00183 #endif

Generated on Thu Jun 15 19:56:09 2006 for Conjecture by  doxygen 1.4.6