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