FLOPC++
|
00001 // ******************** FlopCpp ********************************************** 00002 // File: MP_index.hpp 00003 // $Id$ 00004 // Author: Tim Helge Hultberg (thh@mat.ua.pt) 00005 // Copyright (C) 2003 Tim Helge Hultberg 00006 // All Rights Reserved. 00007 // **************************************************************************** 00008 00009 #ifndef _MP_index_hpp_ 00010 #define _MP_index_hpp_ 00011 00012 #include "MP_utilities.hpp" 00013 #include "MP_constant.hpp" 00014 00015 namespace flopc { 00016 00017 class MP_index; 00018 class MP_domain; 00019 class MP_set; 00020 00026 class MP_index_base { 00027 friend class Handle<MP_index_base*>; 00028 friend class MP_index_exp; 00029 public: 00030 virtual int evaluate() const = 0; 00031 virtual MP_index* getIndex() const = 0; 00032 virtual MP_domain getDomain(MP_set* s) const = 0; 00033 // virtual void display()const; 00034 protected: 00035 MP_index_base() : count(0) {} 00036 virtual ~MP_index_base() {} 00037 private: 00038 int count; 00039 }; 00040 00053 class MP_index : public MP_index_base { 00054 friend class MP_domain_set; 00055 template<int nbr> friend class MP_domain_subset; 00056 public: 00058 MP_index() : index(0), instantiated(false) {} 00059 int evaluate() const { 00060 return index; 00061 } 00063 static MP_index &getEmpty(); 00065 static MP_index &Any(); 00066 private: 00069 bool isInstantiated() const { 00070 return instantiated; 00071 } 00075 void assign(int i) { 00076 index = i; 00077 } 00080 void unInstantiate() { 00081 instantiated = false; 00082 } 00085 void instantiate() { 00086 instantiated = true; 00087 } 00091 MP_index* getIndex() const { 00092 return const_cast<MP_index*>(this); 00093 } 00095 virtual MP_domain getDomain(MP_set* s) const; 00096 00097 static MP_index& Empty; 00098 static MP_index& Any_index; 00099 int index; 00100 bool instantiated; 00101 }; 00102 00103 00105 Constant operator+(MP_index& a, MP_index& b); 00107 Constant operator-(MP_index& a, MP_index& b); 00108 00112 MP_index_exp operator-(MP_index& i,const int& j); 00116 MP_index_exp operator+(MP_index& i,const int& j); 00120 MP_index_exp operator+(MP_index& i,const Constant& j); 00124 MP_index_exp operator*(MP_index& i,const Constant& j); 00125 00126 class SUBSETREF; 00127 00141 class MP_index_exp : public Handle<MP_index_base*> { 00142 public: 00144 MP_index_exp(MP_index_base* r) : Handle<MP_index_base*>(r) {} 00146 MP_index_exp(int i=0); 00148 MP_index_exp(const Constant& c); 00150 MP_index_exp(MP_index& i); 00154 MP_index_exp(const SUBSETREF& d); 00156 MP_index_exp(const MP_index_exp& other); 00157 virtual ~MP_index_exp() {} 00159 static const MP_index_exp &getEmpty(); 00160 private: 00161 static MP_index_exp Empty; 00162 }; 00163 00170 class MP_index_mult : public MP_index_base { 00171 friend MP_index_exp operator*(MP_index& i,const Constant& j); 00172 private: 00173 MP_index_mult(MP_index& i, const Constant& j) : left(i), right(j) {} 00174 00175 int evaluate() const { 00176 return left->evaluate()*int(right->evaluate()); 00177 } 00178 MP_index* getIndex() const { 00179 return left->getIndex(); 00180 } 00181 virtual MP_domain getDomain(MP_set* s) const; 00182 MP_index_exp left; 00183 Constant right; 00184 }; 00185 00192 class MP_index_sum : public MP_index_base { 00193 friend MP_index_exp operator+(MP_index& i,const Constant& j); 00194 friend MP_index_exp operator+(MP_index& i,const int& j); 00195 private: 00196 MP_index_sum(MP_index& i, const Constant& j) : left(i), right(j) {} 00197 00198 int evaluate() const { 00199 return left->evaluate()+int(right->evaluate()); 00200 } 00201 MP_index* getIndex() const { 00202 return left->getIndex(); 00203 } 00204 virtual MP_domain getDomain(MP_set* s) const; 00205 MP_index_exp left; 00206 Constant right; 00207 }; 00208 00215 class MP_index_dif : public MP_index_base { 00216 friend MP_index_exp operator-(MP_index& i,const Constant& j); 00217 friend MP_index_exp operator-(MP_index& i,const int& j); 00218 private: 00219 MP_index_dif(MP_index& i, const Constant& j) : left(i), right(j) {} 00220 00221 int evaluate() const { 00222 return left->evaluate()-int(right->evaluate()); 00223 } 00224 MP_index* getIndex() const { 00225 return left->getIndex(); 00226 } 00227 virtual MP_domain getDomain(MP_set* s) const; 00228 MP_index_exp left; 00229 Constant right; 00230 }; 00231 00232 } // End of namespace flopc 00233 #endif