]>
Dogcows Code - chaz/yoink/blob - src/stlplus/portability/debug.hpp
a7aafd646ca9c7ae3453c07f5bdbdc7c62b555f8
3 ////////////////////////////////////////////////////////////////////////////////
5 // Author: Andy Rushton
6 // Copyright: (c) Southampton University 1999-2004
7 // (c) Andy Rushton 2004-2009
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 ////////////////////////////////////////////////////////////////////////////////
22 // this macro is used in debugging but was missing in Visual Studio prior to version 7
23 // it also has a different name in Borland
25 #if defined(_MSC_VER) && (_MSC_VER < 1300)
26 #define __FUNCTION__ 0
30 #define __FUNCTION__ __FUNC__
33 ////////////////////////////////////////////////////////////////////////////////
34 // Exception thrown if an assertion fails
39 class assert_failed
: public std::logic_error
42 assert_failed(const char* file
, int line
, const char* function
, const char* message
) throw();
43 ~assert_failed(void) throw();
46 } // end namespace stlplus
48 ////////////////////////////////////////////////////////////////////////////////
49 // The macros used in debugging
53 #define DEBUG_TRACE stlplus::debug_trace stlplus_debug_trace(__FILE__,__LINE__,__FUNCTION__)
54 #define IF_DEBUG(stmts) {if (stlplus_debug_trace.debug()){stlplus_debug_trace.prefix(__LINE__);stmts;}}
55 #define DEBUG_REPORT(str) IF_DEBUG(stlplus_debug_trace.report(__LINE__,str))
56 #define DEBUG_ERROR(str) stlplus_debug_trace.error(__LINE__,str)
57 #define DEBUG_STACKDUMP(str) stlplus_debug_trace.stackdump(__LINE__,str)
58 #define DEBUG_ON stlplus_debug_trace.debug_on(__LINE__,true)
59 #define DEBUG_ON_LOCAL stlplus_debug_trace.debug_on(__LINE__,false)
60 #define DEBUG_ON_GLOBAL stlplus::debug_global(__FILE__,__LINE__,__FUNCTION__,true)
61 #define DEBUG_OFF_GLOBAL stlplus::debug_global(__FILE__,__LINE__,__FUNCTION__,false)
62 #define DEBUG_OFF stlplus_debug_trace.debug_off(__LINE__)
63 #define DEBUG_ASSERT(test) if (!(test))stlplus::debug_assert_fail(__FILE__,__LINE__,__FUNCTION__,#test)
68 #define IF_DEBUG(stmts)
69 #define DEBUG_REPORT(str)
70 #define DEBUG_ERROR(str)
71 #define DEBUG_STACKDUMP(str)
73 #define DEBUG_ON_LOCAL
74 #define DEBUG_ON_GLOBAL
75 #define DEBUG_OFF_GLOBAL
77 #define DEBUG_ASSERT(test)
81 ////////////////////////////////////////////////////////////////////////////////
82 // infrastructure - don't use directly
87 void debug_global(const char* file
, int line
, const char* function
, bool state
= true);
88 void debug_assert_fail(const char* file
, int line
, const char* function
, const char* test
) throw(assert_failed
);
93 debug_trace(const char* f
, int l
, const char* fn
);
95 const char* file(void) const;
97 bool debug(void) const;
98 void debug_on(int l
, bool recurse
);
99 void debug_off(int l
);
100 void prefix(int l
) const;
101 void report(int l
, const std::string
& message
) const;
102 void report(const std::string
& message
) const;
103 void error(int l
, const std::string
& message
) const;
104 void error(const std::string
& message
) const;
105 void stackdump(int l
, const std::string
& message
) const;
106 void stackdump(const std::string
& message
) const;
107 void stackdump(void) const;
112 const char* m_function
;
114 const debug_trace
* m_last
;
117 void do_report(int l
, const std::string
& message
) const;
118 void do_report(const std::string
& message
) const;
120 // make this class uncopyable
121 debug_trace(const debug_trace
&);
122 debug_trace
& operator = (const debug_trace
&);
125 } // end namespace stlplus
127 ////////////////////////////////////////////////////////////////////////////////
This page took 0.037328 seconds and 4 git commands to generate.