OpenMS
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 More...
 

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. More...
 
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. More...
 
template<typename T >
static std::vector< StringtoStringList (const std::vector< T > &s)
 Converts a vector of T's to a vector of Strings. More...
 
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. More...
 
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. More...
 
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) More...
 
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. More...
 
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. More...
 
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) More...
 

Detailed Description

Collection of utility functions for management of vectors.

Member Enumeration Documentation

◆ CASE

enum CASE
strong
Enumerator
SENSITIVE 
INSENSITIVE 

Member Function Documentation

◆ concatenate() [1/2]

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
containerThe container to concatenate;
glueThe string to add in between elements.

Referenced by ProteinIdentification::Mapping::create(), and NucleicAcidSearchEngine::generateLFQInput_().

◆ concatenate() [2/2]

static String concatenate ( const T &  container,
const String glue = "" 
)
inlinestatic

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

Parameters
containerThe container <T> to concatenate; must have begin() and end() iterator.
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
containerThe container of doubles to check.
elemThe element to check whether it is in the container or not.
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  cs 
)
inlinestatic

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

Parameters
containerThe container of String to check.
elemThe element to check whether it is in the container or not.
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]

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

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

Parameters
containerThe container to check.
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]

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
sThe vector of strings that should be converted.
Returns
A vector containing the elements of input vector converted into type T.

References OpenMS::Constants::c, and String::trim().

◆ create() [2/3]

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]

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
strThe string that should be split and converted to a list.
Returns
A vector containing the elements of the string converted into type T.

References String::split().

◆ getIndex()

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()

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

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

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