COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/alpar/rw_nonref_map.cc @ 349:42c660f58702

Last change on this file since 349:42c660f58702 was 342:c98125b3f47c, checked in by Alpar Juttner, 18 years ago

An example for a readable/writeable but non-referrable map
without get() and set().

File size: 1.4 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
46int 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
Note: See TracBrowser for help on using the repository browser.