CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkCmdLineModuleBackendFunctionPointer.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  Library: CTK
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =============================================================================*/
21 
22 #ifndef CTKCMDLINEMODULEBACKENDFUNCTIONPOINTER_H
23 #define CTKCMDLINEMODULEBACKENDFUNCTIONPOINTER_H
24 
26 
27 #include "ctkCommandLineModulesBackendFunctionPointerExport.h"
29 #include "ctkCmdLineModuleBackendFPUtil_p.h"
30 
31 #include <QScopedPointer>
32 #include <QSharedPointer>
33 #include <QString>
34 #include <QUrl>
35 #include <QMetaType>
36 
37 #include <QDebug>
38 
39 
40 namespace ctk {
41 namespace CmdLineModuleBackendFunctionPointer {
42 
43 struct FunctionPointerProxy;
44 
45 template<typename T>
47 
48 struct ImageType {};
49 
50 // default parameter description
51 template<typename T, typename Enable = void>
53 {
54  static QString parameter(int index, const QString& typeName, const QString& label = QString(), const QString& description = QString())
55  {
56  QString xmlParameter;
57  QTextStream str(&xmlParameter);
58  str << " <" << typeName << ">\n";
59  str << " <name>" << QString("param%1").arg(index) << "</name>\n";
60  str << " <index>" << index << "</index>\n";
61  str << " <description>" << (description.isEmpty() ? "Description not available." : description) << "</description>\n";
62  str << " <label>" << (label.isEmpty() ? QString("Parameter %1").arg(index) : label) << "</label>\n";
63  str << " </" << typeName << ">\n";
64  return xmlParameter;
65  }
66 };
67 
68 // specialization for input image types
69 template<typename T>
70 struct CreateXmlFor<T, typename EnableIf<IsBaseOf<ImageType, T>::value >::Type >
71 {
72  static QString parameter(int index, const QString& typeName, const QString& label = QString(), const QString& description = QString())
73  {
74  QString xmlParameter;
75  QTextStream str(&xmlParameter);
76  str << " <" << typeName << ">\n";
77  str << " <name>" << QString("param%1").arg(index) << "</name>\n";
78  str << " <index>" << index << "</index>\n";
79  str << " <description>" << (description.isEmpty() ? "Description not available." : description) << "</description>\n";
80  str << " <label>" << (label.isEmpty() ? QString("Parameter %1").arg(index) : label) << "</label>\n";
81  str << " <channel>input</channel>\n";
82  str << " </" << typeName << ">\n";
83  return xmlParameter;
84  }
85 };
86 
87 }
88 }
89 
91 
92 struct ctkCmdLineModuleBackendFunctionPointerPrivate;
93 
102 class CTK_CMDLINEMODULEBACKENDFP_EXPORT ctkCmdLineModuleBackendFunctionPointer : public ctkCmdLineModuleBackend
103 {
104 
105 public:
106 
107  class DescriptionPrivate;
108 
110  {
111  public:
112 
115 
116  QUrl moduleLocation() const;
117 
118  QString moduleCategory() const;
119  void setModuleCategory(const QString &category);
120 
121  QString moduleTitle() const;
122  void setModuleTitle(const QString& title);
123 
124  QString moduleDescription() const;
125  void setModuleDescription(const QString& description);
126 
127  QString moduleVersion() const;
128  void setModuleVersion(const QString& version);
129 
130  QString moduleContributor() const;
131  void setModuleContributor(const QString& contributor);
132 
133  private:
134 
136  friend class ctkCmdLineModuleFunctionPointerTask;
137  Description(const QUrl& location, const ctk::CmdLineModuleBackendFunctionPointer::FunctionPointerProxy& fpProxy);
138 
139  QSharedPointer<DescriptionPrivate> d;
140 
141  };
142 
145 
146  virtual QString name() const;
147  virtual QString description() const;
148 
149  virtual QList<QString> schemes() const;
150 
151  virtual qint64 timeStamp(const QUrl &location) const;
152 
153  virtual QByteArray rawXmlDescription(const QUrl& location, int timeout);
154 
156 
157  template<typename A>
158  Description* registerFunctionPointer(const QString& title, void (*fp)(A),
159  const QString& paramLabel = QString(), const QString& paramDescr = QString())
160  {
162 
163  QList<QString> params;
164  params << ctk::CmdLineModuleBackendFunctionPointer::CreateXmlFor<RawTypeA>::
165  parameter(0,
166  ctk::CmdLineModuleBackendFunctionPointer::GetParameterTypeName<RawTypeA>(),
167  paramLabel, paramDescr);
168  return this->registerFunctionPointerProxy(title, ctk::CmdLineModuleBackendFunctionPointer::FunctionPointerProxy(fp), params);
169  }
170 
171  template<typename A, typename B>
172  Description* registerFunctionPointer(const QString& title, void (*fp)(A,B),
173  const QString& paramLabel0 = QString(), const QString& paramDescr0 = QString(),
174  const QString& paramLabel1 = QString(), const QString& paramDescr1 = QString())
175  {
178 
179  QList<QString> params;
180  params << ctk::CmdLineModuleBackendFunctionPointer::CreateXmlFor<RawTypeA>::
181  parameter(0,
182  ctk::CmdLineModuleBackendFunctionPointer::GetParameterTypeName<RawTypeA>(),
183  paramLabel0, paramDescr0);
184  params << ctk::CmdLineModuleBackendFunctionPointer::CreateXmlFor<RawTypeB>::
185  parameter(1,
186  ctk::CmdLineModuleBackendFunctionPointer::GetParameterTypeName<RawTypeB>(),
187  paramLabel1, paramDescr1);
188  return this->registerFunctionPointerProxy(title, ctk::CmdLineModuleBackendFunctionPointer::FunctionPointerProxy(fp), params);
189  }
190 
191 protected:
192 
194 
196 
197 private:
198 
199  Description* registerFunctionPointerProxy(const QString &title,
200  const ctk::CmdLineModuleBackendFunctionPointer::FunctionPointerProxy& proxy,
201  const QList<QString>& params);
202 
203 
204  QScopedPointer<ctkCmdLineModuleBackendFunctionPointerPrivate> d;
205 
206 };
207 
208 
209 #endif // CTKCMDLINEMODULEBACKENDFUNCTIONPOINTER_H
void setModuleCategory(const QString &category)
void setModuleContributor(const QString &contributor)
void setModuleDescription(const QString &description)
Provides a back-end implementation to enable directly calling a function pointer.
virtual ctkCmdLineModuleFuture run(ctkCmdLineModuleFrontend *frontend)
The main method to actually execute the back-end process.
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())
virtual QList< QString > schemes() const
Returns a list of URL schemes this back-end can handle.
virtual QString name() const
Returns the name of the type of the backend, not the name of the thing or application that is run.
Description * registerFunctionPointer(const QString &title, void(*fp)(A), const QString &paramLabel=QString(), const QString &paramDescr=QString())
virtual qint64 timeStamp(const QUrl &location) const
Returns a timestap of the backend, which for example in the case of the LocalProcess may be the last ...
virtual QList< QVariant > arguments(ctkCmdLineModuleFrontend *frontend) const
virtual QString description() const
Returns a brief description of the type of the backend.
QList< QUrl > registeredFunctionPointers() const
virtual QByteArray rawXmlDescription(const QUrl &location, int timeout)
Get the XML parameter description from the given location.
Abstract base class for all front-end command line module implementations.
QFuture sub-class for enhanced communication with running modules.
Select< isPointer, typename UnConst< PointeeType >::Result, typename Select< isReference, typename UnConst< ReferenceType >::Result, typename UnConst< T >::Result >::Result >::Result RawType
Q_DECLARE_METATYPE(ctkDICOMPersonName)
Abstract base class for all back-end command line module implementations.
static QString parameter(int index, const QString &typeName, const QString &label=QString(), const QString &description=QString())
static QString parameter(int index, const QString &typeName, const QString &label=QString(), const QString &description=QString())