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

Tools/Debugging/Debugging.h

Go to the documentation of this file.
00001 /**
00002 * @file Tools/Debugging/Debugging.h
00003 *
00004 * Macros and functions for debugging
00005 * 
00006 * @author Martin Lötzsch
00007 */ 
00008 #ifndef __Debugging_h_
00009 #define __Debugging_h_
00010 
00011 // Please don't include GTAssert.h here. GTAssert.h includes afx.h in the Win32 version,
00012 // which makes it a bit slow and is not needed in the most files where Debugging.h is used.
00013 // M.L.
00014 //#include "Platform/GTAssert.h"
00015 
00016 #include "Tools/Debugging/DebugKeyTable.h"
00017 #include "Tools/MessageQueue/OutMessage.h"
00018 #include "Tools/Debugging/DebugRequest.h"
00019 #include "Tools/Debugging/DebugDataTable.h"
00020 
00021 /**
00022 * Sets a pointer to an OutMessage and to a DebugKeyTable to be used by the macros.
00023 *
00024 * @param queue A pointer to an OutMessage.
00025 * @param table A pointer to a DebugKeyTable.
00026 */
00027 void initDebugging(OutMessage* queue, DebugKeyTable* table, DebugRequestTable* debugRequestTable);
00028 
00029 /**
00030 * Returns a reference to a process wide OutMessage.
00031 */
00032 OutMessage& getDebugOut();
00033 
00034 /**
00035 * Returns a reference to a process wide debug key table
00036 */
00037 DebugKeyTable& getDebugKeyTable();
00038 
00039 /**
00040 * Returns a reference to a process wide debug request table
00041 */
00042 DebugRequestTable& getDebugRequestTable();
00043 
00044 
00045 #ifdef NDEBUG
00046 
00047 #define INFO(key,type,format,expression) /**/
00048 #define OUTPUT(type,format,expression) /**/
00049 #define WATCH(key,type,format,expression) /**/
00050 #define DEBUG_RESPONSE(description, expression) /**/
00051 #define DEBUG_RESPONSE_NOT(description, expression) { expression }
00052 #define NOT_POLLABLE_DEBUG_RESPONSE(description, expression) /**/
00053 #define DEBUG_CHECK_CRASH /**/
00054 
00055 #else //NDEBUG
00056 
00057 /**
00058 * A macro for sending debug messages depending on a debug key.
00059 *
00060 * @param key A key from the DebugKeyTable::debugKeyID enum.
00061 * @param type The type of the message from the MessageID enum in MessageIDs.h
00062 * @param format The message format of the message (bin or text)
00063 * @param expression A streamable expression
00064 *
00065 * Examples:
00066 * <pre>
00067 * INFO(sendImages,idImage,bin,myImage);
00068 * INFO(sendInterestingValue,idInterestingValue,text,"value: " << value);
00069 * INFO(sendWorldState,idWorldState,bin,worldState);
00070 * </pre>
00071 */
00072 #define INFO(key,type,format,expression) \
00073   if (getDebugKeyTable().isActive(DebugKeyTable::key)) {\
00074     getDebugOut().format << expression;\
00075     getDebugOut().finishMessage(type);\
00076   }\
00077 
00078 /**
00079 * A macro for sending debug messages.
00080 *
00081 * @param type The type of the message from the MessageID enum in MessageIDs.h
00082 * @param format The message format of the message (bin or text)
00083 * @param expression A streamable expression
00084 *
00085 * Examples:
00086 * <pre>
00087 * OUTPUT(idImage, bin, *pMyImage);
00088 * OUTPUT(idText, text, "MyObject::myFunction() invoked");
00089 * OUTPUT(idText, text, "i: " << i << ", j:" << j);
00090 * </pre>
00091 */
00092 #define OUTPUT(type,format,expression) \
00093   { getDebugOut().format << expression;\
00094   getDebugOut().finishMessage(type); }
00095 
00096 #define DEBUG_RESPONSE(description, expression) \
00097 {\
00098   if(getDebugRequestTable().poll && getDebugRequestTable().notYetPolled(description)) \
00099   { \
00100     OUTPUT(idDebugResponse, text, description << \
00101            int(getDebugRequestTable().isActive(description) && !getDebugRequestTable().once(description))); \
00102   } \
00103   if(getDebugRequestTable().isActive(description)) \
00104   { \
00105     if(getDebugRequestTable().once(description)) \
00106       getDebugRequestTable().disable(description); \
00107     expression \
00108   } \
00109 }
00110 
00111 #define NOT_POLLABLE_DEBUG_RESPONSE(description, expression) \
00112 {\
00113   if(getDebugRequestTable().isActive(description)) \
00114   { \
00115     if(getDebugRequestTable().once(description)) \
00116       getDebugRequestTable().disable(description); \
00117     expression \
00118   } \
00119 }
00120 
00121 #define DEBUG_RESPONSE_NOT(description, expression) \
00122 {\
00123   if(getDebugRequestTable().poll && getDebugRequestTable().notYetPolled(description)) \
00124   { \
00125     OUTPUT(idDebugResponse, text, description << \
00126            int(getDebugRequestTable().isActive(description) && !getDebugRequestTable().once(description))); \
00127   } \
00128   if(! (getDebugRequestTable().isActive(description))) \
00129   { \
00130     if(getDebugRequestTable().once(description)) \
00131       getDebugRequestTable().disable(description); \
00132     expression \
00133   } \
00134 }
00135 
00136 #if defined(_WIN32) && !defined(SIMROBOT)
00137 
00138 /**
00139 * A macro for sending debug messages that differs between Windows and Aperios.
00140 * The parameters equal to the parameters if the INFO macro.
00141 * Different from INFO, the output is sent automatically on the WIN32 platform
00142 */
00143 #define WATCH(key,type,format,expression) \
00144   OUTPUT(type,format,expression);
00145 
00146 
00147 #else
00148 
00149 /**
00150 * A macro for sending debug messages that differs between Windows and Aperios.
00151 * The parameters equal to the parameters if the INFO macro.
00152 * Different from INFO, the output is sent automatically on the WIN32 platform
00153 */
00154 #define WATCH(key,type,format,expression) \
00155   INFO(key,type,format,expression);
00156 
00157 #endif
00158 
00159 #include <iostream>
00160 
00161 #define DEBUG_CHECK_CRASH { if (SystemCall::getCurrentSystemTime () - entryTime > 2000) {std::cout << "breakpoint in " << __FILE__ << ":" << __LINE__ << "; \n  was executed more than 2 seconds\n"; while (true); };  };
00162 
00163 #endif //NDEBUG
00164 
00165 #endif //__Debugging_h_

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