FlopCpp trunk
Loading...
Searching...
No Matches
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
15namespace flopc {
16
17 class MP_index;
18 class MP_domain;
19 class MP_set;
20
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 }
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;
104 bool instantiated;
105 };
106
107
112
129
130 class SUBSETREF;
131
145 class MP_index_exp : public Handle<MP_index_base*> {
146 public:
150 MP_index_exp(int i=0);
161 virtual ~MP_index_exp() {}
163 static const MP_index_exp &getEmpty();
164 private:
165 static MP_index_exp Empty;
166 };
167
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;
186 MP_index_exp left;
187 Constant right;
188 };
189
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;
209 MP_index_exp left;
210 Constant right;
211 };
212
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;
232 MP_index_exp left;
233 Constant right;
234 };
235
236} // End of namespace flopc
237#endif
Reference counted class for all "constant" types of data.
Utility for doing reference counted pointers.
Range over which some other constuct is defined.
Definition MP_domain.hpp:61
Internal representation of a index.
Definition MP_index.hpp:26
virtual MP_domain getDomain(MP_set *s) const =0
friend class MP_index_exp
Definition MP_index.hpp:28
virtual int evaluate() const =0
virtual ~MP_index_base()
Definition MP_index.hpp:36
virtual MP_index * getIndex() const =0
virtual void display() const
Internal representation of an index expression.
Definition MP_index.hpp:219
friend MP_index_exp operator-(MP_index &i, const int &j)
returns an index expression from a difference between an MP_index and an integer.
friend MP_index_exp operator-(MP_index &i, const Constant &j)
Representation of an expression involving an index.
Definition MP_index.hpp:145
MP_index_exp(int i=0)
create an index expression from a constant integer.
MP_index_exp(MP_index_base *r)
For internal use.
Definition MP_index.hpp:148
MP_index_exp(MP_index &i)
create an index expression from an MP_index.
MP_index_exp(const SUBSETREF &d)
create an index expression from a SUBSETREF
MP_index_exp(const Constant &c)
create an index expression from a Constant
static const MP_index_exp & getEmpty()
Return the unique empty expression.
MP_index_exp(const MP_index_exp &other)
copy constructor from another MP_index_exp
virtual ~MP_index_exp()
Definition MP_index.hpp:161
Internal representation of an index expression.
Definition MP_index.hpp:174
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.
Internal representation of an index expression.
Definition MP_index.hpp:196
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.
friend MP_index_exp operator+(MP_index &i, const int &j)
returns an index expression from a sum between an MP_index and an integer.
Representation of an index.
Definition MP_index.hpp:53
bool isInstantiated() const
interrogate state of instatiation of data.
Definition MP_index.hpp:63
void assign(int i)
Setter for the index.
Definition MP_index.hpp:70
void instantiate()
setter for instatiated.
Definition MP_index.hpp:82
static MP_index & getEmpty()
returns a reference to the distinct "empty" index.
static MP_index & Any
Definition MP_index.hpp:97
int evaluate() const
Definition MP_index.hpp:57
MP_index()
Default constructor.
Definition MP_index.hpp:56
MP_index * getIndex() const
getter for MP_index * data type.
Definition MP_index.hpp:89
virtual MP_domain getDomain(MP_set *s) const
Getter for domain over which this index is applied.
void unInstantiate()
unsetter for instatiated.
Definition MP_index.hpp:76
Representation of a set for indexing into some other construct.
Definition MP_set.hpp:78
Internal representation of a "set".
Definition MP_set.hpp:273
Constant operator+(const Constant &a, const Constant &b)
Returns the sum of two constants.
Constant operator*(const Constant &a, const Constant &b)
Returns the product of two constants.
Constant operator-(const Constant &a, const Constant &b)
Returns the difference of two constants.
All flopc++ code is contained within the flopc namespace.
Definition flopc.hpp:49