29 #define STRINGIFY(x) #x
42 #if __cplusplus >= 201103L || _MSC_VER >= 1600
43 template <
class C,
size_t N>
46 static_assert(!std::is_same<C[N],
char[N]>::value,
"Character arrays are not allowed");
47 std::ostringstream convert;
58 std::ostringstream convert;
65 inline bool starts_with(
const std::string & haystack,
const std::string & needle )
67 std::string::const_iterator it1 = haystack.begin();
68 std::string::const_iterator it2 = needle.begin();
69 while ( it2!=needle.end() )
71 if ( it1 == haystack.end() || *it1 != *it2)
return false;
79 inline bool ends_with(
const std::string & haystack,
const std::string & needle )
81 if (needle.size() > haystack.size())
return false;
83 return std::equal(needle.rbegin(), needle.rend(), haystack.rbegin());
86 #if __cplusplus > 199711L || _MSC_VER >= 1600
95 template<
class ForwardIterator,
class T>
96 void iota(ForwardIterator first, ForwardIterator last, T value)
98 while(first != last) {
105 inline int stoi(
const std::string& str)
107 std::istringstream ss(str);
109 if (!(ss >> std::skipws >> i))
111 throw std::invalid_argument(
"stoi");
123 inline double stod(
const std::string& str)
125 std::istringstream ss(str);
129 throw std::invalid_argument(
"stod");
135 if(i == 0 && (((pos = str.find(
"0x")) != std::string::npos) || ((pos = str.find(
"0X")) != std::string::npos)))
137 bool negative =
false;
139 if (str[pos - 1] ==
'-')
142 size_t comma = str.find(
".", pos+2);
144 size_t integer, decimal;
145 std::istringstream ssi(str.substr(pos+2, comma - pos - 2));
146 std::istringstream ssd(str.substr(++comma));
148 if (!(ssi >> std::hex >> integer))
149 throw std::invalid_argument(
"stod");
151 if (!(ssd >> std::hex >> decimal))
152 throw std::invalid_argument(
"stod");
154 size_t lenght = str.find_first_not_of(
"0123456789abcdefABCDEF", comma);
155 if (lenght == std::string::npos)
156 lenght = str.length() - comma;
160 i = (integer + (decimal/pow(16, lenght))) * (negative ? -1. : 1.);
172 const std::string& oldStr,
173 const std::string& newStr)
176 while((pos = str.find(oldStr, pos)) != std::string::npos)
178 str.replace(pos, oldStr.length(), newStr);
179 pos += newStr.length();
187 inline std::string tokenize(
const std::string& str,
188 const std::string& delim,
191 size_t token_end = std::string::npos;
192 size_t token_begin = 0;
193 size_t token_count = 0;
194 bool catched =
false;
199 "Requested token exceeds the number of tokens");
201 token_begin = token_end + 1;
202 token_end = str.find_first_of(delim, token_begin);
204 if(token_end == std::string::npos)
207 if (token_end != token_begin)
210 while (token_count <= token);
212 return str.substr(token_begin, token_end - token_begin);
219 str[0] =
static_cast<char>(toupper(str[0]));
226 std::string newStr = str;
237 static std::string name()
241 #if __cplusplus > 199711L
242 memory::unique_ptr<char,decltype(std::free)*>
243 dm(__cxxabiv1::__cxa_demangle(
typeid(T).name(), NULL, NULL, &status ), std::free);
244 return (status==0) ? dm.get() :
typeid(T).name();
246 char * dm = __cxxabiv1::__cxa_demangle(
typeid(T).name(), NULL, NULL, &status );
250 return typeid(T).name();
256 #else // not __GNUC__
257 return typeid(T).name();
266 size_t seed = end - start;
267 for(; start!=end; ++start)
268 seed ^= *start + 0x9e3779b9 + (seed << 6) + (seed >> 2);
272 #if __cplusplus >= 201703L || _MSVC_LANG >= 201703L
275 template <
class T,
size_t N>
276 size_t size(
const T (&)[N])
281 size_t size(
const T& t)
291 #define GISMO_DELEGATING_COMPARISON_OPERATORS( T ) \
292 inline bool operator!= (const T& a, const T& b) { return !(a==b); } \
293 inline bool operator> (const T& a, const T& b) { return b<a; } \
294 inline bool operator<= (const T& a, const T& b) { return !(b<a); } \
295 inline bool operator>= (const T& a, const T& b) { return !(a<b); }
300 #if __cplusplus >= 201103L || _MSC_VER >= 1600
301 #define GISMO_DELETE_COMPARISON_OPERATORS( S, T ) \
302 inline bool operator== (const S& a, const T& b) = delete; \
303 inline bool operator!= (const S& a, const T& b) = delete; \
304 inline bool operator< (const S& a, const T& b) = delete; \
305 inline bool operator> (const S& a, const T& b) = delete; \
306 inline bool operator<= (const S& a, const T& b) = delete; \
307 inline bool operator>= (const S& a, const T& b) = delete; \
308 inline bool operator== (const T& a, const S& b) = delete; \
309 inline bool operator!= (const T& a, const S& b) = delete; \
310 inline bool operator< (const T& a, const S& b) = delete; \
311 inline bool operator> (const T& a, const S& b) = delete; \
312 inline bool operator<= (const T& a, const S& b) = delete; \
313 inline bool operator>= (const T& a, const S& b) = delete;
315 #define GISMO_DELETE_COMPARISON_OPERATORS( S, T ) \
316 inline bool operator== (const S& a, const T& b); \
317 inline bool operator!= (const S& a, const T& b); \
318 inline bool operator< (const S& a, const T& b); \
319 inline bool operator> (const S& a, const T& b); \
320 inline bool operator<= (const S& a, const T& b); \
321 inline bool operator>= (const S& a, const T& b); \
322 inline bool operator== (const T& a, const S& b); \
323 inline bool operator!= (const T& a, const S& b); \
324 inline bool operator< (const T& a, const S& b); \
325 inline bool operator> (const T& a, const S& b); \
326 inline bool operator<= (const T& a, const S& b); \
327 inline bool operator>= (const T& a, const S& b);
Print name of template type as a string.
Definition: gsUtils.h:234
double stod(const std::string &str)
equivalent to std::stod(str)
Definition: gsUtils.h:123
std::string to_string(const C &value)
Converts value to string, assuming "operator<<" defined on C.
Definition: gsUtils.h:56
void string_replace(std::string &str, const std::string &oldStr, const std::string &newStr)
Replaces appearance of oldStr with newStr inside the string str.
Definition: gsUtils.h:171
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
Provides utility function related to memory management.
OpenMP stub routines to be used when omp.h is not available.
This file contains the debugging and messaging system of G+Smo.
Handles shared library creation and other class attributes.
void capitalize(std::string &str)
Capitalize string in situ.
Definition: gsUtils.h:217
int stoi(const std::string &str)
equivalent to std::stoi(str), and therefore std::stoi(str, 0, 10)
Definition: gsUtils.h:105
size_t hash_range(T const *start, const T *const end)
Create hash key for a rangle of (integral) numbers.
Definition: gsUtils.h:264
std::string returnCapitalized(const std::string &str)
Capitalize string.
Definition: gsUtils.h:224
bool starts_with(const std::string &haystack, const std::string &needle)
Checks if a string haystack begins with the string needle.
Definition: gsUtils.h:65
bool ends_with(const std::string &haystack, const std::string &needle)
Checks if a string haystack ends with the string needle.
Definition: gsUtils.h:79