OpenMS
ParamValue Class Reference

Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl types. More...

#include <OpenMS/DATASTRUCTURES/ParamValue.h>

Collaboration diagram for ParamValue:
[legend]

Public Types

enum  ValueType : unsigned char {
  STRING_VALUE , INT_VALUE , DOUBLE_VALUE , STRING_LIST ,
  INT_LIST , DOUBLE_LIST , EMPTY_VALUE
}
 Supported types for ParamValue. More...
 

Public Member Functions

Constructors and destructors
 ParamValue ()
 Default constructor. More...
 
 ParamValue (const ParamValue &)
 Copy constructor. More...
 
 ParamValue (ParamValue &&) noexcept
 Move constructor. More...
 
 ParamValue (const char *)
 specific constructor for char* (converted to string) More...
 
 ParamValue (const std::string &)
 specific constructor for std::string values More...
 
 ParamValue (const std::vector< std::string > &)
 specific constructor for string vectors More...
 
 ParamValue (const std::vector< int > &)
 specific constructor for integer vectors More...
 
 ParamValue (const std::vector< double > &)
 specific constructor for double vectors More...
 
 ParamValue (long double)
 specific constructor for long double values (note: the implementation uses double) More...
 
 ParamValue (double)
 specific constructor for double values (note: the implementation uses double) More...
 
 ParamValue (float)
 specific constructor for float values (note: the implementation uses double) More...
 
 ParamValue (short int)
 specific constructor for short int values (note: the implementation uses ptrdiff_t) More...
 
 ParamValue (unsigned short int)
 specific constructor for unsigned short int values (note: the implementation uses ptrdiff_t) More...
 
 ParamValue (int)
 specific constructor for int values (note: the implementation uses ptrdiff_t) More...
 
 ParamValue (unsigned)
 specific constructor for unsigned int values (note: the implementation uses ptrdiff_t) More...
 
 ParamValue (long int)
 specific constructor for long int values (note: the implementation uses ptrdiff_t) More...
 
 ParamValue (unsigned long)
 specific constructor for unsigned long int values (note: the implementation uses ptrdiff_t) More...
 
 ParamValue (long long)
 specific constructor for long long int values (note: the implementation uses ptrdiff_t) More...
 
 ParamValue (unsigned long long)
 specific constructor for unsigned long long int values (note: the implementation uses ptrdiff_t) More...
 
 ~ParamValue ()
 Destructor. More...
 
Cast operators

These methods are used when the DataType is known. If they are applied to a ParamValue with the wrong DataType, an exception (Exception::ConversionError) is thrown. In particular, none of these operators will work for an empty ParamValue (DataType EMPTY_VALUE) - except toChar(), which will return 0.

 operator std::string () const
 conversion operator to string More...
 
 operator std::vector< std::string > () const
 conversion operator to string vector More...
 
 operator std::vector< int > () const
 conversion operator to integer vector More...
 
 operator std::vector< double > () const
 conversion operator to double vector More...
 
 operator long double () const
 conversion operator to long double More...
 
 operator double () const
 conversion operator to double More...
 
 operator float () const
 conversion operator to float More...
 
 operator short int () const
 conversion operator to short int More...
 
 operator unsigned short int () const
 conversion operator to unsigned short int More...
 
 operator int () const
 conversion operator to int More...
 
 operator unsigned int () const
 conversion operator to unsigned int More...
 
 operator long int () const
 conversion operator to long int More...
 
 operator unsigned long int () const
 conversion operator to unsigned long int More...
 
 operator long long () const
 conversion operator to long long More...
 
 operator unsigned long long () const
 conversion operator to unsigned long long More...
 
bool toBool () const
 Conversion to bool. More...
 
const char * toChar () const
 Convert ParamValues to char*. More...
 
std::string toString (bool full_precision=true) const
 Convert ParamValue to string. More...
 
std::vector< std::string > toStringVector () const
 Explicitly convert ParamValue to string vector. More...
 
std::vector< int > toIntVector () const
 Explicitly convert ParamValue to IntList. More...
 
std::vector< double > toDoubleVector () const
 Explicitly convert ParamValue to DoubleList. More...
 

Static Public Attributes

static const ParamValue EMPTY
 Empty data value for comparisons. More...
 

Assignment operators

