1 #ifndef ROSE_GraphUtility_H
2 #define ROSE_GraphUtility_H
4 #include <boost/cstdint.hpp>
5 #include <Sawyer/Graph.h>
10 namespace GraphUtility {
19 boost::uint32_t n = 0;
20 output.write((
const char*)&n, 4);
22 n = graph.nVertices();
23 output.write((
const char*)&n, 4);
26 output.write((
const char*)&n, 4);
28 for (
size_t i=0; i<graph.nVertices(); ++i) {
29 typename Graph::ConstVertexIterator vertex = graph.findVertex(i);
30 vertex->value().serialize(output);
33 for (
size_t i=0; i<graph.nEdges(); ++i) {
34 typename Graph::ConstEdgeIterator edge = graph.findEdge(i);
35 n = edge->source()->id();
36 output.write((
const char*)&n, 4);
37 n = edge->target()->id();
38 output.write((
const char*)&n, 4);
39 edge->value().serialize(output);
45 deserialize(std::istream &input, Graph &graph)
50 input.read((
char*)&n, 4);
51 ASSERT_require2(n==0,
"incorrect version number");
53 input.read((
char*)&n, 4);
56 input.read((
char*)&n, 4);
59 for (
size_t i=0; i<nverts; ++i) {
60 typename Graph::VertexIterator vertex = graph.insertVertex();
61 ASSERT_require2(vertex->id()==i,
"unexpected vertex numbering");
62 vertex->value().deserialize(input);
65 for (
size_t i=0; i<nedges; ++i) {
66 input.read((
char*)&n, 4);
67 typename Graph::VertexIterator source = graph.findVertex(n);
68 input.read((
char*)&n, 4);
69 typename Graph::VertexIterator target = graph.findVertex(n);
70 typename Graph::EdgeIterator edge = graph.insertEdge(source, target);
71 ASSERT_require2(edge->id()==i,
"unexpected edge numbering");
72 edge->value().deserialize(input);