Documentation for OpenFLUID 2.2.0
MiscHelpers.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 MiscHelpers.hpp
35 
36  @author Jean-Christophe Fabre <jean-christophe.fabre@inra.fr>
37 */
38 
39 
40 #ifndef __OPENFLUID_TOOLS_MISCHELPERS_HPP__
41 #define __OPENFLUID_TOOLS_MISCHELPERS_HPP__
42 
43 
44 #include <vector>
45 #include <string>
46 #include <cmath>
47 
48 #include <openfluid/dllexport.hpp>
49 #include <openfluid/core/TypeDefs.hpp>
50 
51 
52 #define STRINGIFY(x) XSTRINGIFY(x)
53 #define XSTRINGIFY(x) #x
54 
55 
56 namespace openfluid { namespace tools {
57 
58 
59 /**
60  Checks if the given string matches the given pattern, including * and ? wildcards
61  @param[in] Pattern The pattern to match
62  @param[in] Str The string to test
63  @return true if the given string matches the given pattern
64 */
65 bool OPENFLUID_API matchWithWildcard(const std::string& Pattern, const std::string& Str);
66 
67 
68 /**
69  Replaces a string by another string if it is empty
70  @param[in] SourceStr the source string to process
71  @param[in] ReplaceStr the replacement string to use
72  @return the processed string
73 */
74 std::string OPENFLUID_API replaceEmptyString(std::string SourceStr,
75  const std::string& ReplaceStr);
76 
77 
78 /**
79  Compares two OpenFLUID software versions. Only numeric numbers are accepted (no alphabetic character)
80  @param[in] VersionA the first version number
81  @param[in] VersionB the second version number
82  @return 1 if VersionA is greater than VersionB,
83  -1 if VersionB is greater than VersionA,
84  0 if versions are equals,
85  -2 if a version format is not well-formed
86 */
87 int OPENFLUID_API compareVersions(const std::string& VersionA, const std::string& VersionB);
88 
89 
90 /**
91  Compares two OpenFLUID software versions. Version number must be formed as major.minor.patch[~status]
92  @param[in] VersionA the first version number
93  @param[in] VersionB the second version number
94  @param[in] Strict If true, the comparison include the status part of the version (it ignores it otherwise)
95  @return 1 if VersionA is greater than VersionB,
96  -1 if VersionB is greater than VersionA,
97  0 if versions are equals,
98  -2 if a version format is not well-formed
99 */
100 int OPENFLUID_API compareOpenFLUIDVersions(const std::string& VersionA, const std::string& VersionB,
101  bool Strict = true);
102 
103 
104 /**
105  Suspends execution of current thread for milliseconds
106  @param[in] MSec the milliseconds interval
107 */
108 void OPENFLUID_API millisleep(const unsigned long MSec);
109 
110 
111 /**
112  Suspend execution of current thread for microseconds
113  @param[in] USec the microseconds interval
114 */
115 void OPENFLUID_API microsleep(const unsigned long USec);
116 
117 
118 /**
119  Returns the current date and time as a formatted string
120  @param[in] Format an strftime()-like format string
121  @return the formatted date-time
122 */
123 std::string OPENFLUID_API getNowAsString(const std::string& Format); // TODO to replace by DateTime::now()
124 
125 
126 /**
127  Generates a pseudo-unique identifier using alphanumeric characters and Mersenne Twister random engine.
128  @param[in] Length the length of the identifier to generate
129  @return the generated identifier
130 */
131 std::string OPENFLUID_API generatePseudoUniqueIdentifier(const unsigned int Length);
132 
133 
134 /**
135  Returns the given regex pattern string with special chars that are escaped
136  @param[in] Str the regex pattern
137  @return the regex pattern with special chars that are escaped
138 */
139 std::string OPENFLUID_API escapePattern(const std::string& Str);
140 
141 
142 /**
143  Returns the given string with special chars that are escaped
144  @param[in] Str the string
145  @return the string with special chars that are escaped
146 */
147 std::string OPENFLUID_API escapeString(const std::string& Str);
148 
149 
150 /**
151  Returns a pair of integer values extracted from a geometry string
152  @param[in] Str the geometry string (e.g. "@Point(127 82)", "@Size(1024 768)")
153  @param[in] GeomInfo the expected geometry information type (e.g. "Point", "Size")
154  @return the pair of values extracted from the geometry string
155 */
156 std::pair<int,int> OPENFLUID_API fromGeometryString(const std::string& Str, const std::string& GeomInfo);
157 
158 
159 /**
160  Returns a geometry string from a geometry info type and a pair of integer values
161  @param[in] GeomInfo the geometry information type (e.g. "Point", "Size")
162  @param[in] Value1 the first value
163  @param[in] Value2 the second value
164  @return the geometry string
165 */
166 std::string OPENFLUID_API toGeometryString(const std::string& GeomInfo, int Value1, int Value2);
167 
168 
169 } } //namespaces
170 
171 
172 #endif /* __OPENFLUID_TOOLS_MISCHELPERS_HPP__ */
173 
#define OPENFLUID_API
Definition: dllexport.hpp:86
void OPENFLUID_API microsleep(const unsigned long USec)
std::string OPENFLUID_API replaceEmptyString(std::string SourceStr, const std::string &ReplaceStr)
bool OPENFLUID_API matchWithWildcard(const std::string &Pattern, const std::string &Str)
std::string OPENFLUID_API toGeometryString(const std::string &GeomInfo, int Value1, int Value2)
std::string OPENFLUID_API generatePseudoUniqueIdentifier(const unsigned int Length)
std::pair< int, int > OPENFLUID_API fromGeometryString(const std::string &Str, const std::string &GeomInfo)
std::string OPENFLUID_API escapeString(const std::string &Str)
std::string OPENFLUID_API escapePattern(const std::string &Str)
int OPENFLUID_API compareOpenFLUIDVersions(const std::string &VersionA, const std::string &VersionB, bool Strict=true)
std::string OPENFLUID_API getNowAsString(const std::string &Format)
int OPENFLUID_API compareVersions(const std::string &VersionA, const std::string &VersionB)
void OPENFLUID_API millisleep(const unsigned long MSec)
Definition: ApplicationException.hpp:47