/*========================================================================= Library: CTK Copyright (c) 2010 Kitware Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.commontk.org/LICENSE Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =========================================================================*/ #ifndef __ctkAbstractPluginFactory_tpp #define __ctkAbstractPluginFactory_tpp // CTK includes #include "ctkAbstractPluginFactory.h" // QT includes #include #include //---------------------------------------------------------------------------- // ctkFactoryPluginItem methods //---------------------------------------------------------------------------- template ctkFactoryPluginItem::ctkFactoryPluginItem(const QString& _key, const QString& _path) :ctkAbstractFactoryItem(_key),Path(_path) { } //---------------------------------------------------------------------------- template bool ctkFactoryPluginItem::load() { this->Loader.setFileName(this->path()); return this->Loader.load(); } //---------------------------------------------------------------------------- template QString ctkFactoryPluginItem::path()const { return this->Path; } //---------------------------------------------------------------------------- template QString ctkFactoryPluginItem::loadErrorString()const { return this->Loader.errorString(); } //---------------------------------------------------------------------------- template BaseClassType* ctkFactoryPluginItem::instanciator() { //qDebug() << "PluginItem::instantiate - name:" << this->path(); QObject * object = this->Loader.instance(); if (!object) { if (this->verbose()) { qWarning() << "Failed to instantiate plugin:" << this->path(); } return 0; } BaseClassType* castedObject = qobject_cast(object); if (!castedObject) { if (this->verbose()) { qWarning() << "Failed to access interface [" << BaseClassType::staticMetaObject.className() << "] in plugin:" << this->path(); } delete object; // Clean memory return 0; } return castedObject; } //---------------------------------------------------------------------------- // ctkAbstractPluginFactory methods //---------------------------------------------------------------------------- template ctkAbstractPluginFactory::ctkAbstractPluginFactory():ctkAbstractFactory() { } //---------------------------------------------------------------------------- template ctkAbstractPluginFactory::~ctkAbstractPluginFactory() { } //----------------------------------------------------------------------------- template QString ctkAbstractPluginFactory::fileNameToKey( const QString& fileName) { return fileName; } //---------------------------------------------------------------------------- template bool ctkAbstractPluginFactory::registerLibrary(const QFileInfo& file, QString& key) { key = this->fileNameToKey(file.fileName()); // Check if already registered if (this->item(key)) { return false; } QSharedPointer _item = QSharedPointer(new FactoryItemType(key, file.filePath())); _item->setVerbose(this->verbose()); return this->registerItem(_item); } #endif