- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/svn-release/Smi-0.93.1/FlopCpp/src/MP_index.hpp

Go to the documentation of this file.

    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     public:
    00056         MP_index() : index(0), instantiated(false) {}
    00057         int evaluate() const {
    00058             return index;
    00059         }
    00063         bool isInstantiated() const {
    00064             return instantiated;
    00065         }
    00070         void assign(int i) {
    00071             index = i;
    00072         }
    00076         void unInstantiate() {
    00077             instantiated = false;
    00078         }
    00082         void instantiate() {
    00083             instantiated = true;
    00084         }
    00089         MP_index* getIndex() const {
    00090             return const_cast<MP_index*>(this);
    00091         }
    00093         virtual MP_domain getDomain(MP_set* s) const;
    00097         static MP_index& Any;
    00099         static MP_index &getEmpty();
    00100
    00101     private:
    00102         static MP_index& Empty;
    00103         int index;
    00104         bool instantiated;
    00105     };
    00106
    00107
    00109     Constant operator+(MP_index& a, MP_index& b);
    00111     Constant operator-(MP_index& a, MP_index& b);
    00112
    00116     MP_index_exp operator-(MP_index& i,const int& j);
    00120     MP_index_exp operator+(MP_index& i,const int& j);
    00124     MP_index_exp operator+(MP_index& i,const Constant& j);
    00128     MP_index_exp operator*(MP_index& i,const Constant& j);
    00129
    00130     class SUBSETREF;
    00131
    00145     class MP_index_exp : public Handle<MP_index_base*> {
    00146     public:
    00148         MP_index_exp(MP_index_base* r) : Handle<MP_index_base*>(r) {}
    00150         MP_index_exp(int i=0);
    00152         MP_index_exp(const Constant& c);
    00154         MP_index_exp(MP_index& i);
    00158         MP_index_exp(const SUBSETREF& d);
    00160         MP_index_exp(const MP_index_exp& other);
    00161         virtual ~MP_index_exp() {}
    00163         static const MP_index_exp &getEmpty();
    00164     private:
    00165         static MP_index_exp Empty;
    00166     };
    00167
    00174     class MP_index_mult : public MP_index_base {
    00175         friend MP_index_exp operator*(MP_index& i,const Constant& j);
    00176     private:
    00177         MP_index_mult(MP_index& i, const Constant& j) : left(i), right(j) {}
    00178
    00179         int evaluate() const {
    00180             return left->evaluate()*int(right->evaluate());
    00181         }
    00182         MP_index* getIndex() const {
    00183             return left->getIndex();
    00184         }
    00185         virtual MP_domain getDomain(MP_set* s) const;
    00186         MP_index_exp left;
    00187         Constant right;
    00188     };
    00189
    00196     class MP_index_sum : public MP_index_base {
    00197         friend MP_index_exp operator+(MP_index& i,const Constant& j);
    00198         friend MP_index_exp operator+(MP_index& i,const int& j);
    00199     private:
    00200         MP_index_sum(MP_index& i, const Constant& j) : left(i), right(j) {}
    00201
    00202         int evaluate() const {
    00203             return left->evaluate()+int(right->evaluate());
    00204         }
    00205         MP_index* getIndex() const {
    00206             return left->getIndex();
    00207         }
    00208         virtual MP_domain getDomain(MP_set* s) const;
    00209         MP_index_exp left;
    00210         Constant right;
    00211     };
    00212
    00219     class MP_index_dif : public MP_index_base {
    00220         friend MP_index_exp operator-(MP_index& i,const Constant& j);
    00221         friend MP_index_exp operator-(MP_index& i,const int& j);
    00222     private:
    00223         MP_index_dif(MP_index& i, const Constant& j) : left(i), right(j) {}
    00224
    00225         int evaluate() const {
    00226             return left->evaluate()-int(right->evaluate());
    00227         }
    00228         MP_index* getIndex() const {
    00229             return left->getIndex();
    00230         }
    00231         virtual MP_domain getDomain(MP_set* s) const;
    00232         MP_index_exp left;
    00233         Constant right;
    00234     };
    00235
    00236 } // End of namespace flopc
    00237 #endif