All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 /**
35  @file MiscHelpers.hpp
36 
37  @author Jean-Christophe Fabre <jean-christophe.fabre@supagro.inra.fr>
38 */
39 
40 
41 #ifndef __OPENFLUID_TOOLS_MISCHELPERS_HPP__
42 #define __OPENFLUID_TOOLS_MISCHELPERS_HPP__
43 
44 
45 #include <vector>
46 #include <string>
47 #include <cmath>
48 
49 #include <openfluid/dllexport.hpp>
50 #include <openfluid/core/TypeDefs.hpp>
51 
52 
53 namespace openfluid { namespace core {
54  class DateTime;
55 } }
56 
57 
58 #define STRINGIFY(x) XSTRINGIFY(x)
59 #define XSTRINGIFY(x) #x
60 
61 
62 namespace openfluid { namespace tools {
63 
64 
65 /**
66  Checks if the given string matches the given pattern, including * and ? wildcards
67  @param[in] Pattern The pattern to match
68  @param[in] Str The string to test
69  @return true if the given string matches the given pattern
70 */
71 bool OPENFLUID_API matchWithWildcard(const std::string& Pattern, const std::string& Str);
72 
73 
74 /**
75  Replaces a string by another string if it is empty
76  @param[in] SourceStr the source string to process
77  @param[in] ReplaceStr the replacement string to use
78  @return the processed string
79 */
80 std::string OPENFLUID_API replaceEmptyString(std::string SourceStr,
81  const std::string& ReplaceStr);
82 
83 
84 /**
85  Removes trailing slashes if any, useful for cleaning paths
86  @param[in] Str the string to process
87  @return the processed string
88 */
89 std::string OPENFLUID_API removeTrailingSlashes(const std::string& Str);
90 
91 
92 /**
93  Compares two OpenFLUID software versions. Version number must be formed as major.minor.patch[~status]
94  @param[in] VersionA the first version number
95  @param[in] VersionB the second version number
96  @param[in] Strict If true, the comparison include the status part of the version (it ignores it otherwise)
97  @return 1 if VersionA is greater than VersionB,
98  -1 if VersionB is greater than VersionA,
99  0 if versions are equals,
100  -2 if a version format is not well-formed
101 */
102 int OPENFLUID_API compareVersions(const std::string& VersionA, const std::string& VersionB, bool Strict = true);
103 
104 
105 /*
106  Suspend execution of current thread for milliseconds
107  @param[in] MSec the milliseconds interval
108 */
109 void OPENFLUID_API millisleep(const unsigned long MSec);
110 
111 
112 /*
113  Suspend execution of current thread for microseconds
114  @param[in] USec the microseconds interval
115 */
116 void OPENFLUID_API microsleep(const unsigned long USec);
117 
118 
119 
120 std::string OPENFLUID_API generatePseudoUniqueIdentifier(const unsigned int Length);
121 
122 
123 } } //namespaces
124 
125 
126 #endif // __OPENFLUID_TOOLS_MISCHELPERS_HPP__
127 
std::string OPENFLUID_API removeTrailingSlashes(const std::string &Str)
int OPENFLUID_API compareVersions(const std::string &VersionA, const std::string &VersionB, bool Strict=true)
std::string OPENFLUID_API generatePseudoUniqueIdentifier(const unsigned int Length)
void OPENFLUID_API millisleep(const unsigned long MSec)
bool OPENFLUID_API matchWithWildcard(const std::string &Pattern, const std::string &Str)
#define OPENFLUID_API
Definition: dllexport.hpp:87
void OPENFLUID_API microsleep(const unsigned long USec)
std::string OPENFLUID_API replaceEmptyString(std::string SourceStr, const std::string &ReplaceStr)