File: adjacency_list_io.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (113 lines) | stat: -rw-r--r-- 2,667 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//  (C) Copyright Francois Faure 2001
//  Distributed under the Boost Software License, Version 1.0. (See
//  accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

#include <boost/config.hpp>

#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
#error adjacency_list_io.hpp has not been ported to work with VC++
#endif

#include <boost/graph/adjacency_list_io.hpp>
#include <fstream>

using namespace boost;

//======== my data structure
struct MyStruct
{
    double value;
};
std::ostream& operator<<(std::ostream& out, const MyStruct& s)
{
    out << s.value << " ";
    return out;
}
std::istream& operator>>(std::istream& in, MyStruct& s)
{
    in >> s.value;
    return in;
}

//======== vertex properties
struct n1_t
{
    enum
    {
        num = 23063
    };
    typedef vertex_property_tag kind;
};
struct n2_t
{
    enum
    {
        num = 23062
    };
    typedef vertex_property_tag kind;
};
struct n3_t
{
    enum
    {
        num = 23061
    };
    typedef vertex_property_tag kind;
};
typedef property< n1_t, int,
    property< n2_t, double, property< n3_t, MyStruct > > >
    VertexProperty;

//====== edge properties
struct e1_t
{
    enum
    {
        num = 23064
    };
    typedef edge_property_tag kind;
};
typedef property< e1_t, double > EdgeProperty;

//===== graph types

typedef adjacency_list< vecS, listS, directedS, no_property, no_property >
    Graph1;

typedef adjacency_list< setS, setS, bidirectionalS, VertexProperty,
    EdgeProperty >
    Graph2;

int main()
{
    // read Graph1
    Graph1 g1;
    std::ifstream readFile1("data1.txt");
    readFile1 >> read(g1);
    std::cout << "graph g1 from file data1.txt:\n" << write(g1) << std::endl;

    // read Graph2 and all internal properties
    Graph2 g2;
    std::ifstream readFile2("data2.txt");
    readFile2 >> read(g2);
    std::cout << "graph g2 from file data2.txt:\n" << write(g2) << std::endl;

    // read Graph2, no property given. Write no property.
    Graph2 g21;
    std::ifstream readFile21("data1.txt");
    readFile21 >> read(g21, no_property(), no_property());
    std::cout << "graph g21 from file data1.txt:\n"
              << write(g21, no_property(), no_property()) << std::endl;

    // read Graph2, incomplete data in a different order. Write it diffently.
    Graph2 g31;
    std::ifstream readFile31("data3.txt");
    typedef property< n3_t, MyStruct, property< n1_t, int > > readNodeProp;
    readFile31 >> read(g31, readNodeProp(), EdgeProperty());
    std::cout << "graph g31 from file data3.txt:\n"
              << write(g31, property< n3_t, MyStruct >(), EdgeProperty())
              << std::endl;

    return 0;
}