libsolidcontrol
singletondefs.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SOLID_CONTROL_SINGLETONDEFS_H
00021 #define SOLID_CONTROL_SINGLETONDEFS_H
00022
00023 #include <kglobal.h>
00024
00025 class QObject;
00026
00027 namespace Solid
00028 {
00029 namespace Control
00030 {
00034 template<typename T>
00035 class SingletonHelper { public: T instance; };
00036
00037 #define SOLID_SINGLETON(Type) \
00038 public: \
00039 static Type &self(); \
00040 static Type &selfForceBackend(QObject *backend); \
00041 private: \
00042 friend class Solid::Control::SingletonHelper< Type >;
00043
00044 #define SOLID_SINGLETON_IMPLEMENTATION(Type, Name) \
00045 K_GLOBAL_STATIC(Solid::Control::SingletonHelper< Type >, global##Name) \
00046 \
00047 Type &Type::self() \
00048 { \
00049 Solid::Control::SingletonHelper< Type > *singleton = global##Name; \
00050 \
00051 return singleton->instance; \
00052 }
00053 }
00054 }
00055
00056 #endif