classlogger.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /******************************************************************************
  2. *
  3. * package: Log4Qt
  4. * file: classlogger.h
  5. * created: September 2007
  6. * author: Martin Heinrich
  7. *
  8. *
  9. * changes: Sep 2008, Martin Heinrich:
  10. * - Replaced usage of q_atomic_test_and_set_ptr with
  11. * QAtomicPointer
  12. *
  13. *
  14. * Copyright 2007 - 2008 Martin Heinrich
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the "License");
  17. * you may not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * http://www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an "AS IS" BASIS,
  24. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. *
  28. ******************************************************************************/
  29. #ifndef LOG4QT_CLASSLOGGER_H
  30. #define LOG4QT_CLASSLOGGER_H
  31. /******************************************************************************
  32. * Dependencies
  33. ******************************************************************************/
  34. #include <QtCore/QObject>
  35. #if QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)
  36. # include <QtCore/QAtomicPointer>
  37. # ifndef Q_ATOMIC_POINTER_TEST_AND_SET_IS_ALWAYS_NATIVE
  38. # warning "QAtomicPointer test and set is not native. The class Log4Qt::ClassLogger is not thread-safe."
  39. # endif
  40. #endif
  41. /******************************************************************************
  42. * Declarations
  43. ******************************************************************************/
  44. namespace Log4Qt
  45. {
  46. class Logger;
  47. /*!
  48. * \brief The class ClassLogger provides logging for a QObject derived
  49. * class.
  50. *
  51. * The class ClassLogger provides a logger for a specified QObject derived
  52. * object. It is used by \ref LOG4QT_DECLARE_QCLASS_LOGGER to implement the
  53. * member functions provided by the macro.
  54. *
  55. * \note All the functions declared in this class are thread-safe.
  56. *
  57. * \sa LOG4QT_DECLARE_QCLASS_LOGGER
  58. */
  59. class ClassLogger
  60. {
  61. public:
  62. /*!
  63. * Creates a ClassLogger object.
  64. */
  65. ClassLogger();
  66. // ~ClassLogger(); // Use compiler default
  67. // ClassLogger(const ClassLogger &rOther); // Use compiler default
  68. // ClassLogger &operator=(const ClassLogger &rOther); // Use compiler default
  69. /*!
  70. * Returns a pointer to a Logger named after the class of the object
  71. * \a pObject.
  72. *
  73. * On the first invocation the Logger is requested by a call to
  74. * LogManager::logger(const char *pName). The pointer is stored to be
  75. * returned on subsequent invocations.
  76. *
  77. * \sa LogManager::logger(const char *pName)
  78. */
  79. Logger *logger(const QObject *pObject);
  80. private:
  81. #if QT_VERSION < QT_VERSION_CHECK(4, 4, 0)
  82. volatile Logger *mpLogger;
  83. #else
  84. mutable QAtomicPointer<Logger> mpLogger;
  85. #endif
  86. };
  87. /******************************************************************************
  88. * Operators, Helper
  89. ******************************************************************************/
  90. /**************************************************************************
  91. * Inline
  92. **************************************************************************/
  93. } // namespace Log4Qt
  94. // Q_DECLARE_TYPEinfo(Log4Qt::ClassLogger, Q_COMPLEX_TYPE); // Use default
  95. #endif // LOG4QT_CLASSLOGGER_H