FLOPC++
MP_index.hpp
Go to the documentation of this file.
1 // ******************** FlopCpp **********************************************
2 // File: MP_index.hpp
3 // $Id$
4 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 // Copyright (C) 2003 Tim Helge Hultberg
6 // All Rights Reserved.
7 // ****************************************************************************
8 
9 #ifndef _MP_index_hpp_
10 #define _MP_index_hpp_
11 
12 #include "MP_utilities.hpp"
13 #include "MP_constant.hpp"
14 
15 namespace flopc {
16 
17  class MP_index;
18  class MP_domain;
19  class MP_set;
20 
26  class MP_index_base {
27  friend class Handle<MP_index_base*>;
28  friend class MP_index_exp;
29  public:
30  virtual int evaluate() const = 0;
31  virtual MP_index* getIndex() const = 0;
32  virtual MP_domain getDomain(MP_set* s) const = 0;
33 // virtual void display()const;
34  protected:
35  MP_index_base() : count(0) {}
36  virtual ~MP_index_base() {}
37  private:
38  int count;
39  };
40 
53  class MP_index : public MP_index_base {
54  friend class MP_domain_set;
55  template<int nbr> friend class MP_domain_subset;
56  public:
58  MP_index() : index(0), instantiated(false) {}
59  int evaluate() const {
60  return index;
61  }
63  static MP_index &getEmpty();
65  static MP_index &Any();
66  private:
69  bool isInstantiated() const {
70  return instantiated;
71  }
75  void assign(int i) {
76  index = i;
77  }
80  void unInstantiate() {
81  instantiated = false;
82  }
85  void instantiate() {
86  instantiated = true;
87  }
91  MP_index* getIndex() const {
92  return const_cast<MP_index*>(this);
93  }
95  virtual MP_domain getDomain(MP_set* s) const;
96 
97  static MP_index& Empty;
99  int index;
101  };
102 
103 
108 
112  MP_index_exp operator-(MP_index& i,const int& j);
116  MP_index_exp operator+(MP_index& i,const int& j);
125 
126  class SUBSETREF;
127 
141  class MP_index_exp : public Handle<MP_index_base*> {
142  public:
146  MP_index_exp(int i=0);
148  MP_index_exp(const Constant& c);
154  MP_index_exp(const SUBSETREF& d);
156  MP_index_exp(const MP_index_exp& other);
157  virtual ~MP_index_exp() {}
159  static const MP_index_exp &getEmpty();
160  private:
162  };
163 
170  class MP_index_mult : public MP_index_base {
171  friend MP_index_exp operator*(MP_index& i,const Constant& j);
172  private:
173  MP_index_mult(MP_index& i, const Constant& j) : left(i), right(j) {}
174 
175  int evaluate() const {
176  return left->evaluate()*int(right->evaluate());
177  }
178  MP_index* getIndex() const {
179  return left->getIndex();
180  }
181  virtual MP_domain getDomain(MP_set* s) const;
184  };
185 
192  class MP_index_sum : public MP_index_base {
193  friend MP_index_exp operator+(MP_index& i,const Constant& j);
194  friend MP_index_exp operator+(MP_index& i,const int& j);
195  private:
196  MP_index_sum(MP_index& i, const Constant& j) : left(i), right(j) {}
197 
198  int evaluate() const {
199  return left->evaluate()+int(right->evaluate());
200  }
201  MP_index* getIndex() const {
202  return left->getIndex();
203  }
204  virtual MP_domain getDomain(MP_set* s) const;
207  };
208 
215  class MP_index_dif : public MP_index_base {
216  friend MP_index_exp operator-(MP_index& i,const Constant& j);
217  friend MP_index_exp operator-(MP_index& i,const int& j);
218  private:
219  MP_index_dif(MP_index& i, const Constant& j) : left(i), right(j) {}
220 
221  int evaluate() const {
222  return left->evaluate()-int(right->evaluate());
223  }
224  MP_index* getIndex() const {
225  return left->getIndex();
226  }
227  virtual MP_domain getDomain(MP_set* s) const;
230  };
231 
232 } // End of namespace flopc
233 #endif