mutDebug.h
gehe zur Dokumentation dieser Datei
00001 
00023 /*
00024  *  mutDebug.h
00025  *  Mutabor
00026  *
00027  *  Created by Tobias Schlemmer on 25.03.10.
00028  *  Copyright 2010 TU Dresden. All rights reserved.
00029  *
00030  */
00031 
00032 #ifndef __MUTDEBUGFLAGS__
00033 #define __MUTDEBUGFLAGS__
00034 
00035 #ifdef DEBUG
00036 
00037 
00038 #include <bitset>
00039 #include "wx/cmdline.h"
00040 
00041 #define DEBUGFLAG(flag,description) flag,
00042 
00043 struct debugFlags {
00044         enum {
00045 #include "mutDebugFlags.h"
00046                 debugFlagCount
00047         };
00048         typedef std::bitset<debugFlagCount> debugFlagSet;
00049         static debugFlagSet flags;
00050         static void InitCommandLine(wxCmdLineParser&  parser);
00051         static void ProcessCommandLine(wxCmdLineParser&  parser);
00052 };
00053 #undef DEBUGFLAG
00054 
00055 #define isDebugFlag(level) (debugFlags::flags[debugFlags::level])
00056 # define DEBUGLOGBASEINT(level,type, ...) \
00057         if (debugFlags::flags[level]) { \
00058                  std::cerr << __FILE__ << ":" << __LINE__ << ": " \
00059                            << ((const char *) type) << "::" << __WXFUNCTION__ << ": "   \
00060                            << (const char *)((wxString::Format(__VA_ARGS__)).ToUTF8()) << std::endl; \
00061         }
00062 #define DEBUGLOGBASE(level,...) DEBUGLOGBASEINT(debugFlags::level,__VA_ARGS__)
00063 #define mutRefCast(type,value) dynamic_cast<type &>(value)
00064 #define mutPtrCast(type,value) (wxASSERT(dynamic_cast<type *>(value)), dynamic_cast<type *>(value))
00065 #define mutPtrDynCast mutPtrCast
00066 #define WATCHEDPTR(T,f,P) watchedPtr<T,debugFlags::f,P>
00067 #define DEFWATCHEDPTR \
00068         template <class T,int flag, class P> \
00069         const int watchedPtr<T,flag,P>::myflag = flag;
00070 #else
00071 
00072 #define isDebugFlag(level) false
00073 # define DEBUGLOGBASEINT(...) do {} while (0)
00074 # define DEBUGLOGBASE(...) do {} while (0)
00075 # define PRINTSIZER(X) do {} while (0)
00076 
00077 #define mutRefCast(type,value) static_cast<type &>(value)
00078 #define mutPtrCast(type,value) static_cast<type *>(value)
00079 #define mutPtrDynCast(type,value) dynamic_cast<type *>(value)
00080 
00081 #define WATCHEDPTR(T,f,P) watchedPtr<T,-1,P>
00082 #define DEFWATCHEDPTR
00083 #endif
00084 
00085 #define DEBUGLOG(level, ...) DEBUGLOGBASE(level, typeid(*this).name(),__VA_ARGS__)
00086 #define DEBUGLOG2(level, ...) DEBUGLOGBASE(level, _T(""),__VA_ARGS__)
00087 #define DEBUGLOGTYPE(level, type, ...) DEBUGLOGBASE(level, typeid(type).name(), __VA_ARGS__)
00088 #define DEBUGLOGTYPEINT(level, type, ...) DEBUGLOGBASEINT(level, typeid(type).name(), __VA_ARGS__)
00089 
00090 template <class T,int flag, class P>
00091 class watchedPtr {
00092 private:
00093         typedef T datatype;
00094         typedef T* dataptr;
00095         typedef P parenttype;
00096         datatype * data;
00097 #ifdef DEBUG
00098         static const int myflag;
00099         parenttype * parent;
00100         wxString name;
00101 #endif
00102 public:
00103         watchedPtr(parenttype * p, const wxString & varname = _T("watchedPtr"), datatype * d = NULL)
00104         {
00105 #ifdef DEBUG
00106                 parent = p;
00107                 name = varname;
00108 #endif
00109                 (*this) = d;
00110         }
00111         
00112         watchedPtr<T,flag,P> &operator= (datatype * d)
00113         {
00114                 DEBUGLOGTYPEINT(myflag,parenttype,_T("Setting %s in %p from %p to %p"),name.c_str(),parent,data,d);
00115                 data = d;
00116                 return *this;
00117         }
00118         
00119         
00120         operator dataptr () const
00121         {
00122                 return data;
00123         }
00124         
00125 #if 0
00126         datatype & operator -> ()
00127         {
00128                 return *data;
00129         }
00130         
00131         const datatype & operator -> () const
00132         {
00133                 return *data;
00134         }
00135 #endif
00136 };
00137 
00138 DEFWATCHEDPTR
00139 
00140 
00141 
00142 #endif
00143 

Erzeugt am Sun Aug 21 2011 10:51:56 für Mutabor von doxygen 1.7.4