Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

nci/suif/suif2b/common/suif_map.h

Go to the documentation of this file.
00001 #ifndef _MAP_H_
00002 #define _MAP_H_
00003 
00004 #include <assert.h>
00005 
00015 class suif_map_inner
00016     {
00017         void dup_list(const suif_map_inner &x);
00018     public:
00019         class pair_inner {
00020           public:
00021             pair_inner *next;
00022             };
00023 
00024         class helper_inner {
00025           public:
00026             virtual pair_inner* clone(const pair_inner &) const = 0;
00027             virtual void set_range(const pair_inner *val,pair_inner *x) = 0;
00028             };
00029 
00030 
00031         class key_inner
00032             {
00033             public:
00034                 virtual bool operator == (pair_inner *p) const =0;
00035             };
00036 
00037         class iterator_inner {
00038             const suif_map_inner *suif_map;
00039             pair_inner *current;
00040           public:
00041             bool operator ==(const iterator_inner &x) const {return current == x.current;}
00042             bool operator !=(const iterator_inner &x) const {return current != x.current;}
00043             pair_inner *get() const {return current;}
00044             iterator_inner & operator ++();
00045             iterator_inner operator ++(int dummy);
00046             iterator_inner &operator --();
00047             iterator_inner operator --(int dummy);
00048             iterator_inner(const suif_map_inner *x,pair_inner *t) : suif_map(x),current(t) {}
00049             iterator_inner() : suif_map(0),current(0) {}
00050             pair_inner *get_current() {return current;}
00051           public:
00052             iterator_inner(const iterator_inner &other) :
00053               suif_map(other.suif_map), current(other.current) { }
00054           iterator_inner &operator=(const iterator_inner &other) {
00055             suif_map = other.suif_map;
00056             current = other.current;
00057             return(*this);
00058           }
00059           };
00060 
00061         suif_map_inner(helper_inner &x);
00062 
00063         iterator_inner insert(iterator_inner &x,const pair_inner &p);
00064         iterator_inner find(const key_inner &x) const;
00065         void erase(iterator_inner &x);
00066         pair_inner* enter_value(const key_inner &x,const pair_inner &y);
00067         pair_inner* enter_value_no_change(const key_inner &x,const pair_inner &y);
00068 
00069         iterator_inner begin() const {return iterator_inner(this,table);}
00070         iterator_inner end() const {
00071           return iterator_inner(this,(pair_inner *)0);}
00072         iterator_inner insert(iterator_inner &x,pair_inner *y);
00073 
00074         virtual ~suif_map_inner();
00075 
00076         suif_map_inner(const suif_map_inner &x);
00077         suif_map_inner &operator =(const suif_map_inner &x);
00078 
00079 
00080         pair_inner *table;
00081         helper_inner *help;
00082         int m_nSize;
00083         void clear();
00084     };
00085 
00086 
00087 template <class domain, class range>
00088 #ifndef MSVC
00089 class suif_map : private suif_map_inner {
00090 #else
00091 class suif_map : public suif_map_inner {
00092 #endif
00093         class key : public suif_map_inner::key_inner {
00094                 const domain &value;
00095             public:
00096                 key(const domain &v) : value(v) {}
00097                 virtual bool operator == (suif_map_inner::pair_inner *p)const  
00098                         {return ((pair *)p)->first == value;}
00099             };
00100     class helper : public suif_map_inner::helper_inner {
00101           public:
00102             virtual pair_inner* clone(const pair_inner &x) const
00103                 {
00104                 pair *y = (pair *)&x;
00105                 return new pair(y->first,y->second);
00106                 }
00107             virtual void set_range(const pair_inner *val,pair_inner *x)
00108                 {
00109                 pair *yval = (pair *)val;
00110                 pair *ref = (pair *)x;
00111                 ref->second = yval->second;
00112                 }
00113             };
00114 
00115         helper the_helper;
00116 
00117 
00118     public:
00119         class pair : public suif_map_inner::pair_inner {
00120             public:
00121                 domain first;
00122                 range  second;
00123                 pair & operator =(range &x) {second = x;return *this;}
00124                 pair(domain x,range y) : pair_inner() , first(x),second(y) {}
00125                 pair(domain x) : pair_inner() , first(x) {}
00126             private:
00127                 pair(const pair &other) : first(other.first), second(other.second) {}
00128                 pair &operator=(const pair &other) 
00129                         { first = other.first; second= other.second; return (*this); }
00130             };
00131         typedef pair value_type;
00132         typedef domain key_type;
00133         typedef range data_type;
00134 
00135         class iterator : public suif_map_inner::iterator_inner {
00136             public:
00137                 iterator(iterator_inner x) : iterator_inner(x) {}
00138                 iterator() : iterator_inner() {}
00139                 pair & operator *() const {return *(pair *)get();}
00140             };
00141 
00142         suif_map() : suif_map_inner(the_helper), the_helper() {}
00143         virtual ~suif_map() {}
00145         pair & enter_value(domain x,range y) {
00146           key k( x );
00147           pair p( x,y );
00148           return *(pair *)suif_map_inner::enter_value( k,p );
00149           }
00151         iterator find(const domain &x) const {
00152             return suif_map_inner :: find(key(x));
00153             }
00157         range   lookup(const domain &x) {
00158             iterator iter = find(x);
00159             assert(iter != end());
00160             return (*iter).second;
00161         }
00162 
00165         iterator begin() const {return iterator(suif_map_inner :: begin());}
00166         iterator end() const {return iterator(suif_map_inner :: end());}
00167 
00169         void erase(iterator &iter) {suif_map_inner::erase(iter);}
00171         unsigned size() const { return suif_map_inner::m_nSize; }
00174         iterator insert(iterator &x,const pair &p) {return suif_map_inner::insert(x,p);}
00175 
00177         void clear(void) { suif_map_inner::clear(); };
00178     };
00179 
00180 
00181 #endif

Generated at Mon Jul 31 13:41:41 2000 for NCI SUIF by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000