COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/alpar/rw_nonref_map.cc @ 918:bb77eaa8fa0e

Last change on this file since 918:bb77eaa8fa0e was 351:01fb9da7a363, checked in by Alpar Juttner, 21 years ago

NullMap?

File size: 1.8 KB
Line 
1#include <iostream>
2#include <smart_graph.h>
3
4using namespace hugo;
5
6template<class GG,class TT>
7class CinCoutMap
8{
9public:
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 
39private:
40  Graph &G;
41public:
42  CinCoutMap(Graph &_G) : G(_G) { }
43  RefType operator[] (Edge e) const { return RefType(G,e);} 
44};
45
46template<class K,class T>
47class NullMap
48{
49public:
50  typedef K KeyType;
51  typedef T ValueType;
52 
53  class RefType
54  {
55    ValueType val;
56  public:
57    RefType(ValueType v) : val(v) { }   
58    operator ValueType() const { return val; }
59    ValueType operator = (ValueType v) const { return val; }
60  };
61 
62private:
63  ValueType val;
64public:
65  NullMap(ValueType v) : val(v) { }
66  RefType operator[] (KeyType e) const { return RefType(v);} 
67};
68
69int main()
70{
71  typedef SmartGraph Graph;
72  typedef Graph::NodeIt NodeIt;
73  typedef Graph::OutEdgeIt OutEdgeIt;
74  typedef Graph::EdgeIt EdgeIt;
75 
76  Graph G;
77
78  CinCoutMap<Graph,int> map(G);
79
80  Graph::EdgeMap<int> emap(G);
81 
82  for(int i=0;i<3;i++) G.addNode();
83
84  for(NodeIt n(G);G.valid(n);G.next(n))
85    for(NodeIt m(G);G.valid(m);G.next(m)) if(n!=m)
86      G.addEdge(n,m);
87
88  //for(OutEdgeIt e(G,NodeIt(G));G.valid(e);G.next(e))
89   
90  for(EdgeIt e(G);G.valid(e);G.next(e)) emap[e] = map[e];
91 
92  std::cout << '\n';
93 
94  for(EdgeIt e(G);G.valid(e);G.next(e))  map[e] = emap[e];
95
96}
97
Note: See TracBrowser for help on using the repository browser.