These methods are used to assign supported types directly to a ParamValue object.

ValueType value_type_
 Type of the currently stored value. More...
 
union {
ptrdiff_t ssize_
 
double dou_
 
std::string * str_
 
std::vector< std::string > * str_list_
 
std::vector< int > * int_list_
 
std::vector< double > * dou_list_
 
data_
 Space to store the data. More...
 
ParamValueoperator= (const ParamValue &)
 Assignment operator. More...
 
ParamValueoperator= (ParamValue &&) noexcept
 Move assignment operator. More...
 
ParamValueoperator= (const char *)
 specific assignment for char* (converted to string) More...
 
ParamValueoperator= (const std::string &)
 specific assignment for std::string values More...
 
ParamValueoperator= (const std::vector< std::string > &)
 specific assignment for string vectors More...
 
ParamValueoperator= (const std::vector< int > &)
 specific assignment for integer vectors More...
 
ParamValueoperator= (const std::vector< double > &)
 specific assignment for double vectors More...
 
ParamValueoperator= (const long double)
 specific assignment for long double values (note: the implementation uses double) More...
 
ParamValueoperator= (const double)
 specific assignment for double values (note: the implementation uses double) More...
 
ParamValueoperator= (const float)
 specific assignment for float values (note: the implementation uses double) More...
 
ParamValueoperator= (const short int)
 specific assignment for short int values (note: the implementation uses ptrdiff_t) More...
 
ParamValueoperator= (const unsigned short int)
 specific assignment for unsigned short int values (note: the implementation uses ptrdiff_t) More...
 
ParamValueoperator= (const int)
 specific assignment for int values (note: the implementation uses ptrdiff_t) More...
 
ParamValueoperator= (const unsigned)
 specific assignment for unsigned int values (note: the implementation uses ptrdiff_t) More...
 
ParamValueoperator= (const long int)
 specific assignment for long int values (note: the implementation uses ptrdiff_t) More...
 
ParamValueoperator= (const unsigned long)
 specific assignment for unsigned long int values (note: the implementation uses ptrdiff_t) More...
 
ParamValueoperator= (const long long)
 specific assignment for long long int values (note: the implementation uses ptrdiff_t) More...
 
ParamValueoperator= (const unsigned long long)
 specific assignment for unsigned long long int values (note: the implementation uses ptrdiff_t) More...
 
ValueType valueType () const
 returns the type of value stored More...
 
bool isEmpty () const
 Test if the value is empty. More...
 
std::ostream & operator<< (std::ostream &, const ParamValue &)
 output stream operator More...
 
bool operator== (const ParamValue &, const ParamValue &)
 Equality comparator. More...
 
bool operator< (const ParamValue &, const ParamValue &)
 Smaller than comparator (for vectors we use the size) More...
 
bool operator> (const ParamValue &, const ParamValue &)
 Greater than comparator (for vectors we use the size) More...
 
bool operator!= (const ParamValue &, const ParamValue &)
 Equality comparator. More...
 
void clear_ () noexcept
 Clears the current state of the ParamValue and release every used memory. More...
 
static std::string doubleToString (double value, bool full_precision=true)
 

Detailed Description

Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl types.

