OpenMS  2.7.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 <string>
39 #include <vector>
40 
41 namespace OpenMS
42 {
52  class OPENMS_DLLAPI ParamValue
53  {
54 
55 public:
56 
58  static const ParamValue EMPTY;
59 
61  enum ValueType : unsigned char
62  {
69  EMPTY_VALUE
70  };
71 
73 
74  ParamValue();
79  ParamValue(ParamValue&&) noexcept;
81  ParamValue(const char*);
83  ParamValue(const std::string&);
85  ParamValue(const std::vector<std::string>&);
87  ParamValue(const std::vector<int>&);
89  ParamValue(const std::vector<double>&);
91  ParamValue(long double);
93  ParamValue(double);
95  ParamValue(float);
97  ParamValue(short int);
99  ParamValue(unsigned short int);
103  ParamValue(unsigned);
105  ParamValue(long int);
107  ParamValue(unsigned long);
109  ParamValue(long long);
111  ParamValue(unsigned long long);
115 
119 
120 
126  operator std::string() const;
127 
133  operator std::vector<std::string>() const;
134 
140  operator std::vector<int>() const;
141 
147  operator std::vector<double>() const;
148 
156  operator long double() const;
157 
165  operator double() const;
166 
174  operator float() const;
175 
183  operator short int() const;
184 
192  operator unsigned short int() const;
193 
202  operator int() const;
203 
211  operator unsigned int() const;
212 
220  operator long int() const;
221 
229  operator unsigned long int() const;
230 
238  operator long long() const;
239 
247  operator unsigned long long() const;
248 
256  bool toBool() const;
257 
264  const char* toChar() const;
265 
272  std::string toString(bool full_precision = true) const;
273 
279  std::vector<std::string> toStringVector() const;
280 
286  std::vector<int> toIntVector() const;
287 
293  std::vector<double> toDoubleVector() const;
295 
298 
299  ParamValue& operator=(const ParamValue&);
302  ParamValue& operator=(ParamValue&&) noexcept;
304  ParamValue& operator=(const char*);
306  ParamValue& operator=(const std::string&);
308  ParamValue& operator=(const std::vector<std::string>&);
310  ParamValue& operator=(const std::vector<int>&);
312  ParamValue& operator=(const std::vector<double>&);
314  ParamValue& operator=(const long double);
316  ParamValue& operator=(const double);
318  ParamValue& operator=(const float);
320  ParamValue& operator=(const short int);
322  ParamValue& operator=(const unsigned short int);
324  ParamValue& operator=(const int);
326  ParamValue& operator=(const unsigned);
328  ParamValue& operator=(const long int);
330  ParamValue& operator=(const unsigned long);
332  ParamValue& operator=(const long long);
334  ParamValue& operator=(const unsigned long long);
336 
338  inline ValueType valueType() const
339  {
340  return value_type_;
341  }
342 
348  inline bool isEmpty() const
349  {
350  return value_type_ == EMPTY_VALUE;
351  }
352 
354  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const ParamValue&);
355 
357  friend OPENMS_DLLAPI bool operator==(const ParamValue&, const ParamValue&);
358 
360  friend OPENMS_DLLAPI bool operator<(const ParamValue&, const ParamValue&);
361 
363  friend OPENMS_DLLAPI bool operator>(const ParamValue&, const ParamValue&);
364 
366  friend OPENMS_DLLAPI bool operator!=(const ParamValue&, const ParamValue&);
367 
368 protected:
369 
372 
374  union
375  {
376  ptrdiff_t ssize_;
377  double dou_;
378  std::string* str_;
379  std::vector<std::string>* str_list_;
380  std::vector<int>* int_list_;
381  std::vector<double>* dou_list_;
382  } data_;
383 
384 private:
385 
387  void clear_() noexcept;
388 
392  static std::string doubleToString(double value, bool full_precision = true);
393 
394  };
395 }
396 
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition: ParamValue.h:53
ValueType value_type_
Type of the currently stored value.
Definition: ParamValue.h:371
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:348
friend bool operator>(const ParamValue &, const ParamValue &)
Greater than comparator (for vectors we use the size)
ValueType
Supported types for ParamValue.
Definition: ParamValue.h:62
@ DOUBLE_VALUE
double value
Definition: ParamValue.h:65
@ INT_LIST
integer vector
Definition: ParamValue.h:67
@ STRING_VALUE
string value
Definition: ParamValue.h:63
@ STRING_LIST
string vector
Definition: ParamValue.h:66
@ INT_VALUE
integer value
Definition: ParamValue.h:64
@ DOUBLE_LIST
double vector
Definition: ParamValue.h:68
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:58
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
const std::string & toString(const DriftTimeUnit value)