OpenMS  2.4.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-2018.
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 {
56  class OPENMS_DLLAPI DataValue
57  {
58 
59 public:
60 
62  static const DataValue EMPTY;
63 
65  enum DataType : unsigned char
66  {
73  EMPTY_VALUE
74  };
75 
77  enum UnitType : unsigned char
78  {
81  OTHER
82  };
83 
85 
86  DataValue();
89  DataValue(const DataValue&);
91  DataValue(DataValue&&) noexcept;
93  DataValue(const char*);
95  DataValue(const std::string&);
97  DataValue(const String&);
99  DataValue(const QString&);
101  DataValue(const StringList&);
103  DataValue(const IntList&);
105  DataValue(const DoubleList&);
107  DataValue(long double);
109  DataValue(double);
111  DataValue(float);
113  DataValue(short int);
115  DataValue(unsigned short int);
117  DataValue(int);
119  DataValue(unsigned);
121  DataValue(long int);
123  DataValue(unsigned long);
125  DataValue(long long);
127  DataValue(unsigned long long);
129  ~DataValue();
131 
135 
136 
142  operator std::string() const;
143 
149  operator StringList() const;
150 
156  operator IntList() const;
157 
163  operator DoubleList() const;
164 
172  operator long double() const;
173 
181  operator double() const;
182 
190  operator float() const;
191 
199  operator short int() const;
200 
208  operator unsigned short int() const;
209 
218  operator int() const;
219 
227  operator unsigned int() const;
228 
236  operator long int() const;
237 
245  operator unsigned long int() const;
246 
254  operator long long() const;
255 
263  operator unsigned long long() const;
264 
272  bool toBool() const;
273 
280  const char* toChar() const;
281 
287  StringList toStringList() const;
288 
294  IntList toIntList() const;
295 
301  DoubleList toDoubleList() const;
303 
306 
307  DataValue& operator=(const DataValue&);
310  DataValue& operator=(DataValue&&) noexcept;
312  DataValue& operator=(const char*);
314  DataValue& operator=(const std::string&);
316  DataValue& operator=(const String&);
318  DataValue& operator=(const QString&);
320  DataValue& operator=(const StringList&);
322  DataValue& operator=(const IntList&);
324  DataValue& operator=(const DoubleList&);
326  DataValue& operator=(const long double);
328  DataValue& operator=(const double);
330  DataValue& operator=(const float);
332  DataValue& operator=(const short int);
334  DataValue& operator=(const unsigned short int);
336  DataValue& operator=(const int);
338  DataValue& operator=(const unsigned);
340  DataValue& operator=(const long int);
342  DataValue& operator=(const unsigned long);
344  DataValue& operator=(const long long);
346  DataValue& operator=(const unsigned long long);
348 
352 
353 
355  String toString() const;
356 
358  QString toQString() const;
360 
362  inline DataType valueType() const
363  {
364  return value_type_;
365  }
366 
372  inline bool isEmpty() const
373  {
374  return value_type_ == EMPTY_VALUE;
375  }
376 
379 
380 
382  inline UnitType getUnitType() const
383  {
384  return unit_type_;
385  }
386 
387  inline void setUnitType(const UnitType & u)
388  {
389  unit_type_ = u;
390  }
391 
393  inline bool hasUnit() const
394  {
395  return unit_ != -1;
396  }
397 
399  const int32_t & getUnit() const;
400 
402  void setUnit(const int32_t & unit);
403 
405 
407  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const DataValue&);
408 
410  friend OPENMS_DLLAPI bool operator==(const DataValue&, const DataValue&);
411 
413  friend OPENMS_DLLAPI bool operator<(const DataValue&, const DataValue&);
414 
416  friend OPENMS_DLLAPI bool operator>(const DataValue&, const DataValue&);
417 
419  friend OPENMS_DLLAPI bool operator!=(const DataValue&, const DataValue&);
420 
421 protected:
422 
425 
428 
430  int32_t unit_;
431 
433  union
434  {
436  double dou_;
441  } data_;
442 
443 private:
444 
446  void clear_() noexcept;
447  };
448 }
449 
UnitType
Supported types for DataValue.
Definition: DataValue.h:77
StringList * str_list_
Definition: DataValue.h:438
A more convenient string class.
Definition: String.h:58
bool hasUnit() const
Check if the value has a unit.
Definition: DataValue.h:393
DataType value_type_
Type of the currently stored value.
Definition: DataValue.h:424
int32_t unit_
The unit of the data value (if it has one) using UO identifier, otherwise -1.
Definition: DataValue.h:430
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:65
UnitType unit_type_
Type of the currently stored unit.
Definition: DataValue.h:427
static const DataValue EMPTY
Empty data value for comparisons.
Definition: DataValue.h:62
unit.ontology UO:
Definition: DataValue.h:79
double dou_
Definition: DataValue.h:436
DataType
Supported types for DataValue.
Definition: DataValue.h:65
string value
Definition: DataValue.h:67
STL namespace.
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:58
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
void setUnitType(const UnitType &u)
Definition: DataValue.h:387
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
IntList * int_list_
Definition: DataValue.h:439
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:56
string list
Definition: DataValue.h:70
integer list
Definition: DataValue.h:71
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
UnitType getUnitType() const
returns the type of value stored
Definition: DataValue.h:382
double list
Definition: DataValue.h:72
DoubleList * dou_list_
Definition: DataValue.h:440
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:73
SignedSize ssize_
Definition: DataValue.h:435
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
integer value
Definition: DataValue.h:68
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:372
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:68
String * str_
Definition: DataValue.h:437
double value
Definition: DataValue.h:69
ms.ontology MS:
Definition: DataValue.h:80