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
221
222public:
226
228 TransformEngine(QDate currentDate, QTime currentTime);
229
231 bool setTemplateString(QString templateString);
232
240 // or a function (e.g. "/tmp/$upperCamelCase(name)$.h" will use upperCamelCase(data[name]) to determine the actual filename)
241 bool transformToFile(const QJsonObject& data, const QString& filename, bool overwrite = true);
242
246 QString transformToString(const QString& templateString, const QJsonObject& data);
247
248private:
250 QString templateString;
251
253 QDate currentDate;
254 QTime currentTime;
255
257 int indexInLoop;
258
260 int indexInSubLoop;
261
266 QString transformLoop(const QString& textToTransform, const QJsonObject& data);
267
273 QString transformCondition(const QString& textToTransform, const QJsonObject& data);
275
278 QString transformVariable(const QString& textToTransform, const QJsonObject& data);
279
282 QString transformFunctions(const QString& textToTransform, const QJsonObject& data);
283
292
324 QString transformConditionInLoop(const QString& loopContent, const QJsonObject& loopContentData, const QString& variableName);
325
329 QString transformVariableInLoop(const QString& loopContent, const QJsonObject& loopContentData, const QString& variableName);
330
333 QString transformFunctionsInLoop(const QString& loopContent, const QJsonObject& loopContentData, const QString& variableName);
334
336 QString transformLoopInLoop(const QString& loopContent, const QJsonObject& loopContentData, const QString& variableName);
338
344 QString genericTransform(const QString& textToTransform, const QString& regularExpression, const std::function<QString(const QStringList&)>& matchFunction, bool withoutTrailingSpace = false);
345
348 QString substring(const QString& str, int startIndex, int endIndex = -1);
349
351 QString extractLeadingSpaces(const QString& str);
352
354 QString removeTrailingSpaces(const QString& str);
355
357 QString titleCase(const QString& str, const QString& separator = "");
358
360 QString clean(const QString& str);
361
363 QString camelCase(const QString& str, const QString& separator = "");
364
367 QVariant valueOf(const QJsonObject& data, const QString& key, const QString& subkey = QString());
368
371 QString append(QStringList& result, const QString& str, int startIndex = -1, int endIndex = -1, bool removeTrailingSpace = false);
372 QString appendWithoutTrailingSpace(QStringList& result, const QString& str, int startIndex = -1, int endIndex = -1);
373
377 bool saveToFile(const QString& content, const QString& filename, bool overwrite = true);
378
380 QString evaluateFunction(const QString& functionName, const QJsonObject& data, const QString& parameter, const QString& parameterField);
382
383};
384
385#endif // __TRANSFORM_ENGINE__
Utility class to transform strings depending on json object values.
Definition TransformEngine.h:220
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