Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Argument.h
Go to the documentation of this file.
1#ifndef STORM_SETTINGS_ARGUMENT_H_
2#define STORM_SETTINGS_ARGUMENT_H_
3
4#include <functional>
5#include <iostream>
6#include <list>
7#include <memory>
8#include <sstream>
9#include <string>
10#include <unordered_map>
11#include <utility>
12#include <vector>
13
16
19
20namespace storm {
21namespace settings {
22
23template<typename ValueType>
24class ArgumentValidator;
25
31template<typename T>
32class Argument : public ArgumentBase {
33 public:
42 Argument(std::string const& name, std::string const& description, std::vector<std::shared_ptr<ArgumentValidator<T>>> const& validators);
43
52 Argument(std::string const& name, std::string const& description, std::vector<std::shared_ptr<ArgumentValidator<T>>> const& validators, bool isOptional,
53 T defaultValue);
54
55 virtual bool getIsOptional() const override;
56
57 bool setFromStringValue(std::string const& fromStringValue) override;
58
59 bool setFromTypeValue(T const& newValue, bool hasBeenSet = true);
60
61 virtual ArgumentType getType() const override;
62
69 template<typename S>
70 bool isCompatibleWith(Argument<S> const& other) const {
71 STORM_LOG_THROW(this->getType() == other.getType(), storm::exceptions::ArgumentUnificationException,
72 "Unable to unify the arguments " << this->getName() << " and " << other.getName() << ", because they have different types.");
73 STORM_LOG_THROW(this->getIsOptional() == other.getIsOptional(), storm::exceptions::ArgumentUnificationException,
74 "Unable to unify the arguments '" << this->getName() << "' and '" << other.getName()
75 << "', because one of them is optional and the other one is not.");
76 STORM_LOG_THROW(this->getHasDefaultValue() == other.getHasDefaultValue(), storm::exceptions::ArgumentUnificationException,
77 "Unable to unify the arguments " << this->getName() << " and " << other.getName()
78 << ", because one of them has a default value and the other one does not.");
79 return true;
80 }
81
87 T const& getArgumentValue() const;
88
89 virtual bool getHasDefaultValue() const override;
90
91 void setFromDefaultValue() override;
92
93 virtual bool wasSetFromDefaultValue() const override;
94
95 virtual std::string getValueAsString() const override;
96
97 virtual int_fast64_t getValueAsInteger() const override;
98
99 virtual uint_fast64_t getValueAsUnsignedInteger() const override;
100
101 virtual double getValueAsDouble() const override;
102
103 virtual bool getValueAsBoolean() const override;
104
105 virtual void printToStream(std::ostream& out) const override;
106
107 private:
108 // The value of the argument (in case it has been set).
109 T argumentValue;
110
111 // The type of the argument.
112 ArgumentType argumentType;
113
114 // The validation functions that were registered for this argument.
115 std::vector<std::shared_ptr<ArgumentValidator<T>>> validators;
116
117 // A flag indicating whether this argument is optional.
118 bool isOptional;
119
120 // The default value for the argument (in case one has been provided).
121 T defaultValue;
122
123 // A flag indicating whether a default value has been provided.
124 bool hasDefaultValue;
125
126 // A flag indicating whether the argument was set from the default value.
127 bool wasSetFromDefaultValueFlag;
128
134 void setDefaultValue(T const& newDefault);
135
143 bool validate(T const& value) const;
144};
145} // namespace settings
146} // namespace storm
147
148#endif // STORM_SETTINGS_ARGUMENT_H_
This class serves as the (untemplated) base class of argument classes.
This class subclasses the argument base to actually implement the pure virtual functions.
Definition Argument.h:32
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:70
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
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:30
SettingsType const & getModule()
Get module.
ArgumentType
This enum captures all possible types for arguments.
LabParser.cpp.
Definition cli.cpp:18