Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifndef DFAGenDFSet_H
00008 #define DFAGenDFSet_H
00009
00010 #include <iostream>
00011 #include <set>
00012 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00013 #include <OpenAnalysis/IRInterface/IRHandles.hpp>
00014 #include <OpenAnalysis/DataFlow/DataFlowSet.hpp>
00015
00016 namespace OA {
00017 namespace DataFlow {
00018
00026 template<typename T>
00027 class DFAGenDFSet : public virtual DataFlowSet, public std::set<T> {
00028 public:
00029
00030
00031
00032 DFAGenDFSet () {}
00033
00034 DFAGenDFSet (std::set<T> copy) {
00035 typename std::set<T>::iterator iter;
00036 for(iter = copy.begin(); iter != copy.end(); iter++) {
00037 insert(*iter);
00038 }
00039 }
00040
00041 virtual ~DFAGenDFSet() {}
00042
00043 void unionEqu(const DFAGenDFSet<T> &rhs);
00044 void intersectEqu(const DFAGenDFSet<T> &rhs);
00045 void minusEqu(const DFAGenDFSet<T> &rhs);
00046
00047 bool isEmpty() { return this->empty(); }
00048 bool isSubset(const DFAGenDFSet<T> &rhs);
00049 bool isProperSubset(const DFAGenDFSet<T> &rhs);
00050 bool isSuperset(const DFAGenDFSet<T> &rhs);
00051 bool isProperSuperset(const DFAGenDFSet<T> &rhs);
00052
00053 bool operator==(DataFlowSet &other) const;
00054 bool operator!=(DataFlowSet &other) const;
00055
00056 void dump(std::ostream &os) { assert(false); }
00057
00058 void dump(std::ostream &os, OA_ptr<IRHandlesIRInterface>) {
00059 assert(false);
00060 }
00061
00062 virtual OA_ptr<DataFlowSet> clone();
00063 };
00064
00065 template<typename T>
00066 void DFAGenDFSet<T>::unionEqu(const DFAGenDFSet<T> &rhs) {
00067
00068 copy(rhs.begin(), rhs.end(), inserter(*this, this->begin()));
00069 }
00070
00071 template<typename T>
00072 void DFAGenDFSet<T>::intersectEqu(const DFAGenDFSet<T> &rhs) {
00073 typename DFAGenDFSet<T>::iterator lhsIter, lhsEnd;
00074 typename DFAGenDFSet<T>::const_iterator rhsIter, rhsEnd;
00075
00076 lhsIter = this->begin();
00077 rhsIter = rhs.begin();
00078 lhsEnd = this->end();
00079 rhsEnd = rhs.end();
00080
00081
00082
00083
00084
00085 while(lhsIter != lhsEnd) {
00086
00087
00088 if(rhsIter == rhsEnd) {
00089 this->erase(lhsIter, lhsEnd);
00090 return;
00091 }
00092
00093
00094
00095 while(rhsIter != rhsEnd && *rhsIter < *lhsIter) { ++rhsIter; }
00096
00097
00098
00099 if(*lhsIter != *rhsIter) {
00100 this->erase(lhsIter++);
00101 lhsEnd = this->end();
00102 } else {
00103 ++lhsIter;
00104 }
00105 }
00106 }
00107
00108 template<typename T>
00109 void DFAGenDFSet<T>::minusEqu(const DFAGenDFSet<T> &rhs) {
00110 typename DFAGenDFSet<T>::iterator lhsIter, lhsEnd;
00111 typename DFAGenDFSet<T>::const_iterator rhsIter, rhsEnd;
00112
00113 lhsIter = this->begin();
00114 rhsIter = rhs.begin();
00115 lhsEnd = this->end();
00116 rhsEnd = rhs.end();
00117
00118
00119
00120
00121 while(rhsIter != rhsEnd) {
00122 if(lhsIter == lhsEnd) { return; }
00123
00124 while(lhsIter != lhsEnd && *lhsIter < *rhsIter) { ++lhsIter; }
00125
00126
00127
00128 if(*lhsIter == *rhsIter) {
00129 this->erase(lhsIter++);
00130 lhsEnd = this->end();
00131 } else {
00132 ++rhsIter;
00133 }
00134 }
00135 }
00136
00137
00138 template<typename T>
00139 bool DFAGenDFSet<T>::isSubset(const DFAGenDFSet<T> &rhs) {
00140
00141 typename DFAGenDFSet<T>::iterator iter;
00142
00143 for(iter = this->begin(); iter != this->end(); iter++) {
00144 if(rhs.find(*iter) == rhs.end()) {
00145 return false;
00146 }
00147 }
00148
00149 return true;
00150 }
00151
00152
00153 template<typename T>
00154 bool DFAGenDFSet<T>::isProperSubset(const DFAGenDFSet<T> &rhs) {
00155 return isSubset(rhs) && this->size() != rhs.size();
00156 }
00157
00158 template<typename T>
00159 bool DFAGenDFSet<T>::isSuperset(const DFAGenDFSet<T> &rhs) {
00160 assert(false);
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 }
00171
00172
00173 template<typename T>
00174 bool DFAGenDFSet<T>::isProperSuperset(const DFAGenDFSet<T> &rhs) {
00175 return isSuperset(rhs) && this->size() != rhs.size();
00176 }
00177
00178
00179 template<typename T>
00180 bool DFAGenDFSet<T>::operator==(DataFlowSet &other) const {
00181 DFAGenDFSet<T> *castOther;
00182
00183 castOther = dynamic_cast<DFAGenDFSet<T> *>(&other);
00184
00185 return std::set<T>(*this) == std::set<T>(*castOther);
00186 }
00187
00188
00189 template<typename T>
00190 bool DFAGenDFSet<T>::operator!=(DataFlowSet &other) const {
00191 DFAGenDFSet<T> *castOther;
00192
00193 castOther = dynamic_cast<DFAGenDFSet<T> *>(&other);
00194
00195 return std::set<T>(*this) != std::set<T>(*castOther);
00196 }
00197
00198
00199 template<typename T>
00200 OA_ptr<DataFlowSet> DFAGenDFSet<T>::clone() {
00201 OA_ptr<DataFlowSet> newSet;
00202 newSet = new DFAGenDFSet<T>(*this);
00203 return newSet;
00204 }
00205
00206
00207 }
00208 }
00209
00210 #endif