OpenMS
DataValue.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg$
6 // $Authors: Marc Sturm $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
13 
14 #include <OpenMS/CONCEPT/Types.h>
15 #include <OpenMS/OpenMSConfig.h>
16 
17 class QString;
18 
19 namespace OpenMS
20 {
21  class ParamValue;
22 
32  class OPENMS_DLLAPI DataValue
33  {
34 
35 public:
36 
38  static const DataValue EMPTY;
39 
41  enum DataType : unsigned char
42  {
50  SIZE_OF_DATATYPE
51  };
52 
54  static const std::string NamesOfDataType[SIZE_OF_DATATYPE];
55 
57  enum UnitType : unsigned char
58  {
61  OTHER
62  };
63 
65 
66  DataValue();
71  DataValue(DataValue&&) noexcept;
73  DataValue(const char*);
75  DataValue(const std::string&);
77  DataValue(const String&);
79  DataValue(const QString&);
83  DataValue(const IntList&);
87  DataValue(long double);
89  DataValue(double);
91  DataValue(float);
93  DataValue(short int);
95  DataValue(unsigned short int);
97  DataValue(int);
99  DataValue(unsigned);
101  DataValue(long int);
103  DataValue(unsigned long);
105  DataValue(long long);
107  DataValue(unsigned long long);
113 
117 
118 
122  operator ParamValue() const;
123 
129  operator std::string() const;
130 
136  operator StringList() const;
137 
143  operator IntList() const;
144 
150  operator DoubleList() const;
151 
159  operator long double() const;
160 
168  operator double() const;
169 
177  operator float() const;
178 
186  operator short int() const;
187 
195  operator unsigned short int() const;
196 
205  operator int() const;
206 
214  operator unsigned int() const;
215 
223  operator long int() const;
224 
232  operator unsigned long int() const;
233 
241  operator long long() const;
242 
250  operator unsigned long long() const;
251 
259  bool toBool() const;
260 
267  const char* toChar() const;
268 
274  StringList toStringList() const;
275 
281  IntList toIntList() const;
282 
288  DoubleList toDoubleList() const;
290 
293 
294  DataValue& operator=(const DataValue&);
297  DataValue& operator=(DataValue&&) noexcept;
299  DataValue& operator=(const char*);
301  DataValue& operator=(const std::string&);
303  DataValue& operator=(const String&);
305  DataValue& operator=(const QString&);
307  DataValue& operator=(const StringList&);
309  DataValue& operator=(const IntList&);
311  DataValue& operator=(const DoubleList&);
313  DataValue& operator=(const long double);
315  DataValue& operator=(const double);
317  DataValue& operator=(const float);
319  DataValue& operator=(const short int);
321  DataValue& operator=(const unsigned short int);
323  DataValue& operator=(const int);
325  DataValue& operator=(const unsigned);
327  DataValue& operator=(const long int);
329  DataValue& operator=(const unsigned long);
331  DataValue& operator=(const long long);
333  DataValue& operator=(const unsigned long long);
335 
339 
340 
345  String toString(bool full_precision = true) const;
346 
348  QString toQString() const;
350 
352  inline DataType valueType() const
353  {
354  return value_type_;
355  }
356 
362  inline bool isEmpty() const
363  {
364  return value_type_ == EMPTY_VALUE;
365  }
366 
369 
370 
372  inline UnitType getUnitType() const
373  {
374  return unit_type_;
375  }
376 
377  inline void setUnitType(const UnitType & u)
378  {
379  unit_type_ = u;
380  }
381 
383  inline bool hasUnit() const
384  {
385  return unit_ != -1;
386  }
387 
389  const int32_t & getUnit() const;
390 
392  void setUnit(const int32_t & unit);
393 
395 
397  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const DataValue&);
398 
400  friend OPENMS_DLLAPI bool operator==(const DataValue&, const DataValue&);
401 
403  friend OPENMS_DLLAPI bool operator<(const DataValue&, const DataValue&);
404 
406  friend OPENMS_DLLAPI bool operator>(const DataValue&, const DataValue&);
407 
409  friend OPENMS_DLLAPI bool operator!=(const DataValue&, const DataValue&);
410 
411 protected:
412 
415 
418 
420  int32_t unit_;
421 
423  union
424  {
425  SignedSize ssize_;
426  double dou_;
427  String* str_;
428  StringList* str_list_;
429  IntList* int_list_;
430  DoubleList* dou_list_;
431  } data_;
432 
433 private:
434 
436  void clear_() noexcept;
437  };
438 }
439 
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:33
static const DataValue EMPTY
Empty data value for comparisons.
Definition: DataValue.h:38
friend std::ostream & operator<<(std::ostream &, const DataValue &)
output stream operator
void setUnitType(const UnitType &u)
Definition: DataValue.h:377
UnitType
Supported types for DataValue.
Definition: DataValue.h:58
@ MS_ONTOLOGY
ms.ontology MS
Definition: DataValue.h:60
@ UNIT_ONTOLOGY
unit.ontology UO
Definition: DataValue.h:59
int32_t unit_
The unit of the data value (if it has one) using UO identifier, otherwise -1.
Definition: DataValue.h:420
DataValue(const DataValue &)
Copy constructor.
friend bool operator>(const DataValue &, const DataValue &)
Greater than comparator (for lists we use the size)
DataType
Supported types for DataValue.
Definition: DataValue.h:42
@ DOUBLE_VALUE
double value
Definition: DataValue.h:45
@ EMPTY_VALUE
empty
Definition: DataValue.h:49
@ INT_LIST
integer list
Definition: DataValue.h:47
@ STRING_VALUE
string value
Definition: DataValue.h:43
@ STRING_LIST
string list
Definition: DataValue.h:46
@ INT_VALUE
integer value
Definition: DataValue.h:44
@ DOUBLE_LIST
double list
Definition: DataValue.h:48
friend bool operator<(const DataValue &, const DataValue &)
Smaller than comparator (for lists we use the size)
void setUnit(const int32_t &unit)
Sets the unit to the given String.
const int32_t & getUnit() const
Return the unit associated to this DataValue.
friend bool operator==(const DataValue &, const DataValue &)
Equality comparator.
UnitType unit_type_
Type of the currently stored unit.
Definition: DataValue.h:417
UnitType getUnitType() const
returns the type of value stored
Definition: DataValue.h:372
void clear_() noexcept
Clears the current state of the DataValue and release every used memory.
bool hasUnit() const
Check if the value has a unit.
Definition: DataValue.h:383
DataValue(DataValue &&) noexcept
Move constructor.
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:362
DataType value_type_
Type of the currently stored value.
Definition: DataValue.h:414
friend bool operator!=(const DataValue &, const DataValue &)
Equality comparator.
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition: ParamValue.h:29
A more convenient string class.
Definition: String.h:34
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:108
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:29
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:44
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:36
static QString toQString(const String &this_s)
Definition: StringUtils.h:196
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
const std::string & toString(const DriftTimeUnit value)