00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00056 #ifndef __SWISSTOOLS_HPP__
00057 #define __SWISSTOOLS_HPP__
00058
00059 #include <vector>
00060 #include <string>
00061 #include <sstream>
00062 #include <cmath>
00063
00064 #include <openfluid/dllexport.hpp>
00065 #include <openfluid/core.hpp>
00066
00067 namespace openfluid { namespace tools {
00068
00075 template<typename T>
00076 inline bool ConvertString(const std::string& StrToConvert, T* Converted)
00077 {
00078 std::istringstream iss(StrToConvert);
00079 return !(iss >> (*Converted)).fail();
00080 }
00081
00082
00083
00084
00091 template<typename T>
00092 inline bool ConvertValue(const T ValueToConvert, std::string * StrConverted)
00093 {
00094 std::ostringstream oss;
00095 bool IsOK = !(oss << ValueToConvert).fail();
00096
00097 if (IsOK) *StrConverted = oss.str();
00098
00099 return IsOK;
00100 }
00101
00102
00103
00104
00105
00112 void DLLEXPORT TokenizeString(const std::string& StrToTokenize,
00113 std::vector<std::string>& Tokens,
00114 const std::string& Delimiters);
00115
00116
00117
00118
00119
00130 inline bool IsCloseEnough(double A, double B, double Epsilon = 0.00001)
00131 {
00132
00133 return ((std::fabs(A - B)) <= (Epsilon * std::fabs(A)));
00134 }
00135
00136
00137
00138
00139
00140
00151 inline bool IsVeryClose(double A, double B, double Epsilon = 0.00001)
00152 {
00153
00154 return (((std::fabs(A - B)) <= (Epsilon * std::fabs(A))) && ((std::fabs(A - B)) <= (Epsilon * std::fabs(B))));
00155 }
00156
00157
00158
00159
00160
00161
00162 bool DLLEXPORT WildcardMatching(const std::string Pattern, const std::string Str);
00163
00164
00165
00166
00167
00168
00169
00170
00178 std::vector<std::string> DLLEXPORT GetFilesByExt(const std::string DirToExplore,
00179 const std::string Ext,
00180 bool WithPath = false,
00181 bool ExtIncludeDot = false);
00182
00190 std::vector<std::string> DLLEXPORT SplitString(const std::string StrToSplit,
00191 const std::string Separators,
00192 bool ReturnsEmpty = false);
00193
00194 bool DLLEXPORT EmptyDirectoryRecursively(const std::string DirPath);
00195
00196 std::string DLLEXPORT ReplaceEmptyString(std::string SourceStr, std::string ReplaceStr);
00197
00198 bool DLLEXPORT IsVectorNamedVariable(std::string Name);
00199
00200 std::string DLLEXPORT GetVectorNamedVariableName(std::string Name);
00201
00202 std::string DLLEXPORT RemoveTrailingSlashes(std::string Str);
00203
00204 void DLLEXPORT printSTDOUT(std::vector<std::string> Strings, std::string Sep);
00205
00206 openfluid::core::DateTime DLLEXPORT GenerateDateTimeFromStep(openfluid::core::DateTime DT0, openfluid::core::TimeStep_t TS, unsigned int CurrentStep);
00207
00208 void DLLEXPORT CopyDirectoryRecursively(const std::string SourcePath, const std::string IntoPath, const bool DontCopyDotDirs = false);
00209
00210 std::vector<std::string> DLLEXPORT GetFileLocationsUsingPATHEnvVar(const std::string Filename);
00211
00212
00213 } }
00214
00215
00216 #endif // __SWISSTOOLS_H__
00217