#pragma once #include #include #include #include namespace storm { namespace settings { template class ArgumentValidator { public: virtual ~ArgumentValidator() = default; /*! * Checks whether the argument passes the validation. */ virtual bool isValid(ValueType const& value) = 0; /*! * Retrieves a string representation of the valid values. */ virtual std::string toString() const = 0; }; template class RangeArgumentValidator : public ArgumentValidator { public: RangeArgumentValidator(boost::optional const& lower, boost::optional const& upper, bool lowerIncluded, bool upperIncluded); virtual bool isValid(ValueType const& value) override; virtual std::string toString() const override; private: boost::optional lower; boost::optional upper; bool lowerIncluded; bool upperIncluded; }; class FileValidator : public ArgumentValidator { public: enum class Mode { Exists, Writable }; FileValidator(Mode mode); virtual bool isValid(std::string const& value) override; virtual std::string toString() const override; private: Mode mode; }; class MultipleChoiceValidator : public ArgumentValidator { public: MultipleChoiceValidator(std::vector const& legalValues); virtual bool isValid(std::string const& value) override; virtual std::string toString() const override; private: std::vector legalValues; }; class ArgumentValidatorFactory { public: static std::shared_ptr> createIntegerRangeValidatorExcluding(int_fast64_t lowerBound, int_fast64_t upperBound); static std::shared_ptr> createUnsignedRangeValidatorExcluding(uint64_t lowerBound, uint64_t upperBound); static std::shared_ptr> createUnsignedRangeValidatorIncluding(uint64_t lowerBound, uint64_t upperBound); static std::shared_ptr> createDoubleRangeValidatorExcluding(double lowerBound, double upperBound); static std::shared_ptr> createDoubleRangeValidatorIncluding(double lowerBound, double upperBound); static std::shared_ptr> createIntegerGreaterValidator(int_fast64_t lowerBound); static std::shared_ptr> createUnsignedGreaterValidator(uint64_t lowerBound); static std::shared_ptr> createDoubleGreaterValidator(double lowerBound); static std::shared_ptr> createIntegerGreaterEqualValidator(int_fast64_t lowerBound); static std::shared_ptr> createUnsignedGreaterEqualValidator(uint64_t lowerBound); static std::shared_ptr> createDoubleGreaterEqualValidator(double lowerBound); static std::shared_ptr> createExistingFileValidator(); static std::shared_ptr> createWritableFileValidator(); static std::shared_ptr> createMultipleChoiceValidator(std::vector const& choices); private: template static std::shared_ptr> createRangeValidatorExcluding(ValueType lowerBound, ValueType upperBound); template static std::shared_ptr> createRangeValidatorIncluding(ValueType lowerBound, ValueType upperBound); template static std::shared_ptr> createGreaterValidator(ValueType lowerBound, bool equalAllowed); }; } }