ndc.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /******************************************************************************
  2. *
  3. * package: Log4Qt
  4. * file: ndc.h
  5. * created: September 2007
  6. * author: Martin Heinrich
  7. *
  8. *
  9. * Copyright 2007 Martin Heinrich
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. *
  23. ******************************************************************************/
  24. #ifndef LOG4QT_NDC_H
  25. #define LOG4QT_NDC_H
  26. /******************************************************************************
  27. * Dependencies
  28. ******************************************************************************/
  29. #include <QtCore/QString>
  30. #include <QtCore/QStack>
  31. #include <QtCore/QThreadStorage>
  32. #include "log4qt/log4qt.h"
  33. /******************************************************************************
  34. * Declarations
  35. ******************************************************************************/
  36. namespace Log4Qt
  37. {
  38. /*!
  39. * \brief The class NDC implements a nested diagnostic context.
  40. *
  41. * The method remove() is not required. QThreadStorage cleans up on thread
  42. * exit.
  43. *
  44. * \note All the functions declared in this class are thread-safe.
  45. */
  46. class NDC
  47. {
  48. private:
  49. NDC();
  50. NDC(const NDC &rOther); // Not implemented
  51. // virtual ~NDC(); // Use compiler default
  52. NDC &operator=(const NDC &rOther); // Not implemented
  53. public:
  54. static void clear();
  55. // JAVA: static QStack<QString> cloneStack();
  56. // JAVA: static QString get();
  57. static int depth();
  58. // JAVA: inherit(Stack stack)
  59. /*!
  60. * Returns the NDC instance.
  61. */
  62. static NDC *instance();
  63. static QString pop();
  64. static void push(const QString &rMessage);
  65. // JAVA: static void remove(); // Not required
  66. static void setMaxDepth(int maxDepth);
  67. static QString peek();
  68. private:
  69. QThreadStorage< QStack<QString> * > mStack;
  70. };
  71. /******************************************************************************
  72. * Operators, Helper
  73. ******************************************************************************/
  74. #ifndef QT_NO_DEBUG_STREAM
  75. /*!
  76. * \relates NDC
  77. *
  78. * Writes all object member variables to the given debug stream \a rDebug and
  79. * returns the stream.
  80. *
  81. * <tt>
  82. * %NDC(thread:"main" peek:"i = 3" depth:4)
  83. * </tt>
  84. * \sa QDebug
  85. */
  86. QDebug operator<<(QDebug debug,
  87. const NDC &rNDC);
  88. #endif // QT_NO_DEBUG_STREAM
  89. /******************************************************************************
  90. * Inline
  91. ******************************************************************************/
  92. inline NDC::NDC() :
  93. mStack()
  94. {}
  95. } // namespace Log4Qt
  96. // Q_DECLARE_TYPEINFO(Log4Qt::NDC, Q_COMPLEX_TYPE); // Use default
  97. #endif // LOG4QT_NDC_H