COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/alpar/rw_nonref_map.cc @ 987:87f7c54892df

Last change on this file since 987:87f7c54892df was 987:87f7c54892df, checked in by Alpar Juttner, 20 years ago

Naming changes:

File size: 1.8 KB
Line 
1#include <iostream>
2#include <smart_graph.h>
3
4using namespace lemon;
5
6template<class GG,class TT>
7class CinCoutMap
8{
9public:
10  typedef GG Graph;
11  typedef typename GG::Edge Edge;
12 
13  typedef Edge Key;
14  typedef TT Value;
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 Value() const
24    {
25      Value tmp;
26      std::cout << G.id(G.source(e)) << "->"
27                << G.id(G.target(e)) << ": ";
28      std::cin  >> tmp;
29      return tmp;
30    }
31    Value operator = (Value v) const
32    {
33      std::cout << G.id(G.source(e)) << "->"
34                << G.id(G.target(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 Key;
51  typedef T Value;
52 
53  class RefType
54  {
55    Value val;
56  public:
57    RefType(Value v) : val(v) { }   
58    operator Value() const { return val; }
59    Value operator = (Value v) const { return val; }
60  };
61 
62private:
63  Value val;
64public:
65  NullMap(Value v) : val(v) { }
66  RefType operator[] (Key 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.