OpenMS
Loading...
Searching...
No Matches
OpenMS::Helpers Namespace Reference

Functions

template<class ContainerType >
Size indexOf (const ContainerType &cont, const typename ContainerType::value_type &val)
 
template<class EnumType >
std::vector< std::string > enumNames (const std::string *names, EnumType size_value)
 Returns the names of all enum values, i.e. the first size_value entries of names.
 
template<class EnumType >
const std::string & enumToName (const std::string *names, EnumType value, EnumType size_value, const char *size_name, const char *function)
 Converts an enum value to its entry in names.
 
template<class EnumType >
EnumType enumFromName (const std::string *names, EnumType size_value, const std::string &name, const char *message, const char *function)
 Converts a name to the enum value at its index in names.
 
template<class T >
const std::vector< std::shared_ptr< const T > > & constifyPointerVector (const std::vector< std::shared_ptr< T > > &vec)
 Helper function to add constness to a vector of shared pointers.
 
template<class PtrType >
bool cmpPtrSafe (const PtrType &a, const PtrType &b)
 Helper comparing two pointers for equality (taking NULL into account)
 
template<class ContainerType >
bool cmpPtrContainer (const ContainerType &a, const ContainerType &b)
 Helper function to compare two pointer-containers for equality of all elements.
 

Function Documentation

◆ cmpPtrContainer()

template<class ContainerType >
bool cmpPtrContainer ( const ContainerType &  a,
const ContainerType &  b 
)
inline

Helper function to compare two pointer-containers for equality of all elements.

References cmpPtrSafe().

◆ cmpPtrSafe()

template<class PtrType >
bool cmpPtrSafe ( const PtrType &  a,
const PtrType &  b 
)
inline

Helper comparing two pointers for equality (taking NULL into account)

Referenced by cmpPtrContainer().

◆ constifyPointerVector()

template<class T >
const std::vector< std::shared_ptr< const T > > & constifyPointerVector ( const std::vector< std::shared_ptr< T > > &  vec)

Helper function to add constness to a vector of shared pointers.

◆ enumFromName()

template<class EnumType >
EnumType enumFromName ( const std::string *  names,
EnumType  size_value,
const std::string &  name,
const char *  message,
const char *  function 
)

Converts a name to the enum value at its index in names.

Implements the toX(const std::string&) functions of enums with a NamesOfX[] array and a trailing SIZE_OF_X value. Unlike indexOf(), this throws Exception::InvalidValue.

Parameters
[in]namesArray of names, indexed by enum value
[in]size_valueThe enum's SIZE_OF_X value (number of valid enum values)
[in]nameThe name to convert
[in]messageMessage of the exception thrown if name is unknown (e.g. "Value unknown")
[in]functionName of the calling function, reported by the exception
Exceptions
Exception::InvalidValueif name is not among the first size_value entries of names

References first.

◆ enumNames()

template<class EnumType >
std::vector< std::string > enumNames ( const std::string *  names,
EnumType  size_value 
)

Returns the names of all enum values, i.e. the first size_value entries of names.

Implements the getAllNamesOfX() functions of enums with a NamesOfX[] array and a trailing SIZE_OF_X value.

Parameters
[in]namesArray of names, indexed by enum value
[in]size_valueThe enum's SIZE_OF_X value (number of valid enum values)

◆ enumToName()

template<class EnumType >
const std::string & enumToName ( const std::string *  names,
EnumType  value,
EnumType  size_value,
const char *  size_name,
const char *  function 
)

Converts an enum value to its entry in names.

Implements the xToString(X) functions of enums with a NamesOfX[] array and a trailing SIZE_OF_X value.

Parameters
[in]namesArray of names, indexed by enum value
[in]valueThe enum value to convert
[in]size_valueThe enum's SIZE_OF_X value, which is rejected
[in]size_nameName of size_value, reported as the invalid value (e.g. "SIZE_OF_X")
[in]functionName of the calling function, reported by the exception
Exceptions
Exception::InvalidValue("Value not allowed") if value is size_value

◆ indexOf()

template<class ContainerType >
Size indexOf ( const ContainerType &  cont,
const typename ContainerType::value_type &  val 
)

return the index of an element in a container useful for matching 'names_of_...' arrays to their enum value