Ipopt Documentation  
 
Loading...
Searching...
No Matches
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
47namespace Ipopt
48{
49// forward definition
50class Journalist;
51
59class IPOPTLIB_EXPORT DebugJournalistWrapper
60{
61public:
64 DebugJournalistWrapper(
65 const std::string& func_name,
66 Index verbose_level
67 );
68
69 DebugJournalistWrapper(
70 const std::string& func_name,
71 Index verbose_level,
72 const void* const method_owner
73 );
74 ~DebugJournalistWrapper();
76
79 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#ifdef __GNUC__
95 __attribute__((format(printf, 3, 4)))
96#endif
97 void DebugPrintf(
98 Index verbosity,
99 const char* pformat,
100 ...
101 );
102
103private:
104 friend class IpoptApplication;
105 /* Method for initialization of the static GLOBAL journalist,
106 * through with all debug printout is to be written.
107 *
108 * This needs to be set before any debug printout can be done.
109 * It is expected that this is only called by the IpoptApplication constructor.
110 */
111 static void SetJournalist(
112 Journalist* jrnl
113 );
114
125
126 DebugJournalistWrapper();
127
129 DebugJournalistWrapper(
130 const DebugJournalistWrapper&
131 );
132
134 DebugJournalistWrapper& operator=(
135 const DebugJournalistWrapper&
136 );
138
139 static Index indentation_level_;
140 std::string func_name_;
141 Index verbose_level_;
142 const void* method_owner_;
143
144 static Journalist* jrnl_;
145};
146}
147
148# define DBG_START_FUN(__func_name, __verbose_level) \
149 DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level)); \
150
151# define DBG_START_METH(__func_name, __verbose_level) \
152 DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level), this);
153
154# define DBG_PRINT(__args) \
155 dbg_jrnl.DebugPrintf __args;
156
157# define DBG_EXEC(__verbose_level, __cmd) \
158 if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
159 (__cmd); \
160 }
161
162# define DBG_VERBOSITY() \
163 dbg_jrnl.Verbosity()
164
165#endif
166
167#endif
IPOPT_DEPRECATED typedef int Index
Type for all indices.
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.