summaryrefslogtreecommitdiff
path: root/newstructure/thirdparty/linux/include/coin/IpDebug.hpp
blob: b8aae13c93cb79ea5a979fa1061ece8681a03faa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (C) 2004, 2007 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// $Id: IpDebug.hpp 2005 2011-06-06 12:55:16Z stefan $
//
// Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13

#ifndef __IPDEBUG_HPP__
#define __IPDEBUG_HPP__

#include "IpoptConfig.h"
#include "IpTypes.hpp"

#ifdef COIN_IPOPT_CHECKLEVEL
#ifdef HAVE_CASSERT
# include <cassert>
#else
# ifdef HAVE_ASSERT_H
#  include <assert.h>
# else
#  error "don't have header file for assert"
# endif
#endif
#else
#define COIN_IPOPT_CHECKLEVEL 0
#endif

#if COIN_IPOPT_CHECKLEVEL > 0
# ifdef NDEBUG
#  undef NDEBUG
# endif
# define DBG_ASSERT(test) assert(test)
# define DBG_ASSERT_EXCEPTION(__condition, __except_type, __msg) \
   ASSERT_EXCEPTION( (__condition), __except_type, __msg);
# define DBG_DO(__cmd) __cmd
#else
# define DBG_ASSERT(test)
# define DBG_ASSERT_EXCEPTION(__condition, __except_type, __msg)
# define DBG_DO(__cmd)
#endif

#ifndef COIN_IPOPT_VERBOSITY
#define COIN_IPOPT_VERBOSITY 0
#endif

#if COIN_IPOPT_VERBOSITY < 1
# define DBG_START_FUN(__func_name, __verbose_level)
# define DBG_START_METH(__func_name, __verbose_level)
# define DBG_PRINT(__printf_args)
# define DBG_PRINT_VECTOR(__verbose_level, __vec_name, __vec)
# define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
# define DBG_EXEC(__verbosity, __cmd)
# define DBG_VERBOSITY() 0
#else
#include <string>

namespace Ipopt
{
  // forward definition
  class Journalist;

  /** Class that lives throughout the execution of a method or
  *  function for which debug output is to be generated.  The output
  *  is sent to the unique debug journalist that is set with
  *  SetJournalist at the beginning of program execution. */
  class DebugJournalistWrapper
  {
  public:
    /** @name Constructors/Destructors. */
    //@{
    DebugJournalistWrapper(std::string func_name, Index verbose_level);
    DebugJournalistWrapper(std::string func_name, Index verbose_level,
                           const void* const method_owner);
    ~DebugJournalistWrapper();
    //@}

    /** @name accessor methods */
    //@{
    Index Verbosity()
    {
      return verbose_level_;
    }
    const Journalist* Jnlst()
    {
      return jrnl_;
    }
    Index IndentationLevel()
    {
      return indentation_level_;
    }
    //@}

    /** Printing */
    void DebugPrintf(Index verbosity, const char* pformat, ...);

    /* Method for initialization of the static GLOBAL journalist,
    * through with all debug printout is to be written.  This needs
    * to be set before any debug printout can be done. */
    static void SetJournalist(Journalist* jrnl);

  private:
    /**@name Default Compiler Generated Methods
    * (Hidden to avoid implicit creation/calling).
    * These methods are not implemented and
    * we do not want the compiler to implement
    * them for us, so we declare them private
    * and do not define them. This ensures that
    * they will not be implicitly created/called. */
    //@{
    /** default constructor */
    DebugJournalistWrapper();

    /** copy contructor */
    DebugJournalistWrapper(const DebugJournalistWrapper&);

    /** Overloaded Equals Operator */
    DebugJournalistWrapper& operator=(const DebugJournalistWrapper&);
    //@}

    static Index indentation_level_;
    std::string func_name_;
    Index verbose_level_;
    const void* method_owner_;

    static Journalist* jrnl_;
  };
}

# define DBG_START_FUN(__func_name, __verbose_level) \
  DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level)); \

# define DBG_START_METH(__func_name, __verbose_level) \
  DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level), this);

# define DBG_PRINT(__args) \
  dbg_jrnl.DebugPrintf __args;

# define DBG_EXEC(__verbose_level, __cmd) \
  if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
    (__cmd); \
  }

# define DBG_VERBOSITY() \
  dbg_jrnl.Verbosity()

#endif


#endif