src/work/alpar/rw_nonref_map.cc
changeset 347 e4ab32225f1c
child 351 01fb9da7a363
equal deleted inserted replaced
-1:000000000000 0:c3d56e14401d
       
     1 #include <iostream>
       
     2 #include <smart_graph.h>
       
     3 
       
     4 using namespace hugo;
       
     5 
       
     6 template<class GG,class TT>
       
     7 class CinCoutMap
       
     8 {
       
     9 public:
       
    10   typedef GG Graph;
       
    11   typedef typename GG::Edge Edge;
       
    12   
       
    13   typedef Edge KeyType;
       
    14   typedef TT ValueType;
       
    15   
       
    16   class RefType 
       
    17   {
       
    18     Graph &G;
       
    19     Edge e;
       
    20   public:
       
    21     RefType(Graph &_G,Edge _e) : G(_G), e(_e) { }
       
    22     
       
    23     operator ValueType() const 
       
    24     {
       
    25       ValueType tmp;
       
    26       std::cout << G.id(G.tail(e)) << "->"
       
    27 		<< G.id(G.head(e)) << ": ";
       
    28       std::cin  >> tmp;
       
    29       return tmp;
       
    30     }
       
    31     ValueType operator = (ValueType v) const
       
    32     {
       
    33       std::cout << G.id(G.tail(e)) << "->"
       
    34 		<< G.id(G.head(e)) << ": " << v << '\n';
       
    35       return v;
       
    36     }
       
    37   };
       
    38   
       
    39 private:
       
    40   Graph &G;
       
    41 public:
       
    42   CinCoutMap(Graph &_G) : G(_G) { }
       
    43   RefType operator[] (Edge e) const { return RefType(G,e);}  
       
    44 };
       
    45 
       
    46 int main()
       
    47 {
       
    48   typedef SmartGraph Graph;
       
    49   typedef Graph::NodeIt NodeIt;
       
    50   typedef Graph::OutEdgeIt OutEdgeIt;
       
    51   typedef Graph::EdgeIt EdgeIt;
       
    52   
       
    53   Graph G;
       
    54 
       
    55   CinCoutMap<Graph,int> map(G);
       
    56 
       
    57   Graph::EdgeMap<int> emap(G);
       
    58   
       
    59   for(int i=0;i<3;i++) G.addNode();
       
    60 
       
    61   for(NodeIt n(G);G.valid(n);G.next(n))
       
    62     for(NodeIt m(G);G.valid(m);G.next(m)) if(n!=m)
       
    63       G.addEdge(n,m);
       
    64 
       
    65   //for(OutEdgeIt e(G,NodeIt(G));G.valid(e);G.next(e))
       
    66     
       
    67   for(EdgeIt e(G);G.valid(e);G.next(e)) emap[e] = map[e];
       
    68   
       
    69   std::cout << '\n';
       
    70   
       
    71   for(EdgeIt e(G);G.valid(e);G.next(e))  map[e] = emap[e];
       
    72 
       
    73 }
       
    74