1 | #include <iostream> |
---|

2 | #include <smart_graph.h> |
---|

3 | |
---|

4 | using namespace lemon; |
---|

5 | |
---|

6 | template<class GG,class TT> |
---|

7 | class CinCoutMap |
---|

8 | { |
---|

9 | public: |
---|

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.source(e)) << "->" |
---|

27 | << G.id(G.target(e)) << ": "; |
---|

28 | std::cin >> tmp; |
---|

29 | return tmp; |
---|

30 | } |
---|

31 | ValueType operator = (ValueType 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 | |
---|

39 | private: |
---|

40 | Graph &G; |
---|

41 | public: |
---|

42 | CinCoutMap(Graph &_G) : G(_G) { } |
---|

43 | RefType operator[] (Edge e) const { return RefType(G,e);} |
---|

44 | }; |
---|

45 | |
---|

46 | template<class K,class T> |
---|

47 | class NullMap |
---|

48 | { |
---|

49 | public: |
---|

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 | |
---|

62 | private: |
---|

63 | ValueType val; |
---|

64 | public: |
---|

65 | NullMap(ValueType v) : val(v) { } |
---|

66 | RefType operator[] (KeyType e) const { return RefType(v);} |
---|

67 | }; |
---|

68 | |
---|

69 | int 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 | |
---|