MeshKit  1.0
MKGraph.hpp
Go to the documentation of this file.
00001 #ifndef MESHKIT_MKGRAPH_HPP
00002 #define MESHKIT_MKGRAPH_HPP
00003 
00006 #include "lemon/list_graph.h"
00007 #include "lemon/bfs.h"
00008 
00009 namespace MeshKit {
00010 
00011 class MeshOp;
00012 class GraphNode;
00013     
00024 class MKGraph
00025 {
00026 public:
00027 
00030   MKGraph();
00031   
00033   virtual ~MKGraph();
00034 
00036   void clear_graph();
00037   
00039   void print_graph(const char * filename = NULL);
00040   
00042   void print_bfs_graph();
00043 
00045   lemon::ListDigraph &get_graph();
00046 
00048   const lemon::ListDigraph &get_graph() const;
00049 
00051   GraphNode *root_node() const;
00052   
00054   GraphNode *leaf_node() const;
00055 
00057   lemon::ListDigraph::NodeMap<GraphNode*> &node_map();
00058 
00060   const lemon::ListDigraph::NodeMap<GraphNode*> &node_map() const;
00061 
00063   MeshOp *get_meshop(lemon::ListDigraph::Node node) const;
00064   
00066   GraphNode *get_node(lemon::ListDigraph::Node node) const;
00067   
00069   GraphNode *source(lemon::ListDigraph::Arc arc) const;
00070   
00072   GraphNode *target(lemon::ListDigraph::Arc arc) const;
00073 
00080   GraphNode *other_node(lemon::ListDigraph::Arc arc, GraphNode *node) const;
00081   
00086   GraphNode *find_node(std::string op_name) const;
00087 
00092   MeshOp *find_meshop(std::string op_name) const;
00093 
00099   void insert_node(GraphNode *inserted, GraphNode *before, GraphNode *after= NULL);
00100 
00105   void add_arc(GraphNode *source, GraphNode *target);
00106   
00111   virtual void setup(bool reset = true);
00112 
00114   virtual void execute();
00115 
00117   virtual void setup_and_execute();
00118 
00119   // run execute on all nodes before this node (it may be a second run)
00120   virtual void execute_before(GraphNode * upto);
00121 
00122 protected:
00124   lemon::ListDigraph mkGraph;
00125 
00127   GraphNode *rootNode, *leafNode;
00128 
00130   lemon::ListDigraph::NodeMap<GraphNode*> nodeMap;
00131 
00132 private:
00133 
00138   MKGraph(const MKGraph &);
00139   
00140 };
00141 
00143 inline const lemon::ListDigraph &MKGraph::get_graph() const
00144 {
00145   return mkGraph;
00146 }
00147 
00149 inline lemon::ListDigraph &MKGraph::get_graph()
00150 {
00151   return mkGraph;
00152 }
00153 
00155 inline GraphNode *MKGraph::root_node() const
00156 {
00157   return rootNode;
00158 }
00159 
00161 inline GraphNode *MKGraph::leaf_node() const
00162 {
00163   return leafNode;
00164 }
00165   
00167 inline const lemon::ListDigraph::NodeMap<GraphNode*> &MKGraph::node_map() const
00168 {
00169   return nodeMap;
00170 }
00171   
00173 inline lemon::ListDigraph::NodeMap<GraphNode*> &MKGraph::node_map() 
00174 {
00175   return nodeMap;
00176 }
00177   
00179 inline GraphNode *MKGraph::get_node(lemon::ListDigraph::Node node) const
00180 {
00181   return nodeMap[node];
00182 }
00183   
00184 inline GraphNode *MKGraph::source(lemon::ListDigraph::Arc arc) const
00185 {
00186   return nodeMap[mkGraph.source(arc)];
00187 }
00188 
00189 inline GraphNode *MKGraph::target(lemon::ListDigraph::Arc arc) const
00190 {
00191   return nodeMap[mkGraph.target(arc)];
00192 }
00193   
00195 inline void MKGraph::setup_and_execute() 
00196 {
00197   setup();
00198   
00199   execute();
00200 }
00201 
00202 } // namespace MeshKit
00203 
00204 #endif
00205 
00206   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines