# HG changeset patch # User alpar # Date 1099991555 0 # Node ID c0fdb1ad8e8d903c4ccfee1034aec3d61420e656 # Parent 643d3192ebc8ed5ff4da47bf8b7d51b513b18811 A graph reader interface proposal diff -r 643d3192ebc8 -r c0fdb1ad8e8d src/work/alpar/file-reader.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/alpar/file-reader.cc Tue Nov 09 09:12:35 2004 +0000 @@ -0,0 +1,122 @@ +#include +#include +#include + +using namespace lemon; + +template +class Reader +{ + +public: + typedef GR Graph; + typedef typename Graph::Node Node; + typedef typename Graph::Edge Edge; + + ///A beolvasando ertekek tipusa. + + ///Ebben gyakorlatilag egy stringet tarolunk. + ///Tovabba ez egy olyan tipus, amitol elvarjuk, hogy konvertalodjon + ///a beolvasando mapok Value-jara. + class InputValue + { + public: + operator int() const { return 0; } + operator double() const { return 0; } + }; + + ///Ez adja a mapok kozos interface-et. + class WrapEdgeMapBase + { + public: + virtual void set(Edge n,const InputValue &v) = 0; + virtual ~WrapEdgeMapBase() {} + }; + + ///Ez meg becsomagol egy mapot a kozos formara. + template + class WrapEdgeMap : public WrapEdgeMapBase + { + M ↦ + + public: + WrapEdgeMap(M &m) : map(m) {} + void set(Edge n,const InputValue &v) {map.set(n,v);} + }; + + ///Ebben a strukturaban adunk meg egy feltoltendo mapot. + struct EdgeMapDesc + { + std::string name; + int column; + WrapEdgeMapBase *map; + + template EdgeMapDesc(char *n,M &m) : name(n), map(&m) {} + ~EdgeMapDesc() {} + }; + + ///Itt vannak felsorolva a feltoltendo mapok + std::list EdgeMaps; + + ///Ezzel lehet egy mapot hozzaadni a feltoltendok listajahoz. + template void addEdgeMap(char *name,M &map) + { + EdgeMaps.push_back(EdgeMapDesc(name,*(new WrapEdgeMap(map)))); + } + + ///Ez meg kiuriti a map-listat. + void removeEdgeMaps() + { + while(EdgeMaps.begin()!=EdgeMaps.end()) { + //Ez igy OK?: + delete EdgeMaps.begin()->map; + EdgeMaps.pop_front(); + } + } + + //Esetleg stream a file-nev helyett... + Reader(char *file,Graph &G) + { + removeEdgeMaps(); + } + + ///Ez inditja a beolvasast. + void read() + { + //Ez olvassa be/vegig a file-t. + } + + ~Reader() + { + //Ez kell!!! + removeEdgeMaps(); + } + +}; + +class SumMap : public MapBase +{ + double sum; +public: + SumMap() : sum(0) {} + void set(ListGraph::Edge e,double d) + { + sum+=d; + } + double getSum() { return sum; } +}; + +int main() +{ + ListGraph g; //Kis g!!! + ListGraph::EdgeMap cost(g); + ListGraph::EdgeMap channels(g); + + SumMap sum_cost; //Ez egy sajat "custom" irhato map + + Reader r("file_name.lgf",g); + r.addEdgeMap("cost",cost); + r.addEdgeMap("channels",channels); + r.addEdgeMap("cost",sum_cost); + r.read(); +}