Ipopt Documentation  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IpDebug.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2007 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6 
7 #ifndef __IPDEBUG_HPP__
8 #define __IPDEBUG_HPP__
9 
10 #include "IpoptConfig.h"
11 #include "IpTypes.hpp"
12 
13 #ifndef IPOPT_CHECKLEVEL
14 #define IPOPT_CHECKLEVEL 0
15 #endif
16 
17 #if IPOPT_CHECKLEVEL > 0
18 # ifdef NDEBUG
19 # undef NDEBUG
20 # endif
21 # include <cassert>
22 # define DBG_ASSERT(test) assert(test)
23 # define DBG_ASSERT_EXCEPTION(__condition, __except_type, __msg) \
24  ASSERT_EXCEPTION( (__condition), __except_type, __msg);
25 # define DBG_DO(__cmd) __cmd
26 #else
27 # define DBG_ASSERT(test)
28 # define DBG_ASSERT_EXCEPTION(__condition, __except_type, __msg)
29 # define DBG_DO(__cmd)
30 #endif
31 
32 #ifndef IPOPT_VERBOSITY
33 #define IPOPT_VERBOSITY 0
34 #endif
35 
36 #if IPOPT_VERBOSITY < 1
37 # define DBG_START_FUN(__func_name, __verbose_level)
38 # define DBG_START_METH(__func_name, __verbose_level)
39 # define DBG_PRINT(__printf_args)
40 # define DBG_PRINT_VECTOR(__verbose_level, __vec_name, __vec)
41 # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
42 # define DBG_EXEC(__verbosity, __cmd)
43 # define DBG_VERBOSITY() 0
44 #else
45 #include <string>
46 
47 namespace Ipopt
48 {
49 // forward definition
50 class Journalist;
51 
59 class IPOPTLIB_EXPORT DebugJournalistWrapper
60 {
61 public:
63  DebugJournalistWrapper(
65  std::string func_name,
66  Index verbose_level
67  );
68 
69  DebugJournalistWrapper(
70  std::string func_name,
71  Index verbose_level,
72  const void* const method_owner
73  );
74  ~DebugJournalistWrapper();
76 
78  Index Verbosity()
80  {
81  return verbose_level_;
82  }
83  const Journalist* Jnlst()
84  {
85  return jrnl_;
86  }
87  Index IndentationLevel()
88  {
89  return indentation_level_;
90  }
92 
94  void DebugPrintf(
95  Index verbosity,
96  const char* pformat,
97  ...
98  );
99 
100 private:
101  friend class IpoptApplication;
102  /* Method for initialization of the static GLOBAL journalist,
103  * through with all debug printout is to be written.
104  *
105  * This needs to be set before any debug printout can be done.
106  * It is expected that this is only called by the IpoptApplication constructor.
107  */
108  static void SetJournalist(
109  Journalist* jrnl
110  );
111 
121 
123  DebugJournalistWrapper();
124 
126  DebugJournalistWrapper(
127  const DebugJournalistWrapper&
128  );
129 
131  DebugJournalistWrapper& operator=(
132  const DebugJournalistWrapper&
133  );
135 
136  static Index indentation_level_;
137  std::string func_name_;
138  Index verbose_level_;
139  const void* method_owner_;
140 
141  static Journalist* jrnl_;
142 };
143 }
144 
145 # define DBG_START_FUN(__func_name, __verbose_level) \
146  DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level)); \
147 
148 # define DBG_START_METH(__func_name, __verbose_level) \
149  DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level), this);
150 
151 # define DBG_PRINT(__args) \
152  dbg_jrnl.DebugPrintf __args;
153 
154 # define DBG_EXEC(__verbose_level, __cmd) \
155  if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
156  (__cmd); \
157  }
158 
159 # define DBG_VERBOSITY() \
160  dbg_jrnl.Verbosity()
161 
162 #endif
163 
164 #endif
int Index
Type for all indices.
#define IPOPTLIB_EXPORT