25 #ifndef __CLOCKUTILS_ARGPARSER_BASICVARIABLE_H__ 26 #define __CLOCKUTILS_ARGPARSER_BASICVARIABLE_H__ 49 BasicVariable(
const std::string & longname,
const std::string & shortname,
const std::string & description,
bool required,
bool multiple);
73 virtual bool isBool()
const = 0;
78 virtual bool setValue(
const std::string & value) = 0;
104 virtual void resetToDefault() = 0;
116 std::string _longname;
121 std::string _shortname;
126 std::string _description;
148 Variable(
const std::string & longname,
const std::string & shortname,
const std::string & description, T value,
bool required,
bool multiple) :
BasicVariable(longname, shortname, description, required, multiple), _value(value), _values(), _defaultValue(value) {
155 return std::is_same<T, bool>::value;
161 bool setValue(
const std::string & value)
override {
162 std::stringstream ss(value);
164 bool ret = !(ss >> (val)).fail() && ss.eof();
168 _values.push_back(val);
177 return first == second._value;
181 return first._value == second;
185 return first != second._value;
189 return first._value != second;
219 return 1 + _values.size();
225 T
at(
size_t idx)
const {
226 return (idx == 0) ? _value : _values[idx - 1];
238 std::vector<T> _values;
249 void resetToDefault()
override {
250 _value = _defaultValue;
base class for Variable handling
bool canHaveMultiple() const
returns true, if this variable can have multiple values
friend std::ostream & operator<<(std::ostream &out, Variable &v)
stream operator
size_t count() const
returns amount of values provided if using multiple
#define CLOCK_ARGPARSER_API
bool isSet() const
returns true, if this variable was set via command line
friend bool operator==(const Variable< T > &first, const T &second)
std::string getShortname() const
returns the argument of the variable
T & operator=(const T &val)
assignment operator taking type T
Variable(const std::string &longname, const std::string &shortname, const std::string &description, T value, bool required, bool multiple)
initializes a new variable taking the argument name, the description text and a default value...
specialization of the variable, depending on the template type
bool setValue(const std::string &value) override
sets the parsed value of the argument and returns true, if value was valid, otherwise false ...
bool isRequired() const
returns true, if this variable is required to be set
bool _set
tells whether the variable was set via command line or not
friend bool operator!=(const Variable< T > &first, const T &second)
std::string getLongname() const
returns the argument of the variable
T at(size_t idx) const
returns value at position idx, idx = 0 is _value, idx = 1 is first element of _values, idx >= count results in undefined behaviour
class handling all known variables being able to be parsed and offering parse functionality ...
friend bool operator==(const T &first, const Variable< T > &second)
operator comparing type T and Variable containing type T
friend bool operator!=(const T &first, const Variable< T > &second)
bool isBool() const override
returns true, if T is bool, otherwise false. Default implementation always returns false...