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
00030
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
00049
00050
00051
00052
00053
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
00086
00087
00088
00089
00090
00091
00092
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
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
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
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
00153
00154 template <class T>
00155 class IRHandleIterator {
00156 public:
00157
00158
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; }
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 }
00179 }
00180
00181 #endif