src/work/alpar/rw_nonref_map.cc
author beckerjc
Sat, 17 Apr 2004 19:19:57 +0000
changeset 349 42c660f58702
child 351 01fb9da7a363
permissions -rw-r--r--
Kruskal lenyegeben kesz.
Kell meg dokumentalni, meg meg egy par jol hasznalhato wrapper fv.
Es valamit meg kene csinalni azzal, hogy nem const ref. a kimeno boolmap,
viszont sokszor "on-the-fly" akarjuk megkonstrualni (es ilyenkor persze a
const-os mapet is lehet set-elni...)
alpar@342
     1
#include <iostream>
alpar@342
     2
#include <smart_graph.h>
alpar@342
     3
alpar@342
     4
using namespace hugo;
alpar@342
     5
alpar@342
     6
template<class GG,class TT>
alpar@342
     7
class CinCoutMap
alpar@342
     8
{
alpar@342
     9
public:
alpar@342
    10
  typedef GG Graph;
alpar@342
    11
  typedef typename GG::Edge Edge;
alpar@342
    12
  
alpar@342
    13
  typedef Edge KeyType;
alpar@342
    14
  typedef TT ValueType;
alpar@342
    15
  
alpar@342
    16
  class RefType 
alpar@342
    17
  {
alpar@342
    18
    Graph &G;
alpar@342
    19
    Edge e;
alpar@342
    20
  public:
alpar@342
    21
    RefType(Graph &_G,Edge _e) : G(_G), e(_e) { }
alpar@342
    22
    
alpar@342
    23
    operator ValueType() const 
alpar@342
    24
    {
alpar@342
    25
      ValueType tmp;
alpar@342
    26
      std::cout << G.id(G.tail(e)) << "->"
alpar@342
    27
		<< G.id(G.head(e)) << ": ";
alpar@342
    28
      std::cin  >> tmp;
alpar@342
    29
      return tmp;
alpar@342
    30
    }
alpar@342
    31
    ValueType operator = (ValueType v) const
alpar@342
    32
    {
alpar@342
    33
      std::cout << G.id(G.tail(e)) << "->"
alpar@342
    34
		<< G.id(G.head(e)) << ": " << v << '\n';
alpar@342
    35
      return v;
alpar@342
    36
    }
alpar@342
    37
  };
alpar@342
    38
  
alpar@342
    39
private:
alpar@342
    40
  Graph &G;
alpar@342
    41
public:
alpar@342
    42
  CinCoutMap(Graph &_G) : G(_G) { }
alpar@342
    43
  RefType operator[] (Edge e) const { return RefType(G,e);}  
alpar@342
    44
};
alpar@342
    45
alpar@342
    46
int main()
alpar@342
    47
{
alpar@342
    48
  typedef SmartGraph Graph;
alpar@342
    49
  typedef Graph::NodeIt NodeIt;
alpar@342
    50
  typedef Graph::OutEdgeIt OutEdgeIt;
alpar@342
    51
  typedef Graph::EdgeIt EdgeIt;
alpar@342
    52
  
alpar@342
    53
  Graph G;
alpar@342
    54
alpar@342
    55
  CinCoutMap<Graph,int> map(G);
alpar@342
    56
alpar@342
    57
  Graph::EdgeMap<int> emap(G);
alpar@342
    58
  
alpar@342
    59
  for(int i=0;i<3;i++) G.addNode();
alpar@342
    60
alpar@342
    61
  for(NodeIt n(G);G.valid(n);G.next(n))
alpar@342
    62
    for(NodeIt m(G);G.valid(m);G.next(m)) if(n!=m)
alpar@342
    63
      G.addEdge(n,m);
alpar@342
    64
alpar@342
    65
  //for(OutEdgeIt e(G,NodeIt(G));G.valid(e);G.next(e))
alpar@342
    66
    
alpar@342
    67
  for(EdgeIt e(G);G.valid(e);G.next(e)) emap[e] = map[e];
alpar@342
    68
  
alpar@342
    69
  std::cout << '\n';
alpar@342
    70
  
alpar@342
    71
  for(EdgeIt e(G);G.valid(e);G.next(e))  map[e] = emap[e];
alpar@342
    72
alpar@342
    73
}
alpar@342
    74