]> vaikene.ee Git - evaf/blob - src/libs/Common/registry.h
Warning fixes and copyright update.
[evaf] / src / libs / Common / registry.h
1 /**
2 * @file Common/registry.h
3 * @brief Common registry implementation
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2011-2019 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #ifndef __COMMON_REGISTRY_H
21 #define __COMMON_REGISTRY_H
22
23 #include "iregistry.h"
24
25 #include <QObject>
26 #include <QString>
27 #include <QHash>
28
29 namespace eVaf {
30 namespace Common {
31 namespace Internal {
32
33 /**
34 * iRegistry interface implementation.
35 *
36 * This class implements the global registry for interfaces. Interfaces are stored in a QHash container
37 * and quarded with QWeakPointer.
38 */
39 class Registry : public iRegistry
40 {
41 Q_OBJECT
42
43 public:
44
45 Registry();
46
47 virtual ~Registry();
48
49 /*
50 iRegistry interface
51 */
52
53 virtual bool registerInterface(QString const & name, QObject * obj);
54
55 virtual QObject * queryInterface(QString const & name) const;
56
57
58 private:
59
60 /// All the registered interfaces
61 typedef QHash<QString, QObject *> Interfaces;
62 Interfaces mInterfaces;
63
64
65 private slots:
66
67 /// Interface object destroyed
68 /// We need to remove the interface from the list of registered interfaces
69 void interfaceDestroyed(QObject * obj = nullptr);
70
71 };
72
73 } // namespace eVaf::Common::Internal
74 } // namespace eVaf::Common
75 } // namespace eVaf
76
77 #endif // registry.h