13#include <OpenMS/OpenMSConfig.h>
14#include <OpenMS/config.h>
61 tolerance_(tolerance),
73 return std::fabs(value - target_) < tolerance_;
94 static std::vector<T>
create(
const std::string& str,
const char splitter =
',')
97 std::vector<std::string> temp_string_vec;
98 StringUtils::split(str, splitter, temp_string_vec);
99 return create<T>(temp_string_vec);
110 template <
typename T>
111 static std::vector<T> create(
const std::vector<std::string>& s);
120 template <
typename T>
124 out.reserve(s.size());
125 for (
const auto& elem : s) out.push_back(StringUtils::toStr(elem));
137 template <
typename T,
typename E>
138 static bool contains(
const std::vector<T>& container,
const E& elem)
140 return find(container.begin(), container.end(), elem) != container.end();
152 static bool contains(
const std::vector<double>& container,
const double& elem,
double tolerance = 0.00001)
158 enum class CASE { SENSITIVE, INSENSITIVE};
168 static bool contains(
const std::vector<std::string>& container, std::string elem,
const CASE case_sensitive)
170 if (case_sensitive == CASE::SENSITIVE)
return contains(container, elem);
172 StringUtils::toLower(elem);
173 return find_if(container.begin(), container.end(), [&elem](std::string ce) {
174 return elem == StringUtils::toLower(ce);
175 }) != container.end();
184 template <
typename T>
185 static std::string
concatenate(
const std::vector<T>& container,
const std::string& glue =
"")
187 return concatenate< std::vector<T> >(container, glue);
196 template <
typename T>
197 static std::string
concatenate(
const T& container,
const std::string& glue =
"")
200 if (container.empty())
return "";
202 typename T::const_iterator it = container.begin();
203 std::string ret =StringUtils::toStr(*it);
207 for (; it != container.end(); ++it)
209 ret += (glue + StringUtils::toStr(*it));
218 template <
typename T,
typename E>
219 static Int getIndex(
const std::vector<T>& container,
const E& elem)
221 typename std::vector<T>::const_iterator pos =
222 std::find(container.begin(), container.end(), elem);
223 if (pos == container.end())
return -1;
225 return static_cast<Int>(std::distance(container.begin(), pos));
232 template <
typename T>
251 inline std::string
convert(
const std::string& s)
253 return static_cast<std::string
>(s);
257 template <
typename T>
262 for (std::vector<std::string>::const_iterator it = s.begin(); it != s.end(); ++it)
270 throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,std::string(
"Could not convert string '") + *it +
"'");
Invalid conversion exception.
Definition Exception.h:331
Collection of utility functions for management of vectors.
Definition ListUtils.h:53
static bool contains(const std::vector< double > &container, const double &elem, double tolerance=0.00001)
Checks whether the element elem is contained in the given container of floating point numbers.
Definition ListUtils.h:152
static bool contains(const std::vector< T > &container, const E &elem)
Checks whether the element elem is contained in the given container.
Definition ListUtils.h:138
static std::vector< T > create(const std::string &str, const char splitter=',')
Returns a list that is created by splitting the given comma-separated string.
Definition ListUtils.h:94
static bool contains(const std::vector< std::string > &container, std::string elem, const CASE case_sensitive)
Checks whether the String elem is contained in the given container (potentially case insensitive)
Definition ListUtils.h:168
static std::string concatenate(const T &container, const std::string &glue="")
Concatenates all elements of the container and puts the glue string between elements.
Definition ListUtils.h:197
static std::vector< std::string > toStringList(const std::vector< T > &s)
Converts a vector of T's to a vector of Strings.
Definition ListUtils.h:121
CASE
Definition ListUtils.h:158
static Int getIndex(const std::vector< T > &container, const E &elem)
Get the index of the first occurrence of an element in the vector (or -1 if not found)
Definition ListUtils.h:219
static std::string concatenate(const std::vector< T > &container, const std::string &glue="")
Concatenates all elements of the container and puts the glue string between elements.
Definition ListUtils.h:185
int32_t Int32
Signed integer type (32bit)
Definition Types.h:26
int Int
Signed integer type.
Definition Types.h:72
std::vector< Int > IntList
Vector of signed integers.
Definition ListUtils.h:29
std::vector< double > DoubleList
Vector of double precision real types.
Definition ListUtils.h:36
std::vector< std::string > StringList
Vector of String.
Definition ListUtils.h:44
bool contains(T value, T min, T max)
Is a value contained in [min, max] ?
Definition MathFunctions.h:71
float toFloat(const std::string &s)
Definition StringUtils.h:338
std::string trimmed(std::string s)
Returns a trimmed copy of s (for use in chained/rvalue expressions)
Definition StringUtils.h:576
double toDouble(const std::string &s)
Definition StringUtils.h:339
Int32 toInt32(const std::string &s)
Definition StringUtils.h:336
T convert(const std::string &s)
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Predicate to check double equality with a given tolerance.
Definition ListUtils.h:59
bool operator()(const double &value) const
Returns true if | value - target | < tolerance.
Definition ListUtils.h:71
double target_
The target value that should be found.
Definition ListUtils.h:80
double tolerance_
The allowed tolerance.
Definition ListUtils.h:78
DoubleTolerancePredicate_(const double &target, const double &tolerance)
Definition ListUtils.h:60