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
66  {
73  EMPTY_VALUE
74  };
75 
77 
78  DataValue();
81  DataValue(const char*);
83  DataValue(const std::string&);
85  DataValue(const String&);
87  DataValue(const QString&);
89  DataValue(const StringList&);
91  DataValue(const IntList&);
93  DataValue(const DoubleList&);
95  DataValue(long double);
97  DataValue(double);
99  DataValue(float);
101  DataValue(short int);
103  DataValue(unsigned short int);
105  DataValue(int);
107  DataValue(unsigned);
109  DataValue(long int);
111  DataValue(unsigned long);
113  DataValue(long long);
115  DataValue(unsigned long long);
117  DataValue(const DataValue&);
119  virtual ~DataValue();
121 
125 
126 
132  operator std::string() const;
133 
139  operator StringList() const;
140 
146  operator IntList() const;
147 
153  operator DoubleList() const;
154 
162  operator long double() const;
163 
171  operator double() const;
172 
180  operator float() const;
181 
189  operator short int() const;
190 
198  operator unsigned short int() const;
199 
208  operator int() const;
209 
217  operator unsigned int() const;
218 
226  operator long int() const;
227 
235  operator unsigned long int() const;
236 
244  operator long long() const;
245 
253  operator unsigned long long() const;
254 
261  const char* toChar() const;
262 
268  StringList toStringList() const;
269 
275  IntList toIntList() const;
276 
282  DoubleList toDoubleList() const;
284 
287 
288 
290  DataValue& operator=(const char*);
292  DataValue& operator=(const std::string&);
294  DataValue& operator=(const String&);
296  DataValue& operator=(const QString&);
298  DataValue& operator=(const StringList&);
300  DataValue& operator=(const IntList&);
302  DataValue& operator=(const DoubleList&);
304  DataValue& operator=(const long double);
306  DataValue& operator=(const double);
308  DataValue& operator=(const float);
310  DataValue& operator=(const short int);
312  DataValue& operator=(const unsigned short int);
314  DataValue& operator=(const int);
316  DataValue& operator=(const unsigned);
318  DataValue& operator=(const long int);
320  DataValue& operator=(const unsigned long);
322  DataValue& operator=(const long long);
324  DataValue& operator=(const unsigned long long);
325 
327 
331 
332 
334  String toString() const;
335 
337  QString toQString() const;
338 
346  bool toBool() const;
348 
350  inline DataType valueType() const
351  {
352  return value_type_;
353  }
354 
356  DataValue& operator=(const DataValue&);
357 
363  inline bool isEmpty() const
364  {
365  return value_type_ == EMPTY_VALUE;
366  }
367 
370 
371 
373  inline bool hasUnit() const
374  {
375  return unit_ != "";
376  }
377 
379  const String& getUnit() const;
380 
382  void setUnit(const String& unit);
383 
385 
387  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const DataValue&);
388 
390  friend OPENMS_DLLAPI bool operator==(const DataValue&, const DataValue&);
391 
393  friend OPENMS_DLLAPI bool operator<(const DataValue&, const DataValue&);
394 
396  friend OPENMS_DLLAPI bool operator>(const DataValue&, const DataValue&);
397 
399  friend OPENMS_DLLAPI bool operator!=(const DataValue&, const DataValue&);
400 
401 protected:
402 
405 
407  union
408  {
410  double dou_;
415  } data_;
416 
417 private:
420 
422  void clear_();
423  };
424 }
425 
StringList * str_list_
Definition: DataValue.h:412
A more convenient string class.
Definition: String.h:57
bool hasUnit() const
Check if the value has a unit.
Definition: DataValue.h:373
DataType value_type_
Type of the currently stored value.
Definition: DataValue.h:404
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:65
double list
Definition: DataValue.h:72
static const DataValue EMPTY
Empty data value for comparisons.
Definition: DataValue.h:62
double dou_
Definition: DataValue.h:410
integer value
Definition: DataValue.h:68
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
string list
Definition: DataValue.h:70
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
DataType valueType() const
returns the type of value stored
Definition: DataValue.h:350
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
IntList * int_list_
Definition: DataValue.h:413
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
DataType
Supported types for DataValue.
Definition: DataValue.h:65
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:56
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
double value
Definition: DataValue.h:69
string value
Definition: DataValue.h:67
DoubleList * dou_list_
Definition: DataValue.h:414
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:73
SignedSize ssize_
Definition: DataValue.h:409
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
integer list
Definition: DataValue.h:71
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:363
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:68
String * str_
Definition: DataValue.h:411
String unit_
The unit of the data value (if it has one), otherwise empty string.
Definition: DataValue.h:419