OpenMS  2.8.0
ParamValue.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-2021.
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 // $Authors: Ruben Grünberg $
32 // --------------------------------------------------------------------------
33 
34 #pragma once
35 
36 #include <OpenMS/OpenMSConfig.h>
37 
38 #include <cstddef> // for ptrdiff_t
39 #include <string>
40 #include <vector>
41 
42 
43 namespace OpenMS
44 {
54  class OPENMS_DLLAPI ParamValue
55  {
56 
57 public:
58 
60  static const ParamValue EMPTY;
61 
63  enum ValueType : unsigned char
64  {
71  EMPTY_VALUE
72  };
73 
75 
76  ParamValue();
81  ParamValue(ParamValue&&) noexcept;
83  ParamValue(const char*);
85  ParamValue(const std::string&);
87  ParamValue(const std::vector<std::string>&);
89  ParamValue(const std::vector<int>&);
91  ParamValue(const std::vector<double>&);
93  ParamValue(long double);
95  ParamValue(double);
97  ParamValue(float);
99  ParamValue(short int);
101  ParamValue(unsigned short int);
105  ParamValue(unsigned);
107  ParamValue(long int);
109  ParamValue(unsigned long);
111  ParamValue(long long);
113  ParamValue(unsigned long long);
117 
121 
122 
128  operator std::string() const;
129 
135  operator std::vector<std::string>() const;
136 
142  operator std::vector<int>() const;
143 
149  operator std::vector<double>() const;
150 
158  operator long double() const;
159 
167  operator double() const;
168 
176  operator float() const;
177 
185  operator short int() const;
186 
194  operator unsigned short int() const;
195 
204  operator int() const;
205 
213  operator unsigned int() const;
214 
222  operator long int() const;
223 
231  operator unsigned long int() const;
232 
240  operator long long() const;
241 
249  operator unsigned long long() const;
250 
258  bool toBool() const;
259 
266  const char* toChar() const;
267 
274  std::string toString(bool full_precision = true) const;
275 
281  std::vector<std::string> toStringVector() const;
282 
288  std::vector<int> toIntVector() const;
289 
295  std::vector<double> toDoubleVector() const;
297 
300 
301  ParamValue& operator=(const ParamValue&);
304  ParamValue& operator=(ParamValue&&) noexcept;
306  ParamValue& operator=(const char*);
308  ParamValue& operator=(const std::string&);
310  ParamValue& operator=(const std::vector<std::string>&);
312  ParamValue& operator=(const std::vector<int>&);
314  ParamValue& operator=(const std::vector<double>&);
316  ParamValue& operator=(const long double);
318  ParamValue& operator=(const double);
320  ParamValue& operator=(const float);
322  ParamValue& operator=(const short int);
324  ParamValue& operator=(const unsigned short int);
326  ParamValue& operator=(const int);
328  ParamValue& operator=(const unsigned);
330  ParamValue& operator=(const long int);
332  ParamValue& operator=(const unsigned long);
334  ParamValue& operator=(const long long);
336  ParamValue& operator=(const unsigned long long);
338 
340  inline ValueType valueType() const
341  {
342  return value_type_;
343  }
344 
350  inline bool isEmpty() const
351  {
352  return value_type_ == EMPTY_VALUE;
353  }
354 
356  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const ParamValue&);
357 
359  friend OPENMS_DLLAPI bool operator==(const ParamValue&, const ParamValue&);
360 
362  friend OPENMS_DLLAPI bool operator<(const ParamValue&, const ParamValue&);
363 
365  friend OPENMS_DLLAPI bool operator>(const ParamValue&, const ParamValue&);
366 
368  friend OPENMS_DLLAPI bool operator!=(const ParamValue&, const ParamValue&);
369 
370 protected:
371 
374 
376  union
377  {
378  ptrdiff_t ssize_;
379  double dou_;
380  std::string* str_;
381  std::vector<std::string>* str_list_;
382  std::vector<int>* int_list_;
383  std::vector<double>* dou_list_;
384  } data_;
385 
386 private:
387 
389  void clear_() noexcept;
390 
394  static std::string doubleToString(double value, bool full_precision = true);
395 
396  };
397 }
398 
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition: ParamValue.h:55
ValueType value_type_
Type of the currently stored value.
Definition: ParamValue.h:373
friend bool operator==(const ParamValue &, const ParamValue &)
Equality comparator.
ParamValue(const ParamValue &)
Copy constructor.
friend std::ostream & operator<<(std::ostream &, const ParamValue &)
output stream operator
void clear_() noexcept
Clears the current state of the ParamValue and release every used memory.
friend bool operator!=(const ParamValue &, const ParamValue &)
Equality comparator.
bool isEmpty() const
Test if the value is empty.
Definition: ParamValue.h:350
friend bool operator>(const ParamValue &, const ParamValue &)
Greater than comparator (for vectors we use the size)
ValueType
Supported types for ParamValue.
Definition: ParamValue.h:64
@ DOUBLE_VALUE
double value
Definition: ParamValue.h:67
@ INT_LIST
integer vector
Definition: ParamValue.h:69
@ STRING_VALUE
string value
Definition: ParamValue.h:65
@ STRING_LIST
string vector
Definition: ParamValue.h:68
@ INT_VALUE
integer value
Definition: ParamValue.h:66
@ DOUBLE_LIST
double vector
Definition: ParamValue.h:70
friend bool operator<(const ParamValue &, const ParamValue &)
Smaller than comparator (for vectors we use the size)
ParamValue(ParamValue &&) noexcept
Move constructor.
static const ParamValue EMPTY
Empty data value for comparisons.
Definition: ParamValue.h:60
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
const std::string & toString(const DriftTimeUnit value)