IpDebug.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __IPDEBUG_HPP__
00010 #define __IPDEBUG_HPP__
00011
00012 #include "IpoptConfig.h"
00013 #include "IpTypes.hpp"
00014
00015 #ifdef HAVE_CASSERT
00016 # include <cassert>
00017 #else
00018 # ifdef HAVE_ASSERT_H
00019 # include <assert.h>
00020 # else
00021 # error "don't have header file for assert"
00022 # endif
00023 #endif
00024
00025 #ifdef IP_DEBUG
00026 # define DBG_ASSERT(test) assert(test)
00027 # define DBG_ASSERT_EXCEPTION(__condition, __except_type, __msg) \
00028 ASSERT_EXCEPTION( (__condition), __except_type, __msg);
00029 # define DBG_DO(__cmd) __cmd
00030 #else
00031 # define DBG_ASSERT(test)
00032 # define DBG_ASSERT_EXCEPTION(__condition, __except_type, __msg)
00033 # define DBG_DO(__cmd)
00034 #endif
00035
00036 #ifndef IP_DEBUG
00037 # define DBG_START_FUN(__func_name, __verbose_level)
00038 # define DBG_START_METH(__func_name, __verbose_level)
00039 # define DBG_PRINT(__printf_args)
00040 # define DBG_PRINT_VECTOR(__verbose_level, __vec_name, __vec)
00041 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
00042 # define DBG_EXEC(__verbosity, __cmd)
00043 # define DBG_VERBOSITY() 0
00044 #else
00045 #include <string>
00046
00047 namespace Ipopt
00048 {
00049
00050 class Journalist;
00051
00056 class DebugJournalistWrapper
00057 {
00058 public:
00061 DebugJournalistWrapper(std::string func_name, Index verbose_level);
00062 DebugJournalistWrapper(std::string func_name, Index verbose_level,
00063 const void* const method_owner);
00064 ~DebugJournalistWrapper();
00066
00069 Index Verbosity()
00070 {
00071 return verbose_level_;
00072 }
00073 const Journalist* Jnlst()
00074 {
00075 return jrnl_;
00076 }
00077 Index IndentationLevel()
00078 {
00079 return indentation_level_;
00080 }
00082
00084 void DebugPrintf(Index verbosity, const char* pformat, ...);
00085
00086
00087
00088
00089 static void SetJournalist(Journalist* jrnl);
00090
00091 private:
00101 DebugJournalistWrapper();
00102
00104 DebugJournalistWrapper(const DebugJournalistWrapper&);
00105
00107 DebugJournalistWrapper& operator=(const DebugJournalistWrapper&);
00109
00110 static Index indentation_level_;
00111 std::string func_name_;
00112 Index verbose_level_;
00113 const void* method_owner_;
00114
00115 static Journalist* jrnl_;
00116 };
00117 }
00118
00119 # define DBG_START_FUN(__func_name, __verbose_level) \
00120 DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level)); \
00121
00122 # define DBG_START_METH(__func_name, __verbose_level) \
00123 DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level), this);
00124
00125 # define DBG_PRINT(__args) \
00126 dbg_jrnl.DebugPrintf __args;
00127
00128 # define DBG_EXEC(__verbose_level, __cmd) \
00129 if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
00130 (__cmd); \
00131 }
00132
00133 # define DBG_VERBOSITY() \
00134 dbg_jrnl.Verbosity()
00135
00136 #endif
00137
00138
00139 #endif