16Option::Option(std::string
const& moduleName, std::string
const& longOptionName, std::string
const& optionDescription,
bool isOptionRequired,
17 bool requireModulePrefix,
bool isAdvanced, std::vector<std::shared_ptr<ArgumentBase>>
const& optionArguments)
18 :
Option(moduleName, longOptionName,
"", false, optionDescription, isOptionRequired, requireModulePrefix, isAdvanced, optionArguments) {
22Option::Option(std::string
const& moduleName, std::string
const& longOptionName, std::string
const& shortOptionName, std::string
const& optionDescription,
23 bool isOptionRequired,
bool requireModulePrefix,
bool isAdvanced, std::vector<std::shared_ptr<ArgumentBase>>
const& optionArguments)
24 :
Option(moduleName, longOptionName, shortOptionName, true, optionDescription, isOptionRequired, requireModulePrefix, isAdvanced, optionArguments) {
30 "Unable to unify two options, because their argument count differs.");
32 for (
size_t i = 0; i != this->arguments.size(); i++) {
37 "Unable to unify two options, because their arguments are incompatible.");
39 switch (firstArgument.
getType()) {
66 return this->arguments.size();
71 return *this->arguments.at(argumentIndex);
76 return *this->arguments.at(argumentIndex);
80 auto argumentIterator = this->argumentNameMap.find(argumentName);
81 STORM_LOG_THROW(argumentIterator != this->argumentNameMap.end(), storm::exceptions::IllegalArgumentException,
82 "Unable to retrieve argument with unknown name '" << argumentName <<
"'.");
83 return *argumentIterator->second;
87 auto argumentIterator = this->argumentNameMap.find(argumentName);
88 STORM_LOG_THROW(argumentIterator != this->argumentNameMap.end(), storm::exceptions::IllegalArgumentException,
89 "Unable to retrieve argument with unknown name '" << argumentName <<
"'.");
90 return *argumentIterator->second;
94 return this->longName;
98 return this->hasShortName;
102 return this->shortName;
106 return this->description;
110 return this->moduleName;
114 return this->isRequired;
118 return this->requireModulePrefix;
122 return this->isAdvanced;
126 return this->hasBeenSet;
130 return this->hasBeenSetWithModulePrefix;
133Option::Option(std::string
const& moduleName, std::string
const& longOptionName, std::string
const& shortOptionName,
bool hasShortOptionName,
134 std::string
const& optionDescription,
bool isOptionRequired,
bool requireModulePrefix,
bool isAdvanced,
135 std::vector<std::shared_ptr<ArgumentBase>>
const& optionArguments)
136 : longName(longOptionName),
137 hasShortName(hasShortOptionName),
138 shortName(shortOptionName),
139 description(optionDescription),
140 moduleName(moduleName),
141 isRequired(isOptionRequired),
142 requireModulePrefix(requireModulePrefix),
143 isAdvanced(isAdvanced),
145 hasBeenSetWithModulePrefix(false),
146 arguments(optionArguments),
149 STORM_LOG_THROW(!longName.empty(), storm::exceptions::IllegalArgumentException,
"Unable to construct option with empty name.");
150 STORM_LOG_THROW(!moduleName.empty(), storm::exceptions::IllegalArgumentException,
"Unable to construct option with empty module name.");
152 bool longNameContainsIllegalCharacter =
153 std::find_if(longName.begin(), longName.end(), [](
char c) { return !(std::isalpha(c) || std::isdigit(c) || c ==
'-' || c ==
'_'); }) != longName.end();
154 STORM_LOG_THROW(!longNameContainsIllegalCharacter, storm::exceptions::IllegalArgumentException,
155 "Unable to construct option with illegal long name '" << longName <<
"'.");
157 bool shortNameContainsIllegalCharacter = std::find_if(shortName.begin(), shortName.end(), [](
char c) {
158 return !(std::isalpha(c) || std::isdigit(c) || c ==
'c' || c ==
'_');
159 }) != shortName.end();
160 STORM_LOG_THROW(!shortNameContainsIllegalCharacter, storm::exceptions::IllegalArgumentException,
161 "Unable to construct option with illegal short name '" << shortName <<
"'.");
164 for (
auto const& argument : arguments) {
165 argumentNameMap.emplace(argument->getName(), argument);
169void Option::setHasOptionBeenSet(
bool newValue) {
170 this->hasBeenSet = newValue;
173void Option::setHasOptionBeenSetWithModulePrefix(
bool newValue) {
174 this->hasBeenSetWithModulePrefix = newValue;
178 uint_fast64_t length = 2;
190 length += argument->getName().size() + 3;
197 return this->arguments;
201 uint_fast64_t width =
static_cast<uint_fast64_t
>(out.width());
203 uint_fast64_t charactersPrinted = 0;
204 out << std::setw(0) <<
"--";
205 charactersPrinted += 2;
217 charactersPrinted += option.
getLongName().length();
220 charactersPrinted += option.
getShortName().length() + 3;
225 out <<
" <" << argument->getName() <<
">";
226 charactersPrinted += argument->getName().size() + 3;
231 for (uint_fast64_t i = charactersPrinted; i < width; ++i) {
232 if (i == charactersPrinted) {
242 out <<
" " << *argument;
This class serves as the (untemplated) base class of argument classes.
virtual ArgumentType getType() const =0
Retrieves the type of the argument.
This class subclasses the argument base to actually implement the pure virtual functions.
This class represents one command-line option.
bool getHasShortName() const
Retrieves whether this option has a short name.
std::string const & getModuleName() const
Retrieves the name of the module to which this option belongs.
std::string const & getDescription() const
Retrieves the description of the option.
uint_fast64_t getArgumentCount() const
Retrieves the argument count this option expects.
ArgumentBase const & getArgumentByName(std::string const &argumentName) const
Returns a reference to the argument with the specified long name.
bool getHasOptionBeenSetWithModulePrefix() const
Retrieves whether the option has been set by including the module prefix.
std::string const & getShortName() const
Retrieves the short name of this option.
std::vector< std::shared_ptr< ArgumentBase > > const & getArguments() const
Retrieves the arguments of the option.
bool getIsAdvanced() const
Retrieves whether the option is only displayed in the advanced help.
ArgumentBase const & getArgument(uint_fast64_t argumentIndex) const
Retrieves the i-th argument of this option.
std::string const & getLongName() const
Retrieves the long name of this option.
uint_fast64_t getPrintLength() const
Retrieves the (print) length of the option.
bool getRequiresModulePrefix() const
Retrieves whether the option requires the module name as a prefix.
Option(std::string const &moduleName, std::string const &longOptionName, std::string const &optionDescription, bool isOptionRequired, bool requireModulePrefix, bool isAdvanced, std::vector< std::shared_ptr< ArgumentBase > > const &optionArguments=std::vector< std::shared_ptr< ArgumentBase > >())
Creates an option with the given parameters.
bool getIsRequired() const
Retrieves whether the option is required.
bool getHasOptionBeenSet() const
Retrieves whether the option has been set.
bool isCompatibleWith(Option const &other)
Checks whether the given option is compatible with the current one.
#define STORM_LOG_THROW(cond, exception, message)
std::ostream & operator<<(std::ostream &out, ArgumentBase const &argument)