00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef LOG4QT_LOGOBJECT_H
00034 #define LOG4QT_LOGOBJECT_H
00035
00036
00037
00038
00039
00040
00041 #include <QtCore/QObject>
00042
00043 #include "log4qt/helpers/classlogger.h"
00044 #if QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)
00045 # include <QtCore/QAtomicInt>
00046 # ifndef Q_ATOMIC_INT_REFERENCE_COUNTING_IS_ALWAYS_NATIVE
00047 # warning "QAtomicInt reference counting is not native. The class Log4Qt::LogObject is not thread-safe."
00048 # endif
00049 #endif
00050
00051
00052 namespace Log4Qt
00053 {
00054
00055 class Logger;
00056
00079 class LogObject : public QObject
00080 {
00081 Q_OBJECT
00082
00083 public:
00087 LogObject(QObject *pObject = 0);
00088
00092 virtual ~LogObject();
00093
00094 private:
00095 LogObject(const LogObject &rOther);
00096 LogObject &operator=(const LogObject &rOther);
00097
00098 public:
00102 int referenceCount() const;
00103
00109 void release();
00110
00114 void retain();
00115
00116 protected:
00117 #ifndef QT_NO_DEBUG_STREAM
00118
00128 virtual QDebug debug(QDebug &rDebug) const = 0;
00129
00130
00131 friend QDebug operator<<(QDebug debug,
00132 const LogObject &rLogObject);
00133 #endif // QT_NO_DEBUG_STREAM
00134
00140 Logger* logger() const;
00141
00142 private:
00143 #if QT_VERSION < QT_VERSION_CHECK(4, 4, 0)
00144 volatile int mReferenceCount;
00145 #else
00146 mutable QAtomicInt mReferenceCount;
00147 #endif
00148 mutable ClassLogger mLog4QtClassLogger;
00149 };
00150
00151
00152
00153
00154
00155
00156 #ifndef QT_NO_DEBUG_STREAM
00157
00168 QDebug operator<<(QDebug debug,
00169 const LogObject &rLogObject);
00170 #endif
00171
00172
00173
00174
00175
00176
00177 inline LogObject::LogObject(QObject *pParent) :
00178 QObject(pParent),
00179 mReferenceCount()
00180 {}
00181
00182 inline LogObject::~LogObject()
00183 {}
00184
00185 inline int LogObject::referenceCount() const
00186 { return mReferenceCount; }
00187
00188 inline void LogObject::release()
00189 #if QT_VERSION < QT_VERSION_CHECK(4, 4, 0)
00190 { if ((q_atomic_decrement(&mReferenceCount) == 0) && !parent())
00191 delete(this); }
00192 #else
00193 { if (!mReferenceCount.deref())
00194 delete(this); }
00195 #endif
00196
00197 inline void LogObject::retain()
00198 #if QT_VERSION < QT_VERSION_CHECK(4, 4, 0)
00199 { q_atomic_increment(&mReferenceCount); }
00200 #else
00201 { mReferenceCount.ref(); }
00202 #endif
00203
00204 inline Logger *LogObject::logger() const
00205 { return mLog4QtClassLogger.logger(this); }
00206
00207 }
00208
00209
00210
00211
00212
00213 #endif // LOG4QT_LOGOBJECT_H