From a8517c724698ec20ee7f7b819d1fb05736b4413f Mon Sep 17 00:00:00 2001 From: gereon Date: Sat, 12 Jan 2013 18:10:41 +0100 Subject: [PATCH] fixed some documentation and changed position of const in Settings class. --- src/utility/Settings.cpp | 36 +++++++++++++++++------------------- src/utility/Settings.h | 26 +++++++++++++------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/utility/Settings.cpp b/src/utility/Settings.cpp index 19f6bee47..096c1b851 100644 --- a/src/utility/Settings.cpp +++ b/src/utility/Settings.cpp @@ -21,7 +21,7 @@ namespace settings { namespace bpo = boost::program_options; /* - * static initializers + * Static initializers. */ std::unique_ptr storm::settings::Settings::desc = nullptr; std::string storm::settings::Settings::binaryName = ""; @@ -42,17 +42,17 @@ std::map< std::pair, std::shared_ptrinitDescriptions(); - // Take care of positional arguments + // Take care of positional arguments. Settings::positional.add("trafile", 1); Settings::positional.add("labfile", 1); - // Check module triggers, add corresponding options + // Check module triggers, add corresponding options. std::map< std::string, std::list< std::string > > options; for (auto it : Settings::modules) { @@ -67,12 +67,12 @@ Settings::Settings(const int argc, const char* argv[], const char* filename) { ; } - // Perform first parse run + // Perform first parse run. this->firstRun(argc, argv, filename); - // Buffer for items to be deleted + // Buffer for items to be deleted. std::list< std::pair< std::string, std::string > > deleteQueue; - // Check module triggers + // Check module triggers. for (auto it : Settings::modules) { std::pair< std::string, std::string > trigger = it.first; if (this->vm.count(trigger.first)) { @@ -84,16 +84,15 @@ Settings::Settings(const int argc, const char* argv[], const char* filename) { } for (auto it : deleteQueue) Settings::modules.erase(it); - - // Stop if help is set + // Stop if help is set. if (this->vm.count("help") > 0) { return; } - // Perform second run + // Perform second run. this->secondRun(argc, argv, filename); - // Finalize parsed options, check for specified requirements + // Finalize parsed options, check for specified requirements. bpo::notify(this->vm); LOG4CPLUS_DEBUG(logger, "Finished loading config."); } @@ -117,7 +116,6 @@ Settings::Settings(const int argc, const char* argv[], const char* filename) { /*! * Initially fill options_description objects. - * First puts some generic options, then calls all register Callbacks. */ void Settings::initDescriptions() { LOG4CPLUS_DEBUG(logger, "Initializing descriptions."); @@ -141,13 +139,13 @@ void Settings::initDescriptions() { * given), but allow for unregistered options, do not check requirements * from options_description objects, do not check positional arguments. */ -void Settings::firstRun(const int argc, const char* argv[], const char* filename) { +void Settings::firstRun(int const argc, char const * const argv[], char const * const filename) { LOG4CPLUS_DEBUG(logger, "Performing first run."); - // parse command line + // Parse command line. bpo::store(bpo::command_line_parser(argc, argv).options(*(Settings::desc)).allow_unregistered().run(), this->vm); /* - * load config file if specified + * Load config file if specified. */ if (this->vm.count("configfile")) { bpo::store(bpo::parse_config_file(this->vm["configfile"].as().c_str(), *(Settings::desc)), this->vm, true); @@ -161,12 +159,12 @@ void Settings::firstRun(const int argc, const char* argv[], const char* filename * given) and check for unregistered options, requirements from * options_description objects and positional arguments. */ -void Settings::secondRun(const int argc, const char* argv[], const char* filename) { +void Settings::secondRun(int const argc, char const * const argv[], char const * const filename) { LOG4CPLUS_DEBUG(logger, "Performing second run."); - // Parse command line + // Parse command line. bpo::store(bpo::command_line_parser(argc, argv).options(*(Settings::desc)).positional(this->positional).run(), this->vm); /* - * load config file if specified + * Load config file if specified. */ if (this->vm.count("configfile")) { bpo::store(bpo::parse_config_file(this->vm["configfile"].as().c_str(), *(Settings::desc)), this->vm, true); diff --git a/src/utility/Settings.h b/src/utility/Settings.h index 37208f990..b85ff9256 100644 --- a/src/utility/Settings.h +++ b/src/utility/Settings.h @@ -51,7 +51,7 @@ namespace settings { * @brief Get value of a generic option. */ template - const T& get(const std::string &name) const { + inline const T& get( std::string const & name) const { if (this->vm.count(name) == 0) throw storm::exceptions::InvalidSettingsException() << "Could not read option " << name << "."; return this->vm[name].as(); } @@ -59,14 +59,14 @@ namespace settings { /*! * @brief Get value of string option */ - const std::string& getString(const std::string &name) const { + inline const std::string& getString(std::string const & name) const { return this->get(name); } /*! * @brief Check if an option is set */ - const bool isSet(const std::string &name) const { + inline const bool isSet(std::string const & name) const { return this->vm.count(name) > 0; } @@ -107,28 +107,28 @@ namespace settings { */ template static void registerModule() { - // get trigger + // Get trigger values. std::pair< std::string, std::string > trigger = T::getOptionTrigger(); - // build description name + // Build description name. std::stringstream str; str << "Options for " << T::getModuleName() << " (" << trigger.first << " = " << trigger.second << ")"; std::shared_ptr desc = std::shared_ptr(new bpo::options_description(str.str())); - // but options + // Put options into description. T::putOptions(desc.get()); - // store + // Store module. Settings::modules[ trigger ] = desc; } friend std::ostream& help(std::ostream& os); friend std::ostream& helpConfigfile(std::ostream& os); friend Settings* instance(); - friend Settings* newInstance(const int argc, const char* argv[], const char* filename); + friend Settings* newInstance(int const argc, char const * const argv[], char const * const filename); private: /*! * @brief Constructor. */ - Settings(const int argc, const char* argv[], const char* filename); + Settings(int const argc, char const * const argv[], char const * const filename); /*! * @brief Initialize options_description object. @@ -138,12 +138,12 @@ namespace settings { /*! * @brief Perform first parser run */ - void firstRun(const int argc, const char* argv[], const char* filename); + void firstRun(int const argc, char const * const argv[], char const * const filename); /*! * @brief Perform second parser run. */ - void secondRun(const int argc, const char* argv[], const char* filename); + void secondRun(int const argc, char const * const argv[], char const * const filename); /*! * @brief Option description for positional arguments on command line. @@ -197,10 +197,10 @@ namespace settings { * * @param argc should be argc passed to main function * @param argv should be argv passed to main function - * @param filename either NULL or name of config file + * @param filename either NULL or name of config file * @return The new instance of Settings. */ - inline Settings* newInstance(const int argc, const char* argv[], const char* filename) { + inline Settings* newInstance(int const argc, char const * const argv[], char const * const filename) { if (Settings::inst != nullptr) delete Settings::inst; Settings::inst = new Settings(argc, argv, filename); return Settings::inst;