Location.cpp

Go to the documentation of this file.
00001 
00015 #include "Location.hpp"
00016 #include <Utils/Util.hpp>
00017 
00018 // included here instead of in hpp file to remove circular reference
00019 #include <OpenAnalysis/Location/LocationVisitor.hpp>
00020 
00021 namespace OA {
00022 
00023 static bool debug = false;
00024 
00025 void dumpLocSet(std::set<OA_ptr<Location> >& set, std::ostream& os, 
00026                 OA_ptr<IRHandlesIRInterface> pIR, bool succinct)
00027 {
00028     os << "LocSet = { ";
00029     std::set<OA_ptr<Location> >::iterator setIter;
00030     for (setIter=set.begin(); setIter!=set.end(); setIter++) {
00031         OA_ptr<Location> loc = *setIter;
00032         if(!succinct) {
00033             loc->dump(os,pIR);
00034             os << " ";
00035         } else {
00036             os << loc->toString(pIR);
00037         }
00038     }
00039     os << " }" << std::endl;   
00040 }
00041 
00042 
00043 OA_ptr<std::set<OA_ptr<Location> > > 
00044 intersectLocSets(std::set<OA_ptr<Location> >& set1,
00045                  std::set<OA_ptr<Location> >& set2)
00046 {
00047     OA_ptr<set<OA_ptr<Location> > > temp;
00048     temp = new set<OA_ptr<Location> >;
00049     std::set_intersection(set1.begin(), set1.end(), 
00050                           set2.begin(), set2.end(),
00051                           std::inserter(*temp,temp->end()));
00052     return temp;
00053 }
00054 
00055 
00056 OA_ptr<std::set<OA_ptr<Location> > > 
00057 unionLocSets(std::set<OA_ptr<Location> >& set1, std::set<OA_ptr<Location> >& set2)
00058 {
00059   OA_ptr<std::set<OA_ptr<Location> > > temp;
00060   temp = new std::set<OA_ptr<Location> >;
00061 
00062   std::set<OA_ptr<Location> >::iterator setIter;
00063   int count1=0;
00064   for (setIter=set1.begin(); setIter!=set1.end(); setIter++) {
00065       OA_ptr<Location> loc = *setIter;
00066       count1++;
00067   }
00068 
00069   int count2=0;
00070   for (setIter=set2.begin(); setIter!=set2.end(); setIter++) {
00071       OA_ptr<Location> loc = *setIter;
00072       count2++;
00073   }
00074   
00075   std::set_union(set1.begin(), set1.end(), 
00076                  set2.begin(), set2.end(),
00077                  std::inserter(*temp,temp->end()));
00078   return temp;
00079 }
00080 
00081 
00086 bool mayOverlapLocSets(std::set<OA_ptr<Location> >& set1,
00087                        std::set<OA_ptr<Location> >& set2)
00088 {
00089     if (debug) {
00090         std::cout << "mayOverlapLocSets: " << std::endl;
00091     }
00092     std::set<OA_ptr<Location> >::iterator setIter1;
00093     std::set<OA_ptr<Location> >::iterator setIter2;
00094     for (setIter1=set1.begin(); setIter1!=set1.end(); setIter1++) {
00095         for (setIter2=set2.begin(); setIter2!=set2.end(); setIter2++) {
00096             OA_ptr<Location> loc1 = *setIter1, loc2 = *setIter2;
00097             loc1 = *setIter1;
00098             loc2 = *setIter2;
00099             if (debug) {
00100                 std::cout << "loc1 = ";
00101                 loc1->dump(std::cout);
00102                 std::cout << "loc2 = ";
00103                 loc2->dump(std::cout);
00104             }
00105             if (loc1->mayOverlap(*loc2)) {
00106                 return true;
00107             }
00108         }
00109     }
00110 
00111     return false;
00112 }
00113 
00114 /*
00115   is set1 a subset of set2?
00116 */
00117 bool subSetOf(std::set<OA_ptr<Location> >& set1, std::set<OA_ptr<Location> >& set2)
00118 {
00119     bool retval = true;
00120 
00121     std::set<OA_ptr<Location> >::iterator setIter1;
00122     std::set<OA_ptr<Location> >::iterator setIter2;
00123     for (setIter1=set1.begin(); setIter1!=set1.end(); setIter1++) {
00124         bool found = false;
00125         for (setIter2=set2.begin(); setIter2!=set2.end(); setIter2++) {
00126             OA_ptr<Location> loc1, loc2;
00127             loc1 = *setIter1;
00128             loc2 = *setIter2;
00129             if (loc1 == loc2) {
00130                 found = true;  
00131                 break;
00132             }
00133         }
00134         if (!found) {
00135             retval = false;
00136             break;
00137         }
00138     }
00139 
00140     return retval;
00141 
00142 }
00143 
00144 Location::Location()
00145 {
00146     OA_DEBUG_CTRL_MACRO("DEBUG_Location:ALL", debug);
00147 }
00148 
00149 } // end namespace

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