diff --git a/src/settings/Argument.h b/src/settings/Argument.h index 141ea5de1..2a7530cb8 100644 --- a/src/settings/Argument.h +++ b/src/settings/Argument.h @@ -19,6 +19,10 @@ #include "src/exceptions/IllegalArgumentValueException.h" #include "src/exceptions/IllegalFunctionCallException.h" +#include "log4cplus/logger.h" +#include "log4cplus/loggingmacros.h" +extern log4cplus::Logger logger; + namespace storm { namespace settings { @@ -41,7 +45,8 @@ namespace storm { Argument(std::string const& argumentName, std::string const& argumentDescription, std::vector const& validationFunctions, bool isOptional): ArgumentBase(argumentName, argumentDescription, isOptional), argumentType(ArgumentTypeInferation::inferToEnumType()), userValidationFunction(validationFunctions), hasDefaultValue(false) { if (isOptional) { - throw storm::exceptions::IllegalArgumentException() << "Error: The Argument \"" << argumentName << "\" is flaged as optional but no default value was given!"; + LOG4CPLUS_ERROR(logger, "Argument::Argument: The Argument \"" << argumentName << "\" is flaged as optional but no default value was given!"); + throw storm::exceptions::IllegalArgumentException() << "The Argument \"" << argumentName << "\" is flaged as optional but no default value was given!"; } } @@ -57,7 +62,7 @@ namespace storm { } virtual ~Argument() { - std::cout << "Destructing an Argument: " << this->getArgumentName() << " of Type " << ArgumentTypeHelper::toString(this->getArgumentType()) << std::endl; + //LOG4CPLUS_DEBUG(logger, "Argument::~Argument: Destructing Argument \"" << this->getArgumentName() << "\" of Type " << ArgumentTypeHelper::toString(this->getArgumentType())); this->userValidationFunction.clear(); this->argumentType = ArgumentType::Invalid; @@ -97,26 +102,26 @@ namespace storm { template void unify(Argument &rhs) { if (this->getArgumentType() != rhs.getArgumentType()) { - // LOG - throw storm::exceptions::ArgumentUnificationException() << "Error while unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": Type Missmatch: \"" << ArgumentTypeHelper::toString(this->getArgumentType()) << "\" against \"" << ArgumentTypeHelper::toString(rhs.getArgumentType()) << "\""; + LOG4CPLUS_ERROR(logger, "Argument::unify: While unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": Type Missmatch: \"" << ArgumentTypeHelper::toString(this->getArgumentType()) << "\" against \"" << ArgumentTypeHelper::toString(rhs.getArgumentType()) << "\""); + throw storm::exceptions::ArgumentUnificationException() << "While unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": Type Missmatch: \"" << ArgumentTypeHelper::toString(this->getArgumentType()) << "\" against \"" << ArgumentTypeHelper::toString(rhs.getArgumentType()) << "\""; } if (this->getIsOptional() != rhs.getIsOptional()) { - // LOG - throw storm::exceptions::ArgumentUnificationException() << "Error while unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": IsOptional Missmatch!"; + LOG4CPLUS_ERROR(logger, "Argument::unify: While unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": IsOptional Missmatch!"); + throw storm::exceptions::ArgumentUnificationException() << "While unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": IsOptional Missmatch!"; } if (this->getHasDefaultValue() != rhs.getHasDefaultValue()) { - // LOG - throw storm::exceptions::ArgumentUnificationException() << "Error while unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": defaultValue Missmatch!"; + LOG4CPLUS_ERROR(logger, "Argument::unify: While unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": defaultValue Missmatch!"); + throw storm::exceptions::ArgumentUnificationException() << "While unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": defaultValue Missmatch!"; } if (this->getArgumentDescription().compare(rhs.getArgumentDescription()) != 0) { - // LOG Warning: Descriptions of unified arguments do not match + LOG4CPLUS_WARN(logger, "Argument::unify: While unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": descriptions Missmatch!"); } if (this->getArgumentName().compare(rhs.getArgumentName()) != 0) { - // LOG Warning: Names of unified arguments do not match + LOG4CPLUS_WARN(logger, "Argument::unify: While unifying Argument \"" << this->getArgumentName() << "\" and Argument \"" << rhs.getArgumentName() << "\": ArgumentName Missmatch!"); } // Add Validation functions @@ -128,8 +133,8 @@ namespace storm { T getArgumentValue() const { if (!this->getHasBeenSet()) { - // LOG - throw storm::exceptions::IllegalFunctionCallException() << "Error: Called getArgumentValue() on Argument \"" << this->getArgumentName() << "\", but it was never set and does not contain a default value."; + LOG4CPLUS_ERROR(logger, "Argument::getArgumentValue: Called getArgumentValue() on Argument \"" << this->getArgumentName() << "\", but it was never set and does not contain a default value."); + throw storm::exceptions::IllegalFunctionCallException() << "Called getArgumentValue() on Argument \"" << this->getArgumentName() << "\", but it was never set and does not contain a default value."; } return this->argumentValue; } @@ -144,12 +149,14 @@ namespace storm { void setFromDefaultValue() override { if (!this->hasDefaultValue) { - throw storm::exceptions::IllegalFunctionCallException() << "Error: The Argument \"" << this->getArgumentName() << "\" (" << this->getArgumentDescription() << ") was asked to set its default value but none was set!"; + LOG4CPLUS_ERROR(logger, "Argument::setFromDefaultValue: The Argument \"" << this->getArgumentName() << "\" (" << this->getArgumentDescription() << ") was asked to set its default value but none was set!"); + throw storm::exceptions::IllegalFunctionCallException() << "The Argument \"" << this->getArgumentName() << "\" (" << this->getArgumentDescription() << ") was asked to set its default value but none was set!"; } // this call also sets the hasBeenSet flag assignmentResult_t result = this->fromTypeValue(this->defaultValue); if (!result.first) { - throw storm::exceptions::IllegalArgumentValueException() << "Error: While parsing a given configuration the Argument \"" << this->getArgumentName() << "\" (" << this->getArgumentDescription() << ") could not receive its Default Value as it was rejected by its Validation Functions with message: " << result.second; + LOG4CPLUS_ERROR(logger, "Argument::setFromDefaultValue: While parsing a given configuration the Argument \"" << this->getArgumentName() << "\" (" << this->getArgumentDescription() << ") could not receive its Default Value as it was rejected by its Validation Functions with message: " << result.second); + throw storm::exceptions::IllegalArgumentValueException() << "While parsing a given configuration the Argument \"" << this->getArgumentName() << "\" (" << this->getArgumentDescription() << ") could not receive its Default Value as it was rejected by its Validation Functions with message: " << result.second; } } @@ -176,9 +183,10 @@ namespace storm { switch (this->argumentType) { case ArgumentType::Integer: return ArgumentTypeInferation::inferToInteger(ArgumentType::Integer, this->getArgumentValue()); - default: - throw storm::exceptions::IllegalFunctionCallException() << "Error: getValueAsInteger() was called on Argument \"" << getArgumentName() << "\" of Type \"" << ArgumentTypeHelper::toString(getArgumentType()) << "\"!"; - + default: { + LOG4CPLUS_ERROR(logger, "Argument::getValueAsInteger() was called on Argument \"" << getArgumentName() << "\" of Type \"" << ArgumentTypeHelper::toString(getArgumentType()) << "\"!"); + throw storm::exceptions::IllegalFunctionCallException() << "getValueAsInteger() was called on Argument \"" << getArgumentName() << "\" of Type \"" << ArgumentTypeHelper::toString(getArgumentType()) << "\"!"; + } } } @@ -186,9 +194,10 @@ namespace storm { switch (this->argumentType) { case ArgumentType::UnsignedInteger: return ArgumentTypeInferation::inferToUnsignedInteger(ArgumentType::UnsignedInteger, this->getArgumentValue()); - default: + default: { + LOG4CPLUS_ERROR(logger, "Argument::getValueAsUnsignedInteger() was called on Argument \"" << getArgumentName() << "\" of Type \"" << ArgumentTypeHelper::toString(getArgumentType()) << "\"!"); throw storm::exceptions::IllegalFunctionCallException() << "Error: getValueAsUnsignedInteger() was called on Argument \"" << getArgumentName() << "\" of Type \"" << ArgumentTypeHelper::toString(getArgumentType()) << "\"!"; - + } } } @@ -196,9 +205,10 @@ namespace storm { switch (this->argumentType) { case ArgumentType::Double: return ArgumentTypeInferation::inferToDouble(ArgumentType::Double, this->getArgumentValue()); - default: + default: { + LOG4CPLUS_ERROR(logger, "Argument::getValueAsDouble() was called on Argument \"" << getArgumentName() << "\" of Type \"" << ArgumentTypeHelper::toString(getArgumentType()) << "\"!"); throw storm::exceptions::IllegalFunctionCallException() << "Error: getValueAsDouble() was called on Argument \"" << getArgumentName() << "\" of Type \"" << ArgumentTypeHelper::toString(getArgumentType()) << "\"!"; - + } } } @@ -206,9 +216,10 @@ namespace storm { switch (this->argumentType) { case ArgumentType::Boolean: return ArgumentTypeInferation::inferToBoolean(ArgumentType::Boolean, this->getArgumentValue()); - default: + default: { + LOG4CPLUS_ERROR(logger, "Argument::getValueAsBoolean() was called on Argument \"" << getArgumentName() << "\" of Type \"" << ArgumentTypeHelper::toString(getArgumentType()) << "\"!"); throw storm::exceptions::IllegalFunctionCallException() << "Error: getValueAsBoolean() was called on Argument \"" << getArgumentName() << "\" of Type \"" << ArgumentTypeHelper::toString(getArgumentType()) << "\"!"; - + } } } private: @@ -224,7 +235,7 @@ namespace storm { std::string errorText = ""; if (!this->validateForEach(newDefault, errorText)) { // A user defined Validation Function was given and it rejected the Input. - // LOG + LOG4CPLUS_ERROR(logger, "Argument::setDefaultValue: Illegal Default Value for Argument \"" << this->getArgumentName() << "\".\nThe Validation Function rejected the Value: " << errorText); throw storm::exceptions::IllegalArgumentValueException() << "Illegal Default Value for Argument \"" << this->getArgumentName() << "\".\nThe Validation Function rejected the Value: " << errorText; } this->defaultValue = newDefault; diff --git a/src/settings/ArgumentBase.h b/src/settings/ArgumentBase.h index a7b3b888a..518910fb7 100644 --- a/src/settings/ArgumentBase.h +++ b/src/settings/ArgumentBase.h @@ -7,6 +7,10 @@ #include "ArgumentType.h" #include "src/utility/StringHelper.h" +#include "log4cplus/logger.h" +#include "log4cplus/loggingmacros.h" +extern log4cplus::Logger logger; + namespace storm { namespace settings { @@ -16,7 +20,7 @@ namespace storm { public: ArgumentBase(std::string const& argumentName, std::string const& argumentDescription, bool isOptional) : isOptional(isOptional), hasBeenSet(false), argumentName(argumentName), argumentDescription(argumentDescription) {} virtual ~ArgumentBase() { - std::cout << "Destructing an ArgumentBase." << std::endl; + //LOG4CPLUS_DEBUG(logger, "ArgumentBase::~ArgumentBase: Destructing ArgumentBase \"" << this->getArgumentName() << "\""); } virtual ArgumentType getArgumentType() const = 0; diff --git a/src/settings/ArgumentBuilder.h b/src/settings/ArgumentBuilder.h index 166b4b969..26de8c31a 100644 --- a/src/settings/ArgumentBuilder.h +++ b/src/settings/ArgumentBuilder.h @@ -20,6 +20,10 @@ #include "src/exceptions/IllegalFunctionCallException.h" #include "src/exceptions/IllegalArgumentTypeException.h" +#include "log4cplus/logger.h" +#include "log4cplus/loggingmacros.h" +extern log4cplus::Logger logger; + namespace storm { namespace settings { @@ -75,12 +79,14 @@ namespace storm { #define PPCAT(A, B) PPCAT_NX(A, B) #define MACROaddValidationFunction(funcName, funcType) ArgumentBuilder& PPCAT(addValidationFunction, funcName) (storm::settings::Argument< funcType >::userValidationFunction_t userValidationFunction) { \ if (this->argumentType != ArgumentType::funcName) { \ - throw storm::exceptions::IllegalFunctionCallException() << "Error: You tried adding a Validation-Function for a \"" << ArgumentTypeHelper::toString(ArgumentType::funcName) << "\" Argument, but this Argument is configured to be of Type \"" << ArgumentTypeHelper::toString(this->argumentType) << "\"."; \ + LOG4CPLUS_ERROR(logger, "ArgumentBuilder::addValidationFunction: Tried adding a Validation-Function for a \"" << ArgumentTypeHelper::toString(ArgumentType::funcName) << "\" Argument, but this Argument is configured to be of Type \"" << ArgumentTypeHelper::toString(this->argumentType) << "\"."); \ + throw storm::exceptions::IllegalFunctionCallException() << "Tried adding a Validation-Function for a \"" << ArgumentTypeHelper::toString(ArgumentType::funcName) << "\" Argument, but this Argument is configured to be of Type \"" << ArgumentTypeHelper::toString(this->argumentType) << "\"."; \ } \ ( PPCAT(this->userValidationFunction_, funcName) ).push_back(userValidationFunction); \ std::string errorMessageTarget = ""; \ if (this->hasDefaultValue && !this->validateDefaultForEach(errorMessageTarget)) { \ - throw storm::exceptions::IllegalArgumentValueException() << "Error: You tried adding a Validation-Function for an Argument which has a Default Value set which is rejected by this Validation-Function:\r\n" << errorMessageTarget; \ + LOG4CPLUS_ERROR(logger, "ArgumentBuilder::addValidationFunction: Tried adding a Validation-Function for an Argument which has a Default Value set which is rejected by this Validation-Function:\r\n" << errorMessageTarget); \ + throw storm::exceptions::IllegalArgumentValueException() << "Tried adding a Validation-Function for an Argument which has a Default Value set which is rejected by this Validation-Function:\r\n" << errorMessageTarget; \ } \ return *this; \ } @@ -94,12 +100,14 @@ namespace storm { #define MACROsetDefaultValue(funcName, funcType) ArgumentBuilder& PPCAT(setDefaultValue, funcName) (funcType const& defaultValue) { \ if (this->argumentType != ArgumentType::funcName) { \ - throw storm::exceptions::IllegalFunctionCallException() << "Error: You tried adding a default Value for a \"" << ArgumentTypeHelper::toString(ArgumentType::String) << "\" Argument, but the Argument \"" << this->argumentName << "\" is configured to be of Type \"" << ArgumentTypeHelper::toString(this->argumentType) << "\"."; \ + LOG4CPLUS_ERROR(logger, "ArgumentBuilder::addValidationFunction: Tried adding a default Value for a \"" << ArgumentTypeHelper::toString(ArgumentType::String) << "\" Argument, but the Argument \"" << this->argumentName << "\" is configured to be of Type \"" << ArgumentTypeHelper::toString(this->argumentType) << "\"."); \ + throw storm::exceptions::IllegalFunctionCallException() << "Tried adding a default Value for a \"" << ArgumentTypeHelper::toString(ArgumentType::String) << "\" Argument, but the Argument \"" << this->argumentName << "\" is configured to be of Type \"" << ArgumentTypeHelper::toString(this->argumentType) << "\"."; \ } \ PPCAT(this->defaultValue_, funcName) = defaultValue; \ std::string errorMessageTarget = ""; \ if (!this->validateDefaultForEach(errorMessageTarget)) { \ - throw storm::exceptions::IllegalArgumentValueException() << "Error: You tried adding a default Value for the Argument \"" << this->argumentName << "\", but a Validation Function rejected it:\r\n" << errorMessageTarget; \ + LOG4CPLUS_ERROR(logger, "ArgumentBuilder::setDefaultValue: Tried adding a default Value for the Argument \"" << this->argumentName << "\", but a Validation Function rejected it:\r\n" << errorMessageTarget); \ + throw storm::exceptions::IllegalArgumentValueException() << "Tried adding a default Value for the Argument \"" << this->argumentName << "\", but a Validation Function rejected it:\r\n" << errorMessageTarget; \ } \ this->hasDefaultValue = true; \ return *this; \ @@ -113,8 +121,8 @@ namespace storm { ArgumentBase* build() { if (this->hasBeenBuild) { - // LOG - throw storm::exceptions::IllegalFunctionCallException() << "Error: Called build() on an instance of ArgumentBuilder which has already build an Instance."; + LOG4CPLUS_ERROR(logger, "ArgumentBuilder::build: Called build() on an instance of ArgumentBuilder which has already build an Instance."); + throw storm::exceptions::IllegalFunctionCallException() << "Called build() on an instance of ArgumentBuilder which has already build an Instance."; } this->hasBeenBuild = true; switch (this->argumentType) { @@ -154,9 +162,10 @@ namespace storm { return dynamic_cast(new Argument(this->argumentName, this->argumentDescription, userValidationFunction_Boolean, this->isOptional)); } break; - default: - // LOG - throw storm::exceptions::InternalTypeErrorException() << "Error: Missing Case in ArgumentBuilder's switch/case Code."; + default: { + LOG4CPLUS_ERROR(logger, "ArgumentBuilder::build: Missing Case in ArgumentBuilder's switch/case Code."); + throw storm::exceptions::InternalTypeErrorException() << "Missing Case in ArgumentBuilder's switch/case Code."; + } } } private: @@ -242,9 +251,10 @@ namespace storm { result = result && lambda(this->defaultValue_Boolean, errorMessageTarget); } break; - default: - // LOG + default: { + LOG4CPLUS_ERROR(logger, "ArgumentBuilder::build: Missing Case in ArgumentBuilder's switch/case Code."); throw storm::exceptions::InternalTypeErrorException() << "Error: Missing Case in ArgumentBuilder's switch/case Code."; + } } return result; diff --git a/src/settings/ArgumentType.h b/src/settings/ArgumentType.h index c93f4d293..d3ea7eb77 100644 --- a/src/settings/ArgumentType.h +++ b/src/settings/ArgumentType.h @@ -3,6 +3,10 @@ #include "src/exceptions/InternalTypeErrorException.h" +#include "log4cplus/logger.h" +#include "log4cplus/loggingmacros.h" +extern log4cplus::Logger logger; + namespace storm { namespace settings { enum class ArgumentType { @@ -38,8 +42,10 @@ namespace storm { case ArgumentType::Boolean: return argumentTypeBoolean; break; - default: - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n" << "Missing a Switch Case in the ArgumentTypeHelper!\n" << "It seems there is a new ArgumentType, but it was not added to the Helper Class!"; + default: { + LOG4CPLUS_ERROR(logger, "ArgumentTypeHelper::toString: Missing Case in ArgumentTypeHelper's switch/case Code."); + throw storm::exceptions::InternalTypeErrorException() << "Missing a Switch Case in the ArgumentTypeHelper!\n" << "It seems there is a new ArgumentType, but it was not added to the Helper Class!"; + } } } private: diff --git a/src/settings/ArgumentTypeInferationHelper.h b/src/settings/ArgumentTypeInferationHelper.h index 2f452143e..dc34236e0 100644 --- a/src/settings/ArgumentTypeInferationHelper.h +++ b/src/settings/ArgumentTypeInferationHelper.h @@ -15,6 +15,10 @@ #include "ArgumentType.h" #include "src/exceptions/InternalTypeErrorException.h" +#include "log4cplus/logger.h" +#include "log4cplus/loggingmacros.h" +extern log4cplus::Logger logger; + namespace storm { namespace settings { class ArgumentTypeInferation { @@ -41,7 +45,8 @@ namespace storm { template ArgumentType ArgumentTypeInferation::inferToEnumType() { // "Missing Template Specialization Case in ArgumentTypeInferation" - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n" << "Missing a Template Specialization Case in the ArgumentTypeInferationHelper!\n" << "It seems you tried to use a new, non-standard Type as a Settings Parameter-Type!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToEnumType: Missing a Template Specialization Case in the ArgumentTypeInferationHelper! It seems you tried to use a new, non-standard Type as a Settings Parameter-Type!"); + throw storm::exceptions::InternalTypeErrorException() << "Missing a Template Specialization Case in the ArgumentTypeInferationHelper!\n" << "It seems you tried to use a new, non-standard Type as a Settings Parameter-Type!"; return ArgumentType::Invalid; } @@ -67,14 +72,16 @@ namespace storm { */ template std::string ArgumentTypeInferation::inferToString(ArgumentType argumentType, T value) { - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n " << "inferToString was called on a non-string Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToString: inferToString was called on a non-string Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"); + throw storm::exceptions::InternalTypeErrorException() << "inferToString was called on a non-string Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; return std::string(); } template <> inline std::string ArgumentTypeInferation::inferToString(ArgumentType argumentType, std::string value) { if (argumentType != ArgumentType::String) { - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n " << "inferToString was called on a string Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToString: inferToString was called on a string Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"); + throw storm::exceptions::InternalTypeErrorException() << "inferToString was called on a string Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; } return value; } @@ -84,14 +91,16 @@ namespace storm { */ template int_fast64_t ArgumentTypeInferation::inferToInteger(ArgumentType argumentType, T value) { - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n " << "inferToInteger was called on a non-int_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToInteger: inferToInteger was called on a non-int_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"); + throw storm::exceptions::InternalTypeErrorException() << "inferToInteger was called on a non-int_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; return 0; } template <> inline int_fast64_t ArgumentTypeInferation::inferToInteger(ArgumentType argumentType, int_fast64_t value) { if (argumentType != ArgumentType::Integer) { - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n " << "inferToInteger was called on an int_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToInteger: inferToInteger was called on a int_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"); + throw storm::exceptions::InternalTypeErrorException() << "inferToInteger was called on an int_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; } return value; } @@ -101,14 +110,16 @@ namespace storm { */ template uint_fast64_t ArgumentTypeInferation::inferToUnsignedInteger(ArgumentType argumentType, T value) { - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n " << "inferToUnsignedInteger was called on a non-uint_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToUnsignedInteger: inferToUnsignedInteger was called on a non-uint_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"); + throw storm::exceptions::InternalTypeErrorException() << "inferToUnsignedInteger was called on a non-uint_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; return 0; } template <> inline uint_fast64_t ArgumentTypeInferation::inferToUnsignedInteger(ArgumentType argumentType, uint_fast64_t value) { if (argumentType != ArgumentType::UnsignedInteger) { - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n " << "inferToUnsignedInteger was called on an uint_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToUnsignedInteger: inferToUnsignedInteger was called on a uint_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"); + throw storm::exceptions::InternalTypeErrorException() << "inferToUnsignedInteger was called on an uint_fast64_t Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; } return value; } @@ -118,14 +129,16 @@ namespace storm { */ template double ArgumentTypeInferation::inferToDouble(ArgumentType argumentType, T value) { - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n " << "inferToDouble was called on a non-double Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToDouble: inferToDouble was called on a non-double Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"); + throw storm::exceptions::InternalTypeErrorException() << "inferToDouble was called on a non-double Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; return 0.0; } template <> inline double ArgumentTypeInferation::inferToDouble(ArgumentType argumentType, double value) { if (argumentType != ArgumentType::Double) { - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n " << "inferToDouble was called on a double Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToDouble: inferToDouble was called on a double Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"); + throw storm::exceptions::InternalTypeErrorException() << "inferToDouble was called on a double Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; } return value; } @@ -135,14 +148,16 @@ namespace storm { */ template bool ArgumentTypeInferation::inferToBoolean(ArgumentType argumentType, T value) { - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n " << "inferToBoolean was called on a non-bool Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToBoolean: inferToBoolean was called on a non-bool Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"); + throw storm::exceptions::InternalTypeErrorException() << "inferToBoolean was called on a non-bool Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; return false; } template <> inline bool ArgumentTypeInferation::inferToBoolean(ArgumentType argumentType, bool value) { if (argumentType != ArgumentType::Boolean) { - throw storm::exceptions::InternalTypeErrorException() << "ERROR:\n " << "inferToBoolean was called on a bool Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; + LOG4CPLUS_ERROR(logger, "ArgumentTypeInferation::inferToBoolean: inferToBoolean was called on a bool Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"); + throw storm::exceptions::InternalTypeErrorException() << "inferToBoolean was called on a bool Template Object to cast to " << ArgumentTypeHelper::toString(argumentType) << "!"; } return value; } diff --git a/src/settings/Option.h b/src/settings/Option.h index a652ba62b..bec6b5a45 100644 --- a/src/settings/Option.h +++ b/src/settings/Option.h @@ -25,6 +25,10 @@ #include "src/exceptions/IllegalArgumentException.h" #include "src/exceptions/OptionUnificationException.h" +#include "log4cplus/logger.h" +#include "log4cplus/loggingmacros.h" +extern log4cplus::Logger logger; + namespace storm { namespace settings { @@ -34,17 +38,7 @@ namespace storm { public: friend class storm::settings::Settings; - /* - std::string longName; - std::string shortName; - std::string description; - std::string moduleName; - bool isRequired; - bool hasBeenSet; - - std::vector> arguments; - */ Option(std::string const& moduleName, std::string const& longOptionName, std::string const& shortOptionName, std::string const& optionDescription, bool isOptionRequired) : longName(longOptionName), shortName(shortOptionName), description(optionDescription), moduleName(moduleName), isRequired(isOptionRequired), hasBeenSet(false) { validateFields(); @@ -78,7 +72,7 @@ namespace storm { } ~Option() { - std::cout << "Destructing an Option." << std::endl; + //std::cout << "Destructing an Option." << std::endl; this->arguments.clear(); this->argumentNameMap.clear(); @@ -90,25 +84,25 @@ namespace storm { void unify(Option& other) { if (this->getLongName().compare(other.getLongName()) != 0) { - // LOG - throw storm::exceptions::OptionUnificationException() << "Error: Could not unify Option \"" << getLongName() << "\" because the Names are different (\"" << getLongName() << "\" vs. \"" << other.getLongName() << "\")!"; + LOG4CPLUS_ERROR(logger, "Option::unify: Could not unify Option \"" << getLongName() << "\" because the Names are different (\"" << getLongName() << "\" vs. \"" << other.getLongName() << "\")!"); + throw storm::exceptions::OptionUnificationException() << "Could not unify Option \"" << getLongName() << "\" because the Names are different (\"" << getLongName() << "\" vs. \"" << other.getLongName() << "\")!"; } if (this->getShortName().compare(other.getShortName()) != 0) { - // LOG - throw storm::exceptions::OptionUnificationException() << "Error: Could not unify Option \"" << getLongName() << "\" because the Shortnames are different (\"" << getShortName() << "\" vs. \"" << other.getShortName() << "\")!"; + LOG4CPLUS_ERROR(logger, "Option::unify: Could not unify Option \"" << getLongName() << "\" because the Shortnames are different (\"" << getShortName() << "\" vs. \"" << other.getShortName() << "\")!"); + throw storm::exceptions::OptionUnificationException() << "Could not unify Option \"" << getLongName() << "\" because the Shortnames are different (\"" << getShortName() << "\" vs. \"" << other.getShortName() << "\")!"; } if (this->getArgumentCount() != other.getArgumentCount()) { - // LOG - throw storm::exceptions::OptionUnificationException() << "Error: Could not unify Option \"" << getLongName() << "\" because the Argument Counts are different!"; + LOG4CPLUS_ERROR(logger, "Option::unify: Could not unify Option \"" << getLongName() << "\" because the Argument Counts are different!"); + throw storm::exceptions::OptionUnificationException() << "Could not unify Option \"" << getLongName() << "\" because the Argument Counts are different!"; } for(auto i = 0; i != this->arguments.size(); i++) { ArgumentBase* A = this->arguments.at(i).get(); ArgumentBase* B = other.arguments.at(i).get(); if (A->getArgumentType() != B->getArgumentType()) { - // LOG - throw storm::exceptions::OptionUnificationException() << "Error: Could not unify Option \"" << getLongName() << "\" because the Argument Types at Index " << i << " are different!"; + LOG4CPLUS_ERROR(logger, "Option::unify: Could not unify Option \"" << getLongName() << "\" because the Argument Types at Index " << i << " are different!"); + throw storm::exceptions::OptionUnificationException() << "Could not unify Option \"" << getLongName() << "\" because the Argument Types at Index " << i << " are different!"; } switch (A->getArgumentType()) { @@ -128,8 +122,8 @@ namespace storm { static_cast*>(A)->unify(*static_cast*>(B)); break; default: - // LOG - throw storm::exceptions::InternalTypeErrorException() << "Error: Missing Case in ArgumentBuilder's switch/case Code."; + LOG4CPLUS_ERROR(logger, "Option::unify: Missing Case in ArgumentBuilder's switch/case Code."); + throw storm::exceptions::InternalTypeErrorException() << "Missing Case in ArgumentBuilder's switch/case Code."; } } @@ -144,8 +138,8 @@ namespace storm { ArgumentBase& getArgument(uint_fast64_t argumentIndex) const { if (argumentIndex >= getArgumentCount()) { - // LOG - throw storm::exceptions::IllegalArgumentException() << "Error: Option::getArgument(): argumentIndex out of bounds!"; + LOG4CPLUS_ERROR(logger, "Option::getArgument: argumentIndex out of bounds!"); + throw storm::exceptions::IllegalArgumentException() << "Option::getArgument(): argumentIndex out of bounds!"; } return *this->arguments.at(argumentIndex).get(); } @@ -158,7 +152,7 @@ namespace storm { auto argumentIterator = this->argumentNameMap.find(storm::utility::StringHelper::stringToLower(argumentName)); if (argumentIterator == this->argumentNameMap.end()) { - // LOG + LOG4CPLUS_ERROR(logger, "Option::getArgumentByName: The Option \"" << this->getLongName() << "\" does not contain an Argument with Name \"" << argumentName << "\"!"); throw storm::exceptions::IllegalArgumentException() << "The Option \"" << this->getLongName() << "\" does not contain an Argument with Name \"" << argumentName << "\"!"; } @@ -207,21 +201,25 @@ namespace storm { void validateFields() const { if (longName.empty()) { - throw storm::exceptions::IllegalArgumentException() << "Error: Tried constructing an Option with an empty longName field!"; + LOG4CPLUS_ERROR(logger, "Option::validateFields: Tried constructing an Option with an empty longName field!"); + throw storm::exceptions::IllegalArgumentException() << "Tried constructing an Option with an empty longName field!"; } if (moduleName.empty()) { - throw storm::exceptions::IllegalArgumentException() << "Error: Tried constructing an Option with an empty moduleName field!"; + LOG4CPLUS_ERROR(logger, "Option::validateFields: Tried constructing an Option with an empty moduleName field!"); + throw storm::exceptions::IllegalArgumentException() << "Tried constructing an Option with an empty moduleName field!"; } bool longNameContainsNonAlpha = std::find_if(longName.begin(), longName.end(), [](char c) { return !std::isalpha(c); }) != longName.end(); bool shortNameContainsNonAlpha = std::find_if(shortName.begin(), shortName.end(), [](char c) { return !std::isalpha(c); }) != shortName.end(); if (longNameContainsNonAlpha) { - throw storm::exceptions::IllegalArgumentException() << "Error: Tried constructing an Option with a longName that contains non-alpha characters!"; + LOG4CPLUS_ERROR(logger, "Option::validateFields: Tried constructing an Option with a longName that contains non-alpha characters!"); + throw storm::exceptions::IllegalArgumentException() << "Tried constructing an Option with a longName that contains non-alpha characters!"; } if (shortNameContainsNonAlpha) { - throw storm::exceptions::IllegalArgumentException() << "Error: Tried constructing an Option with a shortName that contains non-alpha characters!"; + LOG4CPLUS_ERROR(logger, "Option::validateFields: Tried constructing an Option with a shortName that contains non-alpha characters!"); + throw storm::exceptions::IllegalArgumentException() << "Tried constructing an Option with a shortName that contains non-alpha characters!"; } } @@ -236,13 +234,13 @@ namespace storm { //} if (!isCurrentArgumentOptional && lastEntryWasOptional) { - // LOG - throw storm::exceptions::IllegalArgumentException() << "Error: The Argument Vector specified for Option \"" << getLongName() << "\" is invalid!\nIt contains a non-optional argument AFTER an optional argument."; + LOG4CPLUS_ERROR(logger, "Option::isArgumentsVectorValid: The Argument Vector specified for Option \"" << getLongName() << "\" is invalid! It contains a non-optional argument AFTER an optional argument."); + throw storm::exceptions::IllegalArgumentException() << "The Argument Vector specified for Option \"" << getLongName() << "\" is invalid! It contains a non-optional argument AFTER an optional argument."; } std::string lowerArgumentName = storm::utility::StringHelper::stringToLower(i->get()->getArgumentName()); if (argumentNameSet.find(lowerArgumentName) != argumentNameSet.end()) { - // LOG - throw storm::exceptions::IllegalArgumentException() << "Error: The Argument Vector specified for Option \"" << getLongName() << "\" is invalid!\nIt contains two arguments with the same name."; + LOG4CPLUS_ERROR(logger, "Option::isArgumentsVectorValid: The Argument Vector specified for Option \"" << getLongName() << "\" is invalid!\nIt contains two arguments with the same name."); + throw storm::exceptions::IllegalArgumentException() << "The Argument Vector specified for Option \"" << getLongName() << "\" is invalid!\nIt contains two arguments with the same name."; } argumentNameSet.insert(lowerArgumentName); diff --git a/src/settings/OptionBuilder.h b/src/settings/OptionBuilder.h index 16df661bd..b28411cdb 100644 --- a/src/settings/OptionBuilder.h +++ b/src/settings/OptionBuilder.h @@ -29,9 +29,7 @@ namespace storm { public: OptionBuilder(std::string const& newOptionModuleName, std::string const& newOptionLongName, std::string const& newOptionShortName, std::string const& newOptionDescription): longName(newOptionLongName), shortName(newOptionShortName), description(newOptionDescription), moduleName(newOptionModuleName), isRequired(false), isBuild(false) {} - ~OptionBuilder() { - std::cout << "Destructing an OptionBuilder." << std::endl; - } + ~OptionBuilder() {} OptionBuilder& setLongName(std::string const& newLongName) { this->longName = newLongName; @@ -87,24 +85,24 @@ namespace storm { // For automatic management of newArgument's lifetime std::shared_ptr argumentPtr(newArgument); if (this->isBuild) { - // LOG - throw storm::exceptions::IllegalFunctionCallException() << "Error: Called addArgument() on an instance of OptionBuilder which has already build an Instance."; + LOG4CPLUS_ERROR(logger, "OptionBuilder::addArgument: Called addArgument() on an instance of OptionBuilder which has already build an Instance."); + throw storm::exceptions::IllegalFunctionCallException() << "Called addArgument() on an instance of OptionBuilder which has already build an Instance."; } if (newArgument->getArgumentType() == ArgumentType::Invalid) { - // LOG - throw storm::exceptions::InternalTypeErrorException() << "Error: Could not add Argument to Option \"" << getLongName() << "\" because its Type is Invalid!"; + LOG4CPLUS_ERROR(logger, "OptionBuilder::addArgument: Could not add Argument to Option \"" << getLongName() << "\" because its Type is Invalid!"); + throw storm::exceptions::InternalTypeErrorException() << "Could not add Argument to Option \"" << getLongName() << "\" because its Type is Invalid!"; } if (!newArgument->getIsOptional() && (this->arguments.size() > 0) && (this->arguments.at(this->arguments.size() - 1).get()->getIsOptional())) { - // LOG - throw storm::exceptions::IllegalArgumentException() << "Error: Could not add Non-Optional Argument to Option \"" << getLongName() << "\" because it already contains an optional argument! Please note that after an optional argument has been added only arguments which are also optional can be appended."; + LOG4CPLUS_ERROR(logger, "OptionBuilder::addArgument: Could not add Non-Optional Argument to Option \"" << getLongName() << "\" because it already contains an optional argument! Please note that after an optional argument has been added only arguments which are also optional can be appended."); + throw storm::exceptions::IllegalArgumentException() << "Could not add Non-Optional Argument to Option \"" << getLongName() << "\" because it already contains an optional argument! Please note that after an optional argument has been added only arguments which are also optional can be appended."; } std::string lowerArgumentName = storm::utility::StringHelper::stringToLower(newArgument->getArgumentName()); if (argumentNameSet.find(lowerArgumentName) != argumentNameSet.end()) { - // LOG - throw storm::exceptions::IllegalArgumentException() << "Error: Could not add Argument with Name \"" << newArgument->getArgumentName() << "\" to Option \"" << getLongName() << "\" because it already contains an argument with the same name! Please note that all argument names must be unique in its respective option."; + LOG4CPLUS_ERROR(logger, "OptionBuilder::addArgument: Could not add Argument with Name \"" << newArgument->getArgumentName() << "\" to Option \"" << getLongName() << "\" because it already contains an argument with the same name! Please note that all argument names must be unique in its respective option."); + throw storm::exceptions::IllegalArgumentException() << "Could not add Argument with Name \"" << newArgument->getArgumentName() << "\" to Option \"" << getLongName() << "\" because it already contains an argument with the same name! Please note that all argument names must be unique in its respective option."; } argumentNameSet.insert(lowerArgumentName); @@ -115,8 +113,8 @@ namespace storm { Option* build() { if (this->isBuild) { - // LOG - throw storm::exceptions::IllegalFunctionCallException() << "Error: Called build() on an instance of OptionBuilder which has already build an Instance."; + LOG4CPLUS_ERROR(logger, "OptionBuilder::addArgument: Called build() on an instance of OptionBuilder which has already build an Instance."); + throw storm::exceptions::IllegalFunctionCallException() << "Called build() on an instance of OptionBuilder which has already build an Instance."; } this->isBuild = true; diff --git a/src/settings/Settings.cpp b/src/settings/Settings.cpp index 126addaf2..5dd90a588 100644 --- a/src/settings/Settings.cpp +++ b/src/settings/Settings.cpp @@ -7,7 +7,6 @@ #include "src/exceptions/OptionParserException.h" // Static Inits -storm::settings::Settings* storm::settings::Settings::instance = nullptr; storm::settings::Destroyer storm::settings::Settings::destroyer; /*! @@ -52,6 +51,7 @@ void storm::settings::Settings::handleAssignment(std::string const& longOptionNa uint_fast64_t givenArgsCount = arguments.size(); if (givenArgsCount > option->getArgumentCount()) { + LOG4CPLUS_ERROR(logger, "Settings::handleAssignment: Could not parse Arguments for Option \"" << longOptionName << "\": " << arguments.size() << " Arguments given, but max. " << option->getArgumentCount() << " Arguments expected."); throw storm::exceptions::OptionParserException() << "Could not parse Arguments for Option \"" << longOptionName << "\": " << arguments.size() << " Arguments given, but max. " << option->getArgumentCount() << " Arguments expected."; } @@ -59,13 +59,13 @@ void storm::settings::Settings::handleAssignment(std::string const& longOptionNa if (i < givenArgsCount) { storm::settings::fromStringAssignmentResult_t assignmentResult = option->getArgument(i).fromStringValue(arguments.at(i)); if (!assignmentResult.first) { - // LOG + LOG4CPLUS_ERROR(logger, "Settings::handleAssignment: Could not parse Arguments for Option \"" << longOptionName << "\": Argument " << option->getArgument(i).getArgumentName() << " rejected the given Value \"" << arguments.at(i) << "\" with Message:\r\n" << assignmentResult.second); throw storm::exceptions::OptionParserException() << "Could not parse Arguments for Option \"" << longOptionName << "\": Argument " << option->getArgument(i).getArgumentName() << " rejected the given Value \"" << arguments.at(i) << "\" with Message:\r\n" << assignmentResult.second; } } else { // There is no given value for this argument, only optional if (!option->getArgument(i).getIsOptional()) { - // LOG + LOG4CPLUS_ERROR(logger, "Settings::handleAssignment: Could not parse Arguments for Option \"" << longOptionName << "\": " << arguments.size() << " Arguments given, but more Arguments were expected."); throw storm::exceptions::OptionParserException() << "Could not parse Arguments for Option \"" << longOptionName << "\": " << arguments.size() << " Arguments given, but more Arguments were expected."; } else { option->getArgument(i).setFromDefaultValue(); @@ -110,7 +110,7 @@ std::vector storm::settings::Settings::scanForOptions(std::vector stringArgv = argvToStringArray(argc, argv); std::vector optionPositions = scanForOptions(stringArgv); @@ -136,7 +136,7 @@ void storm::settings::Settings::parseCommandLine(int const argc, char const * co // Short Option std::string nextShortOptionName = storm::utility::StringHelper::stringToLower(nextOption.substr(1, nextOption.size() - 1)); if (!this->containsShortName(nextShortOptionName)) { - // LOG + LOG4CPLUS_ERROR(logger, "Settings::parseCommandLine: Found an unknown ShortName for an Option: \"" << nextShortOptionName << "\"."); throw storm::exceptions::OptionParserException() << "Found an unknown ShortName for an Option: \"" << nextShortOptionName << "\"."; } else { longOptionName = this->getByShortName(nextShortOptionName).getLongName(); @@ -146,7 +146,7 @@ void storm::settings::Settings::parseCommandLine(int const argc, char const * co // Long Option std::string nextLongOptionName = storm::utility::StringHelper::stringToLower(nextOption.substr(2, nextOption.size() - 2)); if (!this->containsLongName(nextLongOptionName)) { - // LOG + LOG4CPLUS_ERROR(logger, "Settings::parseCommandLine: Found an unknown LongName for an Option: \"" << nextLongOptionName << "\"."); throw storm::exceptions::OptionParserException() << "Found an unknown LongName for an Option: \"" << nextLongOptionName << "\"."; } else { longOptionName = this->getByLongName(nextLongOptionName).getLongName(); @@ -158,7 +158,7 @@ void storm::settings::Settings::parseCommandLine(int const argc, char const * co argCache.push_back(stringArgv.at(i)); } else { // No Option active and this is no option. - // LOG + LOG4CPLUS_ERROR(logger, "Settings::parseCommandLine: Found a stray argument while parsing a given configuration: \"" << stringArgv.at(i) << "\" is neither a known Option nor preceeded by an Option."); throw storm::exceptions::OptionParserException() << "Found a stray argument while parsing a given configuration: \"" << stringArgv.at(i) << "\" is neither a known Option nor preceeded by an Option."; } } @@ -166,6 +166,7 @@ void storm::settings::Settings::parseCommandLine(int const argc, char const * co for (auto it = this->options.cbegin(); it != this->options.cend(); ++it) { if (!it->second.get()->getHasOptionBeenSet()) { if (it->second.get()->getIsRequired()) { + LOG4CPLUS_ERROR(logger, "Settings::parseCommandLine: Option \"" << it->second.get()->getLongName() << "\" is marked as required, but was not set!"); throw storm::exceptions::OptionParserException() << "Option \"" << it->second.get()->getLongName() << "\" is marked as required, but was not set!"; } else { // Set defaults on optional values @@ -184,17 +185,22 @@ bool storm::settings::Settings::registerNewModule(ModuleRegistrationFunction_t r bool result = false; try { result = registrationFunction(myInstance); + //LOG4CPLUS_DEBUG(logger, "Settings::registerNewModule: Successfully executed a registrationFunction"); } catch (storm::exceptions::IllegalArgumentException e) { + //LOG4CPLUS_ERROR(logger, "Settings::registerNewModule: Internal Error while setting up available Options!" << std::endl << "IllegalArgumentException: " << e.what() << "."); std::cout << "Internal Error while setting up available Options!" << std::endl << "IllegalArgumentException: " << e.what() << "." << std::endl; - std::cout << std::endl << myInstance->getHelpText(); return false; } catch (storm::exceptions::IllegalArgumentValueException e) { + //LOG4CPLUS_ERROR(logger, "Settings::registerNewModule: Internal Error while setting up available Options!" << std::endl << "IllegalArgumentValueException: " << e.what() << "."); std::cout << "Internal Error while setting up available Options!" << std::endl << "IllegalArgumentValueException: " << e.what() << "." << std::endl; - std::cout << std::endl << myInstance->getHelpText(); return false; } catch (storm::exceptions::IllegalFunctionCallException e) { + //LOG4CPLUS_ERROR(logger, "Settings::registerNewModule: Internal Error while setting up available Options!" << std::endl << "IllegalFunctionCallException: " << e.what() << "."); std::cout << "Internal Error while setting up available Options!" << std::endl << "IllegalFunctionCallException: " << e.what() << "." << std::endl; - std::cout << std::endl << myInstance->getHelpText(); + return false; + } catch (std::exception e) { + //LOG4CPLUS_ERROR(logger, "Settings::registerNewModule: Internal Error while setting up available Options!" << std::endl << "std::exception: " << e.what() << "."); + std::cout << "Internal Error while setting up available Options!" << std::endl << "std::exception: " << e.what() << "." << std::endl; return false; } return result; @@ -222,7 +228,7 @@ storm::settings::Settings& storm::settings::Settings::addOption(Option* option) // Not found if (!(shortNameIterator == this->shortNames.end())) { // There exists an option which uses the same shortname - // LOG + //LOG4CPLUS_ERROR(logger, "Settings::addOption: Error: The Option \"" << shortNameIterator->second << "\" from Module \"" << this->options.find(shortNameIterator->second)->second.get()->getModuleName() << "\" uses the same ShortName as the Option \"" << option->getLongName() << "\" from Module \"" << option->getModuleName() << "\"!"); throw storm::exceptions::OptionUnificationException() << "Error: The Option \"" << shortNameIterator->second << "\" from Module \"" << this->options.find(shortNameIterator->second)->second.get()->getModuleName() << "\" uses the same ShortName as the Option \"" << option->getLongName() << "\" from Module \"" << option->getModuleName() << "\"!"; } diff --git a/src/settings/Settings.h b/src/settings/Settings.h index ced1d9fd0..8b27e79c0 100644 --- a/src/settings/Settings.h +++ b/src/settings/Settings.h @@ -22,12 +22,15 @@ // Exceptions that should be catched when performing a parsing run #include "src/exceptions/OptionParserException.h" +#include "log4cplus/logger.h" +#include "log4cplus/loggingmacros.h" + +extern log4cplus::Logger logger; + namespace storm { /*! * @brief Contains Settings class and associated methods. - * - * The settings namespace contains the Settings class some friend methods like instance(). */ namespace settings { class Settings; @@ -60,6 +63,9 @@ namespace settings { class Settings { public: + /*! + * This function handles the static initialization registration of modules and their options + */ static bool registerNewModule(ModuleRegistrationFunction_t registrationFunction); /*! @@ -131,12 +137,16 @@ namespace settings { return this->getByLongName(longName).setHasOptionBeenSet(); } - /* + /*! * This generated a list of all registered options and their arguments together with descriptions and defaults. * @return A std::string containing the help text, delimited by \n */ std::string getHelpText() const; + /*! + * This function is the Singleton interface for the Settings class + * @return Settings* A Pointer to the singleton instance of Settings + */ static Settings* getInstance(); friend class Destroyer; private: @@ -158,9 +168,14 @@ namespace settings { * The object is automatically destroyed when the program terminates by the destroyer. */ virtual ~Settings() { - this->instance = nullptr; + // } + /*! + * Parser for the commdand line parameters of the program. + * The first entry of argv will be ignored, as it represents the program name. + * @throws OptionParserException + */ void parseCommandLine(int const argc, char const * const argv[]); /*! @@ -177,11 +192,6 @@ namespace settings { * The map holding the information regarding registered options and their short names */ std::unordered_map shortNames; - - /*! - * @brief actual instance of this class. - */ - static Settings* instance; /*! * @brief Destroyer object. @@ -197,14 +207,16 @@ namespace settings { bool checkArgumentSyntaxForOption(std::string const& argvString); /*! - * Returns true IFF this accumulator contains an option with the specified longName. + * Returns true IFF this contains an option with the specified longName. + * @return bool true iff there is an option with the specified longName */ bool containsLongName(std::string const& longName) const { return (this->options.find(storm::utility::StringHelper::stringToLower(longName)) != this->options.end()); } /*! - * Returns true IFF this accumulator contains an option with the specified shortName. + * Returns true IFF this contains an option with the specified shortName. + * @return bool true iff there is an option with the specified shortName */ bool containsShortName(std::string const& shortName) const { return (this->shortNames.find(storm::utility::StringHelper::stringToLower(shortName)) != this->shortNames.end()); @@ -213,10 +225,12 @@ namespace settings { /*! * Returns a reference to the Option with the specified longName. * Throws an Exception of Type InvalidArgumentException if there is no such Option. + * @throws InvalidArgumentException */ Option& getByLongName(std::string const& longName) const { auto longNameIterator = this->options.find(storm::utility::StringHelper::stringToLower(longName)); if (longNameIterator == this->options.end()) { + LOG4CPLUS_ERROR(logger, "Settings::getByLongName: This program does not contain an Option named \"" << longName << "\"!"); throw storm::exceptions::IllegalArgumentException() << "This program does not contain an Option named \"" << longName << "\"!"; } return *longNameIterator->second.get(); @@ -230,6 +244,7 @@ namespace settings { Option* getPtrByLongName(std::string const& longName) const { auto longNameIterator = this->options.find(storm::utility::StringHelper::stringToLower(longName)); if (longNameIterator == this->options.end()) { + LOG4CPLUS_ERROR(logger, "Settings::getPtrByLongName: This program does not contain an Option named \"" << longName << "\"!"); throw storm::exceptions::IllegalArgumentException() << "This program does not contain an Option named \"" << longName << "\"!"; } return longNameIterator->second.get(); @@ -238,10 +253,12 @@ namespace settings { /*! * Returns a reference to the Option with the specified shortName. * Throws an Exception of Type InvalidArgumentException if there is no such Option. + * @throws InvalidArgumentException */ Option& getByShortName(std::string const& shortName) const { auto shortNameIterator = this->shortNames.find(storm::utility::StringHelper::stringToLower(shortName)); if (shortNameIterator == this->shortNames.end()) { + LOG4CPLUS_ERROR(logger, "Settings::getByShortName: This program does not contain an Option named \"" << shortName << "\"!"); throw storm::exceptions::IllegalArgumentException() << "This program does not contain an Option with ShortName \"" << shortName << "\"!"; } return *(this->options.find(shortNameIterator->second)->second.get()); @@ -250,10 +267,12 @@ namespace settings { /*! * Returns a pointer to the Option with the specified shortName. * Throws an Exception of Type InvalidArgumentException if there is no such Option. + * @throws InvalidArgumentException */ Option* getPtrByShortName(std::string const& shortName) const { auto shortNameIterator = this->shortNames.find(storm::utility::StringHelper::stringToLower(shortName)); if (shortNameIterator == this->shortNames.end()) { + LOG4CPLUS_ERROR(logger, "Settings::getPtrByShortName: This program does not contain an Option named \"" << shortName << "\"!"); throw storm::exceptions::IllegalArgumentException() << "This program does not contain an Option with ShortName \"" << shortName << "\"!"; } return this->options.find(shortNameIterator->second)->second.get(); @@ -281,8 +300,7 @@ namespace settings { */ virtual ~Destroyer() { if (this->settingsInstance != nullptr) { - std::cout << "Destroying Settings Instance..." << std::endl; - this->settingsInstance->instance = nullptr; + //LOG4CPLUS_DEBUG(logger, "Destroyer::~Destroyer: Destroying Settings Instance..."); // The C++11 Method of Singleton deletes its instance on its own //delete this->settingsInstance; this->settingsInstance = nullptr; diff --git a/src/utility/ErrorHandling.h b/src/utility/ErrorHandling.h index cf1988b40..2e1a22bdc 100644 --- a/src/utility/ErrorHandling.h +++ b/src/utility/ErrorHandling.h @@ -86,10 +86,10 @@ std::string demangle(char const* symbol) { * @param sig The code of the signal that needs to be handled. */ void signalHandler(int sig) { -#define SIZE 128 LOG4CPLUS_FATAL(logger, "The program received signal " << sig << ". The following backtrace shows the status upon reception of the signal."); #ifndef WINDOWS +# define SIZE 128 void *buffer[SIZE]; char **strings; int nptrs;