OpenMS
Loading...
Searching...
No Matches
ListUtils Class Reference

Collection of utility functions for management of vectors. More...

#include <OpenMS/DATASTRUCTURES/ListUtils.h>

Classes

struct  DoubleTolerancePredicate_
 Predicate to check double equality with a given tolerance. More...
 

Public Types

enum class  CASE { SENSITIVE , INSENSITIVE }
 

Public Member Functions

template<>
std::vector< Stringcreate (const std::vector< String > &s)
 create specialization for String since we do not need to cast here
 

Static Public Member Functions

template<typename T >
static std::vector< T > create (const String &str, const char splitter=',')
 Returns a list that is created by splitting the given comma-separated string.
 
template<typename T >
static std::vector< T > create (const std::vector< String > &s)
 Converts a vector of strings to a vector of the target type T.
 
template<typename T >
static std::vector< StringtoStringList (const std::vector< T > &s)
 Converts a vector of T's to a vector of Strings.
 
template<typename T , typename E >
static bool contains (const std::vector< T > &container, const E &elem)
 Checks whether the element elem is contained in the given container.
 
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.
 
static bool contains (const std::vector< String > &container, String elem, const CASE case_sensitive)
 Checks whether the String elem is contained in the given container (potentially case insensitive)
 
template<typename T >
static String concatenate (const std::vector< T > &container, const String &glue="")
 Concatenates all elements of the container and puts the glue string between elements.
 
template<typename T >
static String concatenate (const T &container, const String &glue="")
 Concatenates all elements of the container and puts the glue string between elements.
 
template<typename T , typename E >
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)
 

Detailed Description

Collection of utility functions for management of vectors.

Member Enumeration Documentation

◆ CASE

enum class CASE
strong
Enumerator
SENSITIVE 
INSENSITIVE 

Member Function Documentation

◆ concatenate() [1/2]

template<typename T >
static String concatenate ( const std::vector< T > &  container,
const String glue = "" 
)
inlinestatic

Concatenates all elements of the container and puts the glue string between elements.

Parameters
[in]containerThe container to concatenate;
[in]glueThe string to add in between elements.

Referenced by NucleicAcidSearchEngine::generateLFQInput_().

◆ concatenate() [2/2]

template<typename T >
static String concatenate ( const T &  container,
const String glue = "" 
)
inlinestatic

Concatenates all elements of the container and puts the glue string between elements.

Parameters
[in]containerThe container to concatenate; must have begin() and end() iterator.
[in]glueThe string to add in between elements.

◆ contains() [1/3]

static bool contains ( const std::vector< double > &  container,
const double &  elem,
double  tolerance = 0.00001 
)
inlinestatic

Checks whether the element elem is contained in the given container of floating point numbers.

Parameters
[in]containerThe container of doubles to check.
[in]elemThe element to check whether it is in the container or not.
[in]toleranceThe allowed tolerance for the double.
Returns
True if elem is contained in container, false otherwise.

◆ contains() [2/3]

static bool contains ( const std::vector< String > &  container,
String  elem,
const CASE  case_sensitive 
)
inlinestatic

Checks whether the String elem is contained in the given container (potentially case insensitive)

Parameters
[in]containerThe container of String to check.
[in]elemThe element to check whether it is in the container or not.
[in]case_sensitiveDo the comparison case sensitive or insensitive
Returns
True if elem is contained in container, false otherwise.

References OpenMS::Math::contains(), and String::toLower().

◆ contains() [3/3]

template<typename T , typename E >
static bool contains ( const std::vector< T > &  container,
const E &  elem 
)
inlinestatic

Checks whether the element elem is contained in the given container.

Parameters
[in]containerThe container to check.
[in]elemThe element to check whether it is in the container or not.
Returns
True if elem is contained in container, false otherwise.

Referenced by HasActivationMethod< SpectrumType >::operator()().

◆ create() [1/3]

template<typename T >
std::vector< T > create ( const std::vector< String > &  s)
inlinestatic

Converts a vector of strings to a vector of the target type T.

Note
The strings are trimmed before conversion.
The values get converted by boost::lexical_cast so a valid conversion from String to T needs to be available.
Parameters
[in]sThe vector of strings that should be converted.
Returns
A vector containing the elements of input vector converted into type T.

References String::trim().

◆ create() [2/3]

template<>
std::vector< String > create ( const std::vector< String > &  s)
inline

create specialization for String since we do not need to cast here

◆ create() [3/3]

template<typename T >
static std::vector< T > create ( const String str,
const char  splitter = ',' 
)
inlinestatic

Returns a list that is created by splitting the given comma-separated string.

Note
If converted to vector<String> the strings are not trimmed.
The values get converted by boost::lexical_cast so a valid conversion from String to T needs to be available.
Parameters
[in]strThe string that should be split and converted to a list.
[in]splitterThe separator to look for in str
Returns
A vector containing the elements of the string converted into type T.

References String::split().

◆ getIndex()

template<typename T , typename E >
static Int getIndex ( const std::vector< T > &  container,
const E &  elem 
)
inlinestatic

Get the index of the first occurrence of an element in the vector (or -1 if not found)

◆ toStringList()

template<typename T >
static std::vector< String > toStringList ( const std::vector< T > &  s)
inlinestatic

Converts a vector of T's to a vector of Strings.

Parameters
[in]sThe vector of T's that should be converted.
Returns
A vector containing the elements of input vector converted into Strings.