1 # ifndef TPL_DYN_GRAPH_H
2 # define TPL_DYN_GRAPH_H
4 # include <tpl_agraph.H>
21 typedef typename GT::Node Node;
23 typedef typename GT::Arc Arc;
25 typedef typename Node::Node_Info Node_Info;
27 typedef typename Arc::Arc_Info Arc_Info;
31 static Node * info_to_node(Node_Info & info)
34 long off_set = (long) &node_zero->get_info();
35 long ptr_info = (long) &info;
36 return (Node *) (ptr_info - off_set);
39 static Arc * info_to_arc(Arc_Info & info)
42 long off_set = (long) &arc_zero->get_info();
43 long ptr_info = (long) &info;
44 return (Arc *) (ptr_info - off_set);
65 : graph(std::move(g.graph))
78 Node * node = graph.insert_node(
new Node(info));
79 return node->get_info();
89 Node * node = graph.insert_node(
new Node(std::move(info)));
90 return node->get_info();
103 Arc_Info &
insert_arc(Node_Info & src_info, Node_Info & tgt_info,
104 const Arc_Info & info)
106 Node * src = info_to_node(src_info);
107 Node * tgt = info_to_node(tgt_info);
108 Arc * arc = graph.insert_arc(src, tgt);
109 arc->get_info() = info;
110 return arc->get_info();
124 Arc_Info &
insert_arc(Node_Info & src_info, Node_Info & tgt_info,
125 Arc_Info && info = Arc_Info())
127 Node * src = info_to_node(src_info);
128 Node * tgt = info_to_node(tgt_info);
129 Arc * arc = graph.insert_arc(src, tgt);
130 arc->get_info() = std::move(info);
131 return arc->get_info();
141 Arc * arc = info_to_arc(info);
142 Node * src = graph.get_src_node(arc);
143 return src->get_info();
153 Arc * arc = info_to_arc(info);
154 Node * tgt = graph.get_tgt_node(arc);
155 return tgt->get_info();
158 Node_Info & get_connected_node(Node_Info & node_info, Arc_Info & arc_info)
160 Node * node = info_to_node(node_info);
161 Arc * arc = info_to_arc(arc_info);
162 Node * connected_node(node, arc);
163 return connected_node->get_info();
172 Arc * arc = info_to_arc(info);
173 graph.remove_arc(arc);
182 Node * node = info_to_node(info);
183 graph.remove_node(node);
192 return graph.get_num_nodes();
201 return graph.get_num_arcs();
211 Node * node = info_to_node(info);
212 return graph.get_num_arcs(node);
216 # define GRAPH_SPECIALIZATION(G, N, A) \
217 template <typename Node_Info, typename Arc_Info> \
218 class Dyn_##G : public Dyn_Graph<G<N<Node_Info>, A<Arc_Info>>> \
220 typedef G<N<Node_Info>, A<Arc_Info>> Graph_Type; \
224 : Dyn_Graph <Graph_Type>() { } \
226 Dyn_##G(const Dyn_##G & g) \
227 : Dyn_Graph <Graph_Type>(g) { } \
229 Dyn_##G(Dyn_##G && g) \
230 : Dyn_Graph <Graph_Type>(std::move(g)) { } \
239 # endif // TPL_DYN_GRAPH_H
Node_Info & insert_node(const Node_Info &info)
Definition: tpl_dyn_graph.H:76
Definition: tpl_graph.H:29
Dyn_Graph()
Constructor por omisión.
Definition: tpl_dyn_graph.H:52
Definition: tpl_graph.H:21
Arc_Info & insert_arc(Node_Info &src_info, Node_Info &tgt_info, const Arc_Info &info)
Definition: tpl_dyn_graph.H:103
const size_t & get_num_nodes() const
Definition: tpl_dyn_graph.H:190
const size_t & get_num_arcs(Node_Info &info) const
Definition: tpl_dyn_graph.H:209
Node_Info & insert_node(Node_Info &&info=Node_Info())
Definition: tpl_dyn_graph.H:87
Node_Info & get_tgt_node(Arc_Info &info)
Definition: tpl_dyn_graph.H:151
Arc_Info & insert_arc(Node_Info &src_info, Node_Info &tgt_info, Arc_Info &&info=Arc_Info())
Definition: tpl_dyn_graph.H:124
void remove_arc(Arc_Info &info)
Definition: tpl_dyn_graph.H:170
Node_Info & get_src_node(Arc_Info &info)
Definition: tpl_dyn_graph.H:139
void remove_node(Node_Info &info)
Definition: tpl_dyn_graph.H:180
const size_t & get_num_arcs() const
Definition: tpl_dyn_graph.H:199
Definition: tpl_graph.H:19
Definition: tpl_graph.H:32
Definition: tpl_dyn_graph.H:17