00001 /****************************************************************************** 00002 * 00003 * package: Log4Qt 00004 * file: classlogger.h 00005 * created: September 2007 00006 * author: Martin Heinrich 00007 * 00008 * 00009 * changes: Sep 2008, Martin Heinrich: 00010 * - Replaced usage of q_atomic_test_and_set_ptr with 00011 * QAtomicPointer 00012 * 00013 * 00014 * Copyright 2007 - 2008 Martin Heinrich 00015 * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); 00017 * you may not use this file except in compliance with the License. 00018 * You may obtain a copy of the License at 00019 * 00020 * http://www.apache.org/licenses/LICENSE-2.0 00021 * 00022 * Unless required by applicable law or agreed to in writing, software 00023 * distributed under the License is distributed on an "AS IS" BASIS, 00024 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00025 * See the License for the specific language governing permissions and 00026 * limitations under the License. 00027 * 00028 ******************************************************************************/ 00029 00030 #ifndef LOG4QT_CLASSLOGGER_H 00031 #define LOG4QT_CLASSLOGGER_H 00032 00033 00034 /****************************************************************************** 00035 * Dependencies 00036 ******************************************************************************/ 00037 00038 #include <QtCore/QObject> 00039 #if QT_VERSION >= QT_VERSION_CHECK(4, 4, 0) 00040 # include <QtCore/QAtomicPointer> 00041 # ifndef Q_ATOMIC_POINTER_TEST_AND_SET_IS_ALWAYS_NATIVE 00042 # warning "QAtomicPointer test and set is not native. The class Log4Qt::ClassLogger is not thread-safe." 00043 # endif 00044 #endif 00045 00046 00047 /****************************************************************************** 00048 * Declarations 00049 ******************************************************************************/ 00050 00051 namespace Log4Qt 00052 { 00053 class Logger; 00054 00067 class ClassLogger 00068 { 00069 public: 00073 ClassLogger(); 00074 // ~ClassLogger(); // Use compiler default 00075 // ClassLogger(const ClassLogger &rOther); // Use compiler default 00076 // ClassLogger &operator=(const ClassLogger &rOther); // Use compiler default 00077 00088 Logger *logger(const QObject *pObject); 00089 00090 private: 00091 #if QT_VERSION < QT_VERSION_CHECK(4, 4, 0) 00092 volatile Logger *mpLogger; 00093 #else 00094 mutable QAtomicPointer<Logger> mpLogger; 00095 #endif 00096 }; 00097 00098 00099 /****************************************************************************** 00100 * Operators, Helper 00101 ******************************************************************************/ 00102 00103 00104 /************************************************************************** 00105 * Inline 00106 **************************************************************************/ 00107 00108 00109 } // namespace Log4Qt 00110 00111 00112 // Q_DECLARE_TYPEinfo(Log4Qt::ClassLogger, Q_COMPLEX_TYPE); // Use default 00113 00114 00115 #endif // LOG4QT_CLASSLOGGER_H