OpenMS  2.8.0
Public Types | Static Public Attributes | List of all members
DataValue Class Reference

Class to hold strings, numeric values, lists of strings and lists of numeric values. More...

#include <OpenMS/DATASTRUCTURES/DataValue.h>

Collaboration diagram for DataValue:
[legend]

Public Types

enum  DataType : unsigned char {
  STRING_VALUE , INT_VALUE , DOUBLE_VALUE , STRING_LIST ,
  INT_LIST , DOUBLE_LIST , EMPTY_VALUE
}
 Supported types for DataValue. More...
 
enum  UnitType : unsigned char { UNIT_ONTOLOGY , MS_ONTOLOGY , OTHER }
 Supported types for DataValue. More...
 

Public Member Functions

Constructors and destructors
 DataValue ()
 Default constructor. More...
 
 DataValue (const DataValue &)
 Copy constructor. More...
 
 DataValue (DataValue &&) noexcept
 Move constructor. More...
 
 DataValue (const char *)
 specific constructor for char* (converted to string) More...
 
 DataValue (const std::string &)
 specific constructor for std::string values More...
 
 DataValue (const String &)
 specific constructor for string values More...
 
 DataValue (const QString &)
 specific constructor for QString values More...
 
 DataValue (const StringList &)
 specific constructor for string lists More...
 
 DataValue (const IntList &)
 specific constructor for integer lists More...
 
 DataValue (const DoubleList &)
 specific constructor for double lists More...
 
 DataValue (long double)
 specific constructor for long double values (note: the implementation uses double) More...
 
 DataValue (double)
 specific constructor for double values (note: the implementation uses double) More...
 
 DataValue (float)
 specific constructor for float values (note: the implementation uses double) More...
 
 DataValue (short int)
 specific constructor for short int values (note: the implementation uses SignedSize) More...
 
 DataValue (unsigned short int)
 specific constructor for unsigned short int values (note: the implementation uses SignedSize) More...
 
 DataValue (int)
 specific constructor for int values (note: the implementation uses SignedSize) More...
 
 DataValue (unsigned)
 specific constructor for unsigned int values (note: the implementation uses SignedSize) More...
 
 DataValue (long int)
 specific constructor for long int values (note: the implementation uses SignedSize) More...
 
 DataValue (unsigned long)
 specific constructor for unsigned long int values (note: the implementation uses SignedSize) More...
 
 DataValue (long long)
 specific constructor for long long int values (note: the implementation uses SignedSize) More...
 
 DataValue (unsigned long long)
 specific constructor for unsigned long long int values (note: the implementation uses SignedSize) More...
 
 DataValue (const ParamValue &)
 specific constructor for ParamValue More...
 
 ~DataValue ()
 Destructor. More...
 
Cast operators

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

 operator ParamValue () const
 conversion operator to ParamValue based on DataType More...
 
 operator std::string () const
 conversion operator to string More...
 
 operator StringList () const
 conversion operator to string list More...
 
 operator IntList () const
 conversion operator to integer list More...
 
 operator DoubleList () const
 conversion operator to double list 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 DataValues to char*. More...
 
StringList toStringList () const
 Explicitly convert DataValue to StringList. More...
 
IntList toIntList () const
 Explicitly convert DataValue to IntList. More...
 
DoubleList toDoubleList () const
 Explicitly convert DataValue to DoubleList. More...
 
Assignment operators

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

DataValueoperator= (const DataValue &)
 Assignment operator. More...
 
DataValueoperator= (DataValue &&) noexcept
 Move assignment operator. More...
 
DataValueoperator= (const char *)
 specific assignment for char* (converted to string) More...
 
DataValueoperator= (const std::string &)
 specific assignment for std::string values More...
 
DataValueoperator= (const String &)
 specific assignment for string values More...
 
DataValueoperator= (const QString &)
 specific assignment for QString values More...
 
DataValueoperator= (const StringList &)
 specific assignment for string lists More...
 
DataValueoperator= (const IntList &)
 specific assignment for integer lists More...
 
DataValueoperator= (const DoubleList &)
 specific assignment for double lists More...
 
DataValueoperator= (const long double)
 specific assignment for long double values (note: the implementation uses double) More...
 
DataValueoperator= (const double)
 specific assignment for double values (note: the implementation uses double) More...
 
DataValueoperator= (const float)
 specific assignment for float values (note: the implementation uses double) More...
 
DataValueoperator= (const short int)
 specific assignment for short int values (note: the implementation uses SignedSize) More...
 
DataValueoperator= (const unsigned short int)
 specific assignment for unsigned short int values (note: the implementation uses SignedSize) More...
 
DataValueoperator= (const int)
 specific assignment for int values (note: the implementation uses SignedSize) More...
 
DataValueoperator= (const unsigned)
 specific assignment for unsigned int values (note: the implementation uses SignedSize) More...
 
DataValueoperator= (const long int)
 specific assignment for long int values (note: the implementation uses SignedSize) More...
 
