]> Dogcows Code - chaz/yoink/blobdiff - src/stlplus/portability/debug.hpp
import stlplus 3.7
[chaz/yoink] / src / stlplus / portability / debug.hpp
index 981490b0acbc214549c3cc1c5152350c922f213a..5b82538352b4fa04d7cb81a761834333fa63f4c7 100644 (file)
-#ifndef STLPLUS_DEBUG
-#define STLPLUS_DEBUG
-////////////////////////////////////////////////////////////////////////////////
-
-//   Author:    Andy Rushton
-//   Copyright: (c) Southampton University 1999-2004
-//              (c) Andy Rushton           2004-2009
-//   License:   BSD License, see ../docs/license.html
-
-//   Set of simple debug utilities, all of which are switched off by the
-//   NDEBUG compiler directive
-
-////////////////////////////////////////////////////////////////////////////////
-
-#include "portability_fixes.hpp"
-#include <stdexcept>
-#include <string>
-
-////////////////////////////////////////////////////////////////////////////////
-// Problem with missing __FUNCTION__ macro
-////////////////////////////////////////////////////////////////////////////////
-// this macro is used in debugging but was missing in Visual Studio prior to version 7
-// it also has a different name in Borland
-
-#if defined(_MSC_VER) && (_MSC_VER < 1300)
-#define __FUNCTION__ 0
-#endif
-
-#ifdef __BORLANDC__
-#define __FUNCTION__ __FUNC__
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// Exception thrown if an assertion fails
-
-namespace stlplus
-{
-
-  class assert_failed : public std::logic_error
-  {
-  public:
-    assert_failed(const char* file, int line, const char* function, const char* message) throw();
-    ~assert_failed(void) throw();
-  };
-
-} // end namespace stlplus
-
-  ////////////////////////////////////////////////////////////////////////////////
-  // The macros used in debugging
-
-#ifndef NDEBUG
-
-#define DEBUG_TRACE stlplus::debug_trace stlplus_debug_trace(__FILE__,__LINE__,__FUNCTION__)
-#define IF_DEBUG(stmts) {if (stlplus_debug_trace.debug()){stlplus_debug_trace.prefix(__LINE__);stmts;}}
-#define DEBUG_REPORT(str) IF_DEBUG(stlplus_debug_trace.report(__LINE__,str))
-#define DEBUG_ERROR(str) stlplus_debug_trace.error(__LINE__,str)
-#define DEBUG_STACKDUMP(str) stlplus_debug_trace.stackdump(__LINE__,str)
-#define DEBUG_ON stlplus_debug_trace.debug_on(__LINE__,true)
-#define DEBUG_ON_LOCAL stlplus_debug_trace.debug_on(__LINE__,false)
-#define DEBUG_ON_GLOBAL stlplus::debug_global(__FILE__,__LINE__,__FUNCTION__,true)
-#define DEBUG_OFF_GLOBAL stlplus::debug_global(__FILE__,__LINE__,__FUNCTION__,false)
-#define DEBUG_OFF stlplus_debug_trace.debug_off(__LINE__)
-#define DEBUG_ASSERT(test) if (!(test))stlplus::debug_assert_fail(__FILE__,__LINE__,__FUNCTION__,#test)
-
-#else
-
-#define DEBUG_TRACE
-#define IF_DEBUG(stmts)
-#define DEBUG_REPORT(str)
-#define DEBUG_ERROR(str)
-#define DEBUG_STACKDUMP(str)
-#define DEBUG_ON
-#define DEBUG_ON_LOCAL
-#define DEBUG_ON_GLOBAL
-#define DEBUG_OFF_GLOBAL
-#define DEBUG_OFF
-#define DEBUG_ASSERT(test)
-
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// infrastructure - don't use directly
-
-namespace stlplus
-{
-
-  void debug_global(const char* file, int line, const char* function, bool state = true);
-  void debug_assert_fail(const char* file, int line, const char* function, const char* test) throw(assert_failed);
-
-  class debug_trace
-  {
-  public:
-    debug_trace(const char* f, int l, const char* fn);
-    ~debug_trace(void);
-    const char* file(void) const;
-    int line(void) const;
-    bool debug(void) const;
-    void debug_on(int l, bool recurse);
-    void debug_off(int l);
-    void prefix(int l) const;
-    void report(int l, const std::string& message) const;
-    void report(const std::string& message) const;
-    void error(int l, const std::string& message) const;
-    void error(const std::string& message) const;
-    void stackdump(int l, const std::string& message) const;
-    void stackdump(const std::string& message) const;
-    void stackdump(void) const;
-
-  private:
-    const char* m_file;
-    int m_line;
-    const char* m_function;
-    unsigned m_depth;
-    const debug_trace* m_last;
-    bool m_dbg;
-    bool m_old;
-    void do_report(int l, const std::string& message) const;
-    void do_report(const std::string& message) const;
-
-    // make this class uncopyable
-    debug_trace(const debug_trace&);
-    debug_trace& operator = (const debug_trace&);
-  };
-
-} // end namespace stlplus
-
-  ////////////////////////////////////////////////////////////////////////////////
-#endif
+#ifndef STLPLUS_DEBUG\r
+#define STLPLUS_DEBUG\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+//   Author:    Andy Rushton\r
+//   Copyright: (c) Southampton University 1999-2004\r
+//              (c) Andy Rushton           2004 onwards\r
+//   License:   BSD License, see ../docs/license.html\r
+\r
+//   Set of simple debug utilities, all of which are switched off by the\r
+//   NDEBUG compiler directive\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+#include "portability_fixes.hpp"\r
+#include <stdexcept>\r
+#include <string>\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+// Problem with missing __FUNCTION__ macro\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+// this macro is used in debugging but was missing in Visual Studio prior to version 7\r
+#if defined(_MSC_VER) && (_MSC_VER < 1300)\r
+#define __FUNCTION__ 0\r
+#endif\r
+\r
+// old versions of Borland compiler defined a macro __FUNC__ but more recent ones define __FUNCTION__\r
+// I'm not sure at what version this change was made - assumed C++ Builder 6.32\r
+#if defined(__BORLANDC__) && (__BORLANDC__ < 1585)\r
+#define __FUNCTION__ __FUNC__\r
+#endif\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+// Exception thrown if an assertion fails\r
+\r
+namespace stlplus\r
+{\r
+\r
+  class assert_failed : public std::logic_error\r
+  {\r
+  public:\r
+    assert_failed(const char* file, int line, const char* function, const char* message) throw();\r
+    ~assert_failed(void) throw();\r
+  };\r
+\r
+} // end namespace stlplus\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+  // The macros used in debugging\r
+\r
+#ifndef NDEBUG\r
+\r
+#define DEBUG_TRACE stlplus::debug_trace stlplus_debug_trace(__FILE__,__LINE__,__FUNCTION__)\r
+#define IF_DEBUG(stmts) {if (stlplus_debug_trace.debug()){stlplus_debug_trace.prefix(__LINE__);stmts;}}\r
+#define DEBUG_REPORT(str) IF_DEBUG(stlplus_debug_trace.report(__LINE__,str))\r
+#define DEBUG_ERROR(str) stlplus_debug_trace.error(__LINE__,str)\r
+#define DEBUG_STACKDUMP(str) stlplus_debug_trace.stackdump(__LINE__,str)\r
+#define DEBUG_ON stlplus_debug_trace.debug_on(__LINE__,true)\r
+#define DEBUG_ON_LOCAL stlplus_debug_trace.debug_on(__LINE__,false)\r
+#define DEBUG_ON_GLOBAL stlplus::debug_global(__FILE__,__LINE__,__FUNCTION__,true)\r
+#define DEBUG_OFF_GLOBAL stlplus::debug_global(__FILE__,__LINE__,__FUNCTION__,false)\r
+#define DEBUG_OFF stlplus_debug_trace.debug_off(__LINE__)\r
+#define DEBUG_ASSERT(test) if (!(test))stlplus::debug_assert_fail(__FILE__,__LINE__,__FUNCTION__,#test)\r
+\r
+#else\r
+\r
+#define DEBUG_TRACE\r
+#define IF_DEBUG(stmts)\r
+#define DEBUG_REPORT(str)\r
+#define DEBUG_ERROR(str)\r
+#define DEBUG_STACKDUMP(str)\r
+#define DEBUG_ON\r
+#define DEBUG_ON_LOCAL\r
+#define DEBUG_ON_GLOBAL\r
+#define DEBUG_OFF_GLOBAL\r
+#define DEBUG_OFF\r
+#define DEBUG_ASSERT(test)\r
+\r
+#endif\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+// infrastructure - don't use directly\r
+\r
+namespace stlplus\r
+{\r
+\r
+  void debug_global(const char* file, int line, const char* function, bool state = true);\r
+  void debug_assert_fail(const char* file, int line, const char* function, const char* test) throw(assert_failed);\r
+\r
+  class debug_trace\r
+  {\r
+  public:\r
+    debug_trace(const char* f, int l, const char* fn);\r
+    ~debug_trace(void);\r
+    const char* file(void) const;\r
+    int line(void) const;\r
+    bool debug(void) const;\r
+    void debug_on(int l, bool recurse);\r
+    void debug_off(int l);\r
+    void prefix(int l) const;\r
+    void report(int l, const std::string& message) const;\r
+    void report(const std::string& message) const;\r
+    void error(int l, const std::string& message) const;\r
+    void error(const std::string& message) const;\r
+    void stackdump(int l, const std::string& message) const;\r
+    void stackdump(const std::string& message) const;\r
+    void stackdump(void) const;\r
+\r
+  private:\r
+    const char* m_file;\r
+    int m_line;\r
+    const char* m_function;\r
+    unsigned m_depth;\r
+    const debug_trace* m_last;\r
+    bool m_dbg;\r
+    bool m_old;\r
+    void do_report(int l, const std::string& message) const;\r
+    void do_report(const std::string& message) const;\r
+\r
+    // make this class uncopyable\r
+    debug_trace(const debug_trace&);\r
+    debug_trace& operator = (const debug_trace&);\r
+  };\r
+\r
+} // end namespace stlplus\r
+\r
+  ////////////////////////////////////////////////////////////////////////////////\r
+#endif\r
This page took 0.021127 seconds and 4 git commands to generate.