65 std::filesystem::path temp_dir = std::filesystem::temp_directory_path();
68 auto now = std::chrono::system_clock::now();
70 = std::chrono::duration_cast< std::chrono::milliseconds >(now.time_since_epoch()).count();
75 =
"tempfile_" + std::to_string(timestamp) +
"_" + std::to_string(dis) +
".tmp";
78 std::filesystem::path temp_file_path = temp_dir / filename;
80 return temp_file_path.string();
83 bool endsWith(std::string
const& value, std::string
const& ending) {
84 if (ending.size() > value.size())
return false;
85 return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
88 std::vector< std::string >
split(
const std::string& str,
const std::string& delim) {
89 std::vector< std::string > tokens;
90 size_t prev = 0, pos = 0;
92 pos = str.find(delim, prev);
93 if (pos == std::string::npos) pos = str.length();
94 std::string token = str.substr(prev, pos - prev);
95 if (!token.empty()) tokens.push_back(token);
96 prev = pos + delim.length();
97 }
while (pos < str.length() && prev < str.length());
112 std::string
replace(
const std::string& s,
const std::string& val,
const std::string& new_val) {
114 auto pos = retVal.find(val);
115 while (pos != std::string::npos) {
116 std::stringstream sBuff;
117 sBuff << s.substr(0, pos) << new_val << s.substr(pos + val.size(), std::string::npos);
118 retVal = sBuff.str();
119 pos = retVal.find(val);
125 if (val.empty())
return false;
127 if ((val[0] ==
'+') || (val[0] ==
'-')) { pos = 1; }
129 if (val.find_first_not_of(
"0123456789", pos) != std::string::npos)
return false;
131 if (res !=
nullptr) {
132 const char* p = (val[0] ==
'+') ? 1 + val.c_str() : val.c_str();
140 char* endptr =
nullptr;
141 const char* str = val.c_str();
142 double d = std::strtod(str, &endptr);
144 if (*endptr !=
'\0' || endptr == str)
return false;
145 if (res !=
nullptr) *res = d;
std::string getUniqueFileName()
Returns a path to a unique file name.
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
bool isNumericalWithResult(const std::string &val, double *res)
return true is a string contains a numerical (double) value
std::string replace(const std::string &s, const std::string &val, const std::string &new_val)
not usable for gcc 4.8 std::vector<std::string> split( const std::string& orig, ...
bool isIntegerWithResult(const std::string &val, int *res)
return true is a string contains an integer value
std::vector< std::string > split(const std::string &str, const std::string &delim)
Split str using the delimiter.
bool endsWith(std::string const &value, std::string const &ending)
Returns true if value ends with ending.
gum is the global namespace for all aGrUM entities
Contains useful methods for random stuff.
Utilities for manipulating strings.
Contains usefull methods for random stuff.