src/work/peter/xy-reader.cc
changeset 1299 e2545ef5d7d8
parent 1278 4abea330614d
equal deleted inserted replaced
1:956e029c9089 2:5584cdf57c39
    12 
    12 
    13 typedef ListGraph Graph;
    13 typedef ListGraph Graph;
    14 typedef xy<double> Coordinates;
    14 typedef xy<double> Coordinates;
    15 typedef Graph::NodeMap<Coordinates> CoordinatesMap;
    15 typedef Graph::NodeMap<Coordinates> CoordinatesMap;
    16 typedef Graph::Node Node;
    16 typedef Graph::Node Node;
       
    17 typedef Graph::EdgeIt EdgeIt;
       
    18 typedef Graph::NodeIt NodeIt;
    17 
    19 
    18 class CoordReaderMap: public MapBase<Node, double>
    20 class CoordReaderMap: public MapBase <Node, double>
    19 {
    21 {
    20     CoordinatesMap * cm;
    22     CoordinatesMap & cm;
    21     char xoy;
    23     char xoy;
    22 
    24 
    23 public:
    25 public:
    24     CoordReaderMap(char xory, CoordinatesMap * coordmap): cm(coordmap)
    26     CoordReaderMap(char xory, CoordinatesMap & coordmap): cm(coordmap)
    25     {
    27     {
    26 	switch(xory)
    28 	switch(xory)
    27 	{
    29 	{
    28 	    case 'x':
    30 	    case 'x':
    29 	    case 'y':
    31 	    case 'y':
    37     void set(Node node, double coord)
    39     void set(Node node, double coord)
    38     {
    40     {
    39 	switch(xoy)
    41 	switch(xoy)
    40 	{
    42 	{
    41 	    case 'x':
    43 	    case 'x':
    42 		(*cm)[node].x=coord;
    44 		cm[node].x=coord;
    43 		break;
    45 		break;
    44 	    case 'y':
    46 	    case 'y':
    45 		(*cm)[node].y=coord;
    47 		cm[node].y=coord;
    46 		break;
    48 		break;
    47 	    default:
    49 	    default:
    48 		throw UninitializedParameter() ;
    50 		throw UninitializedParameter() ;
    49 	}
    51 	}
    50     }
    52     }
    53 int main(void)
    55 int main(void)
    54 {
    56 {
    55     Graph g;
    57     Graph g;
    56     CoordinatesMap cm(g);
    58     CoordinatesMap cm(g);
    57 
    59 
    58     CoordReaderMap xreader('x',&cm);
    60     CoordReaderMap xreader('x',cm);
    59     CoordReaderMap yreader('y',&cm);
    61     CoordReaderMap yreader('y',cm);
    60 
    62 
    61     std::ifstream is("dijkstra_test.lemon");
    63     std::ifstream is("graphocska.lemon");
    62     
    64     
    63     GraphReader<Graph> reader(is, g);
    65     GraphReader<Graph> reader(is, g);
    64     reader.addNodeMap("coordinates_x", xreader);
    66     reader.addNodeMap("coordinates_x", xreader);
    65     reader.addNodeMap("coordinates_y", yreader);
    67     reader.addNodeMap("coordinates_y", yreader);
    66     reader.run();
    68     reader.run();
    67     
    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 
    68     return 0;
    75     return 0;
    69 }
    76 }