Documentation for OpenFLUID 2.2.0
IDHelpers.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file IDHelpers.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37  @author Armel THÖNI <armel.thoni@inrae.fr>
38  @author Dorian GERARDIN <dorian.gerardin@inrae.fr>
39 */
40 
41 
42 #ifndef __OPENFLUID_TOOLS_IDHELPERS_HPP__
43 #define __OPENFLUID_TOOLS_IDHELPERS_HPP__
44 
45 
46 #include <regex>
47 #include <string>
48 
49 #include <openfluid/core/TypeDefs.hpp>
51 #include <openfluid/dllexport.hpp>
53 
54 
55 namespace openfluid { namespace tools {
56 
57 
58 // constant regex used for validation
59 // auto stands for char[] here
60 // char[] used instead of string since not compatible with constexpr up to C++ 17 (TOWATCH)
61 
62 
63 // authorized chars: a to z, A to Z, 0 to 9, -, ., _
64 // must start by an alphanumeric char
65 constexpr auto DatasetNameRuleString("[A-Za-z0-9]+([A-Za-z0-9_\\.\\-]*)");
66 
67 constexpr auto WareIDRuleString("[A-Za-z0-9]+([A-Za-z0-9_\\.\\-]*)");
68 constexpr auto WareIDRuleStringAndTpl("[A-Za-z0-9]+([A-Za-z0-9_@\\.\\-]*)");
69 
70 constexpr auto FragmentNameRuleString("[A-Za-z]+([A-Za-z0-9_\\.\\-]*)");
71 
72 
73 // authorized chars: a to z, A to Z, 0 to 9, -, ., _
74 // must start by an alphabetic char
75 constexpr auto VariableNameRuleString("[A-Za-z]+([A-Za-z0-9_\\.\\-]*)");
76 
77 constexpr auto UnitsClassNameRuleString("^[^;:#]+$");
78 
79 
80 /**
81  Generates string from class and ID of a spatial unit using the "Class#ID" pattern.
82  @param[in] Class The units class
83  @param[in] ID The unit ID
84  @return the generated string
85 */
87 
88 
89 /**
90  Checks whether an alphanumeric name is valid or not.\n
91  To be valid, a name must only contain alphanumeric characters.
92  @param[in] Name the name to check
93  @return true if the name is valid
94 */
95 bool OPENFLUID_API isValidAlphaNumName(const std::string& Name);
96 
97 
98 /**
99  Checks whether a dataset or project name is valid or not.\n
100  To be valid, a name must only contain alphanumeric, '_', '-', '.' characters,
101  and must begin by an alphanumeric character.
102  @param[in] Name the name to check
103  @return true if the name is valid
104 */
105 bool OPENFLUID_API isValidDatasetName(const std::string& Name);
106 
107 
108 /**
109  Checks whether a ware ID is valid or not.\n
110  To be valid, a ware ID must only contain alphanumeric, '_', '-', '.' characters,
111  and must begin by an alphanumeric character.
112  @param[in] ID the ware ID to check
113  @param[in] Template True to enable a template on the ware ID
114  @return true if the ID is valid
115 */
116 bool OPENFLUID_API isValidWareID(const openfluid::ware::WareID_t& ID, bool Template=false);
117 
118 
119 /**
120  Checks whether a units classe name is valid or not.\n
121  To be valid, a units class name must not contain any of ';', ':' and '#' characters,
122  @param[in] Name the units class name to check
123  @return true if the name is valid
124 */
126 
127 
128 /**
129  Checks whether a variable name (without type) is valid or not.\n
130  To be valid, a variable name must only contain alphanumeric, '_', '-' or '.' characters,
131  and must begin by an alphanumeric character.
132  @param[in] Name the variable name to check
133  @return true if the name is valid
134 */
136 
137 
138 /**
139  Checks whether a variable sequence (without type) is valid or not.\n
140  To be valid, a sequence must contain triplets of variable separated by ';'
141  @return the regex as string (for compatibility reasons)
142 */
144 
145 
146 /**
147  Checks whether a variable name (with or without type) is valid or not.\n
148  To be valid, a variable name must only contain alphanumeric, '_', '-' or '.' characters,
149  must begin by an alphanumeric character, and can be suffixed by a valid type into square brackets.
150  @param[in] Name the variable name to check
151  @return true if the name is valid
152 */
154 
155 
156 /**
157  Checks whether an attribute name is valid or not.\n
158  To be valid, an attribute name must only contain alphanumeric, '_', '-' or '.' characters,
159  and must begin by an alphanumeric character.
160  @param[in] Name the attribute name to check
161  @return true if the name is valid
162 */
164 
165 
166 /**
167  Checks and extracts variable name and type from a full variable name (with or without type).\n
168  To be valid, a variable name must only contain alphanumeric, '_', '-' or '.' characters,
169  must begin by an alphanumeric character, and can be suffixed by a valid type into square brackets.
170  @param[in] Name the variable name to process
171  @param[out] VarName the extracted variable name
172  @param[out] VarType the extracted variable type
173  @return true if the check and extraction are OK
174 */
178 
179 
180 /**
181  Builds a generator ID
182  @param[in] VarPairs Pair of unit classes/variables to create the generator ID
183  @param[in] StrDimType Dimension type of generator
184 */
186  const std::string& StrDimType);
187 
188 
189 } } // namespaces
190 
191 
192 #endif /* __OPENFLUID_TOOLS_IDHELPERS_HPP__ */
Type
Definition: Value.hpp:66
#define OPENFLUID_API
Definition: dllexport.hpp:86
unsigned int UnitID_t
Definition: TypeDefs.hpp:70
std::string VariableName_t
Definition: TypeDefs.hpp:131
std::string UnitsClass_t
Definition: TypeDefs.hpp:98
std::string AttributeName_t
Definition: TypeDefs.hpp:117
constexpr auto FragmentNameRuleString("[A-Za-z]+([A-Za-z0-9_\\.\\-]*)")
bool OPENFLUID_API isValidUnitsClassName(const openfluid::core::UnitsClass_t &Name)
bool OPENFLUID_API isValidVariableName(const openfluid::core::VariableName_t &Name)
bool OPENFLUID_API isValidDatasetName(const std::string &Name)
constexpr auto DatasetNameRuleString("[A-Za-z0-9]+([A-Za-z0-9_\\.\\-]*)")
constexpr auto VariableNameRuleString("[A-Za-z]+([A-Za-z0-9_\\.\\-]*)")
bool OPENFLUID_API isValidTypedVariableName(const openfluid::core::VariableName_t &Name)
std::string OPENFLUID_API buildGeneratorID(const openfluid::tools::UnitVarPairs_t &VarPairs, const std::string &StrDimType)
constexpr auto WareIDRuleStringAndTpl("[A-Za-z0-9]+([A-Za-z0-9_@\\.\\-]*)")
std::string OPENFLUID_API classIDToString(const openfluid::core::UnitsClass_t &Class, openfluid::core::UnitID_t ID)
bool OPENFLUID_API extractVariableNameAndType(const openfluid::core::VariableName_t &Name, openfluid::core::VariableName_t &VarName, openfluid::core::Value::Type &VarType)
constexpr auto WareIDRuleString("[A-Za-z0-9]+([A-Za-z0-9_\\.\\-]*)")
bool OPENFLUID_API isValidAttributeName(const openfluid::core::AttributeName_t &Name)
std::vector< UnitVarPair > UnitVarPairs_t
Definition: VarHelpers.hpp:168
std::string OPENFLUID_API getVariableSelectionRegExp()
bool OPENFLUID_API isValidAlphaNumName(const std::string &Name)
constexpr auto UnitsClassNameRuleString("^[^;:#]+$")
bool OPENFLUID_API isValidWareID(const openfluid::ware::WareID_t &ID, bool Template=false)
std::string WareID_t
Definition: TypeDefs.hpp:49
Definition: ApplicationException.hpp:47