/*============================================================================= Library: CTK Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics 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.apache.org/licenses/LICENSE-2.0 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 CTKCMDLINEMODULEBACKENDFUNCTIONPOINTER_H #define CTKCMDLINEMODULEBACKENDFUNCTIONPOINTER_H #include "ctkCmdLineModuleBackend.h" #include "ctkCommandLineModulesBackendFunctionPointerExport.h" #include "ctkCmdLineModuleBackendFPTypeTraits.h" #include "ctkCmdLineModuleBackendFPUtil_p.h" #include #include #include #include #include #include namespace ctk { namespace CmdLineModuleBackendFunctionPointer { struct FunctionPointerProxy; template QString GetParameterTypeName(); struct ImageType {}; // default parameter description template struct CreateXmlFor { static QString parameter(int index, const QString& typeName, const QString& label = QString(), const QString& description = QString()) { QString xmlParameter; QTextStream str(&xmlParameter); str << " <" << typeName << ">\n"; str << " " << QString("param%1").arg(index) << "\n"; str << " " << index << "\n"; str << " " << (description.isEmpty() ? "Description not available." : description) << "\n"; str << " \n"; str << " \n"; return xmlParameter; } }; // specialization for input image types template struct CreateXmlFor::value >::Type > { static QString parameter(int index, const QString& typeName, const QString& label = QString(), const QString& description = QString()) { QString xmlParameter; QTextStream str(&xmlParameter); str << " <" << typeName << ">\n"; str << " " << QString("param%1").arg(index) << "\n"; str << " " << index << "\n"; str << " " << (description.isEmpty() ? "Description not available." : description) << "\n"; str << " \n"; str << " input\n"; str << " \n"; return xmlParameter; } }; } } Q_DECLARE_METATYPE(QList*) struct ctkCmdLineModuleBackendFunctionPointerPrivate; /** * \class ctkCmdLineModuleBackendFunctionPointer * \brief Provides a back-end implementation to enable directly calling a function pointer. * \ingroup CommandLineModulesBackendFunctionPointer_API * * \warning This back-end is highly experimental and will not work for most function pointers when * trying to register them via registerFunctionPointer(). */ class CTK_CMDLINEMODULEBACKENDFP_EXPORT ctkCmdLineModuleBackendFunctionPointer : public ctkCmdLineModuleBackend { public: class DescriptionPrivate; class Description { public: Description(); ~Description(); QUrl moduleLocation() const; QString moduleCategory() const; void setModuleCategory(const QString &category); QString moduleTitle() const; void setModuleTitle(const QString& title); QString moduleDescription() const; void setModuleDescription(const QString& description); QString moduleVersion() const; void setModuleVersion(const QString& version); QString moduleContributor() const; void setModuleContributor(const QString& contributor); private: friend class ctkCmdLineModuleBackendFunctionPointer; friend class ctkCmdLineModuleFunctionPointerTask; Description(const QUrl& location, const ctk::CmdLineModuleBackendFunctionPointer::FunctionPointerProxy& fpProxy); QSharedPointer d; }; ctkCmdLineModuleBackendFunctionPointer(); ~ctkCmdLineModuleBackendFunctionPointer(); virtual QString name() const; virtual QString description() const; virtual QList schemes() const; virtual qint64 timeStamp(const QUrl &location) const; virtual QByteArray rawXmlDescription(const QUrl& location); QList registeredFunctionPointers() const; template Description* registerFunctionPointer(const QString& title, void (*fp)(A), const QString& paramLabel = QString(), const QString& paramDescr = QString()) { typedef typename ctk::CmdLineModuleBackendFunctionPointer::TypeTraits::RawType RawTypeA; QList params; params << ctk::CmdLineModuleBackendFunctionPointer::CreateXmlFor:: parameter(0, ctk::CmdLineModuleBackendFunctionPointer::GetParameterTypeName(), paramLabel, paramDescr); return this->registerFunctionPointerProxy(title, ctk::CmdLineModuleBackendFunctionPointer::FunctionPointerProxy(fp), params); } template Description* registerFunctionPointer(const QString& title, void (*fp)(A,B), const QString& paramLabel0 = QString(), const QString& paramDescr0 = QString(), const QString& paramLabel1 = QString(), const QString& paramDescr1 = QString()) { typedef typename ctk::CmdLineModuleBackendFunctionPointer::TypeTraits::RawType RawTypeA; typedef typename ctk::CmdLineModuleBackendFunctionPointer::TypeTraits::RawType RawTypeB; QList params; params << ctk::CmdLineModuleBackendFunctionPointer::CreateXmlFor:: parameter(0, ctk::CmdLineModuleBackendFunctionPointer::GetParameterTypeName(), paramLabel0, paramDescr0); params << ctk::CmdLineModuleBackendFunctionPointer::CreateXmlFor:: parameter(1, ctk::CmdLineModuleBackendFunctionPointer::GetParameterTypeName(), paramLabel1, paramDescr1); return this->registerFunctionPointerProxy(title, ctk::CmdLineModuleBackendFunctionPointer::FunctionPointerProxy(fp), params); } protected: virtual ctkCmdLineModuleFuture run(ctkCmdLineModuleFrontend* frontend); virtual QList arguments(ctkCmdLineModuleFrontend* frontend) const; private: Description* registerFunctionPointerProxy(const QString &title, const ctk::CmdLineModuleBackendFunctionPointer::FunctionPointerProxy& proxy, const QList& params); QScopedPointer d; }; #endif // CTKCMDLINEMODULEBACKENDFUNCTIONPOINTER_H