diff -r 467d7927a901 -r 3f63d9db307b lemon/lemon_writer.h --- a/lemon/lemon_writer.h Wed Oct 05 13:17:42 2005 +0000 +++ b/lemon/lemon_writer.h Wed Oct 05 13:18:51 2005 +0000 @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,85 @@ }; + template + struct Ref { typedef const Map& Type; }; + + template + class ForwardComposeMap { + public: + typedef typename Graph::UndirEdge Key; + typedef typename Map::Value Value; + + ForwardComposeMap(const Graph& _graph, const Map& _map) + : graph(_graph), map(_map) {} + + Value operator[](const Key& key) { + return map[graph.direct(key, false)]; + } + + private: + typename Ref::Type map; + const Graph& graph; + }; + + template + ForwardComposeMap + forwardComposeMap(const Graph& graph, const Map& map) { + return ForwardComposeMap(graph, map); + } + + template + class BackwardComposeMap { + public: + typedef typename Graph::UndirEdge Key; + typedef typename Map::Value Value; + + BackwardComposeMap(const Graph& _graph, const Map& _map) + : graph(_graph), map(_map) {} + + Value operator[](const Key& key) { + return map[graph.direct(key, false)]; + } + + private: + typename Ref::Type map; + const Graph& graph; + }; + + template + BackwardComposeMap + backwardComposeMap(const Graph& graph, const Map& map) { + return BackwardComposeMap(graph, map); + } + + template + struct Ref > { + typedef ForwardComposeMap Type; + }; + + template + struct Ref > { + typedef BackwardComposeMap Type; + }; + + template + struct Ref > { + typedef XMap Type; + }; + template + struct Ref > { + typedef ConstXMap Type; + }; + + template + struct Ref > { + typedef YMap Type; + }; + template + struct Ref > { + typedef ConstYMap Type; + }; + } /// \ingroup io_group @@ -234,7 +314,7 @@ typedef typename Writer::Value Value; typedef _Item Item; - typename SmartConstReference::Type map; + typename _writer_bits::Ref::Type map; Writer writer; MapWriter(const Map& _map, const Writer& _writer) @@ -453,7 +533,7 @@ WriterBase* idMap; bool forceIdMap; - typename SmartConstReference::Type graph; + const Graph& graph; std::string id; }; @@ -627,7 +707,7 @@ WriterBase* idMap; bool forceIdMap; - typename SmartConstReference::Type graph; + const Graph& graph; std::string id; std::auto_ptr > nodeIdWriter; @@ -746,8 +826,10 @@ const Writer& writer = Writer()) { checkConcept, Map>(); checkConcept<_writer_bits::ItemWriter, Writer>(); - writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer); - writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer); + writeUndirEdge("+" + name, + _writer_bits::forwardComposeMap(graph, map), writer); + writeUndirEdge("-" + name, + _writer_bits::backwardComposeMap(graph, map), writer); return *this; } @@ -853,7 +935,7 @@ WriterBase* idMap; bool forceIdMap; - typename SmartConstReference::Type graph; + const Graph& graph; std::string id; std::auto_ptr > nodeIdWriter;