PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/test/debug.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 85 lines | 37 code | 10 blank | 38 comment | 0 complexity | d657de9a080c9fbd550b8caf8ec35a1a MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file debug.h
  3. * @author Nat Goodspeed
  4. * @date 2009-05-28
  5. * @brief Debug output for unit test code
  6. *
  7. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #if ! defined(LL_DEBUG_H)
  29. #define LL_DEBUG_H
  30. #include <iostream>
  31. /*****************************************************************************
  32. * Debugging stuff
  33. *****************************************************************************/
  34. // This class is intended to illuminate entry to a given block, exit from the
  35. // same block and checkpoints along the way. It also provides a convenient
  36. // place to turn std::cout output on and off.
  37. class Debug
  38. {
  39. public:
  40. Debug(const std::string& block):
  41. mBlock(block)
  42. {
  43. (*this)("entry");
  44. }
  45. ~Debug()
  46. {
  47. (*this)("exit");
  48. }
  49. void operator()(const std::string& status)
  50. {
  51. #if defined(DEBUG_ON)
  52. std::cout << mBlock << ' ' << status << std::endl;
  53. #endif
  54. }
  55. private:
  56. const std::string mBlock;
  57. };
  58. // It's often convenient to use the name of the enclosing function as the name
  59. // of the Debug block.
  60. #define DEBUG Debug debug(__FUNCTION__)
  61. // These BEGIN/END macros are specifically for debugging output -- please
  62. // don't assume you must use such for coroutines in general! They only help to
  63. // make control flow (as well as exception exits) explicit.
  64. #define BEGIN \
  65. { \
  66. DEBUG; \
  67. try
  68. #define END \
  69. catch (...) \
  70. { \
  71. debug("*** exceptional "); \
  72. throw; \
  73. } \
  74. }
  75. #endif /* ! defined(LL_DEBUG_H) */