DGraphInterface.hpp

Go to the documentation of this file.
00001 
00015 #ifndef DGraphInterface_H
00016 #define DGraphInterface_H
00017 
00018 #include <cassert>
00019 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00020 #include <OpenAnalysis/OABase/Annotation.hpp>
00021 #include <OpenAnalysis/Utils/OutputBuilder.hpp>
00022 #include <string>
00023 #include <fstream>
00024 #include <iostream>
00025 #include <set>
00026 
00027 namespace OA {
00028   namespace DGraph {
00029 
00030     typedef enum {DEdgeOrg = 0, DEdgeRev = 1} DGraphEdgeDirection;
00031 
00032     class EdgeInterface;
00033     class EdgesIteratorInterface;
00034     class NodeInterface;
00035     class NodesIteratorInterface;
00036     class DGraphInterface;
00037 
00038   class NodeInterface : public virtual Annotation {
00039       public:
00040         //========================================================  
00041         // Information
00042         //========================================================
00043         
00044         virtual ~NodeInterface() { }
00045         
00046         virtual unsigned int getId () const = 0;
00047 
00048         virtual int num_incoming () const = 0;
00049         
00050         virtual int num_outgoing () const = 0;
00051       
00053         virtual bool isAnEntry() const = 0;
00054   
00056         virtual bool isAnExit() const = 0;
00057 
00058 
00059         //========================================================  
00060         // Iterators
00061         //========================================================
00062         virtual OA_ptr<EdgesIteratorInterface> 
00063             getIncomingEdgesIterator() const =0;
00064         
00065         virtual OA_ptr<EdgesIteratorInterface> 
00066             getOutgoingEdgesIterator() const =0;
00067 
00068         virtual OA_ptr<NodesIteratorInterface> 
00069             getSourceNodesIterator() const =0;
00070 
00071         virtual OA_ptr<NodesIteratorInterface> 
00072             getSinkNodesIterator() const =0;
00073 
00074 
00075         //========================================================  
00076         // Comparison operators
00077         //========================================================
00078         virtual bool operator== (NodeInterface& other) = 0;
00079         virtual bool operator< (NodeInterface& other) = 0;
00080 
00081         //========================================================  
00082         // Construction
00083         //========================================================
00084         virtual void addOutgoingEdge(OA_ptr<EdgeInterface>) = 0;
00085         virtual void addIncomingEdge(OA_ptr<EdgeInterface>) = 0;
00086         virtual void removeIncomingEdge(OA_ptr<EdgeInterface> e) = 0;
00087         virtual void removeOutgoingEdge(OA_ptr<EdgeInterface> e) = 0;
00088 
00089         
00090         //========================================================  
00091         // Output
00092         //========================================================
00093         virtual void dump(std::ostream& os) = 0;
00094     };
00095 
00096     // lt_Node: function object that compares by node id.  Useful for sorting.
00097   class lt_NodeInterface {
00098       public:
00099           // return true if n1 < n2; false otherwise
00100           virtual bool operator()(const OA_ptr<NodeInterface> n1,
00101                                   const OA_ptr<NodeInterface> n2) const = 0;
00102     };
00103 
00104  class EdgeInterface : public virtual Annotation {
00105       public:
00106 
00107         virtual ~EdgeInterface() { }
00108         //========================================================  
00109         // Information
00110         //========================================================
00111         virtual unsigned int getId () const = 0;
00112         virtual OA_ptr<NodeInterface> getSource() const = 0;
00113         virtual OA_ptr<NodeInterface> getSink() const = 0;
00114 
00115         //========================================================  
00116         // Comparison operators
00117         //========================================================
00118         virtual bool operator== (EdgeInterface& other) = 0;
00119         virtual bool operator< (EdgeInterface& other) = 0;
00120         //========================================================  
00121         // Output
00122         //========================================================
00123         virtual void dump(std::ostream& os) = 0;
00124     };
00125 
00126  
00127 
00128     // lt_Edge: function object that compares by id.  Useful for sorting.
00129  class lt_EdgeInterface {
00130      public:
00131         // return true if e1 < e2; false otherwise
00132         virtual bool operator()(
00133                                 const OA_ptr<EdgeInterface> e1, 
00134                                 const OA_ptr<EdgeInterface> e2) const = 0;
00135     };
00136 
00137 
00138 
00139  class NodesIteratorInterface {
00140       public:
00141         virtual ~NodesIteratorInterface() { }
00142         virtual OA_ptr<NodeInterface> current() const = 0;
00143         virtual void operator++() = 0;      // prefix
00144         virtual void operator++(int) = 0;   // postfix
00145         virtual bool isValid() const = 0;
00146         virtual void reset() = 0;
00147     };
00148 
00149     class EdgesIteratorInterface {
00150       public:
00151         virtual ~EdgesIteratorInterface() { }
00152         virtual OA_ptr<EdgeInterface> current() const = 0;
00153         virtual void operator++() = 0;      // prefix
00154         virtual void operator++(int) = 0;   // postfix
00155         virtual bool isValid() const = 0;
00156         virtual void reset() = 0;
00157     };
00158 
00159 
00160   class DGraphInterface : public virtual Annotation {
00161       public:
00162 
00163         virtual ~DGraphInterface() { }  
00164 
00165         virtual int getNumNodes () = 0;
00166         virtual int getNumEdges () = 0;
00167 
00168 
00169         //========================================================  
00170         // Iterators
00171         //========================================================
00172         virtual OA_ptr<NodesIteratorInterface> 
00173             getNodesIterator() const = 0;
00174 
00175 
00176         virtual OA_ptr<NodesIteratorInterface> 
00177             getEntryNodesIterator() const =0;
00178         
00179         virtual OA_ptr<NodesIteratorInterface> 
00180             getExitNodesIterator() const =0;
00181 
00182         virtual OA_ptr<NodesIteratorInterface>
00183             getReversePostDFSIterator(
00184                     DGraphEdgeDirection pOrient) =0;
00185 
00186         
00187         virtual OA_ptr<NodesIteratorInterface>
00188             getDFSIterator(OA_ptr<NodeInterface> n) = 0;
00189 
00190 
00191         virtual OA_ptr<EdgesIteratorInterface> 
00192             getEdgesIterator() const =0;
00193 
00194 
00195 
00196         //========================================================
00197         // Construction
00198         //========================================================
00199         virtual void addNode(OA_ptr<NodeInterface> n) = 0;
00200         virtual void addEdge(OA_ptr<EdgeInterface> e) = 0;
00201 
00202         
00203     };
00204 
00205  }// End of namespace DGraph
00206 } // End of namespace OA
00207 
00208 #endif

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