OpenMS  2.7.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 
146  operator std::string() const;
147 
153  operator StringList() const;
154 
160  operator IntList() const;
161 
167  operator DoubleList() const;
168 
176  operator long double() const;
177 
185  operator double() const;
186 
194  operator float() const;
195 
203  operator short int() const;
204 
212  operator unsigned short int() const;
213 
222  operator int() const;
223 
231  operator unsigned int() const;
232 
240  operator long int() const;
241 
249  operator unsigned long int() const;
250 
258  operator long long() const;
259 
267  operator unsigned long long() const;
268 
276  bool toBool() const;
277 
284  const char* toChar() const;
285 
291  StringList toStringList() const;
292 
298  IntList toIntList() const;
299 
305  DoubleList toDoubleList() const;
307 
310 
311  DataValue& operator=(const DataValue&);
314  DataValue& operator=(DataValue&&) noexcept;
316  DataValue& operator=(const char*);
318  DataValue& operator=(const std::string&);
320  DataValue& operator=(const String&);
322  DataValue& operator=(const QString&);
324  DataValue& operator=(const StringList&);
326  DataValue& operator=(const IntList&);
328  DataValue& operator=(const DoubleList&);
330  DataValue& operator=(const long double);
332  DataValue& operator=(const double);
334  DataValue& operator=(const float);
336  DataValue& operator=(const short int);
338  DataValue& operator=(const unsigned short int);
340  DataValue& operator=(const int);
342  DataValue& operator=(const unsigned);
344  DataValue& operator=(const long int);
346  DataValue& operator=(const unsigned long);
348  DataValue& operator=(const long long);
350  DataValue& operator=(const unsigned long long);
352 
356 
357 
362  String toString(bool full_precision = true) const;
363 
365  QString toQString() const;
367 
369  inline DataType valueType() const
370  {
371  return value_type_;
372  }
373 
379  inline bool isEmpty() const
380  {
381  return value_type_ == EMPTY_VALUE;
382  }
383 
386 
387 
389  inline UnitType getUnitType() const
390  {
391  return unit_type_;
392  }
393 
394  inline void setUnitType(const UnitType & u)
395  {
396  unit_type_ = u;
397  }
398 
400  inline bool hasUnit() const
401  {
402  return unit_ != -1;
403  }
404 
406  const int32_t & getUnit() const;
407 
409  void setUnit(const int32_t & unit);
410 
412 
414  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const DataValue&);
415 
417  friend OPENMS_DLLAPI bool operator==(const DataValue&, const DataValue&);
418 
420  friend OPENMS_DLLAPI bool operator<(const DataValue&, const DataValue&);
421 
423  friend OPENMS_DLLAPI bool operator>(const DataValue&, const DataValue&);
424 
426  friend OPENMS_DLLAPI bool operator!=(const DataValue&, const DataValue&);
427 
428 protected:
429 
432 
435 
437  int32_t unit_;
438 
440  union
441  {
442  SignedSize ssize_;
443  double dou_;
444  String* str_;
445  StringList* str_list_;
446  IntList* int_list_;
447  DoubleList* dou_list_;
448  } data_;
449 
450 private:
451 
453  void clear_() noexcept;
454  };
455 }
456 
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:394
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:437
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:434
UnitType getUnitType() const
returns the type of value stored
Definition: DataValue.h:389
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:400
DataValue(DataValue &&) noexcept
Move constructor.
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:379
DataType value_type_
Type of the currently stored value.
Definition: DataValue.h:431
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:53
A more convenient string class.
Definition: String.h:61
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
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
const std::string & toString(const DriftTimeUnit value)