  • To choose one of these types, just use the appropriate constructor.
  • Automatic conversion is supported and throws Exceptions in case of invalid conversions.
  • An empty object is created with the default constructor.

Member Enumeration Documentation

◆ ValueType

enum ValueType : unsigned char

Supported types for ParamValue.

Enumerator
STRING_VALUE 

string value

INT_VALUE 

integer value

DOUBLE_VALUE 

double value

STRING_LIST 

string vector

INT_LIST 

integer vector

DOUBLE_LIST 

double vector

EMPTY_VALUE 

empty value

Constructor & Destructor Documentation

◆ ParamValue() [1/19]

Default constructor.

◆ ParamValue() [2/19]

ParamValue ( const ParamValue )

Copy constructor.

◆ ParamValue() [3/19]

ParamValue ( ParamValue &&  )
noexcept

Move constructor.

◆ ParamValue() [4/19]

ParamValue ( const char *  )

specific constructor for char* (converted to string)

◆ ParamValue() [5/19]

ParamValue ( const std::string &  )

specific constructor for std::string values

◆ ParamValue() [6/19]

ParamValue ( const std::vector< std::string > &  )

specific constructor for string vectors

◆ ParamValue() [7/19]

ParamValue ( const std::vector< int > &  )

specific constructor for integer vectors

◆ ParamValue() [8/19]

ParamValue ( const std::vector< double > &  )

specific constructor for double vectors

◆ ParamValue() [9/19]

ParamValue ( long double  )

specific constructor for long double values (note: the implementation uses double)

◆ ParamValue() [10/19]

ParamValue ( double  )

specific constructor for double values (note: the implementation uses double)

◆ ParamValue() [11/19]

ParamValue ( float  )

specific constructor for float values (note: the implementation uses double)

◆ ParamValue() [12/19]

ParamValue ( short int  )

specific constructor for short int values (note: the implementation uses ptrdiff_t)

◆ ParamValue() [13/19]

ParamValue ( unsigned short int  )

specific constructor for unsigned short int values (note: the implementation uses ptrdiff_t)

◆ ParamValue() [14/19]

ParamValue ( int  )

specific constructor for int values (note: the implementation uses ptrdiff_t)

◆ ParamValue() [15/19]

ParamValue ( unsigned  )

specific constructor for unsigned int values (note: the implementation uses ptrdiff_t)

◆ ParamValue() [16/19]

ParamValue ( long int  )

specific constructor for long int values (note: the implementation uses ptrdiff_t)

◆ ParamValue() [17/19]

ParamValue ( unsigned long  )

specific constructor for unsigned long int values (note: the implementation uses ptrdiff_t)

◆ ParamValue() [18/19]

ParamValue ( long long  )

specific constructor for long long int values (note: the implementation uses ptrdiff_t)

◆ ParamValue() [19/19]

ParamValue ( unsigned long long  )

specific constructor for unsigned long long int values (note: the implementation uses ptrdiff_t)

◆ ~ParamValue()

~ParamValue ( )

Destructor.

Member Function Documentation

◆ clear_()

void clear_ ( )
privatenoexcept

Clears the current state of the ParamValue and release every used memory.

◆ doubleToString()

static std::string doubleToString ( double  value,
bool  full_precision = true 
)
staticprivate

Convert a double to std::string with full precision 15 decimal places are given, otherwise 3 numbers above 10000 or below 0.0001 are given in scientific notation (i.e. 1.0e04)

◆ isEmpty()

bool isEmpty ( ) const
inline

Test if the value is empty.

Note
A ParamValue containing an empty string ("") does not count as empty!

◆ operator double()

operator double ( ) const

conversion operator to double

Note: The implementation uses typedef double (as opposed to float, double, long double.)

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator float()

operator float ( ) const

conversion operator to float

Note: The implementation uses typedef double (as opposed to float, double, long double.)

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator int()

operator int ( ) const

conversion operator to int

Note: The implementation uses typedef ptrdiff_t.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator long double()

operator long double ( ) const

conversion operator to long double

Note: The implementation uses typedef double (as opposed to float, double, long double.)

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator long int()

operator long int ( ) const

conversion operator to long int

Note: The implementation uses typedef ptrdiff_t.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator long long()

operator long long ( ) const

conversion operator to long long

Note: The implementation uses typedef ptrdiff_t.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator short int()

operator short int ( ) const

conversion operator to short int

Note: The implementation uses typedef ptrdiff_t.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator std::string()

operator std::string ( ) const

conversion operator to string

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator std::vector< double >()

operator std::vector< double > ( ) const

conversion operator to double vector

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator std::vector< int >()

operator std::vector< int > ( ) const

conversion operator to integer vector

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator std::vector< std::string >()

operator std::vector< std::string > ( ) const

conversion operator to string vector

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator unsigned int()

operator unsigned int ( ) const

conversion operator to unsigned int

Note: The implementation uses typedef ptrdiff_t.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator unsigned long int()

operator unsigned long int ( ) const

conversion operator to unsigned long int

Note: The implementation uses typedef ptrdiff_t.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator unsigned long long()

operator unsigned long long ( ) const

conversion operator to unsigned long long

Note: The implementation uses typedef ptrdiff_t.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator unsigned short int()

operator unsigned short int ( ) const

conversion operator to unsigned short int

Note: The implementation uses typedef ptrdiff_t.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ operator=() [1/18]

ParamValue& operator= ( const char *  )

specific assignment for char* (converted to string)

◆ operator=() [2/18]

ParamValue& operator= ( const double  )

specific assignment for double values (note: the implementation uses double)

◆ operator=() [3/18]

ParamValue& operator= ( const float  )

specific assignment for float values (note: the implementation uses double)

◆ operator=() [4/18]

ParamValue& operator= ( const int  )

specific assignment for int values (note: the implementation uses ptrdiff_t)

◆ operator=() [5/18]

ParamValue& operator= ( const long double  )

specific assignment for long double values (note: the implementation uses double)

◆ operator=() [6/18]

ParamValue& operator= ( const long int  )

specific assignment for long int values (note: the implementation uses ptrdiff_t)

◆ operator=() [7/18]

ParamValue& operator= ( const long long  )

specific assignment for long long int values (note: the implementation uses ptrdiff_t)

◆ operator=() [8/18]

ParamValue& operator= ( const ParamValue )

Assignment operator.

◆ operator=() [9/18]

ParamValue& operator= ( const short int  )

specific assignment for short int values (note: the implementation uses ptrdiff_t)

◆ operator=() [10/18]

ParamValue& operator= ( const std::string &  )

specific assignment for std::string values

◆ operator=() [11/18]

ParamValue& operator= ( const std::vector< double > &  )

specific assignment for double vectors

◆ operator=() [12/18]

ParamValue& operator= ( const std::vector< int > &  )

specific assignment for integer vectors

◆ operator=() [13/18]

ParamValue& operator= ( const std::vector< std::string > &  )

specific assignment for string vectors

◆ operator=() [14/18]

ParamValue& operator= ( const unsigned long long  )

specific assignment for unsigned long long int values (note: the implementation uses ptrdiff_t)

◆ operator=() [15/18]

ParamValue& operator= ( const unsigned long  )

specific assignment for unsigned long int values (note: the implementation uses ptrdiff_t)

◆ operator=() [16/18]

ParamValue& operator= ( const unsigned short int  )

specific assignment for unsigned short int values (note: the implementation uses ptrdiff_t)

◆ operator=() [17/18]

ParamValue& operator= ( const unsigned  )

specific assignment for unsigned int values (note: the implementation uses ptrdiff_t)

◆ operator=() [18/18]

ParamValue& operator= ( ParamValue &&  )
noexcept

Move assignment operator.

◆ toBool()

bool toBool ( ) const

Conversion to bool.

Converts the strings 'true' and 'false' to a bool.

Exceptions
Exception::ConversionErroris thrown for non-string parameters and string parameters with values other than 'true' and 'false'.

Referenced by SignalToNoiseEstimatorMedian< Container >::updateMembers_().

◆ toChar()

const char* toChar ( ) const

Convert ParamValues to char*.

If the ParamValue contains a string, a pointer to it's char* is returned. If the ParamValue is empty, nullptr is returned.

◆ toDoubleVector()

std::vector<double> toDoubleVector ( ) const

Explicitly convert ParamValue to DoubleList.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ toIntVector()

std::vector<int> toIntVector ( ) const

Explicitly convert ParamValue to IntList.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ toString()

◆ toStringVector()

std::vector<std::string> toStringVector ( ) const

Explicitly convert ParamValue to string vector.

Exceptions
Exception::ConversionErroris thrown if a cast from the the wrong type is requested

◆ valueType()

ValueType valueType ( ) const
inline

returns the type of value stored

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const ParamValue ,
const ParamValue  
)
friend

Equality comparator.

◆ operator<

bool operator< ( const ParamValue ,
const ParamValue  
)
friend

Smaller than comparator (for vectors we use the size)

◆ operator<<

std::ostream& operator<< ( std::ostream &  ,
const ParamValue  
)
friend

output stream operator

◆ operator==

bool operator== ( const ParamValue ,
const ParamValue  
)
friend

Equality comparator.

◆ operator>

bool operator> ( const ParamValue ,
const ParamValue  
)
friend

Greater than comparator (for vectors we use the size)

Member Data Documentation

◆ 

union { ... } data_

Space to store the data.

◆ EMPTY

const ParamValue EMPTY
static

Empty data value for comparisons.

◆ value_type_

ValueType value_type_
protected

Type of the currently stored value.