File: IpDebug.cpp

package info (click to toggle)
coinor-ipopt 3.11.9-2.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 24,616 kB
  • sloc: cpp: 75,373; sh: 11,170; ansic: 2,798; makefile: 2,247; java: 632; fortran: 342
file content (108 lines) | stat: -rw-r--r-- 2,523 bytes parent folder | download | duplicates (5)
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
// Copyright (C) 2004, 2006 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// $Id: IpDebug.cpp 1861 2010-12-21 21:34:47Z andreasw $
//
// Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13

#include "IpoptConfig.h"

#include "IpDebug.hpp"
#include "IpJournalist.hpp"

#if COIN_IPOPT_VERBOSITY > 0

namespace Ipopt
{

  Index DebugJournalistWrapper::indentation_level_ = 0;
  Journalist* DebugJournalistWrapper::jrnl_ = NULL;

  DebugJournalistWrapper::DebugJournalistWrapper(
    std::string func_name,
    Index verbose_level)
      :
      func_name_(func_name),
      verbose_level_(verbose_level),
      method_owner_(NULL)
  {
    if (jrnl_==NULL) {
      verbose_level_ = 0;
      return;
    }
    DebugPrintf(1, "-> Calling to: %s\n", func_name_.c_str());
    if (verbose_level_>0) {
      indentation_level_++;
    }
  }

  DebugJournalistWrapper::DebugJournalistWrapper(
    std::string func_name, Index verbose_level,
    const void* const method_owner)
      :
      func_name_(func_name),
      verbose_level_(verbose_level),
      method_owner_(method_owner)
  {
    if (jrnl_==NULL) {
      verbose_level_ = 0;
      return;
    }
    DebugPrintf(1, "-> Calling to: %s in obj: 0x%x\n", func_name_.c_str(),
                method_owner_);
    if (verbose_level_>0) {
      indentation_level_++;
    }
  }

  DebugJournalistWrapper::~DebugJournalistWrapper()
  {
    if (verbose_level_>0) {
      indentation_level_--;
    }
    if (jrnl_) {
      if (method_owner_ == NULL) {
        DebugPrintf(1, "<- Returning from : %s\n", func_name_.c_str());
      }
      else {
        DebugPrintf(1, "<- Returning from : %s in obj: 0x%x\n",
                    func_name_.c_str(), method_owner_);
      }
    }
  }


  void DebugJournalistWrapper::SetJournalist(Journalist* jrnl)
  {

    if (jrnl == NULL) {
      jrnl_->Printf(J_ERROR, J_DBG,
                    "# Setting Journalist to NULL in DebugJournalistWrapper.\n");
      jrnl_ = NULL;
    }
    else if (!jrnl_) {
      jrnl_ = jrnl;
    }
  }


  void DebugJournalistWrapper::DebugPrintf(Index verbosity, const char* pformat, ...)
  {

    if (Verbosity() >= verbosity) {
      va_list(ap);

      va_start(ap, pformat);

      DBG_ASSERT(jrnl_);
      jrnl_->PrintfIndented(J_ERROR, J_DBG, indentation_level_, "# ");
      jrnl_->VPrintf(J_ERROR, J_DBG, pformat, ap);

      va_end(ap);
    }
  }

} // namespace Ipopt

#endif // #if COIN_IPOPT_VERBOSITY > 0