8 #include <framework/utilities/GeneralCut.h>
19 static_assert(
sizeof(
float) ==
sizeof(int32_t));
21 return std::fabs(*(int32_t*)&a - * (int32_t*)&b) <= 2 or (a == b);
26 static_assert(
sizeof(
double) ==
sizeof(int64_t));
28 return std::fabs(*(int64_t*)&a - * (int64_t*)&b) <= 2 or (a == b);
33 unsigned long int end = 1;
35 unsigned int count = 1;
36 for (end = 1; end < str.size() and count > 0; ++end) {
37 if (str[end] == open) ++count;
38 else if (str[end] == close) --count;
42 throw std::runtime_error(
"Variable string has an invalid format: " + str);
50 if (str.size() < pattern.size())
51 return std::string::npos;
53 for (
unsigned int i = begin; i < str.size() - pattern.size(); ++i) {
67 for (
unsigned int j = 0; j < pattern.size(); ++j) {
68 if (str[i + j] != pattern[j]) {
71 if (j == pattern.size() - 1) {
76 return std::string::npos;
82 std::vector<std::string> result;
83 unsigned int lastdelimiter = 0;
84 for (
unsigned int i = 0; i < str.size(); ++i) {
89 if (str[i] == delimiter) {
90 result.push_back(str.substr(lastdelimiter, i - lastdelimiter));
91 lastdelimiter = i + 1;
94 std::string last = str.substr(lastdelimiter);
95 if (last.size() != 0) {
96 result.push_back(last);
bool almostEqualFloat(const float &a, const float &b)
Helper function to test if two floats are almost equal.
unsigned long int findIgnoringParenthesis(std::string str, std::string pattern, unsigned int begin=0)
Returns the position of a pattern in a string ignoring everything that is in parenthesis.
unsigned long int findMatchedParenthesis(std::string str, char open='[', char close=']')
Returns position of the matched closing parenthesis if the first character in the given string contai...
std::vector< std::string > splitOnDelimiterAndConserveParenthesis(std::string str, char delimiter, char open, char close)
Split into std::vector on delimiter ignoring delimiters between parenthesis.
bool almostEqualDouble(const double &a, const double &b)
Helper function to test if two doubles are almost equal.
Abstract base class for different kinds of events.