WorkListQueue.hpp

Go to the documentation of this file.
00001 
00016 #ifndef WorkListQueue_h
00017 #define WorkListQueue_h
00018 
00019 //#ifndef DirectedGraph_h
00020 //#include <libs/support/graphs/directedGraph/DirectedGraph.h>
00021 //#endif
00022 // Going to attempt to use DGraph instead
00023 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00024 #include <OpenAnalysis/Utils/DGraph/DGraphInterface.hpp>
00025 #include <OpenAnalysis/Utils/DGraph/DGraphImplement.hpp>
00026 #include <OpenAnalysis/CFG/CFGInterface.hpp>
00027 #include <OpenAnalysis/CFG/CFG.hpp>
00028 
00029 #include <iostream>
00030 
00031 #include <sys/times.h>
00032 
00033 #include <vector>
00034 
00035 #include <set>
00036 
00037 #include <queue>
00038 
00039 
00040 
00041 #include <OpenAnalysis/DataFlow/WorkList.hpp>
00042 
00043 namespace OA {
00044   namespace DataFlow {
00045 
00046 //*********************************************************************
00047 // class Worklist
00048 //*********************************************************************
00049  
00050 class Worklist_Queue : public WorkList {
00051 
00052     public:
00053 
00054         Worklist_Queue( OA_ptr<DGraph::DGraphInterface> dg,
00055                         DGraph::DGraphEdgeDirection alongFlow)
00056         {
00057 
00058            OA_ptr<DGraph::NodesIteratorInterface> nodeIterPtr
00059               = dg->getReversePostDFSIterator(alongFlow);
00060 
00061             
00062            for (; nodeIterPtr->isValid(); ++(*nodeIterPtr)) {
00063                 worklist.push(nodeIterPtr->current());
00064                 worklistSet.insert(nodeIterPtr->current());
00065            }
00066         }
00067 
00068         virtual ~Worklist_Queue() { }
00069         
00070         OA_ptr<DGraph::NodeInterface> getNext()
00071         {
00072              OA_ptr<DGraph::NodeInterface> node;     
00073              node = worklist.front();
00074              worklist.pop();
00075              worklistSet.erase(node);
00076              return node; 
00077         }
00078 
00079         void add(OA_ptr<DGraph::NodeInterface> node) 
00080         {
00081              if (worklistSet.find(node)==worklistSet.end()) {
00082                  worklist.push(node);
00083                  worklistSet.insert(node);
00084              }
00085         }
00086 
00087         bool isEmpty() {
00088 
00089              if(worklist.empty()) {
00090                 return true;
00091              } else {
00092                 return false;
00093              }
00094 
00095         }
00096         
00097 
00098 
00099     private:
00100 
00101         // Member Functions
00102 
00103         bool atDGraphNode(OA_ptr<DGraph::NodeInterface>,
00104                                   DGraph::DGraphEdgeDirection)
00105         {
00106             return false;
00107         }
00108 
00109         bool atDGraphEdge(OA_ptr<DGraph::EdgeInterface>,
00110                                   DGraph::DGraphEdgeDirection)
00111         {
00112             return false;
00113         }
00114 
00115         void finalizeNode(OA_ptr<DGraph::NodeInterface> node)
00116         {
00117         }
00118 
00119         void finalizeEdge(OA_ptr<DGraph::EdgeInterface> edge)
00120         {
00121         }
00122 
00123         // Member Variables
00124         
00125         std::queue<OA_ptr<DGraph::NodeInterface> > worklist;
00126         
00127         std::set<OA_ptr<DGraph::NodeInterface> > worklistSet;
00128 };
00129 
00130 
00131   } // end of DataFlow
00132 }  // end of OA namespace
00133 
00134 #endif