QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
RSingleton.h
Go to the documentation of this file.
1
20#ifndef RSINGLETON_H_
21#define RSINGLETON_H_
22
23#include "core_global.h"
24
25#include <QMap>
26#include <QMetaType>
27#include <QString>
28#include <typeinfo>
29
34public:
35 virtual ~RSingleton() {
36 }
37 template<class Derived>
38 static Derived& getInstance();
39 static void cleanUp();
40
41protected:
42 RSingleton();
43
44private:
46};
47
49
50template<class Derived>
52 if (!map.contains(typeid(Derived).name())) {
53 map[typeid(Derived).name()] = new Derived;
54 }
55 Derived* d = dynamic_cast<Derived*> (map[typeid(Derived).name()]);
56 if (d == NULL) {
57 Q_ASSERT("RSingleton::getInstance(): \"Derived\" in not a singleton");
58 }
59 return *d;
60}
61
62#endif /* RSINGLETON_H_ */
Q_DECLARE_METATYPE(RMath *)
Definition RDebug.h:38
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RSingleton.h:33
static Derived & getInstance()
Definition RSingleton.h:51
virtual ~RSingleton()
Definition RSingleton.h:35
static QMap< QString, RSingleton * > map
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RSingleton.h:45
#define QCADCORE_EXPORT
Definition core_global.h:10
#define NULL
Definition opennurbs_system.h:256