jigdo API
Last update by Admin on 2010-05-23
util/debug.hh
Go to the documentation of this file.00001 /* $Id: debug.hh,v 1.5 2003/08/15 11:38:30 atterer Exp $ -*- C++ -*- 00002 __ _ 00003 |_) /| Copyright (C) 1999-2003 | richard@ 00004 | \/¯| Richard Atterer | atterer.net 00005 ¯ '` ¯ 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License, version 2. See 00008 the file COPYING for details. 00009 00010 */ 00029 #ifndef DEBUG_HH 00030 #define DEBUG_HH 00031 00032 #include <config.h> 00033 00034 #include <algorithm> 00035 #include <string> 00036 //______________________________________________________________________ 00037 00038 // class OptDebug { 00039 // public: 00040 // static bool optDebug() { return d; } 00041 // static void setOptDebug(bool dd) { d = dd; } 00042 // private: 00043 // OptDebug(); // Do not instantiate 00044 // static bool d; 00045 // }; 00046 00047 // inline bool optDebug() { return OptDebug::optDebug(); } 00048 //______________________________________________________________________ 00049 00050 /* For C (not C++), GCC 2.95 gives an error if a function param name is not 00051 given. GCC 3.4 gives a warning if it is given, but unused. Define param 00052 name to nothing for 3.4 */ 00053 #if defined __GNUC__ && __GNUC__ < 3 00054 # define UNUSED_PARAM(_p) _p 00055 #else 00056 # define UNUSED_PARAM(_p) 00057 #endif 00058 00059 00062 #if DEBUG 00063 # define DEBUG_ONLY_PARAM(_p) _p 00064 #else 00065 # define DEBUG_ONLY_PARAM(_p) 00066 #endif 00067 //______________________________________________________________________ 00068 00069 namespace Debug { 00070 00072 extern bool abortAfterFailedAssertion; 00073 00075 extern int assertFail(const char* assertion, const char* file, 00076 unsigned int line); 00077 00078 // extern int assertMessage(const char* assertion, const char* file, 00079 // unsigned int line); 00080 00081 } 00082 #if DEBUG 00083 # define Paranoid(_expr) \ 00084 ((void) ((_expr) ? 0 : \ 00085 Debug::assertFail(#_expr, __FILE__, __LINE__))) 00086 #else 00087 # define Paranoid(expr) 00088 #endif 00089 00090 #define Assert(_expr) \ 00091 ((void) ((_expr) ? 0 : \ 00092 Debug::assertFail(#_expr, __FILE__, __LINE__))) 00093 #define Message(_str) Debug::assertFail((_str), __FILE__, __LINE__) 00094 //______________________________________________________________________ 00095 00097 struct Error { 00098 explicit Error(const string& m) : message(m) { } 00099 explicit Error(const char* m) : message(m) { } 00100 # if DEBUG 00101 explicit Error(string& m, bool flag) { 00102 Assert(flag == true); swap(message, m); } 00103 # else 00104 explicit Error(string& m, bool) { swap(message, m); } 00105 # endif 00106 string message; 00107 }; 00108 00111 struct Cleanup { 00112 explicit Cleanup(int r) : returnValue(r) { } 00113 int returnValue; 00114 }; 00115 //______________________________________________________________________ 00116 00117 #endif
Generated on Tue Sep 23 14:27:41 2008 for jigdo by
