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

Tools/Debugging/DebugDataTable.h

Go to the documentation of this file.
00001 /*
00002 * @file Tools/Debugging/DebugDataTable.h
00003 * Table for generic handling of debug data
00004 *
00005 *
00006 */
00007 
00008 #ifndef __DebugRegistry_h_
00009 #define __DebugRegistry_h_
00010 
00011 
00012 
00013 class DebugDataTable;
00014 DebugDataTable& getDebugDataTable();
00015 
00016 
00017 #include "Tools/Streams/InOut.h"
00018 #include <vector>
00019 #include <typeinfo>
00020 #include <string>
00021 
00022 #ifdef WIN32
00023   #pragma warning(disable:4786) 
00024   #include <typeinfo.h>
00025   #if _MSC_VER > 1200
00026     #include <hash_map>
00027     using stdext::hash_map;
00028   #else
00029     #include <map>
00030     #define hash_map map
00031     using std::map;
00032   #endif
00033 #else
00034   #include <typeinfo>
00035   //#include <ext/hash_map>
00036   //using __gnu_cxx::hash_map;
00037   #include <map>
00038   #define hash_map std::map
00039 #endif
00040 
00041 #ifdef NDEBUG
00042 #define MODIFY( name, object)
00043 // #define MODIFYENUM( name, object, numberOfEnumElements, getNameFunctionPtr)
00044 #else
00045 #define MODIFY( names, object) \
00046   getDebugDataTable().registerObject( names, object); \
00047   getDebugDataTable().f( names, object); \
00048   DEBUG_RESPONSE( "debug data:"names, \
00049   OUTPUT( idDebugDataResponse, bin, names << typeid( object ).name() << object); \
00050   );
00051 /*
00052 #define MODIFYENUM( names, object, numberOfEnumElements, getNameFunctionPtr) \
00053   getStreamHandler().registerEnum( object, numberOfEnumElements, getNameFunctionPtr); \
00054   getDebugDataTable().registerEnum( names, object); \
00055   getDebugDataTable().f( names, object); \
00056   DEBUG_RESPONSE( "debug data:"names, \
00057   OUTPUT( idDebugDataResponse, bin, names << typeid( object ).name() << (int) object); \
00058   );
00059 */
00060 #endif//
00061 
00062 class DebugDataHeader
00063 {
00064   
00065 public:
00066   enum { write, unchanged } request;
00067   virtual void changeData(In&)=0;
00068 };
00069 template< class T>
00070 class DebugData : public DebugDataHeader
00071 {
00072 public:
00073   T data;
00074   virtual void changeData(In& in)
00075   {
00076     in >> data;
00077   }
00078 };
00079 /*
00080 template< class T>
00081 class EnumDebugData : public DebugDataHeader
00082 {
00083 public:
00084   T data;
00085   virtual void changeData(In& in)
00086   {
00087     int i;
00088     in >> i;
00089     data = (T)i;
00090   }
00091 };
00092 */
00093 class DebugDataTable
00094 {
00095   hash_map< std::string, DebugDataHeader*> table;
00096 public:
00097   ~DebugDataTable()
00098   {
00099     for(hash_map< std::string, DebugDataHeader*>::iterator iter = table.begin(); iter != table.end(); ++iter)
00100       delete iter->second;
00101   }
00102 
00103   template< class T>
00104   void f( const char* name, T& t)
00105   {
00106     hash_map< std::string, DebugDataHeader*>::iterator iter = table.find( name);
00107     if( iter != table.end() && iter->second->request == DebugDataHeader::write)
00108     {
00109       DebugData<T>* debugData = dynamic_cast<DebugData<T>*>(iter->second);
00110       if( debugData != NULL)
00111         t = debugData->data;
00112     }
00113   }
00114 
00115   template< class T>
00116   void registerObject( const char* name, T& t)
00117   {
00118     hash_map< std::string, DebugDataHeader*>::iterator iter = table.find( name);
00119     if( iter == table.end())
00120     {
00121       DebugData<T>* data = new DebugData<T>();
00122       data->request = DebugDataHeader::unchanged;
00123       data->data = t;
00124       table[ name] = data;
00125     }
00126   }
00127   /*
00128   template< class T>
00129   void registerEnum( const char* name, T& t)
00130   {
00131     hash_map< std::string, DebugDataHeader*>::iterator iter = table.find( name);
00132     if( iter == table.end())
00133     {
00134       EnumDebugData<T>* data = new EnumDebugData<T>();
00135       data->request = DebugDataHeader::unchanged;
00136       data->data = t;
00137       table[ name] = data;
00138     }
00139   }
00140   */
00141   bool processChangeRequest( In& in)
00142   {
00143     char name[100];
00144     in >> name;
00145     
00146     if( strcmp( name, "disable all") == 0)
00147     {
00148       for( 
00149         hash_map< std::string, DebugDataHeader*>::iterator iter = table.begin();
00150         iter != table.end();
00151         ++iter
00152           )
00153           iter->second->request = DebugDataHeader::unchanged;
00154     }
00155     else
00156     {
00157       char change;
00158       in >> change;
00159       hash_map< std::string, DebugDataHeader*>::iterator iter = table.find( name);
00160       if( iter != table.end())
00161       {
00162         if( change)
00163         {
00164           iter->second->request = DebugDataHeader::write;
00165           iter->second->changeData( in);
00166         }
00167         else
00168           iter->second->request = DebugDataHeader::unchanged;
00169       }
00170     }
00171     return true;
00172 
00173   }
00174  
00175 };
00176 In& operator>>(In& in, DebugDataTable& debugDataTable);
00177 // global StreamHandler stuff
00178 // global StreamHandler Object
00179 void initDebugDataTable(DebugDataTable* debugDataTablePtr);
00180 DebugDataTable& getDebugDataTable();
00181 
00182 #ifndef WIN32
00183 #undef hash_map
00184 #endif
00185 #endif // DebugRegistry

Generated on Mon Mar 20 22:00:04 2006 for GT2005 by doxygen 1.3.6