MeshKit  1.0
GraphNode.hpp
Go to the documentation of this file.
00001 #ifndef MESHKIT_GRAPH_NODE_HPP
00002 #define MESHKIT_GRAPH_NODE_HPP
00003 
00004 #include "lemon/list_graph.h"
00005 #include <string>
00006 
00007 namespace MeshKit {
00008 
00009 class MKGraph;
00010     
00020 class GraphNode
00021 {
00022 public:
00023 
00025 
00026   friend class MKGraph;
00027   
00029   GraphNode(const GraphNode &graph_node);
00030   
00032   GraphNode(MKGraph *graph);
00033 
00035   virtual ~GraphNode();
00036   
00038   MKGraph *get_graph() const;
00039 
00041   lemon::ListDigraph::Node get_node() const;
00042 
00044   lemon::ListDigraph::InArcIt in_arcs() const;
00045   
00047   lemon::ListDigraph::OutArcIt out_arcs() const;
00048 
00053   GraphNode *other_node(lemon::ListDigraph::Arc arc);
00054 
00056   virtual std::string get_name() const;
00057 
00059   virtual void set_name(std::string new_name);
00060 
00062   virtual void setup_this() = 0;
00063 
00065   virtual void execute_this() = 0;
00066 
00070   bool setup_called() const;
00071   
00075   void setup_called(bool flag);
00076   
00080   bool execute_called() const;
00081   
00085   void execute_called(bool flag);
00086   
00087 protected:
00089   MKGraph *mkGraph;
00090 
00092   lemon::ListDigraph::Node graphNode;
00093 
00095   std::string nodeName;
00096 
00098   bool setupCalled;
00099   
00101   bool executeCalled;
00102   
00103 private:
00104 };
00105 
00106 inline GraphNode::GraphNode(const GraphNode &node) 
00107         : mkGraph(node.get_graph()), nodeName(node.get_name()), 
00108           setupCalled(node.setup_called()), executeCalled(node.execute_called())
00109 {
00110     // create a node for this meshop
00111   graphNode = get_graph()->get_graph().addNode();
00112 
00113     // this is a copy; set in/out edges from copied node
00114   for (lemon::ListDigraph::InArcIt ait(get_graph()->get_graph(), node.get_node());
00115        ait != lemon::INVALID; ++ait) 
00116     get_graph()->get_graph().addArc(get_graph()->source(ait)->get_node(), graphNode);
00117   for (lemon::ListDigraph::OutArcIt ait(get_graph()->get_graph(), node.get_node());
00118        ait != lemon::INVALID; ++ait) 
00119     get_graph()->get_graph().addArc(graphNode, get_graph()->target(ait)->get_node());
00120 }
00121     
00122 inline GraphNode::GraphNode(MKGraph *graph) 
00123         : mkGraph(graph), nodeName(), setupCalled(false), executeCalled(false)
00124 {
00125     // create a Lemon node 
00126   graphNode = graph->get_graph().addNode();
00127 
00128     // set the nodemap value for this meshop
00129   graph->node_map()[graphNode] = this;
00130   
00131     // might not be root/leaf nodes yet, if this is a root or leaf node being created
00132   if (graph->root_node() && graph->leaf_node()) {
00133     graph->get_graph().addArc(graph->root_node()->get_node(), graphNode);
00134     graph->get_graph().addArc(graphNode, graph->leaf_node()->get_node());
00135   }
00136 }
00137 
00138 inline GraphNode::~GraphNode() 
00139 {
00140   get_graph()->node_map()[graphNode] = NULL;
00141   get_graph()->get_graph().erase(graphNode);
00142 }
00143 
00144 inline std::string GraphNode::get_name() const
00145 {
00146   return nodeName;
00147 }
00148 
00149 inline void GraphNode::set_name(std::string new_name)
00150 {
00151   nodeName = new_name;
00152 }
00153 
00154 inline lemon::ListDigraph::InArcIt GraphNode::in_arcs() const
00155 {
00156   return lemon::ListDigraph::InArcIt(get_graph()->get_graph(), graphNode);
00157 }
00158 
00159 inline lemon::ListDigraph::OutArcIt GraphNode::out_arcs() const
00160 {
00161   return lemon::ListDigraph::OutArcIt(get_graph()->get_graph(), graphNode);
00162 }
00163 
00164 inline MKGraph *GraphNode::get_graph() const
00165 {
00166   return mkGraph;
00167 }
00168 
00170 inline lemon::ListDigraph::Node GraphNode::get_node() const
00171 {
00172   return graphNode;
00173 }
00174 
00175 inline GraphNode *GraphNode::other_node(lemon::ListDigraph::Arc arc)
00176 {
00177   return get_graph()->other_node(arc, this);
00178 }
00179 
00181 inline bool GraphNode::setup_called() const
00182 {
00183   return setupCalled;
00184 }
00185 
00187 inline void GraphNode::setup_called(bool flag) {
00188   setupCalled = flag;
00189 }
00190 
00192 inline bool GraphNode::execute_called() const
00193 {
00194   return executeCalled;
00195 }
00196 
00198 inline void GraphNode::execute_called(bool flag) {
00199   executeCalled = flag;
00200 }
00201 
00202 } // namespace MeshKit
00203 
00204 #endif
00205 
00206   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines