#ifndef OPERATOR_HPP #define OPERATOR_HPP template T infinity() { } template<> float infinity() { return INFINITY; } #include template struct VariableAssignment; template struct Expression; template struct Operator { virtual T operator() (const std::vector< Expression* >&, const VariableAssignment&) const = 0; }; template struct Maximum : public Operator { virtual T operator() (const std::vector< Expression* >& args, const VariableAssignment& assignment) const { T value = -infinity(); for (typename std::vector< Expression* >::const_iterator it = args.begin(); it != args.end(); ++it) { T temporary = (**it)(assignment); value = (temporary < value ? value : temporary); } return value; } }; template struct Minimum : public Operator { virtual T operator() (const std::vector< Expression* >& args, const VariableAssignment& assignment) const { T value = infinity(); for (typename std::vector< Expression* >::const_iterator it = args.begin(); it != args.end(); ++it) { T temporary = (**it)(assignment); value = (temporary > value ? value : temporary); } return value; } }; template struct Constant : public Operator { Constant(const T& val) : _value(val) { } T operator() (const std::vector< Expression* >& args, const VariableAssignment& ass) const { return _value; } private: const T _value; }; template struct Increment: public Operator { T operator() (const std::vector< Expression* >& args, const VariableAssignment& ass) const { return (*args[0])(ass) + 1; } }; #include "VariableAssignment.hpp" #include "Expression.hpp" #endif