/* * RangeValidator_impl.hpp * * Created on: Apr 16, 2012 * Author: ankele */ #ifndef RANGEVALIDATOR_IMPL_HPP_ #define RANGEVALIDATOR_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif template bool RangeValidator::isValid(const T & _value) const { bool isBefore = true; bool isBeyond = true; // check left boundary isBefore = ValidRange.isBefore(_value); // if (isBefore) // LOG(0, "INFO: " << _value << " is before " << ValidRange.first << "."); // check right boundary isBeyond = ValidRange.isBeyond(_value) && (_value != ValidRange.last); // if (isBeyond) // LOG(0, "INFO: " << _value << " is beyond " << ValidRange.last << "."); return (!isBefore) && (!isBeyond); } template Validator* RangeValidator::clone() const { return new RangeValidator(ValidRange); }; // comparator template bool RangeValidator::operator==(const Validator &_instance) const { const RangeValidator *inst = dynamic_cast *>(&_instance); if (inst) return ValidRange == inst->ValidRange; return false; }; /** Setter for the valid range. * * \note Check whether range invalidates values is done in Value. * * @param _range range (pair of values) */ template void RangeValidator::setValidRange(const range &_range) throw(ParameterValueException) { ValidRange = _range; } // specialization for Vector #include "LinearAlgebra/Vector.hpp" class Vector; template <> inline bool RangeValidator::isValid(const Vector & _value) const { return ValidRange.first[0] <= _value[0] && _value[0] < ValidRange.last[0] && ValidRange.first[1] <= _value[1] && _value[1] < ValidRange.last[1] && ValidRange.first[2] <= _value[2] && _value[2] < ValidRange.last[2]; } #endif /* RANGEVALIDATOR_IMPL_HPP_ */