00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "MP_index.hpp"
00010 #include "MP_domain.hpp"
00011 #include "MP_set.hpp"
00012 #include "MP_model.hpp"
00013
00014 namespace flopc {
00015
00016 MP_index& MP_index::Empty = *new MP_index();
00017 MP_index& MP_index::Any = *new MP_index();
00018 MP_index_exp MP_index_exp::Empty = *new MP_index_exp(Constant(0.0));
00019
00020 MP_index &MP_index::getEmpty() {
00021 return Empty;
00022 }
00023 const MP_index_exp &MP_index_exp::getEmpty() {
00024 return Empty;
00025 }
00026
00027 void MP_index_base::display()const {
00029 }
00030
00031 class MP_index_constant : public MP_index_base {
00032 friend class MP_index_exp;
00033 public:
00034 void display()const {
00036 }
00037 private:
00038 MP_index_constant(const Constant& c) : C(c) {}
00039 int evaluate() const {
00040 return int(C->evaluate());
00041 }
00042 MP_index* getIndex() const {
00043 return 0;
00044 }
00045 virtual MP_domain getDomain(MP_set* s) const{
00046 return MP_domain::getEmpty();
00047 }
00048 Constant C;
00049 };
00050
00051 class MP_index_subsetRef : public MP_index_base {
00052 friend class MP_index_exp;
00053 public:
00054 void display()const {
00056 }
00057 private:
00058 MP_index_subsetRef(const SUBSETREF& s) : S(&s) {}
00059 int evaluate() const {
00060 return int(S->evaluate());
00061 }
00062 MP_index* getIndex() const {
00063 return S->getIndex();
00064 }
00065 virtual MP_domain getDomain(MP_set* s) const{
00066 return MP_domain(S->getDomain(s));
00067 }
00068 const SUBSETREF* S;
00069 };
00070
00071 MP_index_exp operator+(MP_index& i,const Constant& j) {
00072 return new MP_index_sum(i,j);
00073 }
00074
00075 MP_index_exp operator+(MP_index& i,const int& j) {
00076 return new MP_index_sum(i,Constant(j));
00077 }
00078
00079 MP_index_exp operator-(MP_index& i,const Constant& j) {
00080 return new MP_index_dif(i,j);
00081 }
00082
00083 MP_index_exp operator-(MP_index& i,const int& j) {
00084 return new MP_index_dif(i,Constant(j));
00085 }
00086
00087 MP_index_exp operator*(MP_index& i,const Constant& j) {
00088 return new MP_index_mult(i,j);
00089 }
00090
00091
00092 }
00093
00094 using namespace flopc;
00095
00096
00097 MP_domain MP_index::getDomain(MP_set* s) const{
00098 return new MP_domain_set(s,const_cast<MP_index*>(this)) ;
00099 }
00100
00101 MP_domain MP_index_mult::getDomain(MP_set* s) const{
00102 return left->getDomain(s);
00103 }
00104
00105 MP_domain MP_index_sum::getDomain(MP_set* s) const{
00106 return left->getDomain(s);
00107 }
00108
00109 MP_domain MP_index_dif::getDomain(MP_set* s) const{
00110 return left->getDomain(s);
00111 }
00112
00113 MP_index_exp::MP_index_exp(int i) :
00114 Handle<MP_index_base*>(new MP_index_constant(Constant(i))) {}
00115
00116 MP_index_exp::MP_index_exp(const SUBSETREF& s) :
00117 Handle<MP_index_base*>(new MP_index_subsetRef(s)) {}
00118
00119 MP_index_exp::MP_index_exp(const Constant& c) :
00120 Handle<MP_index_base*>(new MP_index_constant(c)) {}
00121
00122 MP_index_exp::MP_index_exp(MP_index& i) :
00123 Handle<MP_index_base*>(&i) { operator->()->count++; }
00124
00125 MP_index_exp::MP_index_exp(const MP_index_exp &other):
00126 Handle<MP_index_base*>((const Handle<MP_index_base*> &)other) {}
00127