itom
Loading...
Searching...
No Matches
paramHelper.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2022, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21*********************************************************************** */
22
23#pragma once
24
25#include "addInMgrDefines.h"
26#include "../common/sharedStructures.h"
27#include "../common/param.h"
28#include "../common/paramMeta.h"
29
30#include <qmap.h>
31#include <qsharedpointer.h>
32
33namespace ito
34{
35 class AddInBase; // forward declaration
36 class DataObject; // forward declaration
37
38 class ADDINMGR_EXPORT ParamHelper
39 {
40 public:
41
42 static tCompareResult compareParam(const ito::Param &paramTemplate, const ito::Param &param, ito::RetVal &ret);
43 static tCompareResult compareMetaParam(const ito::ParamMeta *metaTemplate, const ito::ParamMeta *meta, const char* nameTemplate, const char *name, ito::RetVal &ret);
44
46 /*
47 \param meta is the meta information or nullptr if no meta restrictions
48 are given (every value is valid).
49 \param value is the value to be checked
50 \param mandatory must be true, if an error is also returned in value is nullptr
51 \param name is the name of the parameter.
52 \return ito::retOk if the value fits to meta or ito::retError if the
53 value does either not fit to the meta information or if its not
54 given, but mandatory.
55 \sa validateParam, validateAndCastParam
56 */
57 static ito::RetVal validateStringMeta(const ito::StringMeta *meta, const char* value, bool mandatory = false, const char* name = nullptr);
58
60 /*
61 \param meta is the meta information or nullptr if no meta restrictions
62 are given (every value is valid).
63 \param value is the value to be checked
64 \param name is the name of the parameter.
65 \return ito::retOk if the value fits to meta, else ito::retError
66 \sa validateParam, validateAndCastParam
67 */
68 static ito::RetVal validateDoubleMeta(const ito::DoubleMeta *meta, double value, const char* name = nullptr);
69
71 /*
72 This method also verifies, if the value fits to an optionally given
73 step size of the meta information and rounds the wrapped value to the
74 next valid value (if allowRounding is true).
75
76 \param meta is the meta information or nullptr if no meta restrictions
77 are given (every value is valid).
78 \param value is the value to be checked
79 \param allowRounding is true, if an optional rounding according to the
80 step size of the meta information should be done on the fly.
81 \param name is the name of the parameter.
82 \return ito::retOk if the value fits to meta, else ito::retError
83 \sa validateParam, validateAndCastParam
84 */
85 static ito::RetVal validateDoubleMetaAndRoundToStepSize(const ito::DoubleMeta *meta, ito::ParamBase &doubleParam, bool allowRounding = true, const char* name = nullptr);
86
88 /*
89 This method also verifies, if the value fits to an optionally given
90 step size of the meta information and rounds the wrapped value to the
91 next valid value (if allowRounding is true).
92
93 \param meta is the meta information or nullptr if no meta restrictions
94 are given (every value is valid).
95 \param value is the value to be checked
96 \param allowRounding is true, if an optional rounding according to the
97 step size of the meta information should be done on the fly.
98 \param name is the name of the parameter.
99 \return ito::retOk if the value fits to meta, else ito::retError
100 \sa validateParam, validateAndCastParam
101 */
102 static ito::RetVal validateDoubleMetaAndRoundToStepSize(const ito::DoubleMeta *meta, double &value, bool allowRounding = true, const char* name = nullptr);
103 static ito::RetVal validateIntMeta(const ito::IntMeta *meta, int value, const char* name = nullptr);
104 static ito::RetVal validateCharMeta(const ito::CharMeta *meta, char value, const char* name = nullptr);
105 static ito::RetVal validateDObjMeta(const ito::DObjMeta *meta, const ito::DataObject* value, bool mandatory = false, const char* name = nullptr);
106 static ito::RetVal validateCharArrayMeta(const ito::ParamMeta *meta, const char* values, size_t len, const char* name = nullptr);
107 static ito::RetVal validateIntArrayMeta(const ito::ParamMeta *meta, const int* values, size_t len, const char* name = nullptr);
108 static ito::RetVal validateDoubleArrayMeta(const ito::ParamMeta *meta, const double* values, size_t len, const char* name = nullptr);
109 static ito::RetVal validateStringListMeta(const ito::ParamMeta *meta, const ito::ByteArray* values, size_t len, const char* name = nullptr);
110 static ito::RetVal validateHWMeta(const ito::HWMeta *meta, ito::AddInBase *value, bool mandatory = false, const char* name = nullptr);
111
112 static ito::RetVal validateParam(const ito::Param &templateParam, const ito::ParamBase &param, bool strict = true, bool mandatory = false);
113 static ito::RetVal validateAndCastParam(const ito::Param &templateParam, ito::ParamBase &param, bool strict = true, bool mandatory = false, bool roundToSteps = false);
114 static ito::ParamBase convertParam(const ito::ParamBase &source, int destType, bool *ok = nullptr);
115
116 static ito::RetVal getParamFromMapByKey( QMap<QString,ito::Param> &paramMap, const QString &key, QMap<QString,ito::Param>::iterator &found, bool errorIfReadOnly);
117
119 /*
120 Valid parameter keys are:
121
122 * name
123 * name[index]
124 * name:suffix
125 * name[index]:suffix
126
127 where index must be a number.
128
129 \param key is the full parameter name with optional suffix, index etc.
130 \param paramName is the name of the parameter, used in a possible error return value
131 \param hasIndex is true, if an index is set
132 \param index is the parsed index or -1, if no index is given
133 \param additionalTag is the optional suffix, or an empty string
134 \return ito::retOk if key could be properly parsed, else ito::retError.
135 */
136 static ito::RetVal parseParamName(const QString &key, QString &paramName, bool &hasIndex, int &index, QString &additionalTag);
137
138 static ito::RetVal getItemFromArray(const ito::Param &arrayParam, const int index, ito::Param &itemParam);
139 static ito::Param getParam(const ito::Param &param, const bool hasIndex, const int index, ito::RetVal &ret);
140
141 static ito::RetVal updateParameters(QMap<QString, ito::Param> &paramMap, const QVector<QSharedPointer<ito::ParamBase> > &values);
142
143 private:
144 static bool fitToDoubleStepSize(double min, double step, double val);
145 static QString parseNamePrefix(const char *name);
146
147 ParamHelper() = delete;
148 ~ParamHelper() = delete;
149 };
150
151} //end namespace ito
Base class for all plugins.
Definition addInInterface.h:386
This is a Qt-free class for byte arrays (strings) without specific encoding information.
Definition byteArray.h:65
meta-information for Param of type Char.
Definition paramMeta.h:160
Meta-information for Param of type DObjPtr.
Definition paramMeta.h:594
dataObject contains a n-dimensional matrix
Definition dataobj.h:591
Meta-information for ito::Param of type Double.
Definition paramMeta.h:346
Meta-information for Param of type HWPtr.
Definition paramMeta.h:469
Meta-information for Param of type Int.
Definition paramMeta.h:253
<
Definition param.h:95
Definition paramHelper.h:39
class for parameter handling e.g. to pass parameters to plugins
Definition param.h:477
Base class for all meta-information classes.
Definition paramMeta.h:58
Class for managing status values (like errors or warning)
Definition retVal.h:54
Meta-information for Param of type String.
Definition paramMeta.h:527
Definition apiFunctionsGraph.cpp:40
PyObject * getParam(ito::AddInBase *addInObj, PyObject *args)
Definition pythonPlugins.cpp:770
tCompareResult
Definition typeDefs.h:67
ITOMCOMMONQT_EXPORT ito::RetVal parseParamName(const QString &key, QString &paramName, bool &hasIndex, int &index, QString &additionalTag)
searches and returns a parameter from a map based on its full key.
Definition helperCommon.cpp:676