IpDebug.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. // $Id: IpDebug.hpp 2005 2011-06-06 12:55:16Z stefan $
  6. //
  7. // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
  8. #ifndef __IPDEBUG_HPP__
  9. #define __IPDEBUG_HPP__
  10. #include "IpoptConfig.h"
  11. #include "IpTypes.hpp"
  12. #ifdef COIN_IPOPT_CHECKLEVEL
  13. #ifdef HAVE_CASSERT
  14. # include <cassert>
  15. #else
  16. # ifdef HAVE_ASSERT_H
  17. # include <assert.h>
  18. # else
  19. # error "don't have header file for assert"
  20. # endif
  21. #endif
  22. #else
  23. #define COIN_IPOPT_CHECKLEVEL 0
  24. #endif
  25. #if COIN_IPOPT_CHECKLEVEL > 0
  26. # ifdef NDEBUG
  27. # undef NDEBUG
  28. # endif
  29. # define DBG_ASSERT(test) assert(test)
  30. # define DBG_ASSERT_EXCEPTION(__condition, __except_type, __msg) \
  31. ASSERT_EXCEPTION( (__condition), __except_type, __msg);
  32. # define DBG_DO(__cmd) __cmd
  33. #else
  34. # define DBG_ASSERT(test)
  35. # define DBG_ASSERT_EXCEPTION(__condition, __except_type, __msg)
  36. # define DBG_DO(__cmd)
  37. #endif
  38. #ifndef COIN_IPOPT_VERBOSITY
  39. #define COIN_IPOPT_VERBOSITY 0
  40. #endif
  41. #if COIN_IPOPT_VERBOSITY < 1
  42. # define DBG_START_FUN(__func_name, __verbose_level)
  43. # define DBG_START_METH(__func_name, __verbose_level)
  44. # define DBG_PRINT(__printf_args)
  45. # define DBG_PRINT_VECTOR(__verbose_level, __vec_name, __vec)
  46. # define DBG_PRINT_MATRIX(__verbose_level, __mat_name, __mat)
  47. # define DBG_EXEC(__verbosity, __cmd)
  48. # define DBG_VERBOSITY() 0
  49. #else
  50. #include <string>
  51. namespace Ipopt
  52. {
  53. // forward definition
  54. class Journalist;
  55. /** Class that lives throughout the execution of a method or
  56. * function for which debug output is to be generated. The output
  57. * is sent to the unique debug journalist that is set with
  58. * SetJournalist at the beginning of program execution. */
  59. class DebugJournalistWrapper
  60. {
  61. public:
  62. /** @name Constructors/Destructors. */
  63. //@{
  64. DebugJournalistWrapper(std::string func_name, Index verbose_level);
  65. DebugJournalistWrapper(std::string func_name, Index verbose_level,
  66. const void* const method_owner);
  67. ~DebugJournalistWrapper();
  68. //@}
  69. /** @name accessor methods */
  70. //@{
  71. Index Verbosity()
  72. {
  73. return verbose_level_;
  74. }
  75. const Journalist* Jnlst()
  76. {
  77. return jrnl_;
  78. }
  79. Index IndentationLevel()
  80. {
  81. return indentation_level_;
  82. }
  83. //@}
  84. /** Printing */
  85. void DebugPrintf(Index verbosity, const char* pformat, ...);
  86. /* Method for initialization of the static GLOBAL journalist,
  87. * through with all debug printout is to be written. This needs
  88. * to be set before any debug printout can be done. */
  89. static void SetJournalist(Journalist* jrnl);
  90. private:
  91. /**@name Default Compiler Generated Methods
  92. * (Hidden to avoid implicit creation/calling).
  93. * These methods are not implemented and
  94. * we do not want the compiler to implement
  95. * them for us, so we declare them private
  96. * and do not define them. This ensures that
  97. * they will not be implicitly created/called. */
  98. //@{
  99. /** default constructor */
  100. DebugJournalistWrapper();
  101. /** copy contructor */
  102. DebugJournalistWrapper(const DebugJournalistWrapper&);
  103. /** Overloaded Equals Operator */
  104. DebugJournalistWrapper& operator=(const DebugJournalistWrapper&);
  105. //@}
  106. static Index indentation_level_;
  107. std::string func_name_;
  108. Index verbose_level_;
  109. const void* method_owner_;
  110. static Journalist* jrnl_;
  111. };
  112. }
  113. # define DBG_START_FUN(__func_name, __verbose_level) \
  114. DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level)); \
  115. # define DBG_START_METH(__func_name, __verbose_level) \
  116. DebugJournalistWrapper dbg_jrnl((__func_name), (__verbose_level), this);
  117. # define DBG_PRINT(__args) \
  118. dbg_jrnl.DebugPrintf __args;
  119. # define DBG_EXEC(__verbose_level, __cmd) \
  120. if (dbg_jrnl.Verbosity() >= (__verbose_level)) { \
  121. (__cmd); \
  122. }
  123. # define DBG_VERBOSITY() \
  124. dbg_jrnl.Verbosity()
  125. #endif
  126. #endif