Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SettingsManager.h
Go to the documentation of this file.
1#ifndef STORM_SETTINGS_SETTINGSMANAGER_H_
2#define STORM_SETTINGS_SETTINGSMANAGER_H_
3
4#include <functional>
5#include <iostream>
6#include <map>
7#include <memory>
8#include <unordered_map>
9#include <utility>
10#include <vector>
11
12namespace storm {
13namespace settings {
14namespace modules {
15class BuildSettings;
16class ModuleSettings;
17class AbstractionSettings;
18} // namespace modules
19class Option;
20
27 public:
28 // Explicitly delete copy constructor
30 void operator=(SettingsManager const&) = delete;
31
39 void setFromCommandLine(int const argc, char const* const argv[]);
40
48 void setFromString(std::string const& commandLineString);
49
57 void setFromExplodedString(std::vector<std::string> const& commandLineArguments);
58
63 void setFromConfigurationFile(std::string const& configFilename);
64
68 void handleUnknownOption(std::string const& optionName, bool isShort) const;
69
79 void printHelp(std::string const& filter = "frequent") const;
80
88 std::string getHelpForModule(std::string const& moduleName, uint_fast64_t maxLength = 30, bool includeAdvanced = true) const;
89
95 static SettingsManager& manager();
96
102 void setName(std::string const& name, std::string const& executableName);
103
110 void addModule(std::unique_ptr<modules::ModuleSettings>&& moduleSettings, bool doRegister = true);
111
119 bool hasModule(std::string const& moduleName, bool checkHidden = false) const;
120
127 modules::ModuleSettings const& getModule(std::string const& moduleName) const;
128
135 modules::ModuleSettings& getModule(std::string const& moduleName);
136
137 private:
143
147 virtual ~SettingsManager();
148
157 std::string getHelpForSelection(std::vector<std::string> const& selectedModuleNames, std::vector<std::string> const& selectedLongOptionNames,
158 std::string modulesHeader = "", std::string optionsHeader = "") const;
159
160 // The name of the tool
161 std::string name;
162 std::string executableName;
163
164 // The registered modules.
165 std::vector<std::string> moduleNames;
166 std::unordered_map<std::string, std::unique_ptr<modules::ModuleSettings>> modules;
167
168 // Mappings from all known option names to the options that match it. All options for one option name need
169 // to be compatible in the sense that calling isCompatible(...) pairwise on all options must always return true.
170 std::unordered_map<std::string, std::vector<std::shared_ptr<Option>>> longNameToOptions;
171 std::unordered_map<std::string, std::vector<std::shared_ptr<Option>>> shortNameToOptions;
172
173 // A mapping of module names to the corresponding options.
174 std::unordered_map<std::string, std::vector<std::shared_ptr<Option>>> moduleOptions;
175
176 // A list of long option names to keep the order in which they were registered. This is, for example, used
177 // to match the regular expression given to the help option against the option names.
178 std::vector<std::string> longOptionNames;
179
185 void addOption(std::shared_ptr<Option> const& option);
186
194 static void setOptionArguments(std::string const& optionName, std::shared_ptr<Option> option, std::vector<std::string> const& argumentCache);
195
203 static void setOptionsArguments(std::string const& optionName, std::unordered_map<std::string, std::vector<std::shared_ptr<Option>>> const& optionMap,
204 std::vector<std::string> const& argumentCache);
205
209 static bool isCompatible(std::shared_ptr<Option> const& option, std::string const& optionName,
210 std::unordered_map<std::string, std::vector<std::shared_ptr<Option>>> const& optionMap);
211
219 static void addOptionToMap(std::string const& name, std::shared_ptr<Option> const& option,
220 std::unordered_map<std::string, std::vector<std::shared_ptr<Option>>>& optionMap);
221
226 void finalizeAllModules();
227
234 uint_fast64_t getPrintLengthOfLongestOption(bool includeAdvanced) const;
235
243 uint_fast64_t getPrintLengthOfLongestOption(std::string const& moduleName, bool includeAdvanced) const;
244
251 std::map<std::string, std::vector<std::string>> parseConfigFile(std::string const& filename) const;
252};
253
259SettingsManager const& manager();
260
267
271template<typename SettingsType>
272void addModule(bool doRegister = true) {
273 static_assert(std::is_base_of<storm::settings::modules::ModuleSettings, SettingsType>::value, "Template argument must be derived from ModuleSettings");
274 mutableManager().addModule(std::unique_ptr<modules::ModuleSettings>(new SettingsType()), doRegister);
275}
276
282void initializeAll(std::string const& name, std::string const& executableName);
283
289template<typename SettingsType>
291 static_assert(std::is_base_of<storm::settings::modules::ModuleSettings, SettingsType>::value, "Template argument must be derived from ModuleSettings");
292 return dynamic_cast<SettingsType const&>(manager().getModule(SettingsType::moduleName));
293}
294
299template<typename SettingsType>
300bool hasModule() {
301 static_assert(std::is_base_of<storm::settings::modules::ModuleSettings, SettingsType>::value, "Template argument must be derived from ModuleSettings");
302 if (manager().hasModule(SettingsType::moduleName)) {
303 return dynamic_cast<SettingsType const*>(&(manager().getModule(SettingsType::moduleName))) != nullptr;
304 }
305 return false;
306}
307
315
323
324} // namespace settings
325} // namespace storm
326
327#endif /* STORM_SETTINGS_SETTINGSMANAGER_H_ */
Provides the central API for the registration of command line options and parsing the options from th...
void setFromCommandLine(int const argc, char const *const argv[])
This function parses the given command line arguments and sets all registered options accordingly.
std::string getHelpForModule(std::string const &moduleName, uint_fast64_t maxLength=30, bool includeAdvanced=true) const
This function prints a help message for the specified module to the standard output.
void setFromExplodedString(std::vector< std::string > const &commandLineArguments)
This function parses the given command line arguments (represented by several strings) and sets all r...
void operator=(SettingsManager const &)=delete
void setFromString(std::string const &commandLineString)
This function parses the given command line arguments (represented by one big string) and sets all re...
void setFromConfigurationFile(std::string const &configFilename)
This function parses the given file and sets all registered options accordingly.
void addModule(std::unique_ptr< modules::ModuleSettings > &&moduleSettings, bool doRegister=true)
Adds a new module with the given name.
void printHelp(std::string const &filter="frequent") const
This function prints a help message to the standard output.
void handleUnknownOption(std::string const &optionName, bool isShort) const
Throws an exception with a nice error message indicating similar valid option names.
void setName(std::string const &name, std::string const &executableName)
Sets the name of the tool.
SettingsManager(SettingsManager const &)=delete
modules::ModuleSettings const & getModule(std::string const &moduleName) const
Retrieves the settings of the module with the given name.
bool hasModule(std::string const &moduleName, bool checkHidden=false) const
Checks whether the module with the given name exists.
static SettingsManager & manager()
Retrieves the only existing instance of a settings manager.
This class represents the settings for the abstraction procedures.
This is the base class of the settings for a particular module.
storm::settings::modules::BuildSettings & mutableBuildSettings()
Retrieves the build settings in a mutable form.
storm::settings::modules::AbstractionSettings & mutableAbstractionSettings()
Retrieves the abstraction settings in a mutable form.
bool hasModule()
Returns true if the given module is registered.
SettingsType const & getModule()
Get module.
void addModule(bool doRegister=true)
Add new module to use for the settings.
void initializeAll(std::string const &name, std::string const &executableName)
Initialize the settings manager with all available modules.
SettingsManager const & manager()
Retrieves the settings manager.
SettingsManager & mutableManager()
Retrieves the settings manager.
LabParser.cpp.
Definition cli.cpp:18