3#include <boost/algorithm/string.hpp>
8#include <unordered_set>
35 OptionBuilder(std::string
const& moduleName, std::string
const& longName,
bool requireModulePrefix, std::string
const& description)
39 description(description),
40 moduleName(moduleName),
41 requireModulePrefix(requireModulePrefix),
57 this->shortName = shortName;
58 this->hasShortName =
true;
69 this->isRequired = isRequired;
77 this->isAdvanced = isAdvanced;
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.");
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.");
97 argumentNameSet.insert(lowerArgumentName);
98 this->arguments.push_back(argument);
109 STORM_LOG_THROW(!this->isBuild, storm::exceptions::IllegalFunctionCallException,
"Cannot rebuild an option with one builder.");
110 this->isBuild =
true;
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));
116 return std::shared_ptr<Option>(
new Option(this->moduleName, this->longName, this->description, this->isRequired, this->requireModulePrefix,
117 this->isAdvanced, this->arguments));
123 std::string longName;
126 std::string shortName;
132 std::string description;
135 std::string moduleName;
138 bool requireModulePrefix;
150 std::vector<std::shared_ptr<ArgumentBase>> arguments;
153 std::unordered_set<std::string> argumentNameSet;
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.
#define STORM_LOG_THROW(cond, exception, message)