DP3
ParameterValue.h
Go to the documentation of this file.
1 // ParameterValue.h: The value of a parameter
2 //
3 // Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 
6 #ifndef LOFAR_COMMON_PARAMETERVALUE_H
7 #define LOFAR_COMMON_PARAMETERVALUE_H
8 
9 #include "StringTools.h"
10 
11 namespace dp3 {
12 namespace common {
13 
14 // Forward declaration.
15 class ParameterRecord;
16 
18 
25  public:
28 
31  explicit ParameterValue(const std::string& value, bool trim = true);
32 
35 
37  bool isVector() const { return itsValue[0] == '['; }
38 
40  bool isRecord() const { return itsValue[0] == '{'; }
41 
43  const std::string& get() const { return itsValue; }
44 
46  std::vector<ParameterValue> getVector() const;
47 
50 
53  bool getBool() const { return strToBool(itsValue); }
54  int getInt() const { return strToInt(itsValue); }
55  unsigned int getUint() const { return strToUint(itsValue); }
56  int16_t getInt16() const { return strToInt16(itsValue); }
57  uint16_t getUint16() const { return strToUint16(itsValue); }
58  int32_t getInt32() const { return strToInt32(itsValue); }
59  int32_t getUint32() const { return strToUint32(itsValue); }
60  int64_t getInt64() const { return strToInt64(itsValue); }
61  uint64_t getUint64() const { return strToUint64(itsValue); }
62  float getFloat() const { return strToFloat(itsValue); }
63  double getDouble() const { return strToDouble(itsValue); }
64  std::string getString() const;
65  time_t getTime() const { return StringToTime_t(itsValue); }
66  std::vector<bool> getBoolVector() const;
67  std::vector<int> getIntVector() const;
68  std::vector<unsigned int> getUintVector() const;
69  std::vector<int16_t> getInt16Vector() const;
70  std::vector<uint16_t> getUint16Vector() const;
71  std::vector<int32_t> getInt32Vector() const;
72  std::vector<uint32_t> getUint32Vector() const;
73  std::vector<int64_t> getInt64Vector() const;
74  std::vector<uint64_t> getUint64Vector() const;
75  std::vector<float> getFloatVector() const;
76  std::vector<double> getDoubleVector() const;
77  std::vector<std::string> getStringVector() const;
78  std::vector<time_t> getTimeVector() const;
80 
83  operator bool() const { return getBool(); }
84  operator int() const { return getInt(); }
85  operator unsigned int() const { return getUint(); }
86  operator float() const { return getFloat(); }
87  operator double() const { return getDouble(); }
88  operator std::string() const { return getString(); }
89  operator time_t() const { return getTime(); }
90  operator std::vector<bool>() const { return getBoolVector(); }
91  operator std::vector<int>() const { return getIntVector(); }
92  operator std::vector<unsigned int>() const { return getUintVector(); }
93  operator std::vector<float>() const { return getFloatVector(); }
94  operator std::vector<double>() const { return getDoubleVector(); }
95  operator std::vector<std::string>() const { return getStringVector(); }
96  operator std::vector<time_t>() const { return getTimeVector(); }
98 
100  static time_t StringToTime_t(const std::string& aString);
101 
104  friend std::ostream& operator<<(std::ostream& os,
105  const ParameterValue& pval) {
106  os << pval.itsValue;
107  return os;
108  }
109  friend std::istream& operator>>(std::istream& os, ParameterValue& pval) {
110  os >> pval.itsValue;
111  return os;
112  }
114 
115  private:
119  std::vector<ParameterValue> splitValue(unsigned int st,
120  unsigned int last) const;
121 
123  ParameterValue substr(int st, int end) const {
124  return ParameterValue(itsValue.substr(st, end - st));
125  }
126 
127  std::string itsValue;
128 };
129 
130 } // namespace common
131 } // namespace dp3
132 
133 #endif
A record of parameter values. The only difference with a ParameterSet is the output operator.
Definition: ParameterRecord.h:16
The value of a parameter.
Definition: ParameterValue.h:24
ParameterValue()
Default constructor uses empty string.
Definition: ParameterValue.h:27
uint64_t getUint64() const
Definition: ParameterValue.h:61
std::vector< ParameterValue > getVector() const
Get the parameter value as a vector of ParameterValues.
ParameterValue(const std::string &value, bool trim=true)
std::vector< int > getIntVector() const
bool isVector() const
Is the value a vector?
Definition: ParameterValue.h:37
int32_t getInt32() const
Definition: ParameterValue.h:58
ParameterRecord getRecord() const
Get the parameter value as a ParameterRecord.
unsigned int getUint() const
Definition: ParameterValue.h:55
std::vector< double > getDoubleVector() const
bool isRecord() const
Is the value a record?
Definition: ParameterValue.h:40
std::vector< float > getFloatVector() const
std::vector< int32_t > getInt32Vector() const
const std::string & get() const
Get the value string.
Definition: ParameterValue.h:43
std::vector< time_t > getTimeVector() const
std::string getString() const
std::vector< int16_t > getInt16Vector() const
ParameterValue expand() const
Expand the string using StringUtil::expandedArrayString.
int64_t getInt64() const
Definition: ParameterValue.h:60
std::vector< uint64_t > getUint64Vector() const
int getInt() const
Definition: ParameterValue.h:54
friend std::ostream & operator<<(std::ostream &os, const ParameterValue &pval)
Definition: ParameterValue.h:104
bool getBool() const
Definition: ParameterValue.h:53
time_t getTime() const
Definition: ParameterValue.h:65
std::vector< uint16_t > getUint16Vector() const
double getDouble() const
Definition: ParameterValue.h:63
int16_t getInt16() const
Definition: ParameterValue.h:56
std::vector< std::string > getStringVector() const
std::vector< unsigned int > getUintVector() const
uint16_t getUint16() const
Definition: ParameterValue.h:57
std::vector< uint32_t > getUint32Vector() const
std::vector< int64_t > getInt64Vector() const
std::vector< bool > getBoolVector() const
friend std::istream & operator>>(std::istream &os, ParameterValue &pval)
Definition: ParameterValue.h:109
static time_t StringToTime_t(const std::string &aString)
Convert a string to a time.
int32_t getUint32() const
Definition: ParameterValue.h:59
float getFloat() const
Definition: ParameterValue.h:62
int strToInt(const std::string &aString)
unsigned int strToUint(const std::string &aString)
int16_t strToInt16(const std::string &aString)
bool strToBool(const std::string &aString)
int64_t strToInt64(const std::string &aString)
int32_t strToInt32(const std::string &aString)
uint64_t strToUint64(const std::string &aString)
uint32_t strToUint32(const std::string &aString)
uint16_t strToUint16(const std::string &aString)
float strToFloat(const std::string &aString)
double strToDouble(const std::string &aString)
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53