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

base/debugtools

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2002 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: debugtools 1029 2004-02-11 20:45:54Z jungd $
00019   $Revision: 1.8 $
00020   $Date: 2004-02-11 15:45:54 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _BASE_DEBUGTOOLS_
00026 #define _BASE_DEBUGTOOLS_
00027 
00028 // Debug macros
00029 //  Use these to output debugging information
00030 
00031 // Example uses:
00032 //
00033 //  setDebugOutputID(JFKE); // typically in main()
00034 //  Debugln(JFKE,"This is " << getName()); // will output  
00035 //  Debugln(Tmp, "this is unimportant");   // will not output
00036 //  UDebug("this text will always appear -");   // will Unconditionally output regardless of current debug output ID
00037 //  Debugcln(DebugIKOR,"a continuation.");      // will continue the prev line (will not output method names etc. regardless of the value of DEBUG_INCLUDE_CALLER_NAME)
00038 //
00039 // It is also possible to add more valid output id's. e.g.:
00040 //
00041 //  setDebugOutputID(JFKE);
00042 //  addDebugOutputID(IKOR);
00043 //  Debugln(IKOR, Matrix() << " is zero"); // will output
00044 //
00045 // NB: None of these will output anything (or even evaluate the output) if DEBUG is undefined.
00046 
00047 
00048 
00049 
00050 // Only use All & None in setDebugOutputID(), all others in Debug()
00051 //  In the calls the _Debug_ prefix is dropped.
00052 enum DebugID { 
00053   _Debug_All             = 0xffffffff,
00054   _Debug_None            = 0,
00055   _Debug_Tmp             = 1,
00056   _Debug_DJ              = 1 << 1,
00057   _Debug_KF              = 1 << 2,
00058   _Debug_LL              = 1 << 3,
00059   _Debug_Ser             = 1 << 4,
00060   _Debug_Base            = 1 << 5,
00061   _Debug_Gfx             = 1 << 6,
00062   _Debug_Physics         = 1 << 7,
00063   _Debug_Robot           = 1 << 8,
00064   _Debug_RobotSim        = 1 << 9,
00065   _Debug_RobotControl    = 1 << 10,
00066   _Debug_FSP             = 1 << 11,
00067   _Debug_IKOR            = 1 << 12,
00068   _Debug_JFKE            = 1 << 13
00069 };
00070 
00071 
00072 #ifdef DEBUG
00073 extern base::Int _debugID;
00074 #define setDebugOutputID(id) { _debugID = _Debug_##id; }
00075 #define addDebugOutputID(id) { _debugID |= _Debug_##id; }
00076 #else
00077 #define setDebugOutputID(id) {}
00078 #define addDebugOutputID(id) {}
00079 #endif
00080 
00081 
00082 #ifdef DEBUG
00083 #undef Debug
00084 
00085 #ifdef DEBUG_INCLUDE_CALLER_NAME
00086 // include the method or function that invoked Debug() in the message string
00087 #ifndef __GNUC__
00088 #define _DEBUG_CALLER_NAME base::className(typeid(*this)) << "::" << std::string(__func__)+" -- " 
00089 #else
00090 // gcc has a nicer __PRETTY_FUNCTION__ builtin
00091 #define _DEBUG_CALLER_NAME std::string(__PRETTY_FUNCTION__)+" -- "
00092 #endif
00093 #else
00094 #define _DEBUG_CALLER_NAME ""
00095 #endif
00096 
00097 // for use inside methods
00098 #define UDebug(o) { base::_Debug << _DEBUG_CALLER_NAME << o; }
00099 #define UDebugln(o) { base::_Debug << _DEBUG_CALLER_NAME << o << std::endl; }
00100 #define Debug(id,o) { if (_Debug_##id & _debugID) UDebug(o); }
00101 #define Debugln(id,o) { if (_Debug_##id & _debugID) UDebugln(o); }
00102 
00103 // for use inside functions
00104 #define UDebugf(o) { base::_Debug << std::string(__func__)+" -- " << o; }
00105 #define UDebugfln(o) { base::_Debug << std::string(__func__)+" -- " << o << std::endl; }
00106 #define Debugf(id,o) { if (_Debug_##id & _debugID) UDebugf(o); }
00107 #define Debugfln(id,o) { if (_Debug_##id & _debugID) UDebugfln(o); }
00108 // a continuation of the previous output line - doesn't output any prefix (name etc. regardless of DEBUG_INCLUDE_CALLER_NAME)
00109 #define Debugc(id,o) { if (_Debug_##id & _debugID) { base::_Debug << o; } }
00110 #define Debugcln(id,o) { if (_Debug_##id & _debugID) { base::_Debug << o << std::endl; } }
00111 
00112 #define Unimplemented { Logln("unimplemented"); throw std::runtime_error(Exception("unimplemented")); }
00113 
00114 #else
00115 // DEBUG not defined
00116 #define UDebug(o) {}
00117 #define UDebugln(o) {}
00118 #define UDebugf(o) {}
00119 #define UDebugfln(o) {}
00120 #define Debug(id,o) {}
00121 #define Debugln(id,o) {}
00122 #define Debugf(id,o) {}
00123 #define Debugfln(id,o) {}
00124 #define Debugc(id,o) {}
00125 #define Debugcln(id,o) {}
00126 
00127 #define Unimplemented { throw std::runtime_error(Exception("The program attempted to perform a function that has not yet been implemented by the developers.  Please file a bug report. Sorry for the inconvenience.")); }
00128 
00129 #endif
00130 
00131 
00132 #endif

Generated on Thu Jul 29 15:56:04 2004 for OpenSim by doxygen 1.3.6