1.1 --- a/lemon/lemon_reader.h Wed Oct 05 13:17:42 2005 +0000
1.2 +++ b/lemon/lemon_reader.h Wed Oct 05 13:18:51 2005 +0000
1.3 @@ -36,6 +36,8 @@
1.4 #include <lemon/utility.h>
1.5 #include <lemon/bits/item_reader.h>
1.6
1.7 +#include <lemon/xy.h>
1.8 +
1.9 #include <lemon/concept_check.h>
1.10 #include <lemon/concept/maps.h>
1.11
1.12 @@ -94,38 +96,108 @@
1.13 }
1.14 };
1.15
1.16 - template <typename M1, typename M2>
1.17 - class WriteComposeMap {
1.18 + template <typename Map>
1.19 + struct Ref { typedef Map& Type; };
1.20 + template <typename Map>
1.21 + struct Arg { typedef Map& Type; };
1.22 +
1.23 + template <typename Graph, typename Map>
1.24 + class ForwardComposeMap {
1.25 public:
1.26 - typedef True NeedCopy;
1.27 + typedef typename Graph::UndirEdge Key;
1.28 + typedef typename Map::Value Value;
1.29 +
1.30 + ForwardComposeMap(const Graph& _graph, typename Arg<Map>::Type _map)
1.31 + : graph(_graph), map(_map) {}
1.32
1.33 - typedef typename M2::Key Key;
1.34 - typedef typename M1::Value Value;
1.35 -
1.36 - WriteComposeMap(typename SmartParameter<M1>::Type _m1, const M2& _m2)
1.37 - : m1(_m1), m2(_m2) {}
1.38 -
1.39 - void set(const Key& key, const Value& value) {
1.40 - m1.set(m2[key], value);
1.41 + void set(const Key& key, const Value& val) {
1.42 + map.set(graph.direct(key, true), val);
1.43 }
1.44
1.45 private:
1.46 -
1.47 - typename SmartReference<M1>::Type m1;
1.48 - typename SmartConstReference<M2>::Type m2;
1.49 -
1.50 + typename Ref<Map>::Type map;
1.51 + const Graph& graph;
1.52 };
1.53
1.54 - template <typename M1, typename M2>
1.55 - WriteComposeMap<M1, M2> writeComposeMap(M1& m1, const M2& m2) {
1.56 - return WriteComposeMap<M1, M2>(m1, m2);
1.57 + template <typename Graph, typename Map>
1.58 + ForwardComposeMap<Graph, Map>
1.59 + forwardComposeMap(const Graph& graph, const Map& map) {
1.60 + return ForwardComposeMap<Graph, Map>(graph, map);
1.61 }
1.62
1.63 - template <typename M1, typename M2>
1.64 - WriteComposeMap<M1, M2> writeComposeMap(const M1& m1, const M2& m2) {
1.65 - return WriteComposeMap<M1, M2>(m1, m2);
1.66 + template <typename Graph, typename Map>
1.67 + ForwardComposeMap<Graph, Map>
1.68 + forwardComposeMap(const Graph& graph, Map& map) {
1.69 + return ForwardComposeMap<Graph, Map>(graph, map);
1.70 }
1.71 -
1.72 +
1.73 + template <typename Graph, typename Map>
1.74 + class BackwardComposeMap {
1.75 + public:
1.76 + typedef typename Graph::UndirEdge Key;
1.77 + typedef typename Map::Value Value;
1.78 +
1.79 + BackwardComposeMap(const Graph& _graph, typename Arg<Map>::Type _map)
1.80 + : graph(_graph), map(_map) {}
1.81 +
1.82 + void set(const Key& key, const Value& val) {
1.83 + map.set(graph.direct(key, false), val);
1.84 + }
1.85 +
1.86 + private:
1.87 + typename Ref<Map>::Type map;
1.88 + const Graph& graph;
1.89 + };
1.90 +
1.91 +
1.92 + template <typename Graph, typename Map>
1.93 + BackwardComposeMap<Graph, Map>
1.94 + backwardComposeMap(const Graph& graph, const Map& map) {
1.95 + return BackwardComposeMap<Graph, Map>(graph, map);
1.96 + }
1.97 +
1.98 + template <typename Graph, typename Map>
1.99 + BackwardComposeMap<Graph, Map>
1.100 + backwardComposeMap(const Graph& graph, Map& map) {
1.101 + return BackwardComposeMap<Graph, Map>(graph, map);
1.102 + }
1.103 +
1.104 + template <typename Graph, typename Map>
1.105 + struct Ref<ForwardComposeMap<Graph, Map> > {
1.106 + typedef ForwardComposeMap<Graph, Map> Type;
1.107 + };
1.108 + template <typename Graph, typename Map>
1.109 + struct Arg<ForwardComposeMap<Graph, Map> > {
1.110 + typedef const ForwardComposeMap<Graph, Map>& Type;
1.111 + };
1.112 +
1.113 + template <typename Graph, typename Map>
1.114 + struct Ref<BackwardComposeMap<Graph, Map> > {
1.115 + typedef BackwardComposeMap<Graph, Map> Type;
1.116 + };
1.117 + template <typename Graph, typename Map>
1.118 + struct Arg<BackwardComposeMap<Graph, Map> > {
1.119 + typedef const BackwardComposeMap<Graph, Map>& Type;
1.120 + };
1.121 +
1.122 + template <typename Map>
1.123 + struct Ref<XMap<Map> > {
1.124 + typedef XMap<Map> Type;
1.125 + };
1.126 + template <typename Map>
1.127 + struct Arg<XMap<Map> > {
1.128 + typedef const XMap<Map>& Type;
1.129 + };
1.130 +
1.131 + template <typename Map>
1.132 + struct Ref<YMap<Map> > {
1.133 + typedef YMap<Map> Type;
1.134 + };
1.135 + template <typename Map>
1.136 + struct Arg<YMap<Map> > {
1.137 + typedef const YMap<Map>& Type;
1.138 + };
1.139 +
1.140 }
1.141
1.142 /// \ingroup io_group
1.143 @@ -432,11 +504,11 @@
1.144 typedef _Map Map;
1.145 typedef std::map<Value, Item, _reader_bits::Less<Value> > Inverse;
1.146
1.147 - typename SmartReference<Map>::Type map;
1.148 + typename _reader_bits::Ref<Map>::Type map;
1.149 Reader reader;
1.150 Inverse inverse;
1.151
1.152 - MapReaderInverter(typename SmartParameter<Map>::Type _map,
1.153 + MapReaderInverter(typename _reader_bits::Arg<Map>::Type _map,
1.154 const Reader& _reader)
1.155 : map(_map), reader(_reader) {}
1.156
1.157 @@ -526,10 +598,10 @@
1.158 typedef typename Reader::Value Value;
1.159 typedef _Item Item;
1.160
1.161 - typename SmartReference<Map>::Type map;
1.162 + typename _reader_bits::Ref<Map>::Type map;
1.163 Reader reader;
1.164
1.165 - MapReader(typename SmartParameter<Map>::Type _map,
1.166 + MapReader(typename _reader_bits::Arg<Map>::Type _map,
1.167 const Reader& _reader)
1.168 : map(_map), reader(_reader) {}
1.169
1.170 @@ -659,7 +731,7 @@
1.171 /// add the readed nodes to the given Graph. The reader will read
1.172 /// the section when the \c section_id and the \c _id are the same.
1.173 NodeSetReader(LemonReader& _reader,
1.174 - typename SmartParameter<Graph>::Type _graph,
1.175 + Graph& _graph,
1.176 const std::string& _id = std::string(),
1.177 const DefaultSkipper& _skipper = DefaultSkipper())
1.178 : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {}
1.179 @@ -688,14 +760,14 @@
1.180 NodeSetReader& readNodeMap(std::string name, Map& map) {
1.181 return _readMap<
1.182 typename Traits::template Reader<typename Map::Value>, Map,
1.183 - typename SmartParameter<Map>::Type>(name, map);
1.184 + typename _reader_bits::Arg<Map>::Type>(name, map);
1.185 }
1.186
1.187 template <typename Map>
1.188 NodeSetReader& readNodeMap(std::string name, const Map& map) {
1.189 return _readMap<
1.190 typename Traits::template Reader<typename Map::Value>, Map,
1.191 - typename SmartParameter<Map>::Type>(name, map);
1.192 + typename _reader_bits::Arg<Map>::Type>(name, map);
1.193 }
1.194
1.195 /// \brief Add a new node map reader command for the reader.
1.196 @@ -704,14 +776,14 @@
1.197 template <typename Reader, typename Map>
1.198 NodeSetReader& readNodeMap(std::string name, Map& map,
1.199 const Reader& reader = Reader()) {
1.200 - return _readMap<Reader, Map, typename SmartParameter<Map>::Type>
1.201 + return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
1.202 (name, map, reader);
1.203 }
1.204
1.205 template <typename Reader, typename Map>
1.206 NodeSetReader& readNodeMap(std::string name, const Map& map,
1.207 const Reader& reader = Reader()) {
1.208 - return _readMap<Reader, Map, typename SmartParameter<Map>::Type>
1.209 + return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
1.210 (name, map, reader);
1.211 }
1.212
1.213 @@ -817,7 +889,7 @@
1.214 typedef std::map<std::string, ReaderBase<Node>*> MapReaders;
1.215 MapReaders readers;
1.216
1.217 - typename SmartReference<Graph>::Type graph;
1.218 + Graph& graph;
1.219 std::string id;
1.220 SkipReader<Node, DefaultSkipper> skipper;
1.221
1.222 @@ -867,7 +939,7 @@
1.223 /// \c edgset_id are the same.
1.224 template <typename NodeIdReader>
1.225 EdgeSetReader(LemonReader& _reader,
1.226 - typename SmartParameter<Graph>::Type _graph,
1.227 + Graph& _graph,
1.228 const NodeIdReader& _nodeIdReader,
1.229 const std::string& _id = std::string(),
1.230 const DefaultSkipper& _skipper = DefaultSkipper())
1.231 @@ -898,14 +970,14 @@
1.232 EdgeSetReader& readEdgeMap(std::string name, Map& map) {
1.233 return _readMap<
1.234 typename Traits::template Reader<typename Map::Value>, Map,
1.235 - typename SmartParameter<Map>::Type>(name, map);
1.236 + typename _reader_bits::Arg<Map>::Type>(name, map);
1.237 }
1.238
1.239 template <typename Map>
1.240 EdgeSetReader& readEdgeMap(std::string name, const Map& map) {
1.241 return _readMap<
1.242 typename Traits::template Reader<typename Map::Value>, Map,
1.243 - typename SmartParameter<Map>::Type>(name, map);
1.244 + typename _reader_bits::Arg<Map>::Type>(name, map);
1.245 }
1.246
1.247 /// \brief Add a new edge map reader command for the reader.
1.248 @@ -915,14 +987,14 @@
1.249 EdgeSetReader& readEdgeMap(std::string name, Map& map,
1.250 const Reader& reader = Reader()) {
1.251 return _readMap<Reader, Map,
1.252 - typename SmartParameter<Map>::Type>(name, map, reader);
1.253 + typename _reader_bits::Arg<Map>::Type>(name, map, reader);
1.254 }
1.255
1.256 template <typename Reader, typename Map>
1.257 EdgeSetReader& readEdgeMap(std::string name, const Map& map,
1.258 const Reader& reader = Reader()) {
1.259 return _readMap<Reader, Map,
1.260 - typename SmartParameter<Map>::Type>(name, map, reader);
1.261 + typename _reader_bits::Arg<Map>::Type>(name, map, reader);
1.262 }
1.263
1.264 private:
1.265 @@ -1032,7 +1104,7 @@
1.266 typedef std::map<std::string, ReaderBase<Edge>*> MapReaders;
1.267 MapReaders readers;
1.268
1.269 - typename SmartReference<Graph>::Type graph;
1.270 + Graph& graph;
1.271 std::string id;
1.272 SkipReader<Edge, DefaultSkipper> skipper;
1.273
1.274 @@ -1089,7 +1161,7 @@
1.275 /// \c _id and the \c undiredgset_id are the same.
1.276 template <typename NodeIdReader>
1.277 UndirEdgeSetReader(LemonReader& _reader,
1.278 - typename SmartParameter<Graph>::Type _graph,
1.279 + Graph& _graph,
1.280 const NodeIdReader& _nodeIdReader,
1.281 const std::string& _id = std::string(),
1.282 const DefaultSkipper& _skipper = DefaultSkipper())
1.283 @@ -1120,14 +1192,14 @@
1.284 UndirEdgeSetReader& readUndirEdgeMap(std::string name, Map& map) {
1.285 return _readMap<
1.286 typename Traits::template Reader<typename Map::Value>, Map,
1.287 - typename SmartParameter<Map>::Type>(name, map);
1.288 + typename _reader_bits::Arg<Map>::Type>(name, map);
1.289 }
1.290
1.291 template <typename Map>
1.292 UndirEdgeSetReader& readUndirEdgeMap(std::string name, const Map& map) {
1.293 return _readMap<
1.294 typename Traits::template Reader<typename Map::Value>, Map,
1.295 - typename SmartParameter<Map>::Type>(name, map);
1.296 + typename _reader_bits::Arg<Map>::Type>(name, map);
1.297 }
1.298
1.299 /// \brief Add a new undirected edge map reader command for the reader.
1.300 @@ -1136,14 +1208,14 @@
1.301 template <typename Reader, typename Map>
1.302 UndirEdgeSetReader& readUndirEdgeMap(std::string name, Map& map,
1.303 const Reader& reader = Reader()) {
1.304 - return _readMap<Reader, Map, typename SmartParameter<Map>::Type>
1.305 + return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
1.306 (name, map, reader);
1.307 }
1.308
1.309 template <typename Reader, typename Map>
1.310 UndirEdgeSetReader& readUndirEdgeMap(std::string name, const Map& map,
1.311 const Reader& reader = Reader()) {
1.312 - return _readMap<Reader, Map, typename SmartParameter<Map>::Type >
1.313 + return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type >
1.314 (name, map, reader);
1.315 }
1.316
1.317 @@ -1189,14 +1261,14 @@
1.318 UndirEdgeSetReader& readEdgeMap(std::string name, Map& map) {
1.319 return _readDirMap<
1.320 typename Traits::template Reader<typename Map::Value>, Map,
1.321 - typename SmartParameter<Map>::Type>(name, map);
1.322 + typename _reader_bits::Arg<Map>::Type>(name, map);
1.323 }
1.324
1.325 template <typename Map>
1.326 UndirEdgeSetReader& readEdgeMap(std::string name, const Map& map) {
1.327 return _readDirMap<
1.328 typename Traits::template Reader<typename Map::Value>, Map,
1.329 - typename SmartParameter<Map>::Type>(name, map);
1.330 + typename _reader_bits::Arg<Map>::Type>(name, map);
1.331 }
1.332
1.333 /// \brief Add a new directed edge map reader command for the reader.
1.334 @@ -1205,14 +1277,14 @@
1.335 template <typename Reader, typename Map>
1.336 UndirEdgeSetReader& readEdgeMap(std::string name, Map& map,
1.337 const Reader& reader = Reader()) {
1.338 - return _readDirMap<Reader, Map, typename SmartParameter<Map>::Type>
1.339 + return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
1.340 (name, map, reader);
1.341 }
1.342
1.343 template <typename Reader, typename Map>
1.344 UndirEdgeSetReader& readEdgeMap(std::string name, const Map& map,
1.345 const Reader& reader = Reader()) {
1.346 - return _readDirMap<Reader, Map, typename SmartParameter<Map>::Type>
1.347 + return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
1.348 (name, map, reader);
1.349 }
1.350
1.351 @@ -1224,9 +1296,9 @@
1.352 checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
1.353 checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
1.354 readMap("+" + name,
1.355 - _reader_bits::writeComposeMap(map, forwardMap(graph)), reader);
1.356 + _reader_bits::forwardComposeMap(graph, map), reader);
1.357 readMap("-" + name,
1.358 - _reader_bits::writeComposeMap(map, backwardMap(graph)), reader);
1.359 + _reader_bits::backwardComposeMap(graph, map), reader);
1.360 return *this;
1.361 }
1.362
1.363 @@ -1336,7 +1408,7 @@
1.364 typedef std::map<std::string, ReaderBase<UndirEdge>*> MapReaders;
1.365 MapReaders readers;
1.366
1.367 - typename SmartReference<Graph>::Type graph;
1.368 + Graph& graph;
1.369 std::string id;
1.370 SkipReader<UndirEdge, DefaultSkipper> skipper;
1.371