1.1 --- a/lemon/lemon_writer.h Wed Oct 05 13:17:42 2005 +0000
1.2 +++ b/lemon/lemon_writer.h Wed Oct 05 13:18:51 2005 +0000
1.3 @@ -35,6 +35,7 @@
1.4 #include <lemon/bits/item_writer.h>
1.5 #include <lemon/utility.h>
1.6 #include <lemon/maps.h>
1.7 +#include <lemon/xy.h>
1.8
1.9 #include <lemon/concept_check.h>
1.10 #include <lemon/concept/maps.h>
1.11 @@ -84,6 +85,85 @@
1.12
1.13 };
1.14
1.15 + template <typename Map>
1.16 + struct Ref { typedef const Map& Type; };
1.17 +
1.18 + template <typename Graph, typename Map>
1.19 + class ForwardComposeMap {
1.20 + public:
1.21 + typedef typename Graph::UndirEdge Key;
1.22 + typedef typename Map::Value Value;
1.23 +
1.24 + ForwardComposeMap(const Graph& _graph, const Map& _map)
1.25 + : graph(_graph), map(_map) {}
1.26 +
1.27 + Value operator[](const Key& key) {
1.28 + return map[graph.direct(key, false)];
1.29 + }
1.30 +
1.31 + private:
1.32 + typename Ref<Map>::Type map;
1.33 + const Graph& graph;
1.34 + };
1.35 +
1.36 + template <typename Graph, typename Map>
1.37 + ForwardComposeMap<Graph, Map>
1.38 + forwardComposeMap(const Graph& graph, const Map& map) {
1.39 + return ForwardComposeMap<Graph, Map>(graph, map);
1.40 + }
1.41 +
1.42 + template <typename Graph, typename Map>
1.43 + class BackwardComposeMap {
1.44 + public:
1.45 + typedef typename Graph::UndirEdge Key;
1.46 + typedef typename Map::Value Value;
1.47 +
1.48 + BackwardComposeMap(const Graph& _graph, const Map& _map)
1.49 + : graph(_graph), map(_map) {}
1.50 +
1.51 + Value operator[](const Key& key) {
1.52 + return map[graph.direct(key, false)];
1.53 + }
1.54 +
1.55 + private:
1.56 + typename Ref<Map>::Type map;
1.57 + const Graph& graph;
1.58 + };
1.59 +
1.60 + template <typename Graph, typename Map>
1.61 + BackwardComposeMap<Graph, Map>
1.62 + backwardComposeMap(const Graph& graph, const Map& map) {
1.63 + return BackwardComposeMap<Graph, Map>(graph, map);
1.64 + }
1.65 +
1.66 + template <typename Graph, typename Map>
1.67 + struct Ref<ForwardComposeMap<Graph, Map> > {
1.68 + typedef ForwardComposeMap<Graph, Map> Type;
1.69 + };
1.70 +
1.71 + template <typename Graph, typename Map>
1.72 + struct Ref<BackwardComposeMap<Graph, Map> > {
1.73 + typedef BackwardComposeMap<Graph, Map> Type;
1.74 + };
1.75 +
1.76 + template <typename Map>
1.77 + struct Ref<XMap<Map> > {
1.78 + typedef XMap<Map> Type;
1.79 + };
1.80 + template <typename Map>
1.81 + struct Ref<ConstXMap<Map> > {
1.82 + typedef ConstXMap<Map> Type;
1.83 + };
1.84 +
1.85 + template <typename Map>
1.86 + struct Ref<YMap<Map> > {
1.87 + typedef YMap<Map> Type;
1.88 + };
1.89 + template <typename Map>
1.90 + struct Ref<ConstYMap<Map> > {
1.91 + typedef ConstYMap<Map> Type;
1.92 + };
1.93 +
1.94 }
1.95
1.96 /// \ingroup io_group
1.97 @@ -234,7 +314,7 @@
1.98 typedef typename Writer::Value Value;
1.99 typedef _Item Item;
1.100
1.101 - typename SmartConstReference<Map>::Type map;
1.102 + typename _writer_bits::Ref<Map>::Type map;
1.103 Writer writer;
1.104
1.105 MapWriter(const Map& _map, const Writer& _writer)
1.106 @@ -453,7 +533,7 @@
1.107 WriterBase<Node>* idMap;
1.108 bool forceIdMap;
1.109
1.110 - typename SmartConstReference<Graph>::Type graph;
1.111 + const Graph& graph;
1.112 std::string id;
1.113
1.114 };
1.115 @@ -627,7 +707,7 @@
1.116 WriterBase<Edge>* idMap;
1.117 bool forceIdMap;
1.118
1.119 - typename SmartConstReference<Graph>::Type graph;
1.120 + const Graph& graph;
1.121 std::string id;
1.122
1.123 std::auto_ptr<IdWriterBase<Node> > nodeIdWriter;
1.124 @@ -746,8 +826,10 @@
1.125 const Writer& writer = Writer()) {
1.126 checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>();
1.127 checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
1.128 - writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer);
1.129 - writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer);
1.130 + writeUndirEdge("+" + name,
1.131 + _writer_bits::forwardComposeMap(graph, map), writer);
1.132 + writeUndirEdge("-" + name,
1.133 + _writer_bits::backwardComposeMap(graph, map), writer);
1.134 return *this;
1.135 }
1.136
1.137 @@ -853,7 +935,7 @@
1.138 WriterBase<UndirEdge>* idMap;
1.139 bool forceIdMap;
1.140
1.141 - typename SmartConstReference<Graph>::Type graph;
1.142 + const Graph& graph;
1.143 std::string id;
1.144
1.145 std::auto_ptr<IdWriterBase<Node> > nodeIdWriter;