33 #include <lemon/invalid.h> |
33 #include <lemon/invalid.h> |
34 #include <lemon/graph_utils.h> |
34 #include <lemon/graph_utils.h> |
35 #include <lemon/bits/item_writer.h> |
35 #include <lemon/bits/item_writer.h> |
36 #include <lemon/utility.h> |
36 #include <lemon/utility.h> |
37 #include <lemon/maps.h> |
37 #include <lemon/maps.h> |
|
38 #include <lemon/xy.h> |
38 |
39 |
39 #include <lemon/concept_check.h> |
40 #include <lemon/concept_check.h> |
40 #include <lemon/concept/maps.h> |
41 #include <lemon/concept/maps.h> |
41 |
42 |
42 |
43 |
82 const Item& item; |
83 const Item& item; |
83 }; |
84 }; |
84 |
85 |
85 }; |
86 }; |
86 |
87 |
|
88 template <typename Map> |
|
89 struct Ref { typedef const Map& Type; }; |
|
90 |
|
91 template <typename Graph, typename Map> |
|
92 class ForwardComposeMap { |
|
93 public: |
|
94 typedef typename Graph::UndirEdge Key; |
|
95 typedef typename Map::Value Value; |
|
96 |
|
97 ForwardComposeMap(const Graph& _graph, const Map& _map) |
|
98 : graph(_graph), map(_map) {} |
|
99 |
|
100 Value operator[](const Key& key) { |
|
101 return map[graph.direct(key, false)]; |
|
102 } |
|
103 |
|
104 private: |
|
105 typename Ref<Map>::Type map; |
|
106 const Graph& graph; |
|
107 }; |
|
108 |
|
109 template <typename Graph, typename Map> |
|
110 ForwardComposeMap<Graph, Map> |
|
111 forwardComposeMap(const Graph& graph, const Map& map) { |
|
112 return ForwardComposeMap<Graph, Map>(graph, map); |
|
113 } |
|
114 |
|
115 template <typename Graph, typename Map> |
|
116 class BackwardComposeMap { |
|
117 public: |
|
118 typedef typename Graph::UndirEdge Key; |
|
119 typedef typename Map::Value Value; |
|
120 |
|
121 BackwardComposeMap(const Graph& _graph, const Map& _map) |
|
122 : graph(_graph), map(_map) {} |
|
123 |
|
124 Value operator[](const Key& key) { |
|
125 return map[graph.direct(key, false)]; |
|
126 } |
|
127 |
|
128 private: |
|
129 typename Ref<Map>::Type map; |
|
130 const Graph& graph; |
|
131 }; |
|
132 |
|
133 template <typename Graph, typename Map> |
|
134 BackwardComposeMap<Graph, Map> |
|
135 backwardComposeMap(const Graph& graph, const Map& map) { |
|
136 return BackwardComposeMap<Graph, Map>(graph, map); |
|
137 } |
|
138 |
|
139 template <typename Graph, typename Map> |
|
140 struct Ref<ForwardComposeMap<Graph, Map> > { |
|
141 typedef ForwardComposeMap<Graph, Map> Type; |
|
142 }; |
|
143 |
|
144 template <typename Graph, typename Map> |
|
145 struct Ref<BackwardComposeMap<Graph, Map> > { |
|
146 typedef BackwardComposeMap<Graph, Map> Type; |
|
147 }; |
|
148 |
|
149 template <typename Map> |
|
150 struct Ref<XMap<Map> > { |
|
151 typedef XMap<Map> Type; |
|
152 }; |
|
153 template <typename Map> |
|
154 struct Ref<ConstXMap<Map> > { |
|
155 typedef ConstXMap<Map> Type; |
|
156 }; |
|
157 |
|
158 template <typename Map> |
|
159 struct Ref<YMap<Map> > { |
|
160 typedef YMap<Map> Type; |
|
161 }; |
|
162 template <typename Map> |
|
163 struct Ref<ConstYMap<Map> > { |
|
164 typedef ConstYMap<Map> Type; |
|
165 }; |
|
166 |
87 } |
167 } |
88 |
168 |
89 /// \ingroup io_group |
169 /// \ingroup io_group |
90 /// \brief Lemon Format writer class. |
170 /// \brief Lemon Format writer class. |
91 /// |
171 /// |
744 template <typename Writer, typename Map> |
824 template <typename Writer, typename Map> |
745 UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map, |
825 UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map, |
746 const Writer& writer = Writer()) { |
826 const Writer& writer = Writer()) { |
747 checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>(); |
827 checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>(); |
748 checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>(); |
828 checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>(); |
749 writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer); |
829 writeUndirEdge("+" + name, |
750 writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer); |
830 _writer_bits::forwardComposeMap(graph, map), writer); |
|
831 writeUndirEdge("-" + name, |
|
832 _writer_bits::backwardComposeMap(graph, map), writer); |
751 return *this; |
833 return *this; |
752 } |
834 } |
753 |
835 |
754 protected: |
836 protected: |
755 |
837 |