OpenMS
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-2023.
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  {
76  SIZE_OF_DATATYPE
77  };
78 
80  static const std::string NamesOfDataType[SIZE_OF_DATATYPE];
81 
83  enum UnitType : unsigned char
84  {
87  OTHER
88  };
89 
91 
92  DataValue();
97  DataValue(DataValue&&) noexcept;
99  DataValue(const char*);
101  DataValue(const std::string&);
103  DataValue(const String&);
105  DataValue(const QString&);
113  DataValue(long double);
115  DataValue(double);
117  DataValue(float);
119  DataValue(short int);
121  DataValue(unsigned short int);
123  DataValue(int);
125  DataValue(unsigned);
127  DataValue(long int);
129  DataValue(unsigned long);
131  DataValue(long long);
133  DataValue(unsigned long long);
139 
143 
144 
148  operator ParamValue() const;
149 
155  operator std::string() const;
156 
162  operator StringList() const;
163 
169  operator IntList() const;
170 
176  operator DoubleList() const;
177 
185  operator long double() const;
186 
194  operator double() const;
195 
203  operator float() const;
204 
212  operator short int() const;
213 
221  operator unsigned short int() const;
222 
231  operator int() const;
232 
240  operator unsigned int() const;
241 
249  operator long int() const;
250 
258  operator unsigned long int() const;
259 
267  operator long long() const;
268 
276  operator unsigned long long() const;
277 
285  bool toBool() const;
286 
293  const char* toChar() const;
294 
300  StringList toStringList() const;
301 
307  IntList toIntList() const;
308 
314  DoubleList toDoubleList() const;
316 
319 
320  DataValue& operator=(const DataValue&);
323  DataValue& operator=(DataValue&&) noexcept;
325  DataValue& operator=(const char*);
327  DataValue& operator=(const std::string&);
329  DataValue& operator=(const String&);
331  DataValue& operator=(const QString&);
333  DataValue& operator=(const StringList&);
335  DataValue& operator=(const IntList&);
337  DataValue& operator=(const DoubleList&);
339  DataValue& operator=(const long double);
341  DataValue& operator=(const double);
343  DataValue& operator=(const float);
345  DataValue& operator=(const short int);
347  DataValue& operator=(const unsigned short int);
349  DataValue& operator=(const int);
351  DataValue& operator=(const unsigned);
353  DataValue& operator=(const long int);
355  DataValue& operator=(const unsigned long);
357  DataValue& operator=(const long long);
359  DataValue& operator=(const unsigned long long);
361 
365 
366 
371  String toString(bool full_precision = true) const;
372 
374  QString toQString() const;
376 
378  inline DataType valueType() const
379  {
380  return value_type_;
381  }
382 
388  inline bool isEmpty() const
389  {
390  return value_type_ == EMPTY_VALUE;
391  }
392 
395 
396 
398  inline UnitType getUnitType() const
399  {
400  return unit_type_;
401  }
402 
403  inline void setUnitType(const UnitType & u)
404  {
405  unit_type_ = u;
406  }
407 
409  inline bool hasUnit() const
410  {
411  return unit_ != -1;
412  }
413 
415  const int32_t & getUnit() const;
416 
418  void setUnit(const int32_t & unit);
419 
421 
423  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const DataValue&);
424 
426  friend OPENMS_DLLAPI bool operator==(const DataValue&, const DataValue&);
427 
429  friend OPENMS_DLLAPI bool operator<(const DataValue&, const DataValue&);
430 
432  friend OPENMS_DLLAPI bool operator>(const DataValue&, const DataValue&);
433 
435  friend OPENMS_DLLAPI bool operator!=(const DataValue&, const DataValue&);
436 
437 protected:
438 
441 
444 
446  int32_t unit_;
447 
449  union
450  {
451  SignedSize ssize_;
452  double dou_;
453  String* str_;
454  StringList* str_list_;
455  IntList* int_list_;
456  DoubleList* dou_list_;
457  } data_;
458 
459 private:
460 
462  void clear_() noexcept;
463  };
464 }
465 
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:403
UnitType
Supported types for DataValue.
Definition: DataValue.h:84
@ MS_ONTOLOGY
ms.ontology MS
Definition: DataValue.h:86
@ UNIT_ONTOLOGY
unit.ontology UO
Definition: DataValue.h:85
int32_t unit_
The unit of the data value (if it has one) using UO identifier, otherwise -1.
Definition: DataValue.h:446
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
@ EMPTY_VALUE
empty
Definition: DataValue.h:75
@ 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:443
UnitType getUnitType() const
returns the type of value stored
Definition: DataValue.h:398
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:409
DataValue(DataValue &&) noexcept
Move constructor.
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:388
DataType value_type_
Type of the currently stored value.
Definition: DataValue.h:440
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:222
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
const std::string & toString(const DriftTimeUnit value)