]>
Dogcows Code - chaz/yoink/blob - src/stlplus/portability/debug.hpp
3 ////////////////////////////////////////////////////////////////////////////////
5 // Author: Andy Rushton
6 // Copyright: (c) Southampton University 1999-2004
7 // (c) Andy Rushton 2004 onwards
8 // License: BSD License, see ../docs/license.html
10 // Set of simple debug utilities, all of which are switched off by the
11 // NDEBUG compiler directive
13 ////////////////////////////////////////////////////////////////////////////////
15 #include "portability_fixes.hpp"
19 ////////////////////////////////////////////////////////////////////////////////
20 // Problem with missing __FUNCTION__ macro
21 ////////////////////////////////////////////////////////////////////////////////
23 // this macro is used in debugging but was missing in Visual Studio prior to version 7
24 #if defined(_MSC_VER) && (_MSC_VER < 1300)
25 #define __FUNCTION__ 0
28 // old versions of Borland compiler defined a macro __FUNC__ but more recent ones define __FUNCTION__
29 // I'm not sure at what version this change was made - assumed C++ Builder 6.32
30 #if defined(__BORLANDC__) && (__BORLANDC__ < 1585)
31 #define __FUNCTION__ __FUNC__
34 ////////////////////////////////////////////////////////////////////////////////
35 // Exception thrown if an assertion fails
40 class assert_failed
: public std::logic_error
43 assert_failed(const char* file
, int line
, const char* function
, const char* message
) throw();
44 ~assert_failed(void) throw();
47 } // end namespace stlplus
49 ////////////////////////////////////////////////////////////////////////////////
50 // The macros used in debugging
54 #define DEBUG_TRACE stlplus::debug_trace stlplus_debug_trace(__FILE__,__LINE__,__FUNCTION__)
55 #define IF_DEBUG(stmts) {if (stlplus_debug_trace.debug()){stlplus_debug_trace.prefix(__LINE__);stmts;}}
56 #define DEBUG_REPORT(str) IF_DEBUG(stlplus_debug_trace.report(__LINE__,str))
57 #define DEBUG_ERROR(str) stlplus_debug_trace.error(__LINE__,str)
58 #define DEBUG_STACKDUMP(str) stlplus_debug_trace.stackdump(__LINE__,str)
59 #define DEBUG_ON stlplus_debug_trace.debug_on(__LINE__,true)
60 #define DEBUG_ON_LOCAL stlplus_debug_trace.debug_on(__LINE__,false)
61 #define DEBUG_ON_GLOBAL stlplus::debug_global(__FILE__,__LINE__,__FUNCTION__,true)
62 #define DEBUG_OFF_GLOBAL stlplus::debug_global(__FILE__,__LINE__,__FUNCTION__,false)
63 #define DEBUG_OFF stlplus_debug_trace.debug_off(__LINE__)
64 #define DEBUG_ASSERT(test) if (!(test))stlplus::debug_assert_fail(__FILE__,__LINE__,__FUNCTION__,#test)
69 #define IF_DEBUG(stmts)
70 #define DEBUG_REPORT(str)
71 #define DEBUG_ERROR(str)
72 #define DEBUG_STACKDUMP(str)
74 #define DEBUG_ON_LOCAL
75 #define DEBUG_ON_GLOBAL
76 #define DEBUG_OFF_GLOBAL
78 #define DEBUG_ASSERT(test)
82 ////////////////////////////////////////////////////////////////////////////////
83 // infrastructure - don't use directly
88 void debug_global(const char* file
, int line
, const char* function
, bool state
= true);
89 void debug_assert_fail(const char* file
, int line
, const char* function
, const char* test
) throw(assert_failed
);
94 debug_trace(const char* f
, int l
, const char* fn
);
96 const char* file(void) const;
98 bool debug(void) const;
99 void debug_on(int l
, bool recurse
);
100 void debug_off(int l
);
101 void prefix(int l
) const;
102 void report(int l
, const std::string
& message
) const;
103 void report(const std::string
& message
) const;
104 void error(int l
, const std::string
& message
) const;
105 void error(const std::string
& message
) const;
106 void stackdump(int l
, const std::string
& message
) const;
107 void stackdump(const std::string
& message
) const;
108 void stackdump(void) const;
113 const char* m_function
;
115 const debug_trace
* m_last
;
118 void do_report(int l
, const std::string
& message
) const;
119 void do_report(const std::string
& message
) const;
121 // make this class uncopyable
122 debug_trace(const debug_trace
&);
123 debug_trace
& operator = (const debug_trace
&);
126 } // end namespace stlplus
128 ////////////////////////////////////////////////////////////////////////////////
This page took 0.042954 seconds and 4 git commands to generate.