OpenMS
ParamValue.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Authors: Ruben Grünberg $
6 // --------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <OpenMS/OpenMSConfig.h>
11 
12 #include <cstddef> // for ptrdiff_t
13 #include <string>
14 #include <vector>
15 
16 
17 namespace OpenMS
18 {
28  class OPENMS_DLLAPI ParamValue
29  {
30 
31 public:
32 
34  static const ParamValue EMPTY;
35 
37  enum ValueType : unsigned char
38  {
45  EMPTY_VALUE
46  };
47 
49 
50  ParamValue();
55  ParamValue(ParamValue&&) noexcept;
57  ParamValue(const char*);
59  ParamValue(const std::string&);
61  ParamValue(const std::vector<std::string>&);
63  ParamValue(const std::vector<int>&);
65  ParamValue(const std::vector<double>&);
67  ParamValue(long double);
69  ParamValue(double);
71  ParamValue(float);
73  ParamValue(short int);
75  ParamValue(unsigned short int);
77  ParamValue(int);
79  ParamValue(unsigned);
81  ParamValue(long int);
83  ParamValue(unsigned long);
85  ParamValue(long long);
87  ParamValue(unsigned long long);
91 
95 
96 
102  operator std::string() const;
103 
109  operator std::vector<std::string>() const;
110 
116  operator std::vector<int>() const;
117 
123  operator std::vector<double>() const;
124 
132  operator long double() const;
133 
141  operator double() const;
142 
150  operator float() const;
151 
159  operator short int() const;
160 
168  operator unsigned short int() const;
169 
178  operator int() const;
179 
187  operator unsigned int() const;
188 
196  operator long int() const;
197 
205  operator unsigned long int() const;
206 
214  operator long long() const;
215 
223  operator unsigned long long() const;
224 
232  bool toBool() const;
233 
240  const char* toChar() const;
241 
248  std::string toString(bool full_precision = true) const;
249 
255  std::vector<std::string> toStringVector() const;
256 
262  std::vector<int> toIntVector() const;
263 
269  std::vector<double> toDoubleVector() const;
271 
274 
275  ParamValue& operator=(const ParamValue&);
278  ParamValue& operator=(ParamValue&&) noexcept;
280  ParamValue& operator=(const char*);
282  ParamValue& operator=(const std::string&);
284  ParamValue& operator=(const std::vector<std::string>&);
286  ParamValue& operator=(const std::vector<int>&);
288  ParamValue& operator=(const std::vector<double>&);
290  ParamValue& operator=(const long double);
292  ParamValue& operator=(const double);
294  ParamValue& operator=(const float);
296  ParamValue& operator=(const short int);
298  ParamValue& operator=(const unsigned short int);
300  ParamValue& operator=(const int);
302  ParamValue& operator=(const unsigned);
304  ParamValue& operator=(const long int);
306  ParamValue& operator=(const unsigned long);
308  ParamValue& operator=(const long long);
310  ParamValue& operator=(const unsigned long long);
312 
314  inline ValueType valueType() const
315  {
316  return value_type_;
317  }
318 
324  inline bool isEmpty() const
325  {
326  return value_type_ == EMPTY_VALUE;
327  }
328 
330  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream&, const ParamValue&);
331 
333  friend OPENMS_DLLAPI bool operator==(const ParamValue&, const ParamValue&);
334 
336  friend OPENMS_DLLAPI bool operator<(const ParamValue&, const ParamValue&);
337 
339  friend OPENMS_DLLAPI bool operator>(const ParamValue&, const ParamValue&);
340 
342  friend OPENMS_DLLAPI bool operator!=(const ParamValue&, const ParamValue&);
343 
344 protected:
345 
348 
350  union
351  {
352  ptrdiff_t ssize_;
353  double dou_;
354  std::string* str_;
355  std::vector<std::string>* str_list_;
356  std::vector<int>* int_list_;
357  std::vector<double>* dou_list_;
358  } data_;
359 
360 private:
361 
363  void clear_() noexcept;
364 
368  static std::string doubleToString(double value, bool full_precision = true);
369 
370  };
371 }
372 
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition: ParamValue.h:29
ValueType value_type_
Type of the currently stored value.
Definition: ParamValue.h:347
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:324
friend bool operator>(const ParamValue &, const ParamValue &)
Greater than comparator (for vectors we use the size)
ValueType
Supported types for ParamValue.
Definition: ParamValue.h:38
@ DOUBLE_VALUE
double value
Definition: ParamValue.h:41
@ INT_LIST
integer vector
Definition: ParamValue.h:43
@ STRING_VALUE
string value
Definition: ParamValue.h:39
@ STRING_LIST
string vector
Definition: ParamValue.h:42
@ INT_VALUE
integer value
Definition: ParamValue.h:40
@ DOUBLE_LIST
double vector
Definition: ParamValue.h:44
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:34
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
const std::string & toString(const DriftTimeUnit value)