32 changed files with 528 additions and 524 deletions
-
10src/storm-dft/settings/modules/DFTSettings.cpp
-
9src/storm/abstraction/MenuGameRefiner.cpp
-
6src/storm/abstraction/MenuGameRefiner.h
-
6src/storm/modelchecker/abstraction/GameBasedMdpModelChecker.cpp
-
14src/storm/settings/Argument.cpp
-
28src/storm/settings/Argument.h
-
120src/storm/settings/ArgumentBuilder.h
-
186src/storm/settings/ArgumentValidators.cpp
-
308src/storm/settings/ArgumentValidators.h
-
115src/storm/settings/modules/AbstractionSettings.cpp
-
75src/storm/settings/modules/AbstractionSettings.h
-
2src/storm/settings/modules/BisimulationSettings.cpp
-
13src/storm/settings/modules/CoreSettings.cpp
-
2src/storm/settings/modules/CounterexampleGeneratorSettings.cpp
-
7src/storm/settings/modules/CuddSettings.cpp
-
9src/storm/settings/modules/EigenEquationSolverSettings.cpp
-
6src/storm/settings/modules/EliminationSettings.cpp
-
9src/storm/settings/modules/ExplorationSettings.cpp
-
4src/storm/settings/modules/GSPNSettings.cpp
-
5src/storm/settings/modules/GeneralSettings.cpp
-
2src/storm/settings/modules/GlpkSettings.cpp
-
9src/storm/settings/modules/GmmxxEquationSolverSettings.cpp
-
2src/storm/settings/modules/GurobiSettings.cpp
-
19src/storm/settings/modules/IOSettings.cpp
-
2src/storm/settings/modules/JaniExportSettings.cpp
-
4src/storm/settings/modules/MinMaxEquationSolverSettings.cpp
-
13src/storm/settings/modules/MultiObjectiveSettings.cpp
-
9src/storm/settings/modules/NativeEquationSolverSettings.cpp
-
2src/storm/settings/modules/PGCLSettings.cpp
-
2src/storm/settings/modules/ParametricSettings.cpp
-
8src/storm/settings/modules/RegionSettings.cpp
-
2src/storm/settings/modules/TopologicalValueIterationEquationSolverSettings.cpp
@ -0,0 +1,186 @@ |
|||||
|
#include "storm/settings/ArgumentValidators.h"
|
||||
|
|
||||
|
#include <boost/algorithm/string/join.hpp>
|
||||
|
|
||||
|
#include <sys/stat.h>
|
||||
|
|
||||
|
#include "storm/settings/Argument.h"
|
||||
|
#include "storm/utility/macros.h"
|
||||
|
#include "storm/exceptions/InvalidArgumentException.h"
|
||||
|
#include "storm/exceptions/IllegalArgumentException.h"
|
||||
|
#include "storm/exceptions/IllegalArgumentValueException.h"
|
||||
|
#include "storm/exceptions/IllegalFunctionCallException.h"
|
||||
|
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace settings { |
||||
|
|
||||
|
template <typename ValueType> |
||||
|
RangeArgumentValidator<ValueType>::RangeArgumentValidator(boost::optional<ValueType> const& lower, boost::optional<ValueType> const& upper, bool lowerIncluded, bool upperIncluded) : lower(lower), upper(upper), lowerIncluded(lowerIncluded), upperIncluded(upperIncluded) { |
||||
|
// Intentionally left empty.
|
||||
|
} |
||||
|
|
||||
|
template <typename ValueType> |
||||
|
bool RangeArgumentValidator<ValueType>::isValid(ValueType const& value) { |
||||
|
bool result = true; |
||||
|
if (lower) { |
||||
|
if (lowerIncluded) { |
||||
|
result &= value >= lower.get(); |
||||
|
} else { |
||||
|
result &= value > lower.get(); |
||||
|
} |
||||
|
} |
||||
|
if (upper) { |
||||
|
if (upperIncluded) { |
||||
|
result &= value <= upper.get(); |
||||
|
} else { |
||||
|
result &= value < upper.get(); |
||||
|
} |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
template <typename ValueType> |
||||
|
std::string RangeArgumentValidator<ValueType>::toString() const { |
||||
|
std::stringstream stream; |
||||
|
stream << "in "; |
||||
|
if (lower) { |
||||
|
if (lowerIncluded) { |
||||
|
stream << "["; |
||||
|
} else { |
||||
|
stream << "("; |
||||
|
} |
||||
|
stream << lower.get(); |
||||
|
} else { |
||||
|
stream << "(-inf"; |
||||
|
} |
||||
|
stream << ", "; |
||||
|
if (upper) { |
||||
|
stream << upper.get(); |
||||
|
if (upperIncluded) { |
||||
|
stream << "]"; |
||||
|
} else { |
||||
|
stream << ")"; |
||||
|
} |
||||
|
} else { |
||||
|
stream << "+inf)"; |
||||
|
} |
||||
|
|
||||
|
return stream.str(); |
||||
|
} |
||||
|
|
||||
|
FileValidator::FileValidator(Mode mode) : mode(mode) { |
||||
|
// Intentionally left empty.
|
||||
|
} |
||||
|
|
||||
|
bool FileValidator::isValid(std::string const& filename) { |
||||
|
if (mode == Mode::Exists) { |
||||
|
// First check existence as ifstream::good apparently also returns true for directories.
|
||||
|
struct stat info; |
||||
|
stat(filename.c_str(), &info); |
||||
|
STORM_LOG_THROW(info.st_mode & S_IFREG, storm::exceptions::IllegalArgumentValueException, "Unable to read from non-existing file '" << filename << "'."); |
||||
|
|
||||
|
// Now that we know it's a file, we can check its readability.
|
||||
|
std::ifstream istream(filename); |
||||
|
STORM_LOG_THROW(istream.good(), storm::exceptions::IllegalArgumentValueException, "Unable to read from file '" << filename << "'."); |
||||
|
|
||||
|
return true; |
||||
|
} else if (mode == Mode::Writable) { |
||||
|
struct stat info; |
||||
|
STORM_LOG_THROW(stat (filename.c_str(), &info) != 0, storm::exceptions::IllegalArgumentValueException , "Could not open file '" << filename << "' for writing because file or directory already exists."); |
||||
|
|
||||
|
std::ofstream filestream(filename); |
||||
|
STORM_LOG_THROW(filestream.is_open(), storm::exceptions::IllegalArgumentValueException , "Could not open file '" << filename << "' for writing."); |
||||
|
filestream.close(); |
||||
|
std::remove(filename.c_str()); |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
std::string FileValidator::toString() const { |
||||
|
if (mode == Mode::Exists) { |
||||
|
return "existing file"; |
||||
|
} else { |
||||
|
return "writable file"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
MultipleChoiceValidator::MultipleChoiceValidator(std::vector<std::string> const& legalValues) : legalValues(legalValues) { |
||||
|
// Intentionally left empty.
|
||||
|
} |
||||
|
|
||||
|
bool MultipleChoiceValidator::isValid(std::string const& value) { |
||||
|
for (auto const& legalValue : legalValues) { |
||||
|
if (legalValue == value) { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
std::string MultipleChoiceValidator::toString() const { |
||||
|
return "in {" + boost::join(legalValues, ", ") + "}"; |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<int64_t>> ArgumentValidatorFactory::createIntegerRangeValidatorExcluding(int_fast64_t lowerBound, int_fast64_t upperBound) { |
||||
|
return createRangeValidatorExcluding<int64_t>(lowerBound, upperBound); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<uint64_t>> ArgumentValidatorFactory::createUnsignedRangeValidatorExcluding(uint64_t lowerBound, uint64_t upperBound) { |
||||
|
return createRangeValidatorExcluding<uint64_t>(lowerBound, upperBound); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<double>> ArgumentValidatorFactory::createDoubleRangeValidatorExcluding(double lowerBound, double upperBound) { |
||||
|
return createRangeValidatorExcluding<double>(lowerBound, upperBound); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<int64_t>> ArgumentValidatorFactory::createIntegerGreaterValidator(int_fast64_t lowerBound) { |
||||
|
return createGreaterValidator<int64_t>(lowerBound, false); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<uint64_t>> ArgumentValidatorFactory::createUnsignedGreaterValidator(uint64_t lowerBound) { |
||||
|
return createGreaterValidator<uint64_t>(lowerBound, false); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<double>> ArgumentValidatorFactory::createDoubleGreaterValidator(double lowerBound) { |
||||
|
return createGreaterValidator<double>(lowerBound, false); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<int64_t>> ArgumentValidatorFactory::createIntegerGreaterEqualValidator(int_fast64_t lowerBound) { |
||||
|
return createGreaterValidator<int64_t>(lowerBound, true); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<uint64_t>> ArgumentValidatorFactory::createUnsignedGreaterEqualValidator(uint64_t lowerBound) { |
||||
|
return createGreaterValidator<uint64_t>(lowerBound, true); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<double>> ArgumentValidatorFactory::createDoubleGreaterEqualValidator(double lowerBound) { |
||||
|
return createGreaterValidator<double>(lowerBound, true); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<std::string>> ArgumentValidatorFactory::createExistingFileValidator() { |
||||
|
return std::make_unique<FileValidator>(FileValidator::Mode::Exists); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<std::string>> ArgumentValidatorFactory::createWritableFileValidator() { |
||||
|
return std::make_unique<FileValidator>(FileValidator::Mode::Writable); |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<ArgumentValidator<std::string>> ArgumentValidatorFactory::createMultipleChoiceValidator(std::vector<std::string> const& choices) { |
||||
|
return std::make_unique<MultipleChoiceValidator>(choices); |
||||
|
} |
||||
|
|
||||
|
template <typename ValueType> |
||||
|
std::shared_ptr<ArgumentValidator<ValueType>> ArgumentValidatorFactory::createRangeValidatorExcluding(ValueType lowerBound, ValueType upperBound) { |
||||
|
return std::make_unique<RangeArgumentValidator<ValueType>>(lowerBound, upperBound, false, false); |
||||
|
} |
||||
|
|
||||
|
template <typename ValueType> |
||||
|
std::shared_ptr<ArgumentValidator<ValueType>> ArgumentValidatorFactory::createGreaterValidator(ValueType lowerBound, bool equalAllowed) { |
||||
|
return std::make_unique<RangeArgumentValidator<ValueType>>(lowerBound, boost::none, equalAllowed, false); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -1,275 +1,95 @@ |
|||||
#ifndef STORM_SETTINGS_ARGUMENTVALIDATORS_H_ |
#pragma once |
||||
#define STORM_SETTINGS_ARGUMENTVALIDATORS_H_ |
|
||||
|
|
||||
#include <iostream> |
|
||||
#include <ostream> |
|
||||
#include <fstream> |
|
||||
#include <list> |
|
||||
#include <utility> |
|
||||
#include <functional> |
|
||||
#include <vector> |
|
||||
#include <memory> |
#include <memory> |
||||
|
#include <vector> |
||||
#include <string> |
#include <string> |
||||
#include <stdio.h> |
|
||||
|
|
||||
#include "storm/settings/Argument.h" |
|
||||
#include "storm/utility/macros.h" |
|
||||
#include "storm/exceptions/InvalidArgumentException.h" |
|
||||
#include "storm/exceptions/IllegalArgumentException.h" |
|
||||
#include "storm/exceptions/IllegalArgumentValueException.h" |
|
||||
#include "storm/exceptions/IllegalFunctionCallException.h" |
|
||||
|
|
||||
#include <sys/stat.h> |
#include <boost/optional.hpp> |
||||
|
|
||||
namespace storm { |
namespace storm { |
||||
namespace settings { |
namespace settings { |
||||
class ArgumentValidators { |
|
||||
public: |
|
||||
/*! |
|
||||
* Creates a validation function that checks whether an integer is in the given range (including the bounds). |
|
||||
* |
|
||||
* @param lowerBound The lower bound of the valid range. |
|
||||
* @param upperBound The upper bound of the valid range. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (int_fast64_t const&)> integerRangeValidatorIncluding(int_fast64_t lowerBound, int_fast64_t upperBound) { |
|
||||
return rangeValidatorIncluding<int_fast64_t>(lowerBound, upperBound); |
|
||||
} |
|
||||
|
|
||||
/*! |
|
||||
* Creates a validation function that checks whether an integer is in the given range (excluding the bounds). |
|
||||
* |
|
||||
* @param lowerBound The lower bound of the valid range. |
|
||||
* @param upperBound The upper bound of the valid range. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (int_fast64_t const&)> integerRangeValidatorExcluding(int_fast64_t lowerBound, int_fast64_t upperBound) { |
|
||||
return rangeValidatorExcluding<int_fast64_t>(lowerBound, upperBound); |
|
||||
} |
|
||||
|
|
||||
|
template <typename ValueType> |
||||
|
class ArgumentValidator { |
||||
|
public: |
||||
/*! |
/*! |
||||
* Creates a validation function that checks whether an integer is greater than or equal to the given threshold. |
* Checks whether the argument passes the validation. |
||||
* |
|
||||
* @param threshold The threshold. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
*/ |
||||
static std::function<bool (int_fast64_t const&)> integerGreaterValidatorIncluding(int_fast64_t threshold) { |
virtual bool isValid(ValueType const& value) = 0; |
||||
return greaterValidatorIncluding<int_fast64_t>(threshold); |
|
||||
} |
|
||||
|
|
||||
/*! |
/*! |
||||
* Creates a validation function that checks whether an integer is greater than the given threshold. |
* Retrieves a string representation of the valid values. |
||||
* |
|
||||
* @param threshold The threshold. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
*/ |
||||
static std::function<bool (int_fast64_t const&)> integerGreaterValidatorExcluding(int_fast64_t threshold) { |
virtual std::string toString() const = 0; |
||||
return greaterValidatorExcluding<int_fast64_t>(threshold); |
}; |
||||
} |
|
||||
|
|
||||
/*! |
template <typename ValueType> |
||||
* Creates a validation function that checks whether an unsigned integer is in the given range (including the bounds). |
class RangeArgumentValidator : public ArgumentValidator<ValueType> { |
||||
* |
public: |
||||
* @param lowerBound The lower bound of the valid range. |
RangeArgumentValidator(boost::optional<ValueType> const& lower, boost::optional<ValueType> const& upper, bool lowerIncluded, bool upperIncluded); |
||||
* @param upperBound The upper bound of the valid range. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (uint_fast64_t const&)> unsignedIntegerRangeValidatorIncluding(uint_fast64_t lowerBound, uint_fast64_t upperBound) { |
|
||||
return rangeValidatorIncluding<uint_fast64_t>(lowerBound, upperBound); |
|
||||
} |
|
||||
|
|
||||
/*! |
virtual bool isValid(ValueType const& value) override; |
||||
* Creates a validation function that checks whether an unsigned integer is in the given range (excluding the bounds). |
virtual std::string toString() const override; |
||||
* |
|
||||
* @param lowerBound The lower bound of the valid range. |
|
||||
* @param upperBound The upper bound of the valid range. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (uint_fast64_t const&)> unsignedIntegerRangeValidatorExcluding(uint_fast64_t lowerBound, uint_fast64_t upperBound) { |
|
||||
return rangeValidatorExcluding<uint_fast64_t>(lowerBound, upperBound); |
|
||||
} |
|
||||
|
|
||||
/*! |
private: |
||||
* Creates a validation function that checks whether an unsigned integer is greater than or equal to the given threshold. |
boost::optional<ValueType> lower; |
||||
* |
boost::optional<ValueType> upper; |
||||
* @param threshold The threshold. |
bool lowerIncluded; |
||||
* @return The resulting validation function. |
bool upperIncluded; |
||||
*/ |
}; |
||||
static std::function<bool (uint_fast64_t const&)> unsignedIntegerGreaterValidatorIncluding(uint_fast64_t threshold) { |
|
||||
return greaterValidatorIncluding<uint_fast64_t>(threshold); |
|
||||
} |
|
||||
|
|
||||
/*! |
class FileValidator : public ArgumentValidator<std::string> { |
||||
* Creates a validation function that checks whether an unsigned integer is greater than the given threshold. |
public: |
||||
* |
enum class Mode { |
||||
* @param threshold The threshold. |
Exists, Writable |
||||
* @return The resulting validation function. |
}; |
||||
*/ |
|
||||
static std::function<bool (uint_fast64_t const&)> unsignedIntegerGreaterValidatorExcluding(uint_fast64_t threshold) { |
|
||||
return greaterValidatorExcluding<uint_fast64_t>(threshold); |
|
||||
} |
|
||||
|
|
||||
/*! |
FileValidator(Mode mode); |
||||
* Creates a validation function that checks whether a double is in the given range (including the bounds). |
|
||||
* |
|
||||
* @param lowerBound The lower bound of the valid range. |
|
||||
* @param upperBound The upper bound of the valid range. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (double const&)> doubleRangeValidatorIncluding(double lowerBound, double upperBound) { |
|
||||
return rangeValidatorIncluding<double>(lowerBound, upperBound); |
|
||||
} |
|
||||
|
|
||||
/*! |
virtual bool isValid(std::string const& value) override; |
||||
* Creates a validation function that checks whether a double is in the given range (excluding the bounds). |
virtual std::string toString() const override; |
||||
* |
|
||||
* @param lowerBound The lower bound of the valid range. |
|
||||
* @param upperBound The upper bound of the valid range. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (double const&)> doubleRangeValidatorExcluding(double lowerBound, double upperBound) { |
|
||||
return rangeValidatorExcluding<double>(lowerBound, upperBound); |
|
||||
} |
|
||||
|
|
||||
/*! |
private: |
||||
* Creates a validation function that checks whether a double is greater than or equal to the given threshold. |
Mode mode; |
||||
* |
}; |
||||
* @param threshold The threshold. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (double const&)> doubleGreaterValidatorIncluding(double threshold) { |
|
||||
return greaterValidatorIncluding<double>(threshold); |
|
||||
} |
|
||||
|
|
||||
/*! |
class MultipleChoiceValidator : public ArgumentValidator<std::string> { |
||||
* Creates a validation function that checks whether a double is greater than the given threshold. |
public: |
||||
* |
MultipleChoiceValidator(std::vector<std::string> const& legalValues); |
||||
* @param threshold The threshold. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (double const&)> doubleGreaterValidatorExcluding(double threshold) { |
|
||||
return greaterValidatorExcluding<double>(threshold); |
|
||||
} |
|
||||
|
|
||||
/*! |
virtual bool isValid(std::string const& value) override; |
||||
* Creates a validation function that checks whether a given string corresponds to an existing and readable |
virtual std::string toString() const override; |
||||
* file. |
|
||||
* |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (std::string const&)> existingReadableFileValidator() { |
|
||||
return [] (std::string const fileName) -> bool { |
|
||||
// First check existence as ifstream::good apparently als returns true for directories. |
|
||||
struct stat info; |
|
||||
stat(fileName.c_str(), &info); |
|
||||
STORM_LOG_THROW(info.st_mode & S_IFREG, storm::exceptions::IllegalArgumentValueException, "Unable to read from non-existing file '" << fileName << "'."); |
|
||||
|
|
||||
// Now that we know it's a file, we can check its readability. |
private: |
||||
std::ifstream istream(fileName); |
std::vector<std::string> legalValues; |
||||
STORM_LOG_THROW(istream.good(), storm::exceptions::IllegalArgumentValueException, "Unable to read from file '" << fileName << "'."); |
}; |
||||
|
|
||||
return true; |
class ArgumentValidatorFactory { |
||||
}; |
public: |
||||
} |
static std::shared_ptr<ArgumentValidator<int64_t>> createIntegerRangeValidatorExcluding(int_fast64_t lowerBound, int_fast64_t upperBound); |
||||
|
static std::shared_ptr<ArgumentValidator<uint64_t>> createUnsignedRangeValidatorExcluding(uint64_t lowerBound, uint64_t upperBound); |
||||
|
static std::shared_ptr<ArgumentValidator<double>> createDoubleRangeValidatorExcluding(double lowerBound, double upperBound); |
||||
|
|
||||
/*! |
static std::shared_ptr<ArgumentValidator<int64_t>> createIntegerGreaterValidator(int_fast64_t lowerBound); |
||||
* Creates a validation function that checks whether a given string corresponds to a path to non-existing file in which we can write |
static std::shared_ptr<ArgumentValidator<uint64_t>> createUnsignedGreaterValidator(uint64_t lowerBound); |
||||
* |
static std::shared_ptr<ArgumentValidator<double>> createDoubleGreaterValidator(double lowerBound); |
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (std::string const&)> writableFileValidator() { |
|
||||
return [] (std::string const fileName) -> bool { |
|
||||
struct stat info; |
|
||||
STORM_LOG_THROW(stat (fileName.c_str(), &info) != 0, storm::exceptions::IllegalArgumentValueException , "Could not open file '" << fileName << "' for writing because file or directory already exists."); |
|
||||
|
|
||||
std::ofstream filestream(fileName); |
static std::shared_ptr<ArgumentValidator<int64_t>> createIntegerGreaterEqualValidator(int_fast64_t lowerBound); |
||||
STORM_LOG_THROW(filestream.is_open(), storm::exceptions::IllegalArgumentValueException , "Could not open file '" << fileName << "' for writing."); |
static std::shared_ptr<ArgumentValidator<uint64_t>> createUnsignedGreaterEqualValidator(uint64_t lowerBound); |
||||
filestream.close(); |
static std::shared_ptr<ArgumentValidator<double>> createDoubleGreaterEqualValidator(double lowerBound); |
||||
std::remove(fileName.c_str()); |
|
||||
|
|
||||
return true; |
|
||||
}; |
|
||||
} |
|
||||
|
|
||||
/*! |
|
||||
* Creates a validation function that checks whether a given string is in a provided list of strings. |
|
||||
* |
|
||||
* @param list The list of valid strings. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
static std::function<bool (std::string const&)> stringInListValidator(std::vector<std::string> const& list) { |
|
||||
return [list] (std::string const& inputString) -> bool { |
|
||||
for (auto const& validString : list) { |
|
||||
if (inputString == validString) { |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
STORM_LOG_THROW(false, storm::exceptions::IllegalArgumentValueException, "Value '" << inputString << "' does not match any entry in the list of valid items."); |
static std::shared_ptr<ArgumentValidator<std::string>> createExistingFileValidator(); |
||||
return false; |
static std::shared_ptr<ArgumentValidator<std::string>> createWritableFileValidator(); |
||||
}; |
|
||||
} |
|
||||
|
|
||||
private: |
static std::shared_ptr<ArgumentValidator<std::string>> createMultipleChoiceValidator(std::vector<std::string> const& choices); |
||||
/*! |
|
||||
* Creates a validation function that checks whether its argument is in a given range (including the bounds). |
|
||||
* |
|
||||
* @param lowerBound The lower bound of the valid range. |
|
||||
* @param upperBound The upper bound of the valid range. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
template<typename T> |
|
||||
static std::function<bool (T const&)> rangeValidatorIncluding(T lowerBound, T upperBound) { |
|
||||
return std::bind([](T lowerBound, T upperBound, T value) -> bool { |
|
||||
STORM_LOG_THROW(lowerBound <= value && value <= upperBound, storm::exceptions::InvalidArgumentException, "Value " << value << " is out of range."); |
|
||||
return true; |
|
||||
}, lowerBound, upperBound, std::placeholders::_1); |
|
||||
} |
|
||||
|
|
||||
/*! |
private: |
||||
* Creates a validation function that checks whether its argument is in a given range (excluding the bounds). |
template <typename ValueType> |
||||
* |
static std::shared_ptr<ArgumentValidator<ValueType>> createRangeValidatorExcluding(ValueType lowerBound, ValueType upperBound); |
||||
* @param lowerBound The lower bound of the valid range. |
|
||||
* @param upperBound The upper bound of the valid range. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
template<typename T> |
|
||||
static std::function<bool (T const&)> rangeValidatorExcluding(T lowerBound, T upperBound) { |
|
||||
return std::bind([](T lowerBound, T upperBound, T value) -> bool { |
|
||||
STORM_LOG_THROW(lowerBound < value && value < upperBound, storm::exceptions::InvalidArgumentException, "Value " << value << " is out of range."); |
|
||||
return true; |
|
||||
}, lowerBound, upperBound, std::placeholders::_1); |
|
||||
} |
|
||||
|
|
||||
/*! |
template <typename ValueType> |
||||
* Creates a validation function that checks whether its argument is greater than the given threshold. |
static std::shared_ptr<ArgumentValidator<ValueType>> createGreaterValidator(ValueType lowerBound, bool equalAllowed); |
||||
* |
}; |
||||
* @param threshold The threshold. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
template<typename T> |
|
||||
static std::function<bool (T const&)> greaterValidatorExcluding(T threshold) { |
|
||||
return std::bind([](T threshold, T value) -> bool { |
|
||||
STORM_LOG_THROW(threshold < value, storm::exceptions::InvalidArgumentException, "Value " << value << " is out of range."); |
|
||||
return true; |
|
||||
}, threshold, std::placeholders::_1); |
|
||||
} |
|
||||
|
|
||||
/*! |
} |
||||
* Creates a validation function that checks whether its argument is greater than or equal to the given threshold. |
|
||||
* |
|
||||
* @param threshold The threshold. |
|
||||
* @return The resulting validation function. |
|
||||
*/ |
|
||||
template<typename T> |
|
||||
static std::function<bool (T const&)> greaterValidatorIncluding(T threshold) { |
|
||||
return std::bind([](T threshold, T value) -> bool { |
|
||||
STORM_LOG_THROW(threshold <= value, storm::exceptions::InvalidArgumentException, "Value " << value << " is out of range."); |
|
||||
return true; |
|
||||
}, threshold, std::placeholders::_1); |
|
||||
} |
|
||||
}; |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
#endif // STORM_SETTINGS_ARGUMENTVALIDATORS_H_ |
|
Reference in new issue
xxxxxxxxxx