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  public:
56  MP_index() : index(0), instantiated(false) {}
57  int evaluate() const {
58  return index;
59  }
63  bool isInstantiated() const {
64  return instantiated;
65  }
70  void assign(int i) {
71  index = i;
72  }
76  void unInstantiate() {
77  instantiated = false;
78  }
82  void instantiate() {
83  instantiated = true;
84  }
89  MP_index* getIndex() const {
90  return const_cast<MP_index*>(this);
91  }
93  virtual MP_domain getDomain(MP_set* s) const;
97  static MP_index& Any;
99  static MP_index &getEmpty();
100 
101  private:
102  static MP_index& Empty;
103  int index;
105  };
106 
107 
112 
116  MP_index_exp operator-(MP_index& i,const int& j);
120  MP_index_exp operator+(MP_index& i,const int& j);
129 
130  class SUBSETREF;
131 
145  class MP_index_exp : public Handle<MP_index_base*> {
146  public:
150  MP_index_exp(int i=0);
152  MP_index_exp(const Constant& c);
158  MP_index_exp(const SUBSETREF& d);
160  MP_index_exp(const MP_index_exp& other);
161  virtual ~MP_index_exp() {}
163  static const MP_index_exp &getEmpty();
164  private:
166  };
167 
174  class MP_index_mult : public MP_index_base {
175  friend MP_index_exp operator*(MP_index& i,const Constant& j);
176  private:
177  MP_index_mult(MP_index& i, const Constant& j) : left(i), right(j) {}
178 
179  int evaluate() const {
180  return left->evaluate()*int(right->evaluate());
181  }
182  MP_index* getIndex() const {
183  return left->getIndex();
184  }
185  virtual MP_domain getDomain(MP_set* s) const;
188  };
189 
196  class MP_index_sum : public MP_index_base {
197  friend MP_index_exp operator+(MP_index& i,const Constant& j);
198  friend MP_index_exp operator+(MP_index& i,const int& j);
199  private:
200  MP_index_sum(MP_index& i, const Constant& j) : left(i), right(j) {}
201 
202  int evaluate() const {
203  return left->evaluate()+int(right->evaluate());
204  }
205  MP_index* getIndex() const {
206  return left->getIndex();
207  }
208  virtual MP_domain getDomain(MP_set* s) const;
211  };
212 
219  class MP_index_dif : public MP_index_base {
220  friend MP_index_exp operator-(MP_index& i,const Constant& j);
221  friend MP_index_exp operator-(MP_index& i,const int& j);
222  private:
223  MP_index_dif(MP_index& i, const Constant& j) : left(i), right(j) {}
224 
225  int evaluate() const {
226  return left->evaluate()-int(right->evaluate());
227  }
228  MP_index* getIndex() const {
229  return left->getIndex();
230  }
231  virtual MP_domain getDomain(MP_set* s) const;
234  };
235 
236 } // End of namespace flopc
237 #endif
virtual MP_domain getDomain(MP_set *s) const
Representation of an index.
Definition: MP_index.hpp:53
int evaluate() const
Definition: MP_index.hpp:225
virtual ~MP_index_exp()
Definition: MP_index.hpp:161
int evaluate() const
Definition: MP_index.hpp:179
MP_index_sum(MP_index &i, const Constant &j)
Definition: MP_index.hpp:200
Constant operator*(const Constant &a, const Constant &b)
Returns the product of two constants.
void assign(int i)
Setter for the index.
Definition: MP_index.hpp:70
MP_index * getIndex() const
Definition: MP_index.hpp:205
static MP_index & getEmpty()
returns a reference to the distinct &quot;empty&quot; index.
static MP_index & Empty
Definition: MP_index.hpp:102
MP_index()
Default constructor.
Definition: MP_index.hpp:56
MP_index * getIndex() const
Definition: MP_index.hpp:228
Internal representation of an index expression.
Definition: MP_index.hpp:174
static const MP_index_exp & getEmpty()
Return the unique empty expression.
Internal representation of an index expression.
Definition: MP_index.hpp:219
MP_index * getIndex() const
getter for MP_index * data type.
Definition: MP_index.hpp:89
MP_index_exp left
Definition: MP_index.hpp:186
int evaluate() const
Definition: MP_index.hpp:57
Utility for doing reference counted pointers.
void unInstantiate()
unsetter for instatiated.
Definition: MP_index.hpp:76
virtual int evaluate() const =0
Internal representation of an index expression.
Definition: MP_index.hpp:196
Internal representation of a index.
Definition: MP_index.hpp:26
static MP_index & Any
Definition: MP_index.hpp:97
friend MP_index_exp operator*(MP_index &i, const Constant &j)
returns an index expression from a product between an MP_index and a Constant.
int evaluate() const
Definition: MP_index.hpp:202
Representation of a set for indexing into some other construct.
Definition: MP_set.hpp:78
Representation of an expression involving an index.
Definition: MP_index.hpp:145
static MP_index_exp Empty
Definition: MP_index.hpp:165
bool isInstantiated() const
interrogate state of instatiation of data.
Definition: MP_index.hpp:63
virtual void display() const
virtual ~MP_index_base()
Definition: MP_index.hpp:36
MP_index_exp left
Definition: MP_index.hpp:232
virtual MP_index * getIndex() const =0
MP_index_exp left
Definition: MP_index.hpp:209
MP_index_dif(MP_index &i, const Constant &j)
Definition: MP_index.hpp:223
MP_index_mult(MP_index &i, const Constant &j)
Definition: MP_index.hpp:177
Reference counted class for all &quot;constant&quot; types of data.
Definition: MP_constant.hpp:48
MP_index * getIndex() const
Definition: MP_index.hpp:182
Constant operator+(const Constant &a, const Constant &b)
Returns the sum of two constants.
friend MP_index_exp operator-(MP_index &i, const Constant &j)
virtual MP_domain getDomain(MP_set *s) const
Getter for domain over which this index is applied.
virtual MP_domain getDomain(MP_set *s) const =0
Range over which some other constuct is defined.
Definition: MP_domain.hpp:61
virtual MP_domain getDomain(MP_set *s) const
Internal representation of a &quot;set&quot;.
Definition: MP_set.hpp:273
MP_index_exp(MP_index_base *r)
For internal use.
Definition: MP_index.hpp:148
void instantiate()
setter for instatiated.
Definition: MP_index.hpp:82
virtual MP_domain getDomain(MP_set *s) const
friend MP_index_exp operator+(MP_index &i, const Constant &j)
returns an index expression from a sum between an MP_index and a Constant.
Constant operator-(const Constant &a, const Constant &b)
Returns the difference of two constants.