/*************************************************************************** * Copyright (C) gempa GmbH * * All rights reserved. * * Contact: gempa GmbH (seiscomp-dev@gempa.de) * * * * GNU Affero General Public License Usage * * This file may be used under the terms of the GNU Affero * * 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 following information to ensure the GNU Affero * * Public License version 3.0 requirements will be met: * * https://www.gnu.org/licenses/agpl-3.0.html. * * * * Other Usage * * Alternatively, this file may be used in accordance with the terms and * * conditions contained in a signed written agreement between you and * * gempa GmbH. * ***************************************************************************/ #include namespace Seiscomp { namespace Core { namespace Generic { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template ClassFactoryInterface::ClassFactoryInterface(const RTTI* typeInfo, bool reregister) { _typeInfo = typeInfo; // while construction the interface will be added // to the classpool RegisterFactory(this, reregister); } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template ClassFactoryInterface::~ClassFactoryInterface() { // remove the Factory from the classpool UnregisterFactory(this); } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template ROOT_TYPE* ClassFactoryInterface::Create(const char* className) { ClassFactoryInterface* factoryInterface = FindByClassName(className); if ( factoryInterface ) return factoryInterface->create(); return nullptr; } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template bool ClassFactoryInterface::IsTypeOf(const char* baseName, const char* derivedName) { ClassFactoryInterface* derivedFactory = FindByClassName(derivedName); if ( !derivedFactory ) return false; ClassFactoryInterface* baseFactory = FindByClassName(baseName); if ( !baseFactory ) return false; return derivedFactory->typeInfo()->isTypeOf(*baseFactory->typeInfo()); } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template ROOT_TYPE* ClassFactoryInterface::Create(const std::string& className) { return Create(className.c_str()); } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template const char* ClassFactoryInterface::ClassName(const ROOT_TYPE* object) { ClassNames::iterator it = Names().find(&object->typeInfo()); return it == Names().end() ? nullptr : (*it).second.c_str(); } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template const char* ClassFactoryInterface::ClassName(const RTTI* info) { ClassNames::iterator it = Names().find(info); return it == Names().end() ? nullptr : (*it).second.c_str(); } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template ClassFactoryInterface* ClassFactoryInterface::FindByClassName(const char* className) { if ( !className ) return nullptr; typename ClassPool::iterator it = Classes().find(className); if ( it == Classes().end() ) return nullptr; return (*it).second; } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template unsigned int ClassFactoryInterface::NumberOfRegisteredClasses() { return static_cast(Classes().size()); } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template const char* ClassFactoryInterface::className() const { return _typeInfo->className(); } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template const RTTI* ClassFactoryInterface::typeInfo() const { return _typeInfo; } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template typename ClassFactoryInterface::ClassPool& ClassFactoryInterface::Classes() { static typename ClassFactoryInterface::ClassPool* classes = new typename ClassFactoryInterface::ClassPool; return *classes; } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template typename ClassFactoryInterface::ClassNames& ClassFactoryInterface::Names() { static typename ClassFactoryInterface::ClassNames* names = new typename ClassFactoryInterface::ClassNames; return *names; } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template bool ClassFactoryInterface::RegisterFactory(ClassFactoryInterface* factory, bool reregister) { if ( !factory ) return false; if ( !reregister ) { if ( Classes().find(factory->className()) != Classes().end() ) { throw DuplicateClassname(factory->className()); return false; } } Classes()[factory->className()] = factory; Names()[factory->typeInfo()] = factory->className(); return true; } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template bool ClassFactoryInterface::UnregisterFactory(ClassFactoryInterface* factory) { if ( !factory ) return false; typename ClassPool::iterator it = Classes().find(factory->className()); if ( it == Classes().end() ) // the factory has not been registered already return false; Classes().erase(it); typename ClassNames::iterator it_names = Names().find(factory->typeInfo()); if ( it_names != Names().end() ) Names().erase(it_names); return true; } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> } } }