Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-2017.
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 #ifndef OPENMS_DATASTRUCTURES_DATAVALUE_H
36 #define OPENMS_DATASTRUCTURES_DATAVALUE_H
37 
40 
41 #include <OpenMS/CONCEPT/Types.h>
42 #include <OpenMS/OpenMSConfig.h>
43 
44 class QString;
45 
46 namespace OpenMS
47 {
57  class OPENMS_DLLAPI DataValue
58  {
59 
60 public:
61 
63  static const DataValue EMPTY;
64 
66  enum DataType
67  {
74  EMPTY_VALUE
75  };
76 
78 
79  DataValue();
82  DataValue(const char*);
84  DataValue(const std::string&);
86  DataValue(const String&);
88  DataValue(const QString&);
90  DataValue(const StringList&);
92  DataValue(const IntList&);
94  DataValue(const DoubleList&);
96  DataValue(long double);
98  DataValue(double);
100  DataValue(float);
102  DataValue(short int);
104  DataValue(unsigned short int);
106  DataValue(int);
108  DataValue(unsigned);
110  DataValue(long int);
112  DataValue(unsigned long);
114  DataValue(long long);
116  DataValue(unsigned long long);
118  DataValue(const DataValue&);
120  virtual ~DataValue();
122 
126 
127 
133  operator std::string() const;
134 
140  operator StringList() const;
141 
147  operator IntList() const;
148 
154  operator DoubleList() const;
155 
163  operator long double() const;
164 
172  operator double() const;
173 
181  operator float() const;
182 
190  operator short int() const;
191 
199  operator unsigned short int() const;
200 
209  operator int() const;
210 
218  operator unsigned int() const;
219 
227  operator long int() const;
228 
236  operator unsigned long int() const;
237 
245  operator long long() const;
246 
254  operator unsigned long long() const;
255 
262  const char* toChar() const;
263 
269  StringList toStringList() const;
270 
276  IntList toIntList() const;
277 
283  DoubleList toDoubleList() const;
285 
288 
289 
291  DataValue& operator=(const char*);
293  DataValue& operator=(const std::string&);
295  DataValue& operator=(const String&);
297  DataValue& operator=(const QString&);
299  DataValue& operator=(const StringList&);
301  DataValue& operator=(const IntList&);
303  DataValue& operator=(const DoubleList&);
305  DataValue& operator=(const long double);
307  DataValue& operator=(const double);
309  DataValue& operator=(const float);
311  DataValue& operator=(const short int);
313  DataValue& operator=(const unsigned short int);
315  DataValue& operator=(const int);
317  DataValue& operator=(const unsigned);
319  DataValue& operator=(const long int);
321  DataValue& operator=(const unsigned long);
323  DataValue& operator=(const long long);
325  DataValue& operator=(const unsigned long long);
326 
328 
332 
333 
335  String toString() const;
336 
338  QString toQString() const;
339 
347  bool toBool() const;
349 
351  inline DataType valueType() const
352  {
353  return value_type_;
354  }
355 
357  DataValue& operator=(const DataValue&);
358 
364  inline bool isEmpty() const
365  {
366  return value_type_ == EMPTY_VALUE;
367  }
368 
371 
372 
374  inline bool hasUnit() const
375  {
376  return unit_ != "";
377  }
378 
380  const String& getUnit() const;
381 
383  void setUnit(const String& unit);
384 
386 
388  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const DataValue&);
389 
391  friend OPENMS_DLLAPI bool operator==(const DataValue&, const DataValue&);
392 
394  friend OPENMS_DLLAPI bool operator<(const DataValue&, const DataValue&);
395 
397  friend OPENMS_DLLAPI bool operator>(const DataValue&, const DataValue&);
398 
400  friend OPENMS_DLLAPI bool operator!=(const DataValue&, const DataValue&);
401 
402 protected:
403 
406 
408  union
409  {
411  double dou_;
416  } data_;
417 
418 private:
421 
423  void clear_();
424  };
425 }
426 
427 #endif // OPENMS_DATASTRUCTURES_DATAVALUE_H
StringList * str_list_
Definition: DataValue.h:413
A more convenient string class.
Definition: String.h:57
bool hasUnit() const
Check if the value has a unit.
Definition: DataValue.h:374
DataType value_type_
Type of the currently stored value.
Definition: DataValue.h:405
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:66
double list
Definition: DataValue.h:73
static const DataValue EMPTY
Empty data value for comparisons.
Definition: DataValue.h:63
double dou_
Definition: DataValue.h:411
integer value
Definition: DataValue.h:69
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:59
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
string list
Definition: DataValue.h:71
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:135
DataType valueType() const
returns the type of value stored
Definition: DataValue.h:351
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
IntList * int_list_
Definition: DataValue.h:414
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
DataType
Supported types for DataValue.
Definition: DataValue.h:66
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:57
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
double value
Definition: DataValue.h:70
string value
Definition: DataValue.h:68
DoubleList * dou_list_
Definition: DataValue.h:415
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
SignedSize ssize_
Definition: DataValue.h:410
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
integer list
Definition: DataValue.h:72
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:364
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:69
String * str_
Definition: DataValue.h:412
String unit_
The unit of the data value (if it has one), otherwise empty string.
Definition: DataValue.h:420

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13