src/work/alpar/rw_nonref_map.cc
author athos
Thu, 06 May 2004 15:19:59 +0000
changeset 551 d167149bde95
parent 342 c98125b3f47c
child 921 818510fa3d99
permissions -rw-r--r--
Written hugo/ into includes.
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@351
    46
template<class K,class T>
alpar@351
    47
class NullMap
alpar@351
    48
{
alpar@351
    49
public:
alpar@351
    50
  typedef K KeyType;
alpar@351
    51
  typedef T ValueType;
alpar@351
    52
  
alpar@351
    53
  class RefType 
alpar@351
    54
  {
alpar@351
    55
    ValueType val;
alpar@351
    56
  public:
alpar@351
    57
    RefType(ValueType v) : val(v) { }   
alpar@351
    58
    operator ValueType() const { return val; }
alpar@351
    59
    ValueType operator = (ValueType v) const { return val; }
alpar@351
    60
  };
alpar@351
    61
  
alpar@351
    62
private:
alpar@351
    63
  ValueType val;
alpar@351
    64
public:
alpar@351
    65
  NullMap(ValueType v) : val(v) { }
alpar@351
    66
  RefType operator[] (KeyType e) const { return RefType(v);}  
alpar@351
    67
};
alpar@351
    68
alpar@342
    69
int main()
alpar@342
    70
{
alpar@342
    71
  typedef SmartGraph Graph;
alpar@342
    72
  typedef Graph::NodeIt NodeIt;
alpar@342
    73
  typedef Graph::OutEdgeIt OutEdgeIt;
alpar@342
    74
  typedef Graph::EdgeIt EdgeIt;
alpar@342
    75
  
alpar@342
    76
  Graph G;
alpar@342
    77
alpar@342
    78
  CinCoutMap<Graph,int> map(G);
alpar@342
    79
alpar@342
    80
  Graph::EdgeMap<int> emap(G);
alpar@342
    81
  
alpar@342
    82
  for(int i=0;i<3;i++) G.addNode();
alpar@342
    83
alpar@342
    84
  for(NodeIt n(G);G.valid(n);G.next(n))
alpar@342
    85
    for(NodeIt m(G);G.valid(m);G.next(m)) if(n!=m)
alpar@342
    86
      G.addEdge(n,m);
alpar@342
    87
alpar@342
    88
  //for(OutEdgeIt e(G,NodeIt(G));G.valid(e);G.next(e))
alpar@342
    89
    
alpar@342
    90
  for(EdgeIt e(G);G.valid(e);G.next(e)) emap[e] = map[e];
alpar@342
    91
  
alpar@342
    92
  std::cout << '\n';
alpar@342
    93
  
alpar@342
    94
  for(EdgeIt e(G);G.valid(e);G.next(e))  map[e] = emap[e];
alpar@342
    95
alpar@342
    96
}
alpar@342
    97