#ifndef STORM_SETTINGS_OPTIONBUILDER_H_ #define STORM_SETTINGS_OPTIONBUILDER_H_ #include #include #include #include #include #include #include #include "storm/settings/ArgumentType.h" #include "storm/settings/ArgumentBase.h" #include "storm/settings/Option.h" #include "storm/utility/macros.h" #include "storm/exceptions/IllegalArgumentException.h" #include "storm/exceptions/IllegalFunctionCallException.h" namespace storm { namespace settings { /*! * This class provides the interface to create an option... */ class OptionBuilder { public: /*! * Creates a new option builder for an option with the given module, name and description. * * @param moduleName The name of the module to which this option belongs. * @param longName The long name of the option. * @param requireModulePrefix Sets whether this option can only be set by specifying the module name as its prefix. * @param description A description that explains the purpose of this option. */ OptionBuilder(std::string const& moduleName, std::string const& longName, bool requireModulePrefix, std::string const& description) : longName(longName), shortName(""), hasShortName(false), description(description), moduleName(moduleName), requireModulePrefix(requireModulePrefix), isRequired(false), isBuild(false), arguments(), argumentNameSet() { // Intentionally left empty. } /*! * Sets a short name for the option. * * @param shortName A short name for the option. * @return A reference to the current builder. */ OptionBuilder& setShortName(std::string const& shortName) { this->shortName = shortName; this->hasShortName = true; return *this; } /*! * Sets whether the option is required. * * @param isRequired A flag indicating whether the option is required. * @return A reference to the current builder. */ OptionBuilder& setIsRequired(bool isRequired) { this->isRequired = isRequired; return *this; } /*! * Adds the given argument to the arguments of this option. * * @param argument The argument to be added. * @return A reference to the current builder. */ OptionBuilder& addArgument(std::shared_ptr argument) { STORM_LOG_THROW(!this->isBuild, storm::exceptions::IllegalFunctionCallException, "Cannot add an argument to an option builder that was already used to build the option."); STORM_LOG_THROW(this->arguments.empty() || argument->getIsOptional() || !this->arguments.back()->getIsOptional(), storm::exceptions::IllegalArgumentException, "Unable to add non-optional argument after an option that is optional."); std::string lowerArgumentName = boost::algorithm::to_lower_copy(argument->getName()); STORM_LOG_THROW(argumentNameSet.find(lowerArgumentName) == argumentNameSet.end(), storm::exceptions::IllegalArgumentException, "Unable to add argument to option, because it already has an argument with the same name."); argumentNameSet.insert(lowerArgumentName); this->arguments.push_back(argument); return *this; } /*! * Builds an option from the data that was added to this builder. * * @return The resulting option. */ std::shared_ptr