Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Argument.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <iostream>
5#include <list>
6#include <memory>
7#include <sstream>
8#include <string>
9#include <unordered_map>
10#include <utility>
11#include <vector>
12
15
18
19namespace storm {
20namespace settings {
21
22template<typename ValueType>
24
30template<typename T>
31class Argument : public ArgumentBase {
32 public:
41 Argument(std::string const& name, std::string const& description, std::vector<std::shared_ptr<ArgumentValidator<T>>> const& validators);
42
51 Argument(std::string const& name, std::string const& description, std::vector<std::shared_ptr<ArgumentValidator<T>>> const& validators, bool isOptional,
52 T defaultValue);
53
54 virtual bool getIsOptional() const override;
55
56 bool setFromStringValue(std::string const& fromStringValue) override;
57
58 bool setFromTypeValue(T const& newValue, bool hasBeenSet = true);
59
60 virtual ArgumentType getType() const override;
61
68 template<typename S>
69 bool isCompatibleWith(Argument<S> const& other) const {
70 STORM_LOG_THROW(this->getType() == other.getType(), storm::exceptions::ArgumentUnificationException,
71 "Unable to unify the arguments " << this->getName() << " and " << other.getName() << ", because they have different types.");
72 STORM_LOG_THROW(this->getIsOptional() == other.getIsOptional(), storm::exceptions::ArgumentUnificationException,
73 "Unable to unify the arguments '" << this->getName() << "' and '" << other.getName()
74 << "', because one of them is optional and the other one is not.");
75 STORM_LOG_THROW(this->getHasDefaultValue() == other.getHasDefaultValue(), storm::exceptions::ArgumentUnificationException,
76 "Unable to unify the arguments " << this->getName() << " and " << other.getName()
77 << ", because one of them has a default value and the other one does not.");
78 return true;
79 }
80
86 T const& getArgumentValue() const;
87
88 virtual bool getHasDefaultValue() const override;
89
90 void setFromDefaultValue() override;
91
92 virtual bool wasSetFromDefaultValue() const override;
93
94 virtual std::string getValueAsString() const override;
95
96 virtual int_fast64_t getValueAsInteger() const override;
97
98 virtual uint_fast64_t getValueAsUnsignedInteger() const override;
99
100 virtual double getValueAsDouble() const override;
101
102 virtual bool getValueAsBoolean() const override;
103
104 virtual void printToStream(std::ostream& out) const override;
105
106 private:
107 // The value of the argument (in case it has been set).
108 T argumentValue;
109
110 // The type of the argument.
111 ArgumentType argumentType;
112
113 // The validation functions that were registered for this argument.
114 std::vector<std::shared_ptr<ArgumentValidator<T>>> validators;
115
116 // A flag indicating whether this argument is optional.
117 bool isOptional;
118
119 // The default value for the argument (in case one has been provided).
120 T defaultValue;
121
122 // A flag indicating whether a default value has been provided.
123 bool hasDefaultValue;
124
125 // A flag indicating whether the argument was set from the default value.
126 bool wasSetFromDefaultValueFlag;
127
133 void setDefaultValue(T const& newDefault);
134
142 bool validate(T const& value) const;
143};
144} // namespace settings
145} // namespace storm
std::string const & getName() const
Retrieves the name of the argument.
ArgumentBase(std::string const &name, std::string const &description)
Constructs a new argument base with the given name, description and indication whether the argument i...
virtual bool getValueAsBoolean() const override
Retrieves the value of this argument as a boolean.
Definition Argument.cpp:155
virtual double getValueAsDouble() const override
Retrieves the value of this argument as a double.
Definition Argument.cpp:144
virtual std::string getValueAsString() const override
Retrieves the value of this argument as a string.
Definition Argument.cpp:103
virtual bool getHasDefaultValue() const override
Retrieves whether the argument has a default value.
Definition Argument.cpp:83
virtual uint_fast64_t getValueAsUnsignedInteger() const override
Retrieves the value of this argument as an unsigned integer.
Definition Argument.cpp:132
bool setFromStringValue(std::string const &fromStringValue) override
Tries to set the value of the argument from the given string.
Definition Argument.cpp:47
bool isCompatibleWith(Argument< S > const &other) const
Checks whether the given argument is compatible with the current one.
Definition Argument.h:69
bool setFromTypeValue(T const &newValue, bool hasBeenSet=true)
Definition Argument.cpp:57
void setFromDefaultValue() override
Sets the value of the argument from the default value.
Definition Argument.cpp:88
virtual bool getIsOptional() const override
Retrieves whether the argument is optional.
Definition Argument.cpp:42
virtual bool wasSetFromDefaultValue() const override
Definition Argument.cpp:98
virtual void printToStream(std::ostream &out) const override
Prints a string representation of the argument to the provided stream.
Definition Argument.cpp:197
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.
Definition Argument.cpp:15
virtual ArgumentType getType() const override
Retrieves the type of the argument.
Definition Argument.cpp:67
virtual int_fast64_t getValueAsInteger() const override
Retrieves the value of this argument as an integer.
Definition Argument.cpp:121
T const & getArgumentValue() const
Retrieves the value of the argument if any has been set.
Definition Argument.cpp:72
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
ArgumentType
This enum captures all possible types for arguments.