Browse Source

making settings more robust

adding new exception that is thrown whenever loading the settings fails.
this exception is caught in mrmc-cpp.cpp. If this happens, the program is terminated.
tempestpy_adaptions
gereon 12 years ago
parent
commit
ded2e43deb
  1. 35
      src/exceptions/InvalidSettings.h
  2. 26
      src/mrmc-cpp.cpp
  3. 5
      src/utility/settings.h

35
src/exceptions/InvalidSettings.h

@ -0,0 +1,35 @@
#ifndef MRMC_EXCEPTIONS_INVALID_SETTINGS_H_
#define MRMC_EXCEPTIONS_INVALID_SETTINGS_H_
#include <exception>
namespace mrmc {
namespace exceptions {
//!This exception is thrown when a memory request can't be
//!fulfilled.
class InvalidSettings : public std::exception
{
public:
/* The Visual C++-Version of the exception class has constructors accepting
* a char*-constant; The GCC version does not have these
*
* As the "extended" constructor is used in the sparse matrix code, a dummy
* constructor is used under linux (which will ignore the parameter)
*/
#ifdef _WIN32
InvalidSettings() : exception("::mrmc::InvalidSettings"){}
InvalidSettings(const char * const s): exception(s) {}
#else
InvalidSettings() : exception() {}
InvalidSettings(const char * const s): exception() {}
#endif
virtual const char* what() const throw()
{ return "mrmc::InvalidSettings"; }
};
} // namespace exceptions
} // namespace mrmc
#endif // MRMC_EXCEPTIONS_INVALID_SETTINGS_H_

26
src/mrmc-cpp.cpp

@ -31,26 +31,38 @@ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = "mrmc-cpp"
#include "src/utility/settings.h"
#include "Eigen/Sparse"
#include "src/exceptions/InvalidSettings.h"
int main(const int argc, const char* argv[]) {
// Logging init
pantheios_be_file_setFilePath("log.all");
pantheios::log_INFORMATIONAL("MRMC-Cpp started.");
mrmc::settings::Settings s(argc, argv, NULL);
mrmc::settings::Settings* s = NULL;
try
{
s = new mrmc::settings::Settings(argc, argv, NULL);
}
catch (mrmc::exceptions::InvalidSettings)
{
std::cout << "Could not recover from settings error, terminating." << std::endl;
return 1;
}
if (s.isSet("help"))
if (s->isSet("help"))
{
std::cout << s.getHelpForCommandline() << std::endl;
std::cout << s->getHelpForCommandline() << std::endl;
return 0;
}
if (s.isSet("help-config"))
if (s->isSet("help-config"))
{
std::cout << s.getHelpForConfigfile() << std::endl;
std::cout << s->getHelpForConfigfile() << std::endl;
return 0;
}
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::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);

5
src/utility/settings.h

@ -10,6 +10,7 @@
#include <iostream>
#include <boost/program_options.hpp>
#include "src/exceptions/InvalidSettings.h"
namespace mrmc {
namespace settings {
@ -94,8 +95,12 @@ namespace settings {
std::cout << "Could not read config file " << filename << std::endl;
}
catch (bpo::required_option e)
{
if (! (this->vm.count("help") || this->vm.count("help-config")))
{
std::cout << e.what() << std::endl;
throw mrmc::exceptions::InvalidSettings();
}
}
catch (bpo::error e)
{

Loading…
Cancel
Save