diff --git a/CMakeLists.txt b/CMakeLists.txt index 98c97cdd1..510e33d22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,12 @@ project (MRMC-cpp CXX C) set (MRMC_CPP_VERSION_MAJOR 1) set (MRMC_CPP_VERSION_MINOR 0) +set (GTEST_INCLUDE_DIR resources/3rdparty/gtest-1.6.0/include) +set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest.a) +set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest_main.a) +set (STLSOFT_INCLUDE_DIR resources/3rdparty/stlsoft-1.9.116/include) +set (PANTHEIOS_INCLUDE_DIR resources/3rdparty/pantheios-1.0.1-beta214/include) + option(DEBUG "Sets whether the DEBUG mode is used" ON) option(DEFINE_UNIX "Defines the UNIX flag for compilation." OFF) option(USE_POPCNT "Sets whether the popcnt instruction is going to be used." OFF) @@ -155,7 +161,7 @@ string(REGEX REPLACE ";" " " CMAKE_DOXYGEN_INPUT_LIST "${PROJECT_SOURCE_DIR}/src configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) -add_custom_target(doc ALL +add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile COMMENT "Generating API documentation with Doxygen" VERBATIM @@ -189,3 +195,4 @@ endif(THREADS_FOUND) if (DEFINE_UNIX) add_definitions(-DUNIX) endif(DEFINE_UNIX) + diff --git a/src/exceptions/InvalidSettings.h b/src/exceptions/InvalidSettings.h new file mode 100644 index 000000000..8244c6d4c --- /dev/null +++ b/src/exceptions/InvalidSettings.h @@ -0,0 +1,35 @@ +#ifndef MRMC_EXCEPTIONS_INVALID_SETTINGS_H_ +#define MRMC_EXCEPTIONS_INVALID_SETTINGS_H_ + +#include + +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_ diff --git a/src/mrmc-cpp.cpp b/src/mrmc-cpp.cpp index 1a84a4ed9..2de514550 100644 --- a/src/mrmc-cpp.cpp +++ b/src/mrmc-cpp.cpp @@ -30,27 +30,39 @@ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = "mrmc-cpp" #include "src/parser/read_tra_file.h" #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); - if (s.isSet("help")) + 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")) { - 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* 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* 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 e8a4f750d..991862f0b 100644 --- a/src/utility/settings.h +++ b/src/utility/settings.h @@ -5,10 +5,12 @@ * Author: Gereon Kremer */ -#pragma once +#ifndef SETTINGS_H_ +#define SETTINGS_H_ #include #include +#include "src/exceptions/InvalidSettings.h" namespace mrmc { namespace settings { @@ -22,29 +24,6 @@ namespace settings { */ class Settings { - private: - /*! - * @brief option descriptions - */ - bpo::options_description configfile; - bpo::options_description generic; - bpo::options_description commandline; - bpo::positional_options_description positional; - - /*! - * @brief collecing option descriptions - * - * The options for command line and config file are collected - * here - */ - bpo::options_description cli; - bpo::options_description conf; - - /*! - * @brief option mapping - */ - bpo::variables_map vm; - public: /*! @@ -117,7 +96,11 @@ namespace settings { } catch (bpo::required_option e) { - std::cout << e.what() << std::endl; + if (! (this->vm.count("help") || this->vm.count("help-config"))) + { + std::cout << e.what() << std::endl; + throw mrmc::exceptions::InvalidSettings(); + } } catch (bpo::error e) { @@ -151,9 +134,35 @@ namespace settings { const bool isSet(const std::string &name) const { - return this->vm.count(name); + return this->vm.count(name) > 0; } + + private: + /*! + * @brief option descriptions + */ + bpo::options_description configfile; + bpo::options_description generic; + bpo::options_description commandline; + bpo::positional_options_description positional; + + /*! + * @brief collecing option descriptions + * + * The options for command line and config file are collected + * here + */ + bpo::options_description cli; + bpo::options_description conf; + + /*! + * @brief option mapping + */ + bpo::variables_map vm; + }; } // namespace parser -} // namespace mrmc \ No newline at end of file +} // namespace mrmc + +#endif // SETTINGS_H_ \ No newline at end of file