/** * @file Common/registry.cpp * @brief Common registry implementation * @author Enar Vaikene * * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * * This file can be used under the terms of the GNU General Public License * version 3.0 as published by the Free Software Foundation and appearing in * the file LICENSE included in the packaging of this file. Please review the * the following information to ensure the GNU General Public License version * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. * * Alternatively, this file may be used in accordance with the Commercial License * Agreement provided with the Software. */ #include "registry.h" #include "globals.h" #include "version.h" #include //------------------------------------------------------------------- using namespace eVaf::Common; iRegistry * iRegistry::instance() { static Internal::Registry singleton; return &singleton; } //------------------------------------------------------------------- using namespace eVaf::Common::Internal; Registry::Registry() : iRegistry() { setObjectName(QString("%1-iRegistry").arg(VER_MODULE_NAME_STR)); // Register our own interface registerInterface("iRegistry", this); } Registry::~Registry() { mInterfaces.clear(); } bool Registry::registerInterface(QString const & name, QObject * obj) { // Add the interface to the list of registered interfaces and connect to // the destroyed() signal. mInterfaces.insert(name, obj); connect(obj, SIGNAL(destroyed(QObject *)), this, SLOT(interfaceDestroyed(QObject *))); return true; } QObject * Registry::queryInterface(QString const & name) const { Interfaces::const_iterator it = mInterfaces.constFind(name); return it != mInterfaces.constEnd() ? *it : nullptr; } void Registry::interfaceDestroyed(QObject * obj) { // Interface object destroyed. Remove it from the list of registered // interfaces. Interfaces::iterator it = mInterfaces.begin(); Interfaces::const_iterator e = mInterfaces.end(); while (it != e) { if (*it == obj) { it = mInterfaces.erase(it); } else { ++it; } } }