DataValueoperator= (const unsigned long)
 specific assignment for unsigned long int values (note: the implementation uses SignedSize) More...
 
DataValueoperator= (const long long)
 specific assignment for long long int values (note: the implementation uses SignedSize) More...
 
DataValueoperator= (const unsigned long long)
 specific assignment for unsigned long long int values (note: the implementation uses SignedSize) More...
 
Conversion operators

These methods can be used independent of the DataType. If you already know the DataType, you should use a cast operator!
For conversion of string DataValues to numeric types, first use toString() and then the conversion methods of String.

String toString (bool full_precision=true) const
 Conversion to String full_precision Controls number of fractional digits for all double types or lists of double, 3 digits when false, and 15 when true. More...
 
QString toQString () const
 Conversion to QString. More...
 
DataType valueType () const
 returns the type of value stored More...
 
bool isEmpty () const
 Test if the value is empty. More...
 

Static Public Attributes

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

Methods to handle units

These methods are used when the DataValue has an associated unit.

DataType value_type_
 Type of the currently stored value. More...
 
UnitType unit_type_
 Type of the currently stored unit. More...
 
int32_t unit_
 The unit of the data value (if it has one) using UO identifier, otherwise -1. More...
 
union {
SignedSize ssize_
 
double dou_
 
Stringstr_
 
StringListstr_list_
 
IntListint_list_
 
DoubleListdou_list_
 
data_
 Space to store the data. More...
 
UnitType getUnitType () const
 returns the type of value stored More...
 
void setUnitType (const UnitType &u)
 
bool hasUnit () const
 Check if the value has a unit. More...
 
const int32_t & getUnit () const
 Return the unit associated to this DataValue. More...
 
void setUnit (const int32_t &unit)
 Sets the unit to the given String. More...
 
std::ostream & operator<< (std::ostream &, const DataValue &)
 output stream operator More...
 
bool operator== (const DataValue &, const DataValue &)
 Equality comparator. More...
 
bool operator< (const DataValue &, const DataValue &)
 Smaller than comparator (for lists we use the size) More...
 
bool operator> (const DataValue &, const DataValue &)
 Greater than comparator (for lists we use the size) More...
 
bool operator!= (const DataValue &, const DataValue &)
 Equality comparator. More...
 
void clear_ () noexcept
 Clears the current state of the DataValue and release every used memory. More...
 

Detailed Description

Class to hold strings, numeric values, lists of strings and lists of numeric values.

Member Enumeration Documentation

◆ DataType

enum DataType : unsigned char

Supported types for DataValue.

Enumerator
STRING_VALUE 

string value

INT_VALUE 

integer value

DOUBLE_VALUE 

double value

STRING_LIST 

string list

INT_LIST 

integer list

DOUBLE_LIST 

double list

EMPTY_VALUE 

empty value

◆ UnitType

enum UnitType : unsigned char

Supported types for DataValue.

Enumerator
UNIT_ONTOLOGY 

unit.ontology UO

MS_ONTOLOGY 

ms.ontology MS

OTHER 

undefined ontology

Constructor & Destructor Documentation

◆ DataValue() [1/22]

DataValue ( )

Default constructor.

◆ DataValue() [2/22]

DataValue ( const DataValue )

Copy constructor.

◆ DataValue() [3/22]

DataValue ( DataValue &&  )
noexcept

Move constructor.

◆ DataValue() [4/22]

DataValue ( const char *  )

specific constructor for char* (converted to string)

◆ DataValue() [5/22]

DataValue ( const std::string &  )

specific constructor for std::string values

◆ DataValue() [6/22]

DataValue ( const String )

specific constructor for string values

◆ DataValue() [7/22]

DataValue ( const QString &  )

specific constructor for QString values

◆ DataValue() [8/22]

DataValue ( const StringList )

specific constructor for string lists

◆ DataValue() [9/22]

DataValue ( const IntList )

specific constructor for integer lists

◆ DataValue() [10/22]

DataValue ( const DoubleList )

specific constructor for double lists

◆ DataValue() [11/22]

DataValue ( long double  )

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

◆ DataValue() [12/22]

DataValue ( double  )

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

◆ DataValue() [13/22]

DataValue ( float  )

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

◆ DataValue() [14/22]

DataValue ( short int  )

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

◆ DataValue() [15/22]

DataValue ( unsigned short int  )

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

◆ DataValue() [16/22]

DataValue ( int  )

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

◆ DataValue() [17/22]

DataValue ( unsigned  )

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

◆ DataValue() [18/22]

DataValue ( long int  )

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

◆ DataValue() [19/22]

DataValue ( unsigned long  )

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

◆ DataValue() [20/22]

DataValue ( long long  )

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

◆ DataValue() [21/22]

DataValue ( unsigned long long  )

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

◆ DataValue() [22/22]

DataValue ( const ParamValue )

specific constructor for ParamValue

◆ ~DataValue()

~DataValue ( )

Destructor.

Member Function Documentation

◆ clear_()

void clear_ ( )
privatenoexcept

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

◆ getUnit()

const int32_t& getUnit ( ) const

Return the unit associated to this DataValue.

◆ getUnitType()

UnitType getUnitType ( ) const
inline

returns the type of value stored

◆ hasUnit()

bool hasUnit ( ) const
inline

Check if the value has a unit.

◆ isEmpty()

bool isEmpty ( ) const
inline

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

operator DoubleList ( ) const

conversion operator to double list

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 SignedSize.

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

◆ operator IntList()

operator IntList ( ) const

conversion operator to integer list

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 SignedSize.

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 SignedSize.

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

◆ operator ParamValue()

operator ParamValue ( ) const

conversion operator to ParamValue based on DataType

◆ operator short int()

operator short int ( ) const

conversion operator to short int

Note: The implementation uses typedef SignedSize.

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

operator StringList ( ) const

conversion operator to string list

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 SignedSize.

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 SignedSize.

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 SignedSize.

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 SignedSize.

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

◆ operator=() [1/20]

DataValue& operator= ( const char *  )

specific assignment for char* (converted to string)

◆ operator=() [2/20]

DataValue& operator= ( const DataValue )

Assignment operator.

◆ operator=() [3/20]

DataValue& operator= ( const double  )

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

◆ operator=() [4/20]

DataValue& operator= ( const DoubleList )

specific assignment for double lists

◆ operator=() [5/20]

DataValue& operator= ( const float  )

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

◆ operator=() [6/20]

DataValue& operator= ( const int  )

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

◆ operator=() [7/20]

DataValue& operator= ( const IntList )

specific assignment for integer lists

◆ operator=() [8/20]

DataValue& operator= ( const long double  )

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

◆ operator=() [9/20]

DataValue& operator= ( const long int  )

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

◆ operator=() [10/20]

DataValue& operator= ( const long long  )

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

◆ operator=() [11/20]

DataValue& operator= ( const QString &  )

specific assignment for QString values

◆ operator=() [12/20]

DataValue& operator= ( const short int  )

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

◆ operator=() [13/20]

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

specific assignment for std::string values

◆ operator=() [14/20]

DataValue& operator= ( const String )

specific assignment for string values

◆ operator=() [15/20]

DataValue& operator= ( const StringList )

specific assignment for string lists

◆ operator=() [16/20]

DataValue& operator= ( const unsigned long long  )

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

◆ operator=() [17/20]

DataValue& operator= ( const unsigned long  )

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

◆ operator=() [18/20]

DataValue& operator= ( const unsigned short int  )

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

◆ operator=() [19/20]

DataValue& operator= ( const unsigned  )

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

◆ operator=() [20/20]

DataValue& operator= ( DataValue &&  )
noexcept

Move assignment operator.

◆ setUnit()

void setUnit ( const int32_t &  unit)

Sets the unit to the given String.

◆ setUnitType()

void setUnitType ( const UnitType u)
inline

◆ 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'.

◆ toChar()

const char* toChar ( ) const

Convert DataValues to char*.

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

◆ toDoubleList()

DoubleList toDoubleList ( ) const

Explicitly convert DataValue to DoubleList.

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

◆ toIntList()

IntList toIntList ( ) const

Explicitly convert DataValue to IntList.

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

◆ toQString()

QString toQString ( ) const

Conversion to QString.

◆ toString()

String toString ( bool  full_precision = true) const

Conversion to String full_precision Controls number of fractional digits for all double types or lists of double, 3 digits when false, and 15 when true.

Referenced by OpenMS::StringConversions::append(), SiriusAdapterAlgorithm::ParameterSection::getCommandLine(), IDBoostGraph::GetScoreTgTVisitor::operator()(), IDScoreSwitcherAlgorithm::switchScores(), and OpenMS::StringConversions::toString().

◆ toStringList()

StringList toStringList ( ) const

Explicitly convert DataValue to StringList.

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

◆ valueType()

DataType valueType ( ) const
inline

returns the type of value stored

Friends And Related Function Documentation

◆ operator!=

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

Equality comparator.

◆ operator<

bool operator< ( const DataValue ,
const DataValue  
)
friend

Smaller than comparator (for lists we use the size)

◆ operator<<

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

output stream operator

◆ operator==

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

Equality comparator.

◆ operator>

bool operator> ( const DataValue ,
const DataValue  
)
friend

Greater than comparator (for lists we use the size)

Member Data Documentation

◆ 

union { ... } data_

Space to store the data.

◆ EMPTY

const DataValue EMPTY
static

Empty data value for comparisons.

◆ unit_

int32_t unit_
protected

The unit of the data value (if it has one) using UO identifier, otherwise -1.

◆ unit_type_

UnitType unit_type_
protected

Type of the currently stored unit.

◆ value_type_

DataType value_type_
protected

Type of the currently stored value.