32 # include <tpl_graph.H> 42 void operator () (ofstream & output, GT &,
typename GT::Node * p)
44 output.write((
char*) &p->get_info(),
sizeof(
typename GT::Node_Type));
47 void operator () (ostream & output, GT &,
typename GT::Node * p)
49 output << p->get_info() << endl;
56 void operator () (ofstream & output, GT &,
typename GT::Arc * a)
58 output.write((
char*) &a->get_info(),
sizeof(
typename GT::Arc_Type));
61 void operator () (ostream & output, GT &,
typename GT::Arc * a)
63 output << a->get_info() << endl;
70 void operator () (ifstream & input, GT &,
typename GT::Node * p)
72 input.read((
char*) &p->get_info(),
sizeof(
typename GT::Node_Type));
75 void operator () (istream & input, GT &,
typename GT::Node * p)
77 input >> p->get_info();
84 void operator () (ifstream & input, GT &,
typename GT::Arc * a)
86 input.read((
char*) &a->get_info(),
sizeof(
typename GT::Arc_Type));
89 void operator () (istream & input, GT &,
typename GT::Arc * a)
91 input >> a->get_info();
145 class Load_Node = Dft_Load_Node<GT>,
146 class Store_Node = Dft_Store_Node<GT>,
147 class Load_Arc = Dft_Load_Arc<GT>,
148 class Store_Arc = Dft_Store_Arc<GT>,
155 Load_Node load_node = Load_Node();
156 Store_Node store_node = Store_Node();
157 Load_Arc load_arc = Load_Arc();
158 Store_Arc store_arc = Store_Arc();
160 NF node_filter = NF();
161 AF arc_filter = AF();
165 void set_load_node(
const Load_Node & ln) { load_node = ln; }
167 void set_store_node(
const Store_Node & sn) { store_node = sn; }
169 void set_load_arc(
const Load_Arc & la) { load_arc = la; }
171 void set_store_arc(
const Store_Arc & sa) { store_arc = sa; }
173 void set_node_filter(
const NF & nf) { node_filter = nf; }
175 void set_arc_filter(
const AF & af) { arc_filter = af; }
187 const size_t num_nodes = g.get_num_nodes();
190 cout <<
"Storing " << num_nodes <<
" nodes ... ";
192 output.write((
const char*) &num_nodes,
sizeof(num_nodes));
202 auto p = it.get_curr_ne();
207 store_node(output, g, p);
212 const size_t num_arcs = g.get_num_arcs();
215 cout <<
" done " << endl
216 <<
"Storing " << num_arcs <<
" arcs ... " << endl;
218 output.write((
const char*) &num_arcs,
sizeof(num_arcs));
222 auto a = it.get_curr_ne();
224 auto src = g.get_src_node(a);
225 auto tgt = g.get_tgt_node(a);
227 const auto & src_idx = nodes_table.
find(src);
228 const auto & tgt_idx = nodes_table.
find(tgt);
231 output.write((
const char*) &src_idx,
sizeof(
int));
232 output.write((
const char*) &tgt_idx,
sizeof(
int));
235 cout <<
" " << src_idx <<
"--" << tgt_idx <<
" ";
237 store_arc(output, g, a);
244 cout <<
" done " << endl << endl;
252 input.read((
char *) &num_nodes,
sizeof(num_nodes));
255 cout <<
"Loading " << num_nodes <<
" nodes ...";
258 nodes_table.
reserve(0, num_nodes - 1);
260 for (
size_t i = 0; i < num_nodes; ++i)
262 typename GT::Node * p =
new typename GT::Node;
267 load_node(input, g, p);
269 p = g.insert_node(p);
270 nodes_table.
access(i) = p;
274 input.read((
char *) &num_arcs,
sizeof(num_arcs));
277 cout <<
" done " << endl
278 <<
"Loading " << num_arcs <<
" arcs ... " << endl;
280 for (
int i = 0; i < num_arcs; ++i)
283 input.read((
char*) &src_idx,
sizeof(
int));
284 auto src = nodes_table.
access(src_idx);
287 input.read((
char*) &tgt_idx,
sizeof(
int));
288 auto tgt = nodes_table.
access(tgt_idx);
290 auto a = g.insert_arc(src, tgt);
293 cout <<
" " << src_idx <<
"--" << tgt_idx <<
" ";
295 load_arc(input, g, a);
302 cout <<
" done " << endl << endl;
308 const size_t num_nodes = g.get_num_nodes();
309 const size_t num_arcs = g.get_num_arcs();
310 output << num_nodes << endl
314 cout <<
"Storing " << num_nodes <<
" nodes ... ";
324 typename GT::Node * p = it.get_curr_ne();
329 store_node(output, g, p);
335 cout <<
" done " << endl
336 <<
"Storing " << num_arcs <<
" arcs ... " << endl;
340 auto a = it.get_curr_ne();
342 auto src = g.get_src_node(a);
343 auto tgt = g.get_tgt_node(a);
345 const auto & src_idx = nodes_table.
find(src);
346 const auto & tgt_idx = nodes_table.
find(tgt);
349 output << src_idx <<
" " << tgt_idx <<
" ";
352 cout <<
" " << src_idx <<
"--" << tgt_idx <<
" ";
354 store_arc(output, g, a);
361 cout <<
" done " << endl << endl;
371 input >> num_nodes >> num_arcs;
375 cout <<
"Loading " << num_nodes <<
" nodes ...";
378 nodes_table.
reserve(0, num_nodes -
size_t(1));
380 for (
size_t i = 0; i < num_nodes; ++i)
382 auto p =
new typename GT::Node;
387 load_node(input, g, p);
389 p = g.insert_node(p);
390 nodes_table.
access(i) = p;
394 cout <<
" done " << endl
395 <<
"Loading " << num_arcs <<
" arcs ... " << endl;
397 for (
int i = 0; i < num_arcs; ++i)
402 input >> src_idx >> tgt_idx;
404 auto src = nodes_table.
access(src_idx);
405 auto tgt = nodes_table.
access(tgt_idx);
406 auto a = g.insert_arc(src, tgt);
409 cout <<
" " << src_idx <<
"--" << tgt_idx <<
" ";
411 load_arc(input, g, a);
418 cout <<
" done " << endl << endl;
424 # endif // IO_GRAPH_H Definition: io_graph.H:151
void reserve(const size_t l, const size_t r)
Definition: tpl_dynArray.H:998
Definition: tpl_graph.H:1225
IO_Graph(GT &__g) noexcept
Constructor con referencia a grafo.
Definition: io_graph.H:178
Pair * insert(const Key &key, const Type &data)
Definition: tpl_dynMapTree.H:112
T & access(const size_t i) const noexcept
Definition: tpl_dynArray.H:874
Definition: tpl_graph.H:1257
IO_Graph(GT *gptr) noexcept
Constructor con puntero a grafo.
Definition: io_graph.H:181
void save_in_text_mode(ostream &output)
Guarda el grafo en el stream output.
Definition: io_graph.H:306
Definition: tpl_graph.H:1063
void load(ifstream &input)
Carga el grafo desde el stream output.
Definition: io_graph.H:248
void save(ofstream &output)
Guarda el grafo en el stream output.
Definition: io_graph.H:184
Definition: tpl_dynMapTree.H:357
Definition: tpl_graph.H:1270
Definition: tpl_dynArray.H:159
void load_in_text_mode(istream &input)
Carga el grafo desde el stream intput.
Definition: io_graph.H:365
Type & find(const Key &key)
Definition: tpl_dynMapTree.H:242