]>
vaikene.ee Git - evaf/blob - registry.cpp
c3bc2bef251e08c2d0a96a891d845d50fa0ec1a1
2 * @file Common/registry.cpp
3 * @brief Common registry implementation
6 * Copyright (c) 2011-2019 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
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.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
26 //-------------------------------------------------------------------
28 using namespace eVaf::Common
;
30 iRegistry
* iRegistry::instance()
32 static Internal::Registry singleton
;
37 //-------------------------------------------------------------------
39 using namespace eVaf::Common::Internal
;
44 setObjectName(QString("%1-iRegistry").arg(VER_MODULE_NAME_STR
));
46 // Register our own interface
47 registerInterface("iRegistry", this);
55 bool Registry::registerInterface(QString
const & name
, QObject
* obj
)
57 // Add the interface to the list of registered interfaces and connect to
58 // the destroyed() signal.
59 mInterfaces
.insert(name
, obj
);
60 connect(obj
, SIGNAL(destroyed(QObject
*)), this, SLOT(interfaceDestroyed(QObject
*)));
65 QObject
* Registry::queryInterface(QString
const & name
) const
67 Interfaces::const_iterator it
= mInterfaces
.constFind(name
);
68 return it
!= mInterfaces
.constEnd() ? *it
: nullptr;
71 void Registry::interfaceDestroyed(QObject
* obj
)
73 // Interface object destroyed. Remove it from the list of registered
75 Interfaces::iterator it
= mInterfaces
.begin();
76 Interfaces::const_iterator e
= mInterfaces
.end();
79 it
= mInterfaces
.erase(it
);