src/work/peter/xy-reader.cc
author athos
Thu, 07 Apr 2005 10:19:10 +0000
changeset 1315 c91ae3600eea
parent 1278 4abea330614d
permissions -rw-r--r--
A sample file.
     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 
    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;
    17 typedef Graph::EdgeIt EdgeIt;
    18 typedef Graph::NodeIt NodeIt;
    19 
    20 class CoordReaderMap: public MapBase <Node, double>
    21 {
    22     CoordinatesMap & cm;
    23     char xoy;
    24 
    25 public:
    26     CoordReaderMap(char xory, CoordinatesMap & coordmap): cm(coordmap)
    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':
    44 		cm[node].x=coord;
    45 		break;
    46 	    case 'y':
    47 		cm[node].y=coord;
    48 		break;
    49 	    default:
    50 		throw UninitializedParameter() ;
    51 	}
    52     }
    53 };
    54 
    55 int main(void)
    56 {
    57     Graph g;
    58     CoordinatesMap cm(g);
    59 
    60     CoordReaderMap xreader('x',cm);
    61     CoordReaderMap yreader('y',cm);
    62 
    63     std::ifstream is("graphocska.lemon");
    64     
    65     GraphReader<Graph> reader(is, g);
    66     reader.addNodeMap("coordinates_x", xreader);
    67     reader.addNodeMap("coordinates_y", yreader);
    68     reader.run();
    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 
    75     return 0;
    76 }