39 #include <OpenMS/OpenMSConfig.h>
40 #include <OpenMS/config.h>
86 tolerance_(tolerance),
98 return std::fabs(value - target_) < tolerance_;
117 template <
typename T>
118 static std::vector<T>
create(
const String& str,
const char splitter =
',')
121 std::vector<String> temp_string_vec;
122 str.
split(splitter, temp_string_vec);
123 return create<T>(temp_string_vec);
134 template <
typename T>
135 static std::vector<T> create(
const std::vector<String>& s);
144 template <
typename T>
148 out.reserve(s.size());
149 for (
const auto& elem : s) out.push_back(elem);
161 template <
typename T,
typename E>
162 static bool contains(
const std::vector<T>& container,
const E& elem)
164 return find(container.begin(), container.end(), elem) != container.end();
176 static bool contains(
const std::vector<double>& container,
const double& elem,
double tolerance = 0.00001)
182 enum class CASE { SENSITIVE, INSENSITIVE};
194 if (cs == CASE::SENSITIVE)
return contains(container, elem);
197 return find_if(container.begin(), container.end(), [&elem](
String ce) {
198 return elem == ce.toLower();
199 }) != container.end();
208 template <
typename T>
211 return concatenate< std::vector<T> >(container, glue);
220 template <
typename T>
224 if (container.empty())
return "";
226 typename T::const_iterator it = container.begin();
231 for (; it != container.end(); ++it)
233 ret += (glue +
String(*it));
242 template <
typename T,
typename E>
245 typename std::vector<T>::const_iterator pos =
246 std::find(container.begin(), container.end(), elem);
247 if (pos == container.end())
return -1;
249 return static_cast<Int>(std::distance(container.begin(), pos));
256 template <
typename T>
270 inline float convert(
const String& s)
275 inline std::string
convert(
const String& s)
277 return static_cast<std::string
>(s);
281 template <
typename T>
286 for (std::vector<String>::const_iterator it = s.begin(); it != s.end(); ++it)
290 c.push_back(detail::convert<T>(
String(*it).
trim()));
Invalid conversion exception.
Definition: Exception.h:356
Collection of utility functions for management of vectors.
Definition: ListUtils.h:78
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:176
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:162
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:192
static std::vector< String > toStringList(const std::vector< T > &s)
Converts a vector of T's to a vector of Strings.
Definition: ListUtils.h:145
CASE
Definition: ListUtils.h:182
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:209
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:243
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:221
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:118
A more convenient string class.
Definition: String.h:60
Int toInt() const
Conversion to int.
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.
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:102
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
const double c
Definition: Constants.h:209
const double E
Euler's number - base of the natural logarithm.
Definition: Constants.h:78
T convert(const String &s)
Definition: ListUtils.h:260
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Predicate to check double equality with a given tolerance.
Definition: ListUtils.h:84
bool operator()(const double &value) const
Returns true if | value - target | < tolerance.
Definition: ListUtils.h:96
double target_
The target value that should be found.
Definition: ListUtils.h:105
double tolerance_
The allowed tolerance.
Definition: ListUtils.h:103
DoubleTolerancePredicate_(const double &target, const double &tolerance)
Definition: ListUtils.h:85