| OpenMS 2.5.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-2020.
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
37 #include <OpenMS/DATASTRUCTURES/String.h>
38 #include <OpenMS/DATASTRUCTURES/ListUtils.h>
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 {
67 STRING_VALUE,
68 INT_VALUE,
69 DOUBLE_VALUE,
70 STRING_LIST,
71 INT_LIST,
72 DOUBLE_LIST,
73 EMPTY_VALUE
74 };
75
77 enum UnitType : unsigned char
78 {
79 UNIT_ONTOLOGY,
80 MS_ONTOLOGY,
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
358 String toString(bool full_precision = true) const;
359
361 QString toQString() const;
363
365 inline DataType valueType() const
366 {
367 return value_type_;
368 }
369
375 inline bool isEmpty() const
376 {
377 return value_type_ == EMPTY_VALUE;
378 }
379
382
383
385 inline UnitType getUnitType() const
386 {
387 return unit_type_;
388 }
389
390 inline void setUnitType(const UnitType & u)
391 {
392 unit_type_ = u;
393 }
394
396 inline bool hasUnit() const
397 {
398 return unit_ != -1;
399 }
400
402 const int32_t & getUnit() const;
403
405 void setUnit(const int32_t & unit);
406
408
410 friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, 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
422 friend OPENMS_DLLAPI bool operator!=(const DataValue&, const DataValue&);
423
424 protected:
425
427 DataType value_type_;
428
430 UnitType unit_type_;
431
433 int32_t unit_;
434
436 union
437 {
438 SignedSize ssize_;
439 double dou_;
440 String* str_;
441 StringList* str_list_;
442 IntList* int_list_;
443 DoubleList* dou_list_;
444 } data_;
445
446 private:
447
449 void clear_() noexcept;
450 };
451 }
452
OpenMS::DataValue::unit_type_
UnitType unit_type_
Type of the currently stored unit.
Definition: DataValue.h:430
OpenMS::SignedSize
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::DataValue
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:56
OpenMS::DataValue::UnitType
UnitType
Supported types for DataValue.
Definition: DataValue.h:77
OpenMS::operator<
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
OpenMS::DataValue::STRING_LIST
string list
Definition: DataValue.h:70
OpenMS::IntList
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
OpenMS::DataValue::DataType
DataType
Supported types for DataValue.
Definition: DataValue.h:65
OpenMS::DataValue::value_type_
DataType value_type_
Type of the currently stored value.
Definition: DataValue.h:427
OpenMS::StringConversions::toString
String toString(const T &i)
fallback template for general purpose using Boost::Karma; more specializations below ...
Definition: StringUtils.h:85
OpenMS::DataValue::DOUBLE_LIST
double list
Definition: DataValue.h:72
KDTree::operator!=
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
OpenMS::DataValue::UNIT_ONTOLOGY
unit.ontology UO:
Definition: DataValue.h:79
std
STL namespace.
Types.h
OpenMS::DataValue::MS_ONTOLOGY
ms.ontology MS:
Definition: DataValue.h:80
OpenMS::DataValue::INT_VALUE
integer value
Definition: DataValue.h:68
OpenMS::DataValue::hasUnit
bool hasUnit() const
Check if the value has a unit.
Definition: DataValue.h:396
String.h
OpenMS::DoubleList
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
OpenMS::DataValue::getUnitType
UnitType getUnitType() const
returns the type of value stored
Definition: DataValue.h:385
OpenMS::operator<<
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::DataValue::setUnitType
void setUnitType(const UnitType &u)
Definition: DataValue.h:390
OpenMS::DataValue::DOUBLE_VALUE
double value
Definition: DataValue.h:69
OpenMS::DataValue::STRING_VALUE
string value
Definition: DataValue.h:67
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::DataValue::INT_LIST
integer list
Definition: DataValue.h:71
ListUtils.h
OpenMS::DataValue::unit_
int32_t unit_
The unit of the data value (if it has one) using UO identifier, otherwise -1.
Definition: DataValue.h:433
OpenMS::DataValue::isEmpty
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:375
OpenMS::DataValue::EMPTY
static const DataValue EMPTY
Empty data value for comparisons.
Definition: DataValue.h:62
KDTree::operator==
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806