|
OpenMS
2.5.0
|
Go to the documentation of this file.
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);
145 template <
typename T,
typename E>
146 static bool contains(
const std::vector<T>& container,
const E& elem)
148 return find(container.begin(), container.end(), elem) != container.end();
160 static bool contains(
const std::vector<double>& container,
const double& elem,
double tolerance = 0.00001)
166 enum class CASE { SENSITIVE, INSENSITIVE};
178 if (cs == CASE::SENSITIVE)
return contains(container, elem);
181 return find_if(container.begin(), container.end(), [&elem](
String ce) {
183 }) != container.end();
192 template <
typename T>
195 return concatenate< std::vector<T> >(container, glue);
204 template <
typename T>
208 if (container.empty())
return "";
210 typename T::const_iterator it = container.begin();
215 for (; it != container.end(); ++it)
217 ret += (glue +
String(*it));
226 template <
typename T,
typename E>
229 typename std::vector<T>::const_iterator pos =
230 std::find(container.begin(), container.end(), elem);
231 if (pos == container.end())
return -1;
233 return static_cast<Int>(std::distance(container.begin(), pos));
240 template <
typename T>
260 template <
typename T>
265 for (std::vector<String>::const_iterator it = s.begin(); it != s.end(); ++it)
269 c.push_back(detail::convert<T>(
String(*it).
trim()));
double tolerance_
The allowed tolerance.
Definition: ListUtils.h:103
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:227
double target_
The target value that should be found.
Definition: ListUtils.h:105
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:205
double toDouble() const
Conversion to double.
A more convenient string class.
Definition: String.h:58
T convert(const String &s)
Definition: ListUtils.h:244
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
Invalid conversion exception.
Definition: Exception.h:362
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:146
bool operator()(const double &value)
Returns true if | value - target | < tolerance.
Definition: ListUtils.h:96
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
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:193
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
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:160
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:884
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
CASE
Definition: ListUtils.h:166
Predicate to check double equality with a given tolerance.
Definition: ListUtils.h:83
Collection of utility functions for management of vectors.
Definition: ListUtils.h:77
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
DoubleTolerancePredicate_(const double &target, const double &tolerance)
Definition: ListUtils.h:85
Int toInt() const
Conversion to int.
float toFloat() const
Conversion to float.
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:176
const double E
Euler's number - base of the natural logarithm.
String & toLower()
Converts the string to lowercase.