10 changed files with 859 additions and 939 deletions
-
344src/settings/Argument.h
-
230src/settings/ArgumentBase.h
-
271src/settings/ArgumentBuilder.h
-
67src/settings/ArgumentType.h
-
165src/settings/ArgumentValidators.h
-
70src/settings/InternalOptionMemento.h
-
61src/settings/InternalSettingsMemento.h
-
326src/settings/Option.h
-
143src/settings/OptionBuilder.h
-
63src/utility/StringHelper.h
@ -1,58 +1,33 @@ |
|||||
#ifndef STORM_SETTINGS_ARGUMENTTYPE_H_ |
#ifndef STORM_SETTINGS_ARGUMENTTYPE_H_ |
||||
#define STORM_SETTINGS_ARGUMENTTYPE_H_ |
#define STORM_SETTINGS_ARGUMENTTYPE_H_ |
||||
|
|
||||
#include "src/exceptions/InternalTypeErrorException.h" |
|
||||
|
#include <iostream> |
||||
|
|
||||
#include "log4cplus/logger.h" |
|
||||
#include "log4cplus/loggingmacros.h" |
|
||||
extern log4cplus::Logger logger; |
|
||||
|
#include "src/exceptions/ExceptionMacros.h" |
||||
|
|
||||
namespace storm { |
namespace storm { |
||||
namespace settings { |
namespace settings { |
||||
|
|
||||
|
/*! |
||||
|
* This enum captures all possible types for arguments. |
||||
|
*/ |
||||
enum class ArgumentType { |
enum class ArgumentType { |
||||
Invalid, String, Integer, UnsignedInteger, Double, Boolean |
|
||||
|
String, Integer, UnsignedInteger, Double, Boolean |
||||
}; |
}; |
||||
|
|
||||
class ArgumentTypeHelper { |
|
||||
public: |
|
||||
static std::string const& toString(ArgumentType argumentType) { |
|
||||
static std::string argumentTypeInvalid = "Invalid"; |
|
||||
static std::string argumentTypeString = "String"; |
|
||||
static std::string argumentTypeInteger = "Integer"; |
|
||||
static std::string argumentTypeUnsignedInteger = "UnsignedInteger"; |
|
||||
static std::string argumentTypeDouble = "Double"; |
|
||||
static std::string argumentTypeBoolean = "Boolean"; |
|
||||
|
|
||||
switch (argumentType) { |
|
||||
case ArgumentType::Invalid: |
|
||||
return argumentTypeInvalid; |
|
||||
break; |
|
||||
case ArgumentType::String: |
|
||||
return argumentTypeString; |
|
||||
break; |
|
||||
case ArgumentType::Integer: |
|
||||
return argumentTypeInteger; |
|
||||
break; |
|
||||
case ArgumentType::UnsignedInteger: |
|
||||
return argumentTypeUnsignedInteger; |
|
||||
break; |
|
||||
case ArgumentType::Double: |
|
||||
return argumentTypeDouble; |
|
||||
break; |
|
||||
case ArgumentType::Boolean: |
|
||||
return argumentTypeBoolean; |
|
||||
break; |
|
||||
default: { |
|
||||
LOG4CPLUS_ERROR(logger, "ArgumentTypeHelper::toString: Missing case in ArgumentTypeHelper."); |
|
||||
throw storm::exceptions::InternalTypeErrorException() << "Missing case in ArgumentTypeHelper."; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
private: |
|
||||
ArgumentTypeHelper() {} |
|
||||
~ArgumentTypeHelper() {} |
|
||||
}; |
|
||||
} |
|
||||
} |
|
||||
|
std::ostream& operator<<(std::ostream& out, ArgumentType& argumentType) { |
||||
|
switch (argumentType) { |
||||
|
case ArgumentType::String: out << "string"; break; |
||||
|
case ArgumentType::Integer: out << "integer"; break; |
||||
|
case ArgumentType::UnsignedInteger: out << "unsigned integer"; break; |
||||
|
case ArgumentType::Double: out << "double"; break; |
||||
|
case ArgumentType::Boolean: out << "boolean"; break; |
||||
|
} |
||||
|
|
||||
|
return out; |
||||
|
} |
||||
|
|
||||
|
} // namespace settings |
||||
|
} // namespace storm |
||||
|
|
||||
#endif // STORM_SETTINGS_ARGUMENTTYPE_H_ |
#endif // STORM_SETTINGS_ARGUMENTTYPE_H_ |
@ -1,70 +0,0 @@ |
|||||
#ifndef STORM_SETTINGS_INTERNALOPTIONMEMENTO_H_ |
|
||||
#define STORM_SETTINGS_INTERNALOPTIONMEMENTO_H_ |
|
||||
|
|
||||
#include "src/settings/SettingsManager.h" |
|
||||
#include "log4cplus/logger.h" |
|
||||
#include "log4cplus/loggingmacros.h" |
|
||||
|
|
||||
extern log4cplus::Logger logger; |
|
||||
|
|
||||
namespace storm { |
|
||||
namespace settings { |
|
||||
|
|
||||
/*! |
|
||||
* @brief THIS CLASS IS FOR INTERNAL USE IN THE TESTS ONLY |
|
||||
* |
|
||||
* |
|
||||
* If an option is required to be set when executing a test |
|
||||
* the test may instantiate an Object of this class while the |
|
||||
* test itself is executed. |
|
||||
* |
|
||||
* This class ensures that the option has the requested value |
|
||||
* and resets it to its previous value as soon as its destructor |
|
||||
* is called. |
|
||||
*/ |
|
||||
class InternalOptionMemento { |
|
||||
public: |
|
||||
/*! |
|
||||
* @brief The constructor. |
|
||||
* |
|
||||
* @param |
|
||||
*/ |
|
||||
InternalOptionMemento(std::string const& longOptionName, bool requiredHasBeenSetState): instance(storm::settings::SettingsManager::getInstance()), optionName(longOptionName), stateRequired(requiredHasBeenSetState) { |
|
||||
this->stateBefore = instance->isSet(optionName); |
|
||||
if (stateRequired) { |
|
||||
instance->set(optionName); |
|
||||
} else { |
|
||||
instance->unset(optionName); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/*! |
|
||||
* @brief The destructor. |
|
||||
* |
|
||||
* Resets the Options state to its previous state |
|
||||
*/ |
|
||||
virtual ~InternalOptionMemento() { |
|
||||
// Reset the state of the Option |
|
||||
if (stateBefore) { |
|
||||
instance->set(optionName); |
|
||||
} else { |
|
||||
instance->unset(optionName); |
|
||||
} |
|
||||
this->instance = nullptr; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
private: |
|
||||
storm::settings::SettingsManager* instance; |
|
||||
std::string const optionName; |
|
||||
bool stateBefore; |
|
||||
bool stateRequired; |
|
||||
|
|
||||
InternalOptionMemento(InternalOptionMemento& other) {} |
|
||||
}; |
|
||||
|
|
||||
} // namespace settings |
|
||||
} // namespace storm |
|
||||
|
|
||||
#endif // STORM_SETTINGS_INTERNALOPTIONMEMENTO_H_ |
|
@ -0,0 +1,61 @@ |
|||||
|
#ifndef STORM_SETTINGS_INTERNALSETTINGMEMENTO_H_ |
||||
|
#define STORM_SETTINGS_INTERNALSETTINGMEMENTO_H_ |
||||
|
|
||||
|
#include "src/settings/SettingsManager.h" |
||||
|
#include "log4cplus/logger.h" |
||||
|
#include "log4cplus/loggingmacros.h" |
||||
|
|
||||
|
extern log4cplus::Logger logger; |
||||
|
|
||||
|
namespace storm { |
||||
|
namespace settings { |
||||
|
|
||||
|
/*! |
||||
|
* NOTE: THIS CLASS IS FOR INTERNAL USE IN THE TESTS ONLY. |
||||
|
* |
||||
|
* If an option is required to be set when executing a test the test may instantiate an object of this class |
||||
|
* while the test itself is executed. This object then ensures that the option has the requested value and |
||||
|
* resets it to its previous value as soon as its destructor is called. |
||||
|
*/ |
||||
|
class InternalSettingMemento { |
||||
|
public: |
||||
|
/*! |
||||
|
* Constructs a new memento for the specified option. |
||||
|
* |
||||
|
* @param moduleName The name of the module that registered the option. |
||||
|
* @param longOptionName The long name of the option. |
||||
|
* @param requiredHasBeenSetState A flag that indicates whether the setting is to be temporarily set to |
||||
|
* true or false. |
||||
|
*/ |
||||
|
InternalOptionMemento(std::string const& moduleName, std::string const& longOptionName, bool requiredHasBeenSetState): optionName(longOptionName), stateBefore() { |
||||
|
this->stateBefore = storm::settings::SettingsManager::manager().isSet(optionName); |
||||
|
if (requiredHasBeenSetState) { |
||||
|
storm::settings::SettingsManager::manager()..set(optionName); |
||||
|
} else { |
||||
|
storm::settings::SettingsManager::manager().unset(optionName); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/*! |
||||
|
* Destructs the memento object and resets the value of the option to its original state. |
||||
|
*/ |
||||
|
virtual ~InternalOptionMemento() { |
||||
|
if (stateBefore) { |
||||
|
storm::settings::SettingsManager::manager().set(optionName); |
||||
|
} else { |
||||
|
storm::settings::SettingsManager::manager().unset(optionName); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
// The long name of the option that was temporarily set. |
||||
|
std::string const optionName; |
||||
|
|
||||
|
// The state of the option before it was set. |
||||
|
bool stateBefore; |
||||
|
}; |
||||
|
|
||||
|
} // namespace settings |
||||
|
} // namespace storm |
||||
|
|
||||
|
#endif // STORM_SETTINGS_INTERNALSETTINGMEMENTO_H_ |
@ -1,63 +0,0 @@ |
|||||
/* |
|
||||
* StringHelper.h |
|
||||
* |
|
||||
* Created on: 01.09.2013 |
|
||||
* Author: Philipp Berger |
|
||||
*/ |
|
||||
|
|
||||
#ifndef STORM_UTILITY_STRINGHELPER_H_ |
|
||||
#define STORM_UTILITY_STRINGHELPER_H_ |
|
||||
|
|
||||
#include <iostream> |
|
||||
#include <string> |
|
||||
#include <functional> |
|
||||
#include <algorithm> |
|
||||
|
|
||||
|
|
||||
namespace storm { |
|
||||
namespace utility { |
|
||||
|
|
||||
class StringHelper { |
|
||||
public: |
|
||||
/*! |
|
||||
* Returns the String, transformed with toLower. |
|
||||
*/ |
|
||||
static std::string stringToLower(std::string const& sourceString) { |
|
||||
std::string targetString; |
|
||||
targetString.resize(sourceString.size()); |
|
||||
std::transform(sourceString.begin(), sourceString.end(), targetString.begin(), ::tolower); |
|
||||
|
|
||||
return targetString; |
|
||||
} |
|
||||
|
|
||||
/*! |
|
||||
* Returns the String, transformed with toUpper. |
|
||||
*/ |
|
||||
static std::string stringToUpper(std::string const& sourceString) { |
|
||||
std::string targetString; |
|
||||
targetString.resize(sourceString.size()); |
|
||||
std::transform(sourceString.begin(), sourceString.end(), targetString.begin(), ::toupper); |
|
||||
|
|
||||
return targetString; |
|
||||
} |
|
||||
|
|
||||
/*! |
|
||||
* Returns true IFF the two Strings are equal. |
|
||||
*/ |
|
||||
static bool compareIgnoreCase(std::string const& A, std::string const& B) { |
|
||||
std::string stringA; |
|
||||
std::string stringB; |
|
||||
std::transform(A.begin(), A.end(), stringA.begin(), ::tolower); |
|
||||
std::transform(B.begin(), B.end(), stringB.begin(), ::tolower); |
|
||||
|
|
||||
return stringA.compare(stringB) == 0; |
|
||||
} |
|
||||
private: |
|
||||
StringHelper() {} |
|
||||
StringHelper(StringHelper& other) {} |
|
||||
~StringHelper() {} |
|
||||
}; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
#endif // STORM_UTILITY_STRINGHELPER_H_ |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue