Computer Assisted Medical Intervention Tool Kit  version 6.0
Loading...
Searching...
No Matches
TransformEngine.h
Go to the documentation of this file.
1/*****************************************************************************
2 * $CAMITK_LICENCE_BEGIN$
3 *
4 * CamiTK - Computer Assisted Medical Intervention ToolKit
5 * (c) 2001-2025 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
6 *
7 * Visit http://camitk.imag.fr for more information
8 *
9 * This file is part of CamiTK.
10 *
11 * CamiTK is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * CamiTK is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22 *
23 * $CAMITK_LICENCE_END$
24 ****************************************************************************/
25#ifndef __TRANSFORM_ENGINE__
26#define __TRANSFORM_ENGINE__
27
28#include <QJsonObject>
29
220
222
223public:
227
229 TransformEngine(QDate currentDate, QTime currentTime);
230
232 bool setTemplateString(QString templateString);
233
241 // or a function (e.g. "/tmp/$upperCamelCase(name)$.h" will use upperCamelCase(data[name]) to determine the actual filename)
242 bool transformToFile(const QJsonObject& data, const QString& filename, bool overwrite = true);
243
247 QString transformToString(const QString& templateString, const QJsonObject& data);
248
249private:
251 QString templateString;
252
254 QDate currentDate;
255 QTime currentTime;
256
258 int indexInLoop;
259
261 int indexInSubLoop;
262
267 QString transformLoop(const QString& textToTransform, const QJsonObject& data);
268
274 QString transformCondition(const QString& textToTransform, const QJsonObject& data);
276
279 QString transformVariable(const QString& textToTransform, const QJsonObject& data);
280
283 QString transformFunctions(const QString& textToTransform, const QJsonObject& data);
284
293
325 QString transformConditionInLoop(const QString& loopContent, const QJsonObject& loopContentData, const QString& variableName);
326
330 QString transformVariableInLoop(const QString& loopContent, const QJsonObject& loopContentData, const QString& variableName);
331
334 QString transformFunctionsInLoop(const QString& loopContent, const QJsonObject& loopContentData, const QString& variableName);
335
337 QString transformLoopInLoop(const QString& loopContent, const QJsonObject& loopContentData, const QString& variableName);
339
345 QString genericTransform(const QString& textToTransform, const QString& regularExpression, const std::function<QString(const QStringList&)>& matchFunction, bool withoutTrailingSpace = false);
346
349 QString substring(const QString& str, int startIndex, int endIndex = -1);
350
352 QString extractLeadingSpaces(const QString& str);
353
355 QString removeTrailingSpaces(const QString& str);
356
358 QString titleCase(const QString& str, const QString& separator = "");
359
361 QString clean(const QString& str);
362
364 QString camelCase(const QString& str, const QString& separator = "");
365
368 QVariant valueOf(const QJsonObject& data, const QString& key, const QString& subkey = QString());
369
372 QString append(QStringList& result, const QString& str, int startIndex = -1, int endIndex = -1, bool removeTrailingSpace = false);
373 QString appendWithoutTrailingSpace(QStringList& result, const QString& str, int startIndex = -1, int endIndex = -1);
374
378 bool saveToFile(const QString& content, const QString& filename, bool overwrite = true);
379
381 QString evaluateFunction(const QString& functionName, const QJsonObject& data, const QString& parameter, const QString& parameterField);
383
384};
385
386#endif // __TRANSFORM_ENGINE__
bool transformToFile(const QJsonObject &data, const QString &filename, bool overwrite=true)
transform the current template string using the given data and save it to filename
Definition TransformEngine.cpp:75
bool setTemplateString(QString templateString)
set the current template string
Definition TransformEngine.cpp:67
QString transformToString(const QString &templateString, const QJsonObject &data)
transform the given template using the given data to a string.
Definition TransformEngine.cpp:102
TransformEngine()
Constructor set up the date and time.
Definition TransformEngine.cpp:55