OpenMS  2.8.0
DataValue.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 
40 #include <OpenMS/CONCEPT/Types.h>
41 #include <OpenMS/OpenMSConfig.h>
42 
43 class QString;
44 
45 namespace OpenMS
46 {
47  class ParamValue;
48 
58  class OPENMS_DLLAPI DataValue
59  {
60 
61 public:
62 
64  static const DataValue EMPTY;
65 
67  enum DataType : unsigned char
68  {
75  EMPTY_VALUE
76  };
77 
79  enum UnitType : unsigned char
80  {
83  OTHER
84  };
85 
87 
88  DataValue();
93  DataValue(DataValue&&) noexcept;
95  DataValue(const char*);
97  DataValue(const std::string&);
99  DataValue(const String&);
101  DataValue(const QString&);
109  DataValue(long double);
111  DataValue(double);
113  DataValue(float);
115  DataValue(short int);
117  DataValue(unsigned short int);
119  DataValue(int);
121  DataValue(unsigned);
123  DataValue(long int);
125  DataValue(unsigned long);
127  DataValue(long long);
129  DataValue(unsigned long long);
135 
139 
140 
144  operator ParamValue() const;
145 
151  operator std::string() const;
152 
158  operator StringList() const;
159 
165  operator IntList() const;
166 
172  operator DoubleList() const;
173 
181  operator long double() const;
182 
190  operator double() const;
191 
199  operator float() const;
200 
208  operator short int() const;
209 
217  operator unsigned short int() const;
218 
227  operator int() const;
228 
236  operator unsigned int() const;
237 
245  operator long int() const;
246 
254  operator unsigned long int() const;
255 
263  operator long long() const;
264 
272  operator unsigned long long() const;
273 
281  bool toBool() const;
282 
289  const char* toChar() const;
290 
296  StringList toStringList() const;
297 
303  IntList toIntList() const;
304 
310  DoubleList toDoubleList() const;
312 
315 
316  DataValue& operator=(const DataValue&);
319  DataValue& operator=(DataValue&&) noexcept;
321  DataValue& operator=(const char*);
323  DataValue& operator=(const std::string&);
325  DataValue& operator=(const String&);
327  DataValue& operator=(const QString&);
329  DataValue& operator=(const StringList&);
331  DataValue& operator=(const IntList&);
333  DataValue& operator=(const DoubleList&);
335  DataValue& operator=(const long double);
337  DataValue& operator=(const double);
339  DataValue& operator=(const float);
341  DataValue& operator=(const short int);
343  DataValue& operator=(const unsigned short int);
345  DataValue& operator=(const int);
347  DataValue& operator=(const unsigned);
349  DataValue& operator=(const long int);
351  DataValue& operator=(const unsigned long);
353  DataValue& operator=(const long long);
355  DataValue& operator=(const unsigned long long);
357 
361 
362 
367  String toString(bool full_precision = true) const;
368 
370  QString toQString() const;
372 
374  inline DataType valueType() const
375  {
376  return value_type_;
377  }
378 
384  inline bool isEmpty() const
385  {
386  return value_type_ == EMPTY_VALUE;
387  }
388 
391 
392 
394  inline UnitType getUnitType() const
395  {
396  return unit_type_;
397  }
398 
399  inline void setUnitType(const UnitType & u)
400  {
401  unit_type_ = u;
402  }
403 
405  inline bool hasUnit() const
406  {
407  return unit_ != -1;
408  }
409 
411  const int32_t & getUnit() const;
412 
414  void setUnit(const int32_t & unit);
415 
417 
419  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const DataValue&);
420 
422  friend OPENMS_DLLAPI bool operator==(const DataValue&, const DataValue&);
423 
425  friend OPENMS_DLLAPI bool operator<(const DataValue&, const DataValue&);
426 
428  friend OPENMS_DLLAPI bool operator>(const DataValue&, const DataValue&);
429 
431  friend OPENMS_DLLAPI bool operator!=(const DataValue&, const DataValue&);
432 
433 protected:
434 
437 
440 
442  int32_t unit_;
443 
445  union
446  {
447  SignedSize ssize_;
448  double dou_;
449  String* str_;
450  StringList* str_list_;
451  IntList* int_list_;
452  DoubleList* dou_list_;
453  } data_;
454 
455 private:
456 
458  void clear_() noexcept;
459  };
460 }
461 
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:59
static const DataValue EMPTY
Empty data value for comparisons.
Definition: DataValue.h:64
friend std::ostream & operator<<(std::ostream &, const DataValue &)
output stream operator
void setUnitType(const UnitType &u)
Definition: DataValue.h:399
UnitType
Supported types for DataValue.
Definition: DataValue.h:80
@ MS_ONTOLOGY
ms.ontology MS
Definition: DataValue.h:82
@ UNIT_ONTOLOGY
unit.ontology UO
Definition: DataValue.h:81
int32_t unit_
The unit of the data value (if it has one) using UO identifier, otherwise -1.
Definition: DataValue.h:442
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:68
@ DOUBLE_VALUE
double value
Definition: DataValue.h:71
@ INT_LIST
integer list
Definition: DataValue.h:73
@ STRING_VALUE
string value
Definition: DataValue.h:69
@ STRING_LIST
string list
Definition: DataValue.h:72
@ INT_VALUE
integer value
Definition: DataValue.h:70
@ DOUBLE_LIST
double list
Definition: DataValue.h:74
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:439
UnitType getUnitType() const
returns the type of value stored
Definition: DataValue.h:394
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:405
DataValue(DataValue &&) noexcept
Move constructor.
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:384
DataType value_type_
Type of the currently stored value.
Definition: DataValue.h:436
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:55
A more convenient string class.
Definition: String.h:60
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
static QString toQString(const String &this_s)
Definition: StringUtils.h:201
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
const std::string & toString(const DriftTimeUnit value)