Browse Source

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
tempestpy_adaptions
gereon 12 years ago
parent
commit
1c0dab85a9
  1. 21
      src/mrmc-cpp.cpp
  2. 35
      src/utility/settings.h

21
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<double>* probMatrix = mrmc::parser::read_tra_file(argv[1]);
mrmc::models::AtomicPropositionsLabeling* labeling = mrmc::parser::read_lab_file(probMatrix->getRowCount(), argv[2]);
mrmc::sparse::StaticSparseMatrix<double>* 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<double> dtmc(probMatrix, labeling);

35
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<std::string>(), "name of config file")
;
this->generic.add_options()
("trafile", bpo::value<std::string>()->required(), "name of the .tra file")
("labfile", bpo::value<std::string>()->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<char>(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<std::string>();
}
const bool isSet(const std::string &name) const
{
return this->vm.count(name);
}
};
} // namespace parser
Loading…
Cancel
Save