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