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 #ifndef LOG4QT_HELPERS_FACTORY_H
00026 #define LOG4QT_HELPERS_FACTORY_H
00027
00028
00029
00030
00031
00032
00033 #include <QtCore/QHash>
00034 #include <QtCore/QMutex>
00035 #include <QtCore/QStringList>
00036
00037
00038
00039
00040
00041
00042 namespace Log4Qt
00043 {
00044
00045 class Appender;
00046 class Filter;
00047 class Layout;
00048
00069 class Factory
00070 {
00071 public:
00078 typedef Appender *(*AppenderFactoryFunc)();
00079
00086 typedef Filter *(*FilterFactoryFunc)();
00087
00094 typedef Layout *(*LayoutFactoryFunc)();
00095
00096 private:
00097 Factory();
00098 Factory(const Factory &rOther);
00099
00100 Factory &operator=(const Factory &rOther);
00101
00102 public:
00110 static Appender *createAppender(const QString &rAppenderClassName);
00111
00115 static Appender *createAppender(const char *pAppenderClassName);
00116
00124 static Filter *createFilter(const QString &rFilterClassName);
00125
00129 static Filter *createFilter(const char *pFilterClassName);
00130
00138 static Layout *createLayout(const QString &rLayoutClassName);
00139
00143 static Layout *createLayout(const char *pLayoutClassName);
00144
00148 static Factory *instance();
00149
00158 static void registerAppender(const QString &rAppenderClassName,
00159 AppenderFactoryFunc pAppenderFactoryFunc);
00160
00164 static void registerAppender(const char *pAppenderClassName,
00165 AppenderFactoryFunc pAppenderFactoryFunc);
00166
00175 static void registerFilter(const QString &rFilterClassName,
00176 FilterFactoryFunc pFilterFactoryFunc);
00177
00181 static void registerFilter(const char *pFilterClassName,
00182 FilterFactoryFunc pFilterFactoryFunc);
00183
00192 static void registerLayout(const QString &rLayoutClassName,
00193 LayoutFactoryFunc pLayoutFactoryFunc);
00194
00198 static void registerLayout(const char *pLayoutClassName,
00199 LayoutFactoryFunc pLayoutFactoryFunc);
00200
00207 static QStringList registeredAppenders();
00208
00215 static QStringList registeredFilters();
00216
00223 static QStringList registeredLayouts();
00224
00233 static void setObjectProperty(QObject *pObject,
00234 const QString &rProperty,
00235 const QString &rValue);
00236
00240 static void setObjectProperty(QObject *pObject,
00241 const char *pProperty,
00242 const QString &rValue);
00243
00250 static void unregisterAppender(const QString &rAppenderClassName);
00251
00255 static void unregisterAppender(const char *pAppenderClassName);
00256
00263 static void unregisterFilter(const QString &rFilterClassName);
00264
00268 static void unregisterFilter(const char *pFilterClassName);
00269
00276 static void unregisterLayout(const QString &rLayoutClassName);
00277
00281 static void unregisterLayout(const char *pLayoutClassName);
00282
00283 private:
00284 Appender *doCreateAppender(const QString &rAppenderClassName);
00285 Filter *doCreateFilter(const QString &rFilterClassName);
00286 Layout *doCreateLayout(const QString &rLayoutClassName);
00287 void doRegisterAppender(const QString &rAppenderClassName,
00288 AppenderFactoryFunc pAppenderFactoryFunc);
00289 void doRegisterFilter(const QString &rFilterClassName,
00290 FilterFactoryFunc pFilterFactoryFunc);
00291 void doRegisterLayout(const QString &rLayoutClassName,
00292 LayoutFactoryFunc pLayoutFactoryFunc);
00293 void doSetObjectProperty(QObject *pObject,
00294 const QString &rProperty,
00295 const QString &rValue);
00296 void doUnregisterAppender(const QString &rAppenderClassName);
00297 void doUnregisterFilter(const QString &rFilterClassName);
00298 void doUnregisterLayout(const QString &rLayoutClassName);
00299 void registerDefaultAppenders();
00300 void registerDefaultFilters();
00301 void registerDefaultLayouts();
00302 bool validateObjectProperty(QMetaProperty &rMetaProperty,
00303 const QString &rProperty,
00304 QObject *pObject);
00305
00306 private:
00307 mutable QMutex mObjectGuard;
00308 QHash<QString, AppenderFactoryFunc> mAppenderRegistry;
00309 QHash<QString, FilterFactoryFunc> mFilterRegistry;
00310 QHash<QString, LayoutFactoryFunc> mLayoutRegistry;
00311 };
00312
00313
00314
00315
00316
00317
00318 #ifndef QT_NO_DEBUG_STREAM
00319
00346 QDebug operator<<(QDebug debug,
00347 const Factory &rFactory);
00348 #endif // QT_NO_DEBUG_STREAM
00349
00350
00351
00352
00353
00354
00355
00356 inline Appender *Factory::createAppender(const QString &rAppenderClassName)
00357 { return instance()->doCreateAppender(rAppenderClassName); }
00358
00359 inline Appender *Factory::createAppender(const char *pAppenderClassName)
00360 { return instance()->doCreateAppender(QLatin1String(pAppenderClassName)); }
00361
00362 inline Filter *Factory::createFilter(const QString &rFilterClassName)
00363 { return instance()->doCreateFilter(rFilterClassName); }
00364
00365 inline Filter *Factory::createFilter(const char *pFilterClassName)
00366 { return instance()->doCreateFilter(QLatin1String(pFilterClassName)); }
00367
00368 inline Layout *Factory::createLayout(const QString &rLayoutClassName)
00369 { return instance()->doCreateLayout(rLayoutClassName); }
00370
00371 inline Layout *Factory::createLayout(const char *pLayoutClassName)
00372 { return instance()->doCreateLayout(QLatin1String(pLayoutClassName)); }
00373
00374 inline void Factory::registerAppender(const QString &rAppenderClassName,
00375 AppenderFactoryFunc pAppenderFactoryFunc)
00376 { instance()->doRegisterAppender(rAppenderClassName, pAppenderFactoryFunc); }
00377
00378 inline void Factory::registerAppender(const char *pAppenderClassName,
00379 AppenderFactoryFunc pAppenderFactoryFunc)
00380 { instance()->doRegisterAppender(QLatin1String(pAppenderClassName), pAppenderFactoryFunc); }
00381
00382 inline void Factory::registerFilter(const QString &rFilterClassName,
00383 FilterFactoryFunc pFilterFactoryFunc)
00384 { instance()->doRegisterFilter(rFilterClassName, pFilterFactoryFunc); }
00385
00386 inline void Factory::registerFilter(const char *pFilterClassName,
00387 FilterFactoryFunc pFilterFactoryFunc)
00388 { instance()->doRegisterFilter(QLatin1String(pFilterClassName), pFilterFactoryFunc); }
00389
00390 inline void Factory::registerLayout(const QString &rLayoutClassName,
00391 LayoutFactoryFunc pLayoutFactoryFunc)
00392 { instance()->doRegisterLayout(rLayoutClassName, pLayoutFactoryFunc); }
00393
00394 inline void Factory::registerLayout(const char *pLayoutClassName,
00395 LayoutFactoryFunc pLayoutFactoryFunc)
00396 { instance()->doRegisterLayout(QLatin1String(pLayoutClassName), pLayoutFactoryFunc); }
00397
00398 inline QStringList Factory::registeredAppenders()
00399 { QMutexLocker locker(&instance()->mObjectGuard);
00400 return instance()->mAppenderRegistry.keys(); }
00401
00402 inline QStringList Factory::registeredFilters()
00403 { QMutexLocker locker(&instance()->mObjectGuard);
00404 return instance()->mFilterRegistry.keys(); }
00405
00406 inline QStringList Factory::registeredLayouts()
00407 { QMutexLocker locker(&instance()->mObjectGuard);
00408 return instance()->mLayoutRegistry.keys(); }
00409
00410 inline void Factory::setObjectProperty(QObject *pObject,
00411 const QString &rProperty,
00412 const QString &rValue)
00413 { instance()->doSetObjectProperty(pObject, rProperty, rValue); }
00414
00415 inline void Factory::setObjectProperty(QObject *pObject,
00416 const char *pProperty,
00417 const QString &rValue)
00418 { instance()->doSetObjectProperty(pObject, QLatin1String(pProperty), rValue); }
00419
00420 inline void Factory::unregisterAppender(const QString &rAppenderClassName)
00421 { instance()->doUnregisterAppender(rAppenderClassName); }
00422
00423 inline void Factory::unregisterAppender(const char *pAppenderClassName)
00424 { instance()->doUnregisterAppender(QLatin1String(pAppenderClassName)); }
00425
00426 inline void Factory::unregisterFilter(const QString &rFilterClassName)
00427 { instance()->doUnregisterFilter(rFilterClassName); }
00428
00429 inline void Factory::unregisterFilter(const char *pFilterClassName)
00430 { instance()->doUnregisterFilter(QLatin1String(pFilterClassName)); }
00431
00432 inline void Factory::unregisterLayout(const QString &rLayoutClassName)
00433 { instance()->doUnregisterLayout(rLayoutClassName); }
00434
00435 inline void Factory::unregisterLayout(const char *pLayoutClassName)
00436 { instance()->doUnregisterLayout(QLatin1String(pLayoutClassName)); }
00437
00438 }
00439
00440
00441
00442
00443
00444 #endif // LOG4QT_HELPERS_FACTORY_H