IRHandleDataFlowSet.hpp

Go to the documentation of this file.
00001 
00020 #ifndef IRHandleDataFlowSet_h
00021 #define IRHandleDataFlowSet_h
00022 
00023 #include <iostream>
00024 #include <set>
00025 #include <algorithm>
00026 #include <iterator>
00027 #include <OpenAnalysis/DataFlow/DataFlowSet.hpp>
00028 
00029 // abstract interface that this class implements
00030 //#include <OpenAnalysis/DataFlow/DataFlowSet.hpp>
00031 
00032 namespace OA {
00033   namespace DataFlow {
00034 
00035 template <class T> class IRHandleIterator;
00036 
00037 template <class T> 
00038 class IRHandleDataFlowSet : public virtual DataFlowSet {
00039 public:
00040   IRHandleDataFlowSet() {}
00041   IRHandleDataFlowSet(const IRHandleDataFlowSet<T> &other) : mSet(other.mSet) {}
00042   ~IRHandleDataFlowSet() {}
00043 
00044   OA_ptr<DataFlowSet> clone()
00045     { OA_ptr<IRHandleDataFlowSet<T> > retval;
00046       retval = new IRHandleDataFlowSet<T>(*this); return retval; }
00047   
00048   // param for these can't be const because will have to 
00049   // dynamic cast to specific subclass
00050   //IRHandleDataFlowSet<T>& operator =(IRHandleDataFlowSet<T> &other)
00051   //{ 
00052   //  mSet = other.mSet;
00053   //  return *this;
00054  // }
00055 
00056 
00057   bool operator ==(DataFlowSet &other) const
00058   { 
00059     IRHandleDataFlowSet<T>& recastOther 
00060         = dynamic_cast<IRHandleDataFlowSet<T>&>(other);
00061     return mSet == recastOther.mSet; 
00062   }
00063 
00064   bool operator !=(DataFlowSet &other) const
00065   { 
00066     IRHandleDataFlowSet<T>& recastOther 
00067         = dynamic_cast<IRHandleDataFlowSet<T>&>(other);
00068     return mSet != recastOther.mSet; 
00069   }
00070 
00072   IRHandleDataFlowSet<T>& setUnion(DataFlowSet &other)
00073   { 
00074     IRHandleDataFlowSet<T>& recastOther 
00075         = dynamic_cast<IRHandleDataFlowSet<T>&>(other);
00076     std::set<T> temp;
00077     std::set_union(mSet.begin(), mSet.end(), 
00078                    recastOther.mSet.begin(), recastOther.mSet.end(),
00079                    std::inserter(temp,temp.end()));
00080     mSet = temp;
00081     return *this;
00082   }
00083 
00085  /* IRHandleDataFlowSet<T>& setIntersect(IRHandleDataFlowSet<T> &other)
00086   { 
00087     std::set<T> temp;
00088     std::set_intersection(mSet.begin(), mSet.end(), 
00089                           other.mSet.begin(), other.mSet.end(),
00090                           std::inserter(temp,temp.end()));
00091     mSet = temp;
00092     return *this;
00093   }*/
00094 
00095 
00096   IRHandleDataFlowSet<T>& setIntersect(DataFlowSet &other)
00097   {
00098     IRHandleDataFlowSet<T>& recastOther
00099         = dynamic_cast<IRHandleDataFlowSet<T>&>(other);
00100     std::set<T> temp;
00101     std::set_intersection(mSet.begin(), mSet.end(),
00102                    recastOther.mSet.begin(), recastOther.mSet.end(),
00103                    std::inserter(temp,temp.end()));
00104     mSet = temp;
00105     return *this;
00106   }
00107 
00108 
00109   void dump(std::ostream &os)
00110   {
00111       os << "IRHandleDataFlowSet: mSet = ";
00112       // iterate over IRHandle's and print out hvals
00113       typename std::set<T>::iterator iter;
00114       for (iter=mSet.begin(); iter!=mSet.end(); iter++) {
00115           os << (*iter).hval() << ", ";
00116       }
00117       os << std::endl;
00118   }
00119 
00120   void dump(std::ostream &os, OA_ptr<IRHandlesIRInterface> ir)
00121   {
00122       os << "IRHandleDataFlowSet: mSet = ";
00123       // iterate over IRHandle's and have the IR print them out
00124       typename std::set<T>::iterator iter;
00125       for (iter=mSet.begin(); iter!=mSet.end(); iter++) {
00126           os << ir->toString(*iter) << ", ";
00127       }
00128       os << std::endl;
00129   }
00130 
00131   // methods specific to IRHandleDataFlowSet
00132   void insert(T h) { mSet.insert(h); }
00133   void remove(T h) { mSet.erase(h); }
00134 
00136   bool handleInSet(T h) { return (mSet.find(h)!=mSet.end()); }
00137 
00139   bool empty() { return mSet.empty(); }
00140 
00141 protected:
00142   std::set<T> mSet;
00143 
00144   friend class IRHandleIterator<T>;
00145 
00146 };
00147 
00148 //--------------------------------------------------------------------
00151 //--------------------------------------------------------------------
00152 //template <class T> class std::set<T>::iterator;
00153 
00154 template <class T>
00155 class IRHandleIterator {
00156 public:
00157     // have to get OA_ptr to a set because otherwise the set
00158     // might disappear before user of this iterator references it
00159     IRHandleIterator (OA_ptr<IRHandleDataFlowSet<T> > DFSet) : mDFSet(DFSet) 
00160     { hIter = mDFSet->mSet.begin(); }
00161     ~IRHandleIterator () {}
00162 
00163     void operator ++ () { if (hIter != mDFSet->mSet.end()) hIter++; }
00164     void operator++(int) { ++*this; }  // postfix
00165     
00167     bool isValid() const { return (hIter != mDFSet->mSet.end()); }
00168     
00170     T current() const { return (*hIter); }
00171 
00172 private:
00173     OA_ptr<IRHandleDataFlowSet<T> > mDFSet;
00174     typename std::set<T>::iterator hIter;
00175 };
00176  
00177 
00178   } // end of DataFlow namespace
00179 } // end of OA namespace
00180 
00181 #endif

Generated on Sat Oct 31 05:21:22 2009 for OpenAnalysis by  doxygen 1.6.1