You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
4.1 KiB

  1. #include "storm/settings/modules/ModuleSettings.h"
  2. #include "storm/utility/macros.h"
  3. #include "storm/settings/SettingMemento.h"
  4. #include "storm/settings/Option.h"
  5. #include "storm/exceptions/InvalidStateException.h"
  6. #include "storm/exceptions/IllegalFunctionCallException.h"
  7. namespace storm {
  8. namespace settings {
  9. namespace modules {
  10. ModuleSettings::ModuleSettings(std::string const& moduleName) : moduleName(moduleName) {
  11. // Intentionally left empty.
  12. }
  13. bool ModuleSettings::check() const {
  14. return true;
  15. }
  16. void ModuleSettings::finalize() { }
  17. void ModuleSettings::set(std::string const& name) {
  18. return this->getOption(name).setHasOptionBeenSet();
  19. }
  20. void ModuleSettings::unset(std::string const& name) {
  21. return this->getOption(name).setHasOptionBeenSet(false);
  22. }
  23. std::vector<std::shared_ptr<Option>> const& ModuleSettings::getOptions() const {
  24. return this->options;
  25. }
  26. Option const& ModuleSettings::getOption(std::string const& longName) const {
  27. auto optionIterator = this->optionMap.find(longName);
  28. STORM_LOG_THROW(optionIterator != this->optionMap.end(), storm::exceptions::IllegalFunctionCallException, "Cannot retrieve unknown option '" << longName << "'.");
  29. return *optionIterator->second;
  30. }
  31. Option& ModuleSettings::getOption(std::string const& longName) {
  32. auto optionIterator = this->optionMap.find(longName);
  33. STORM_LOG_THROW(optionIterator != this->optionMap.end(), storm::exceptions::IllegalFunctionCallException, "Cannot retrieve unknown option '" << longName << "'.");
  34. return *optionIterator->second;
  35. }
  36. std::string const& ModuleSettings::getModuleName() const {
  37. return this->moduleName;
  38. }
  39. std::unique_ptr<storm::settings::SettingMemento> ModuleSettings::overrideOption(std::string const& name, bool requiredStatus) {
  40. bool currentStatus = this->isSet(name);
  41. if (requiredStatus) {
  42. this->set(name);
  43. } else {
  44. this->unset(name);
  45. }
  46. return std::unique_ptr<storm::settings::SettingMemento>(new storm::settings::SettingMemento(*this, name, currentStatus));
  47. }
  48. bool ModuleSettings::isSet(std::string const& optionName) const {
  49. return this->getOption(optionName).getHasOptionBeenSet();
  50. }
  51. void ModuleSettings::addOption(std::shared_ptr<Option> const& option) {
  52. auto optionIterator = this->optionMap.find(option->getLongName());
  53. STORM_LOG_THROW(optionIterator == this->optionMap.end(), storm::exceptions::IllegalFunctionCallException, "Unable to register the option '" << option->getLongName() << "' in module '" << this->getModuleName() << "', because an option with this name already exists.");
  54. this->optionMap.emplace(option->getLongName(), option);
  55. this->options.push_back(option);
  56. }
  57. uint_fast64_t ModuleSettings::getPrintLengthOfLongestOption() const {
  58. uint_fast64_t length = 0;
  59. for (auto const& option : this->options) {
  60. length = std::max(length, option->getPrintLength());
  61. }
  62. return length;
  63. }
  64. void ModuleSettings::restoreDefaults() {
  65. for (auto& option : options) {
  66. for (auto& argument : option->getArguments()) {
  67. if (argument->getHasDefaultValue()) {
  68. argument->setFromDefaultValue();
  69. }
  70. }
  71. }
  72. }
  73. } // namespace modules
  74. } // namespace settings
  75. } // namespace storm