summaryrefslogtreecommitdiff
path: root/impl/Variable.hpp
blob: 5ebbbedbdca36d7119ad9bd015b872bf79ed2714 (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
#ifndef VARIABLE_HPP
#define VARIABLE_HPP

#include <string>
#include "Operator.hpp"

template<typename T>
struct Variable : public Operator<T> {
  Variable(unsigned int id, const std::string& name)
    : _id(id), _name(name) { }
  Variable(const Variable& other)
    : _id(other._id) { }
  unsigned int id() const {
    return _id;
  }
  std::string name() const {
    return _name;
  }
  //T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& ass) const {
  virtual T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& assignment, VariableSet<T>* visited) const {
    //assert(args.size() == 0)
    if (visited != NULL)
      visited->insert(*this);
    return assignment[*this];
  }
  private:
  const unsigned int _id;
  const std::string _name;
};

template<typename T>
std::ostream& operator<<(std::ostream& cout, const Variable<T>& v) {
  cout << v.name() << "(" << v.id() << ")";
  return cout;
}

#endif