/* * Ops_Validator_impl.hpp * * Created on: May 9, 2012 * Author: ankele */ #ifndef OPS_VALIDATOR_IMPL_HPP_ #define OPS_VALIDATOR_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "Validator.hpp" /** Logical AND composition of two Validators. * */ template class And_Validator : public Validator { public: And_Validator(const Validator &_a, const Validator &_b) : a(_a.clone()), b(_b.clone()) {} virtual ~And_Validator() { delete(a); delete(b); } bool isValid(const T & _value) const { return (*a)(_value) && (*b)(_value); } Validator* clone() const { return new And_Validator(*a, *b); } // comparator bool operator==(const Validator &_instance) const { const And_Validator *inst = dynamic_cast *>(&_instance); if (inst) return (*a == *inst->a) && (*b == *inst->b); return false; } Validator *getA(){ return a; } Validator *getB(){ return b; } const Validator *getA() const { return a; } const Validator *getB() const { return b; } private: Validator *a; Validator *b; }; /** Logical OR composition of two Validators. * */ template class Or_Validator : public Validator { public: Or_Validator(const Validator &_a, const Validator &_b) : a(_a.clone()), b(_b.clone()) {} virtual ~Or_Validator() { delete(a); delete(b); } bool isValid(const T & _value) const { return (*a)(_value) || (*b)(_value); } Validator* clone() const { return new Or_Validator(*a, *b); } // comparator bool operator==(const Validator &_instance) const { const Or_Validator *inst = dynamic_cast *>(&_instance); if (inst) return (*a == *inst->a) && (*b == *inst->b); return false; } Validator *getA(){ return a; } Validator *getB(){ return b; } const Validator *getA() const { return a; } const Validator *getB() const { return b; } private: Validator *a; Validator *b; }; /** Logical NOT composition of a Validator. * */ template class Not_Validator : public Validator { public: Not_Validator(const Validator &_a) : a(_a.clone()) {} virtual ~Not_Validator() { delete(a); } bool isValid(const T & _value) const { return !(*a)(_value); } Validator* clone() const { return new Not_Validator(*a); } // comparator bool operator==(const Validator &_instance) const { const Not_Validator *inst = dynamic_cast *>(&_instance); if (inst) return (*a == *inst->a); return false; } Validator *getA(){ return a; } const Validator *getA() const { return a; } private: Validator *a; }; template And_Validator operator&&(const Validator &a, const Validator &b) { return And_Validator(a, b); } template Or_Validator operator||(const Validator &a, const Validator &b) { return Or_Validator(a, b); } template Not_Validator operator!(const Validator &a) { return Not_Validator(a); } #endif /* OPS_VALIDATOR_IMPL_HPP_ */