From 1c0dab85a9e08c585d986a872881a0748caa7f9a Mon Sep 17 00:00:00 2001 From: gereon Date: Thu, 22 Nov 2012 10:36:07 +0100 Subject: [PATCH] settings are ready to be used, put into mrmc-cpp settings now support positional arguments and proper error handling. mrmc-cpp already uses the settings --- src/mrmc-cpp.cpp | 21 +++++++++++++++------ src/utility/settings.h | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/mrmc-cpp.cpp b/src/mrmc-cpp.cpp index e9db4cd67..1a84a4ed9 100644 --- a/src/mrmc-cpp.cpp +++ b/src/mrmc-cpp.cpp @@ -28,20 +28,29 @@ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = "mrmc-cpp" #include "src/models/atomic_propositions_labeling.h" #include "src/parser/read_lab_file.h" #include "src/parser/read_tra_file.h" +#include "src/utility/settings.h" #include "Eigen/Sparse" -int main(int argc, char* argv[]) { +int main(const int argc, const char* argv[]) { // Logging init pantheios_be_file_setFilePath("log.all"); pantheios::log_INFORMATIONAL("MRMC-Cpp started."); - if (argc < 3) { - std::cout << "Required argument #1 inputTraFile.tra not found!" << std::endl; - exit(-1); + mrmc::settings::Settings s(argc, argv, NULL); + + if (s.isSet("help")) + { + std::cout << s.getHelpForCommandline() << std::endl; + return 0; + } + if (s.isSet("help-config")) + { + std::cout << s.getHelpForConfigfile() << std::endl; + return 0; } - mrmc::sparse::StaticSparseMatrix* probMatrix = mrmc::parser::read_tra_file(argv[1]); - mrmc::models::AtomicPropositionsLabeling* labeling = mrmc::parser::read_lab_file(probMatrix->getRowCount(), argv[2]); + mrmc::sparse::StaticSparseMatrix* probMatrix = mrmc::parser::read_tra_file(s.getString("trafile").c_str()); + mrmc::models::AtomicPropositionsLabeling* labeling = mrmc::parser::read_lab_file(probMatrix->getRowCount(), s.getString("labfile").c_str()); mrmc::models::Dtmc dtmc(probMatrix, labeling); diff --git a/src/utility/settings.h b/src/utility/settings.h index 50292517c..e8a4f750d 100644 --- a/src/utility/settings.h +++ b/src/utility/settings.h @@ -29,6 +29,7 @@ namespace settings { bpo::options_description configfile; bpo::options_description generic; bpo::options_description commandline; + bpo::positional_options_description positional; /*! * @brief collecing option descriptions @@ -72,6 +73,15 @@ namespace settings { ("help-config", "produce help message about config file") ("configfile", bpo::value(), "name of config file") ; + this->generic.add_options() + ("trafile", bpo::value()->required(), "name of the .tra file") + ("labfile", bpo::value()->required(), "name of the .lab file") + ; + this->configfile.add_options() + ; + + this->positional.add("trafile", 1); + this->positional.add("labfile", 1); /* * construct option descriptions for commandline and config file @@ -84,7 +94,7 @@ namespace settings { /* * load command line */ - bpo::store(bpo::parse_command_line(argc, argv, this->cli), this->vm); + bpo::store(bpo::command_line_parser(argc, argv).options(this->cli).positional(this->positional).run(), this->vm); /* * load config file if specified */ @@ -96,6 +106,7 @@ namespace settings { { bpo::store(bpo::parse_config_file(filename, this->conf), this->vm, true); } + bpo::notify(this->vm); } /* * catch errors... @@ -104,17 +115,20 @@ namespace settings { { std::cout << "Could not read config file " << filename << std::endl; } + catch (bpo::required_option e) + { + std::cout << e.what() << std::endl; + } catch (bpo::error e) { std::cout << "Some error occurred: " << e.what() << std::endl; } - bpo::notify(this->vm); } /*! * @brief Get option descriptions for commandline options */ - bpo::options_description getHelpForCommandline() + bpo::options_description& getHelpForCommandline() { return this->cli; } @@ -122,10 +136,23 @@ namespace settings { /*! * @brief Get option descriptions for config file options */ - bpo::options_description getHelpForConfigfile() + bpo::options_description& getHelpForConfigfile() { return this->conf; } + + /*! + * @brief Get value of string argument + */ + const std::string& getString(const std::string &name) const + { + return this->vm[name].as(); + } + + const bool isSet(const std::string &name) const + { + return this->vm.count(name); + } }; } // namespace parser