6 # include <tpl_graph.H>
16 void operator () (ofstream & output, GT &,
typename GT::Node * p)
18 output.write((
char*) &p->get_info(),
sizeof(
typename GT::Node_Type));
21 void operator () (ostream & output, GT &,
typename GT::Node * p)
23 output << p->get_info() << endl;
30 void operator () (ofstream & output, GT &,
typename GT::Arc * a)
32 output.write((
char*) &a->get_info(),
sizeof(
typename GT::Arc_Type));
35 void operator () (ostream & output, GT &,
typename GT::Arc * a)
37 output << a->get_info() << endl;
44 void operator () (ifstream & input, GT &,
typename GT::Node * p)
46 input.read((
char*) &p->get_info(),
sizeof(
typename GT::Node_Type));
49 void operator () (istream & input, GT &,
typename GT::Node * p)
51 input >> p->get_info();
58 void operator () (ifstream & input, GT &,
typename GT::Arc * a)
60 input.read((
char*) &a->get_info(),
sizeof(
typename GT::Arc_Type));
63 void operator () (istream & input, GT &,
typename GT::Arc * a)
65 input >> a->get_info();
142 const size_t num_nodes = g.get_num_nodes();
145 cout <<
"Storing " << num_nodes <<
" nodes ... ";
147 output.write((
const char*) &num_nodes,
sizeof(num_nodes));
156 typename GT::Node * p = it.get_current();
161 Store_Node () (output, g, p);
166 const size_t num_arcs = g.get_num_arcs();
169 cout <<
" done " << endl
170 <<
"Storing " << num_arcs <<
" arcs ... " << endl;
172 output.write((
const char*) &num_arcs,
sizeof(num_arcs));
176 typename GT::Arc * a = it.get_current();
178 typename GT::Node * src = g.get_src_node(a);
179 typename GT::Node * tgt = g.get_tgt_node(a);
181 const int & src_idx = nodes_table.
find(src);
182 const int & tgt_idx = nodes_table.
find(tgt);
185 output.write((
const char*) &src_idx,
sizeof(
int));
186 output.write((
const char*) &tgt_idx,
sizeof(
int));
189 cout <<
" " << src_idx <<
"--" << tgt_idx <<
" ";
191 Store_Arc () (output, g, a);
198 cout <<
" done " << endl << endl;
206 input.read((
char *) &num_nodes,
sizeof(num_nodes));
209 cout <<
"Loading " << num_nodes <<
" nodes ...";
212 nodes_table.
reserve(0, num_nodes - 1);
214 for (
size_t i = 0; i < num_nodes; ++i)
216 typename GT::Node * p =
new typename GT::Node;
221 Load_Node () (input, g, p);
223 p = g.insert_node(p);
224 nodes_table.
access(i) = p;
228 input.read((
char *) &num_arcs,
sizeof(num_arcs));
231 cout <<
" done " << endl
232 <<
"Loading " << num_arcs <<
" arcs ... " << endl;
234 for (
int i = 0; i < num_arcs; ++i)
237 input.read((
char*) &src_idx,
sizeof(
int));
238 typename GT::Node * src = nodes_table.
access(src_idx);
241 input.read((
char*) &tgt_idx,
sizeof(
int));
242 typename GT::Node * tgt = nodes_table.
access(tgt_idx);
244 typename GT::Arc * a = g.insert_arc(src, tgt);
247 cout <<
" " << src_idx <<
"--" << tgt_idx <<
" ";
249 Load_Arc () (input, g, a);
256 cout <<
" done " << endl << endl;
263 const size_t num_nodes = g.get_num_nodes();
264 const size_t num_arcs = g.get_num_arcs();
265 output << num_nodes << endl
269 cout <<
"Storing " << num_nodes <<
" nodes ... ";
278 typename GT::Node * p = it.get_current();
283 Store_Node () (output, g, p);
289 cout <<
" done " << endl
290 <<
"Storing " << num_arcs <<
" arcs ... " << endl;
294 typename GT::Arc * a = it.get_current();
296 typename GT::Node * src = g.get_src_node(a);
297 typename GT::Node * tgt = g.get_tgt_node(a);
299 const int & src_idx = nodes_table.
find(src);
300 const int & tgt_idx = nodes_table.
find(tgt);
303 output << src_idx <<
" " << tgt_idx <<
" ";
306 cout <<
" " << src_idx <<
"--" << tgt_idx <<
" ";
308 Store_Arc () (output, g, a);
315 cout <<
" done " << endl << endl;
326 input >> num_nodes >> num_arcs;
329 cout <<
"Loading " << num_nodes <<
" nodes ...";
332 nodes_table.
reserve(0, num_nodes - 1);
334 for (
size_t i = 0; i < num_nodes; ++i)
336 typename GT::Node * p =
new typename GT::Node;
341 Load_Node () (input, g, p);
343 p = g.insert_node(p);
344 nodes_table.
access(i) = p;
348 cout <<
" done " << endl
349 <<
"Loading " << num_arcs <<
" arcs ... " << endl;
351 for (
int i = 0; i < num_arcs; ++i)
356 input >> src_idx >> tgt_idx;
358 typename GT::Node * src = nodes_table.
access(src_idx);
359 typename GT::Node * tgt = nodes_table.
access(tgt_idx);
361 typename GT::Arc * a = g.insert_arc(src, tgt);
364 cout <<
" " << src_idx <<
"--" << tgt_idx <<
" ";
366 Load_Arc () (input, g, a);
373 cout <<
" done " << endl << endl;
379 # endif // IO_GRAPH_H
Definition: io_graph.H:125
void reserve(const size_t l, const size_t r)
Definition: tpl_dynArray.H:960
Definition: io_graph.H:42
Definition: io_graph.H:28
Definition: io_graph.H:56
Definition: tpl_graph.H:751
Definition: tpl_graph.H:794
IO_Graph(GT *gptr)
Constructor con puntero a grafo.
Definition: io_graph.H:136
Definition: io_graph.H:14
void save_in_text_mode(ostream &output)
Guarda el grafo en el stream output.
Definition: io_graph.H:260
Definition: tpl_graph.H:634
void next()
Adelanta el iterador una posición.
Definition: filter_iterator.H:143
void load(ifstream &input)
Carga el grafo desde el stream output.
Definition: io_graph.H:202
IO_Graph(GT &__g)
Constructor con referencia a grafo.
Definition: io_graph.H:133
void save(ofstream &output)
Guarda el grafo en el stream output.
Definition: io_graph.H:139
Definition: tpl_dynMapTree.H:289
Definition: tpl_graph.H:814
T & access(const size_t i)
Definition: tpl_dynArray.H:793
Key * insert(const Key &key, const Type &data)
Definition: tpl_dynMapTree.H:74
void load_in_text_mode(istream &input)
Carga el grafo desde el stream intput.
Definition: io_graph.H:320
Type & find(const Key &key)
Definition: tpl_dynMapTree.H:223