Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
OptionBuilder.h
Go to the documentation of this file.
1#ifndef STORM_SETTINGS_OPTIONBUILDER_H_
2#define STORM_SETTINGS_OPTIONBUILDER_H_
3
4#include <boost/algorithm/string.hpp>
5#include <cstdint>
6#include <iostream>
7#include <memory>
8#include <string>
9#include <unordered_set>
10#include <vector>
11
15
19
20namespace storm {
21namespace settings {
22
27 public:
36 OptionBuilder(std::string const& moduleName, std::string const& longName, bool requireModulePrefix, std::string const& description)
37 : longName(longName),
38 shortName(""),
39 hasShortName(false),
40 description(description),
41 moduleName(moduleName),
42 requireModulePrefix(requireModulePrefix),
43 isRequired(false),
44 isAdvanced(false),
45 isBuild(false),
46 arguments(),
47 argumentNameSet() {
48 // Intentionally left empty.
49 }
50
57 OptionBuilder& setShortName(std::string const& shortName) {
58 this->shortName = shortName;
59 this->hasShortName = true;
60 return *this;
61 }
62
69 OptionBuilder& setIsRequired(bool isRequired) {
70 this->isRequired = isRequired;
71 return *this;
72 }
73
77 OptionBuilder& setIsAdvanced(bool isAdvanced = true) {
78 this->isAdvanced = isAdvanced;
79 return *this;
80 }
81
88 OptionBuilder& addArgument(std::shared_ptr<ArgumentBase> argument) {
89 STORM_LOG_THROW(!this->isBuild, storm::exceptions::IllegalFunctionCallException,
90 "Cannot add an argument to an option builder that was already used to build the option.");
91 STORM_LOG_THROW(this->arguments.empty() || argument->getIsOptional() || !this->arguments.back()->getIsOptional(),
92 storm::exceptions::IllegalArgumentException, "Unable to add non-optional argument after an option that is optional.");
93
94 std::string lowerArgumentName = boost::algorithm::to_lower_copy(argument->getName());
95 STORM_LOG_THROW(argumentNameSet.find(lowerArgumentName) == argumentNameSet.end(), storm::exceptions::IllegalArgumentException,
96 "Unable to add argument to option, because it already has an argument with the same name.");
97
98 argumentNameSet.insert(lowerArgumentName);
99 this->arguments.push_back(argument);
100
101 return *this;
102 }
103
109 std::shared_ptr<Option> build() {
110 STORM_LOG_THROW(!this->isBuild, storm::exceptions::IllegalFunctionCallException, "Cannot rebuild an option with one builder.");
111 this->isBuild = true;
112
113 if (this->hasShortName) {
114 return std::shared_ptr<Option>(new Option(this->moduleName, this->longName, this->shortName, this->description, this->isRequired,
115 this->requireModulePrefix, this->isAdvanced, this->arguments));
116 } else {
117 return std::shared_ptr<Option>(new Option(this->moduleName, this->longName, this->description, this->isRequired, this->requireModulePrefix,
118 this->isAdvanced, this->arguments));
119 }
120 }
121
122 private:
123 // The long name of the option.
124 std::string longName;
125
126 // A possible short name of the option or the empty string in case the option does not have a short name.
127 std::string shortName;
128
129 // A flag indicating whether the option has a short name.
130 bool hasShortName;
131
132 // The description of the option.
133 std::string description;
134
135 // The name of the module to which this option belongs.
136 std::string moduleName;
137
138 // A flag indicating whether the option has to be prefixed with the module name.
139 bool requireModulePrefix;
140
141 // A flag indicating whether the option is required.
142 bool isRequired;
143
144 // A flag that indicates whether this option is only displayed in the advanced help.
145 bool isAdvanced;
146
147 // A flag indicating whether the builder has already been used to build an option.
148 bool isBuild;
149
150 // The arguments of the option that is being built.
151 std::vector<std::shared_ptr<ArgumentBase>> arguments;
152
153 // The names of the arguments of the option.
154 std::unordered_set<std::string> argumentNameSet;
155};
156} // namespace settings
157} // namespace storm
158
159#endif // STORM_SETTINGS_OPTIONBUILDER_H_
This class provides the interface to create an option...
OptionBuilder & setShortName(std::string const &shortName)
Sets a short name for the option.
OptionBuilder & addArgument(std::shared_ptr< ArgumentBase > argument)
Adds the given argument to the arguments of this option.
OptionBuilder & setIsRequired(bool isRequired)
Sets whether the option is required.
std::shared_ptr< Option > build()
Builds an option from the data that was added to this builder.
OptionBuilder & setIsAdvanced(bool isAdvanced=true)
Sets whether the option is only displayed in the advanced help.
OptionBuilder(std::string const &moduleName, std::string const &longName, bool requireModulePrefix, std::string const &description)
Creates a new option builder for an option with the given module, name and description.
This class represents one command-line option.
Definition Option.h:27
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
SettingsType const & getModule()
Get module.
LabParser.cpp.
Definition cli.cpp:18