13 #include <OpenMS/OpenMSConfig.h>
14 #include <OpenMS/config.h>
60 tolerance_(tolerance),
72 return std::fabs(value - target_) < tolerance_;
92 static std::vector<T>
create(
const String& str,
const char splitter =
',')
95 std::vector<String> temp_string_vec;
96 str.
split(splitter, temp_string_vec);
97 return create<T>(temp_string_vec);
108 template <
typename T>
109 static std::vector<T> create(
const std::vector<String>& s);
118 template <
typename T>
122 out.reserve(s.size());
123 for (
const auto& elem : s) out.push_back(elem);
135 template <
typename T,
typename E>
136 static bool contains(
const std::vector<T>& container,
const E& elem)
138 return find(container.begin(), container.end(), elem) != container.end();
150 static bool contains(
const std::vector<double>& container,
const double& elem,
double tolerance = 0.00001)
156 enum class CASE { SENSITIVE, INSENSITIVE};
168 if (cs == CASE::SENSITIVE)
return contains(container, elem);
171 return find_if(container.begin(), container.end(), [&elem](
String ce) {
172 return elem == ce.toLower();
173 }) != container.end();
182 template <
typename T>
185 return concatenate< std::vector<T> >(container, glue);
194 template <
typename T>
198 if (container.empty())
return "";
200 typename T::const_iterator it = container.begin();
205 for (; it != container.end(); ++it)
207 ret += (glue +
String(*it));
216 template <
typename T,
typename E>
219 typename std::vector<T>::const_iterator pos =
220 std::find(container.begin(), container.end(), elem);
221 if (pos == container.end())
return -1;
223 return static_cast<Int>(std::distance(container.begin(), pos));
230 template <
typename T>
244 inline float convert(
const String& s)
249 inline std::string
convert(
const String& s)
251 return static_cast<std::string
>(s);
255 template <
typename T>
260 for (std::vector<String>::const_iterator it = s.begin(); it != s.end(); ++it)
264 c.push_back(detail::convert<T>(
String(*it).
trim()));
Invalid conversion exception.
Definition: Exception.h:330
Collection of utility functions for management of vectors.
Definition: ListUtils.h:52
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:150
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:136
static bool contains(const std::vector< String > &container, String elem, const CASE cs)
Checks whether the String elem is contained in the given container (potentially case insensitive)
Definition: ListUtils.h:166
static std::vector< String > toStringList(const std::vector< T > &s)
Converts a vector of T's to a vector of Strings.
Definition: ListUtils.h:119
CASE
Definition: ListUtils.h:156
static String concatenate(const std::vector< T > &container, const String &glue="")
Concatenates all elements of the container and puts the glue string between elements.
Definition: ListUtils.h:183
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:217
static String concatenate(const T &container, const String &glue="")
Concatenates all elements of the container and puts the glue string between elements.
Definition: ListUtils.h:195
static std::vector< T > create(const String &str, const char splitter=',')
Returns a list that is created by splitting the given comma-separated string.
Definition: ListUtils.h:92
A more convenient string class.
Definition: String.h:34
double toDouble() const
Conversion to double.
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
Int32 toInt32() const
Conversion to Int32.
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
String & toLower()
Converts the string to lowercase.
int Int
Signed integer type.
Definition: Types.h:76
OPENMS_INT32_TYPE Int32
Signed integer type (32bit)
Definition: Types.h:30
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:29
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:44
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:36
const double c
Definition: Constants.h:188
const double E
Euler's number - base of the natural logarithm.
Definition: Constants.h:52
bool contains(T value, T min, T max)
Is a value contained in [min, max] ?
Definition: MathFunctions.h:62
T convert(const String &s)
Definition: ListUtils.h:234
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
Predicate to check double equality with a given tolerance.
Definition: ListUtils.h:58
bool operator()(const double &value) const
Returns true if | value - target | < tolerance.
Definition: ListUtils.h:70
double target_
The target value that should be found.
Definition: ListUtils.h:79
double tolerance_
The allowed tolerance.
Definition: ListUtils.h:77
DoubleTolerancePredicate_(const double &target, const double &tolerance)
Definition: ListUtils.h:59