summaryrefslogtreecommitdiff
path: root/impl/Expression.hpp
blob: 46ccf23d0d8631bc0af9f52927a597038fc105c5 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef EXPRESSION_HPP
#define EXPRESSION_HPP

#include "VariableAssignment.hpp"
#include "Operator.hpp"

template<typename T>
struct Expression {
  Expression(Operator<T>* op, const std::vector< Expression<T>* >& args)
    : _operator(op), _arguments(args) { }
  virtual ~Expression() {
    /*delete _operator;
    for (typename std::vector< Expression<T>* >::iterator it = _arguments.begin();
         it != _arguments.end();
         ++it) {
      delete *it;
    }*/
  }
  const std::vector<Expression<T>*>& arguments() const {
    return _arguments;
  }
  virtual T operator() (const VariableAssignment<T>& assignment) const {
    return (*_operator)(_arguments, assignment);
  }
  private:
  Operator<T>* _operator;
  std::vector< Expression<T>* > _arguments;
};

template<typename T>
struct MaxExpression : public Expression<T> {
  MaxExpression(const std::vector< Expression<T>* >& args)
    : Expression<T>(new Maximum<T>, args) { }
  unsigned int id() const {
    return _id;
  }
  unsigned int id(unsigned int id) {
    return (_id = id);
  }
  private:
  unsigned int _id;
};

#endif