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.

144 lines
6.2 KiB

  1. #ifndef STORM_SETTINGS_MODULES_MODULESETTINGS_H_
  2. #define STORM_SETTINGS_MODULES_MODULESETTINGS_H_
  3. #include <string>
  4. #include <unordered_map>
  5. #include "src/settings/Option.h"
  6. namespace storm {
  7. namespace settings {
  8. // Forward-declare some classes.
  9. class SettingsManager;
  10. class SettingMemento;
  11. namespace modules {
  12. /*!
  13. * This is the base class of the settings for a particular module.
  14. */
  15. class ModuleSettings {
  16. public:
  17. // Declare the memento class as a friend so it can manipulate the internal state.
  18. friend class storm::settings::SettingMemento;
  19. /*!
  20. * Constructs a new settings object.
  21. *
  22. * @param settingsManager The manager responsible for these settings.
  23. * @param moduleName The name of the module for which to build the settings.
  24. */
  25. ModuleSettings(storm::settings::SettingsManager& settingsManager, std::string const& moduleName);
  26. /*!
  27. * Checks whether the settings are consistent. If they are inconsistent, an exception is thrown.
  28. *
  29. * @return True if the settings are consistent.
  30. */
  31. virtual bool check() const;
  32. /*!
  33. * Sets the option with the given name to the required status. This requires the option to take no
  34. * arguments. As a result, a pointer to an object is returned such that when the object is destroyed
  35. * (i.e. the smart pointer goes out of scope), the option is reset to its original status.
  36. *
  37. * @param name The name of the option to (unset).
  38. * @param requiredStatus The status that is to be set for the option.
  39. * @return A pointer to an object that resets the change upon destruction.
  40. */
  41. std::unique_ptr<storm::settings::SettingMemento> overrideOption(std::string const& name, bool requiredStatus);
  42. /*!
  43. * Retrieves the name of the module to which these settings belong.
  44. *
  45. * @return The name of the module.
  46. */
  47. std::string const& getModuleName() const;
  48. /*!
  49. * Retrieves the options of this module.
  50. *
  51. * @return A list of options of this module.
  52. */
  53. std::vector<std::shared_ptr<Option>> const& getOptions() const;
  54. /*!
  55. * Retrieves the (print) length of the longest option.
  56. *
  57. * @return The length of the longest option.
  58. */
  59. uint_fast64_t getPrintLengthOfLongestOption() const;
  60. protected:
  61. /*!
  62. * Retrieves the manager responsible for the settings.
  63. *
  64. * @return The manager responsible for the settings.
  65. */
  66. storm::settings::SettingsManager const& getSettingsManager() const;
  67. /*!
  68. * Retrieves the option with the given long name. If no such option exists, an exception is thrown.
  69. *
  70. * @param longName The long name of the option to retrieve.
  71. * @return The option associated with the given option name.
  72. */
  73. Option& getOption(std::string const& longName);
  74. /*!
  75. * Retrieves the option with the given long name. If no such option exists, an exception is thrown.
  76. *
  77. * @param longName The long name of the option to retrieve.
  78. * @return The option associated with the given option name.
  79. */
  80. Option const& getOption(std::string const& longName) const;
  81. /*!
  82. * Retrieves whether the option with the given name was set.
  83. *
  84. * @param The name of the option.
  85. * @return True iff the option was set.
  86. */
  87. bool isSet(std::string const& optionName) const;
  88. /*!
  89. * Sets the option with the specified name. This requires the option to not have any arguments. This
  90. * should be used with care and is primarily meant to be used by the SettingMemento.
  91. *
  92. * @param name The name of the option to set.
  93. */
  94. void set(std::string const& name);
  95. /*!
  96. * Unsets the option with the specified name. This requires the option to not have any arguments. This
  97. * should be used with care and is primarily meant to be used by the SettingMemento.
  98. *
  99. * @param name The name of the option to unset.
  100. */
  101. void unset(std::string const& name);
  102. /*!
  103. * Adds and registers the given option.
  104. *
  105. * @param option The option to add and register.
  106. */
  107. void addOption(std::shared_ptr<Option> const& option);
  108. private:
  109. // The settings manager responsible for the settings.
  110. storm::settings::SettingsManager const& settingsManager;
  111. // The name of the module.
  112. std::string moduleName;
  113. // A mapping of option names of the module to the actual options.
  114. std::unordered_map<std::string, std::shared_ptr<Option>> optionMap;
  115. // The list of known option names in the order they were registered.
  116. std::vector<std::shared_ptr<Option>> options;
  117. };
  118. } // namespace modules
  119. } // namespace settings
  120. } // namespace storm
  121. #endif /* STORM_SETTINGS_MODULES_MODULESETTINGS_H_ */