19 validators(validators),
22 hasDefaultValue(
false),
23 wasSetFromDefaultValueFlag(
false) {
29 bool isOptional, T defaultValue)
33 validators(validators),
34 isOptional(isOptional),
36 hasDefaultValue(
true),
37 wasSetFromDefaultValueFlag(
false) {
38 this->setDefaultValue(defaultValue);
43 return this->isOptional;
53 return this->setFromTypeValue(
newValue);
62 this->hasBeenSet = hasBeenSet;
68 return this->argumentType;
73 STORM_LOG_THROW(this->getHasBeenSet() || this->getHasDefaultValue(), storm::exceptions::IllegalFunctionCallException,
74 "Unable to retrieve value of argument '" << this->getName() <<
"', because it was neither set nor specifies a default value.");
75 if (this->getHasBeenSet()) {
76 return this->argumentValue;
78 return this->defaultValue;
84 return this->hasDefaultValue;
89 STORM_LOG_THROW(this->hasDefaultValue, storm::exceptions::IllegalFunctionCallException,
90 "Unable to set value from default value, because the argument " << name <<
" has none.");
91 bool result = this->setFromTypeValue(this->defaultValue,
false);
93 "Unable to assign default value to argument " << name <<
", because it was rejected.");
94 this->wasSetFromDefaultValueFlag =
true;
99 return wasSetFromDefaultValueFlag;
104 switch (this->argumentType) {
122 switch (this->argumentType) {
126 STORM_LOG_THROW(
false, storm::exceptions::IllegalFunctionCallException,
"Unable to retrieve argument value for " << name <<
" as integer.");
133 switch (this->argumentType) {
137 STORM_LOG_THROW(
false, storm::exceptions::IllegalFunctionCallException,
138 "Unable to retrieve argument value for " << name <<
" as unsigned integer.");
145 switch (this->argumentType) {
149 STORM_LOG_THROW(
false, storm::exceptions::IllegalFunctionCallException,
"Unable to retrieve argument value for " << name <<
" as double.");
156 switch (this->argumentType) {
160 STORM_LOG_THROW(
false, storm::exceptions::IllegalFunctionCallException,
"Unable to retrieve argument value for " << name <<
" as Boolean.");
168 "The default value for the argument did not pass all validation functions.");
170 this->hasDefaultValue =
true;
174bool Argument<T>::validate(T
const& value)
const {
176 for (
auto const& validator : validators) {
177 result &= validator->isValid(value);
198 out << std::setw(0) << std::left <<
"<" << this->getName() <<
">";
199 if (!this->validators.empty() ||
this->hasDefaultValue) {
202 if (this->getIsOptional()) {
206 if (!this->validators.empty()) {
210 for (
uint64_t i = 0; i < this->validators.size(); ++i) {
211 out << this->validators[i]->toString();
212 if (i + 1 < this->validators.size()) {
219 if (this->hasDefaultValue) {
229 out <<
": " << this->getDescription();
This class serves as the (untemplated) base class of argument classes.
static std::string convertToString(ValueType const &value)
Converts the given value to a string representation.
This class subclasses the argument base to actually implement the pure virtual functions.
virtual bool getValueAsBoolean() const override
Retrieves the value of this argument as a boolean.
virtual double getValueAsDouble() const override
Retrieves the value of this argument as a double.
virtual std::string getValueAsString() const override
Retrieves the value of this argument as a string.
virtual bool getHasDefaultValue() const override
Retrieves whether the argument has a default value.
virtual uint_fast64_t getValueAsUnsignedInteger() const override
Retrieves the value of this argument as an unsigned integer.
bool setFromStringValue(std::string const &fromStringValue) override
Tries to set the value of the argument from the given string.
bool setFromTypeValue(T const &newValue, bool hasBeenSet=true)
void setFromDefaultValue() override
Sets the value of the argument from the default value.
virtual bool getIsOptional() const override
Retrieves whether the argument is optional.
virtual bool wasSetFromDefaultValue() const override
virtual void printToStream(std::ostream &out) const override
Prints a string representation of the argument to the provided stream.
Argument(std::string const &name, std::string const &description, std::vector< std::shared_ptr< ArgumentValidator< T > > > const &validators)
Creates a new argument with the given parameters.
virtual ArgumentType getType() const override
Retrieves the type of the argument.
virtual int_fast64_t getValueAsInteger() const override
Retrieves the value of this argument as an integer.
T const & getArgumentValue() const
Retrieves the value of the argument if any has been set.
#define STORM_LOG_THROW(cond, exception, message)
void printValue(std::ostream &out, T const &value)
int_fast64_t inferToInteger(ArgumentType const &, T const &)
SettingsType const & getModule()
Get module.
bool inferToBoolean(ArgumentType const &, T const &)
double inferToDouble(ArgumentType const &, T const &)
ArgumentType
This enum captures all possible types for arguments.
uint_fast64_t inferToUnsignedInteger(ArgumentType const &, T const &)
std::string const & inferToString(ArgumentType const &, T const &)
ArgumentType inferToEnumType()
This function infers the type in our enum of possible types from the template parameter.