3#include <boost/algorithm/string/join.hpp>
18template<
typename ValueType>
21 : lower(lower), upper(upper), lowerIncluded(lowerIncluded), upperIncluded(upperIncluded) {
25template<
typename ValueType>
30 result &= value >= lower.get();
32 result &= value > lower.get();
37 result &= value <= upper.get();
39 result &= value < upper.get();
45template<
typename ValueType>
47 std::stringstream stream;
55 stream << lower.get();
61 stream << upper.get();
82 stat(filename.c_str(), &info);
83 STORM_LOG_THROW(info.st_mode & S_IFREG, storm::exceptions::IllegalArgumentValueException,
84 "Unable to read from non-existing file '" << filename <<
"'.");
88 "Unable to read from file '" << filename <<
"'.");
92 std::ofstream filestream;
94 STORM_LOG_THROW(filestream.is_open(), storm::exceptions::IllegalArgumentValueException,
"Could not open file '" << filename <<
"' for writing.");
96 std::remove(filename.c_str());
104 return "existing file";
106 return "writable file";
115 for (
auto const& legalValue : legalValues) {
116 if (legalValue == value) {
124 return "in {" + boost::join(legalValues,
", ") +
"}";
128 return createRangeValidatorExcluding<int64_t>(lowerBound, upperBound);
132 return createRangeValidatorExcluding<uint64_t>(lowerBound, upperBound);
136 return createRangeValidatorIncluding<uint64_t>(lowerBound, upperBound);
140 return createRangeValidatorExcluding<double>(lowerBound, upperBound);
144 return createRangeValidatorIncluding<double>(lowerBound, upperBound);
148 return createGreaterValidator<int64_t>(lowerBound,
false);
152 return createGreaterValidator<uint64_t>(lowerBound,
false);
156 return createGreaterValidator<double>(lowerBound,
false);
160 return createGreaterValidator<int64_t>(lowerBound,
true);
164 return createGreaterValidator<uint64_t>(lowerBound,
true);
168 return createGreaterValidator<double>(lowerBound,
true);
180 return std::make_unique<MultipleChoiceValidator>(choices);
183template<
typename ValueType>
184std::shared_ptr<ArgumentValidator<ValueType>> ArgumentValidatorFactory::createRangeValidatorExcluding(ValueType lowerBound, ValueType upperBound) {
185 return std::make_unique<RangeArgumentValidator<ValueType>>(lowerBound, upperBound,
false,
false);
188template<
typename ValueType>
189std::shared_ptr<ArgumentValidator<ValueType>> ArgumentValidatorFactory::createRangeValidatorIncluding(ValueType lowerBound, ValueType upperBound) {
190 return std::make_unique<RangeArgumentValidator<ValueType>>(lowerBound, upperBound,
true,
true);
193template<
typename ValueType>
194std::shared_ptr<ArgumentValidator<ValueType>> ArgumentValidatorFactory::createGreaterValidator(ValueType lowerBound,
bool equalAllowed) {
195 return std::make_unique<RangeArgumentValidator<ValueType>>(lowerBound, boost::none, equalAllowed,
false);
static std::shared_ptr< ArgumentValidator< uint64_t > > createUnsignedRangeValidatorIncluding(uint64_t lowerBound, uint64_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< double > > createDoubleGreaterValidator(double lowerBound)
static std::shared_ptr< ArgumentValidator< uint64_t > > createUnsignedGreaterValidator(uint64_t lowerBound)
static std::shared_ptr< ArgumentValidator< int64_t > > createIntegerGreaterEqualValidator(int_fast64_t lowerBound)
static std::shared_ptr< ArgumentValidator< int64_t > > createIntegerGreaterValidator(int_fast64_t lowerBound)
static std::shared_ptr< ArgumentValidator< double > > createDoubleGreaterEqualValidator(double lowerBound)
static std::shared_ptr< ArgumentValidator< uint64_t > > createUnsignedGreaterEqualValidator(uint64_t lowerBound)
static std::shared_ptr< ArgumentValidator< std::string > > createMultipleChoiceValidator(std::vector< std::string > const &choices)
static std::shared_ptr< ArgumentValidator< std::string > > createExistingFileValidator()
static std::shared_ptr< ArgumentValidator< int64_t > > createIntegerRangeValidatorExcluding(int_fast64_t lowerBound, int_fast64_t upperBound)
static std::shared_ptr< ArgumentValidator< double > > createDoubleRangeValidatorIncluding(double lowerBound, double upperBound)
static std::shared_ptr< ArgumentValidator< std::string > > createWritableFileValidator()
virtual std::string toString() const override
Retrieves a string representation of the valid values.
virtual bool isValid(std::string const &value) override
Checks whether the argument passes the validation.
MultipleChoiceValidator(std::vector< std::string > const &legalValues)
virtual bool isValid(std::string const &value) override
Checks whether the argument passes the validation.
virtual std::string toString() const override
Retrieves a string representation of the valid values.
RangeArgumentValidator(boost::optional< ValueType > const &lower, boost::optional< ValueType > const &upper, bool lowerIncluded, bool upperIncluded)
virtual bool isValid(ValueType const &value) override
Checks whether the argument passes the validation.
virtual std::string toString() const override
Retrieves a string representation of the valid values.
#define STORM_LOG_THROW(cond, exception, message)
void closeFile(std::ofstream &stream)
Close the given file after writing.
bool fileExistsAndIsReadable(std::string const &filename)
Tests whether the given file exists and is readable.
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.