35 #ifndef OPENMS_DATASTRUCTURES_LISTUTILS_H    36 #define OPENMS_DATASTRUCTURES_LISTUTILS_H    40 #include <OpenMS/OpenMSConfig.h>    41 #include <OpenMS/config.h>    48 #include <boost/lexical_cast.hpp>    49 #include <boost/algorithm/string/trim.hpp>    90         tolerance_(tolerance),
   102         return std::fabs(value - target_) < tolerance_;
   121     template <
typename T>
   122     static std::vector<T> 
create(
const String& str, 
const char splitter = 
',')
   125       std::vector<String> temp_string_vec;
   126       str.
split(splitter, temp_string_vec);
   127       return create<T>(temp_string_vec);
   138     template <
typename T>
   139     static std::vector<T> create(
const std::vector<String>& s);
   149     template <
typename T, 
typename E>
   150     static bool contains(
const std::vector<T>& container, 
const E& elem)
   152       return find(container.begin(), container.end(), elem) != container.end();
   164     static bool contains(
const std::vector<double>& container, 
const double& elem, 
double tolerance = 0.00001)
   175     template <
typename T>
   178       return concatenate< std::vector<T> >(container, glue);
   187     template <
typename T>
   191       if (container.empty()) 
return "";
   193       typename T::const_iterator it = container.begin();
   198       for (; it != container.end(); ++it)
   200         ret += (glue + 
String(*it));
   209     template <
typename T, 
typename E>
   212       typename std::vector<T>::const_iterator pos =
   213         std::find(container.begin(), container.end(), elem);
   214       if (pos == container.end()) 
return -1;
   216       return static_cast<Int>(std::distance(container.begin(), pos));
   221   template <
typename T>
   226     for (std::vector<String>::const_iterator it = s.begin(); it != s.end(); ++it)
   230         c.push_back(boost::lexical_cast<T>(boost::trim_copy(*it))); 
   232       catch (boost::bad_lexical_cast&)
   250 #endif // OPENMS_DATASTRUCTURES_LISTUTILS_H 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:164
 
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:122
 
std::vector< double > DoubleList
Vector of double precision real types. 
Definition: ListUtils.h:66
 
Predicate to check double equality with a given tolerance. 
Definition: ListUtils.h:87
 
std::vector< Int > IntList
Vector of signed integers. 
Definition: ListUtils.h:59
 
Main OpenMS namespace. 
Definition: FeatureDeconvolution.h:47
 
DoubleTolerancePredicate_(const double &target, const double &tolerance)
Definition: ListUtils.h:89
 
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:176
 
Invalid conversion exception. 
Definition: Exception.h:363
 
Collection of utility functions for management of vectors. 
Definition: ListUtils.h:81
 
std::vector< String > StringList
Vector of String. 
Definition: ListUtils.h:74
 
bool operator()(const double &value)
Returns true if | value - target | < tolerance. 
Definition: ListUtils.h:100
 
double target_
The target value that should be found. 
Definition: ListUtils.h:109
 
double tolerance_
The allowed tolerance. 
Definition: ListUtils.h:107
 
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:210
 
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:188
 
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:150
 
int Int
Signed integer type. 
Definition: Types.h:103
 
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.