9#include <framework/utilities/CutHelpers.h>
21 static_assert(
sizeof(float) ==
sizeof(int32_t));
23 return std::fabs(*(int32_t*)&a - * (int32_t*)&b) <= 2 or (a == b);
28 static_assert(
sizeof(double) ==
sizeof(int64_t));
30 return std::fabs(*(int64_t*)&a - * (int64_t*)&b) <= 2 or (a == b);
35 unsigned long int end = 1;
37 unsigned int count = 1;
38 for (end = 1; end < str.size() and count > 0; ++end) {
39 if (str[end] == open) ++count;
40 else if (str[end] == close) --count;
44 throw std::runtime_error(
"Variable string has an invalid format: " + str);
52 if (str.size() < pattern.size())
53 return std::string::npos;
55 for (
unsigned int i = begin; i < str.size() - pattern.size(); ++i) {
69 for (
unsigned int j = 0; j < pattern.size(); ++j) {
70 if (str[i + j] != pattern[j]) {
73 if (j == pattern.size() - 1) {
78 return std::string::npos;
84 std::vector<std::string> result;
85 unsigned int lastdelimiter = 0;
86 for (
unsigned int i = 0; i < str.size(); ++i) {
91 if (str[i] == delimiter) {
92 result.push_back(str.substr(lastdelimiter, i - lastdelimiter));
93 lastdelimiter = i + 1;
96 std::string last = str.substr(lastdelimiter);
97 if (last.size() != 0) {
98 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.