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