39 #include <OpenMS/OpenMSConfig.h> 40 #include <OpenMS/config.h> 47 #include <boost/lexical_cast.hpp> 48 #include <boost/algorithm/string/trim.hpp> 89 tolerance_(tolerance),
101 return std::fabs(value - target_) < tolerance_;
120 template <
typename T>
121 static std::vector<T>
create(
const String& str,
const char splitter =
',')
124 std::vector<String> temp_string_vec;
125 str.
split(splitter, temp_string_vec);
126 return create<T>(temp_string_vec);
137 template <
typename T>
138 static std::vector<T> create(
const std::vector<String>& s);
148 template <
typename T,
typename E>
149 static bool contains(
const std::vector<T>& container,
const E& elem)
151 return find(container.begin(), container.end(), elem) != container.end();
163 static bool contains(
const std::vector<double>& container,
const double& elem,
double tolerance = 0.00001)
174 template <
typename T>
177 return concatenate< std::vector<T> >(container, glue);
186 template <
typename T>
190 if (container.empty())
return "";
192 typename T::const_iterator it = container.begin();
197 for (; it != container.end(); ++it)
199 ret += (glue +
String(*it));
208 template <
typename T,
typename E>
211 typename std::vector<T>::const_iterator pos =
212 std::find(container.begin(), container.end(), elem);
213 if (pos == container.end())
return -1;
215 return static_cast<Int>(std::distance(container.begin(), pos));
220 template <
typename T>
225 for (std::vector<String>::const_iterator it = s.begin(); it != s.end(); ++it)
229 c.push_back(boost::lexical_cast<T>(boost::trim_copy(*it)));
231 catch (boost::bad_lexical_cast&)
const double E
Euler's number - base of the natural logarithm.
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:163
A more convenient string class.
Definition: String.h:57
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:121
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:65
Predicate to check double equality with a given tolerance.
Definition: ListUtils.h:86
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:58
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:884
DoubleTolerancePredicate_(const double &target, const double &tolerance)
Definition: ListUtils.h:88
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:175
Invalid conversion exception.
Definition: Exception.h:362
Collection of utility functions for management of vectors.
Definition: ListUtils.h:80
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:73
bool operator()(const double &value)
Returns true if | value - target | < tolerance.
Definition: ListUtils.h:99
double target_
The target value that should be found.
Definition: ListUtils.h:108
double tolerance_
The allowed tolerance.
Definition: ListUtils.h:106
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:209
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:187
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:149
int Int
Signed integer type.
Definition: Types.h:102
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.