COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/peter/xy-reader.cc @ 1278:4abea330614d

Last change on this file since 1278:4abea330614d was 1278:4abea330614d, checked in by Alpar Juttner, 15 years ago

Correct MapBase? usage.

File size: 1.2 KB
Line 
1#include <fstream>
2#include <iostream>
3
4#include <lemon/xy.h>
5#include <lemon/maps.h>
6#include <lemon/error.h>
7#include <lemon/list_graph.h>
8#include <lemon/graph_reader.h>
9#include <lemon/graph_utils.h>
10
11using namespace lemon;
12
13typedef ListGraph Graph;
14typedef xy<double> Coordinates;
15typedef Graph::NodeMap<Coordinates> CoordinatesMap;
16typedef Graph::Node Node;
17
18class CoordReaderMap: public MapBase<Node, double>
19{
20    CoordinatesMap * cm;
21    char xoy;
22
23public:
24    CoordReaderMap(char xory, CoordinatesMap * coordmap): cm(coordmap)
25    {
26        switch(xory)
27        {
28            case 'x':
29            case 'y':
30                xoy=xory;
31                break;
32            default:
33                throw UninitializedParameter() ;
34        }
35    }
36
37    void set(Node node, double coord)
38    {
39        switch(xoy)
40        {
41            case 'x':
42                (*cm)[node].x=coord;
43                break;
44            case 'y':
45                (*cm)[node].y=coord;
46                break;
47            default:
48                throw UninitializedParameter() ;
49        }
50    }
51};
52
53int main(void)
54{
55    Graph g;
56    CoordinatesMap cm(g);
57
58    CoordReaderMap xreader('x',&cm);
59    CoordReaderMap yreader('y',&cm);
60
61    std::ifstream is("dijkstra_test.lemon");
62   
63    GraphReader<Graph> reader(is, g);
64    reader.addNodeMap("coordinates_x", xreader);
65    reader.addNodeMap("coordinates_y", yreader);
66    reader.run();
67   
68    return 0;
69}
Note: See TracBrowser for help on using the repository browser.