# HG changeset patch # User deba # Date 1128518331 0 # Node ID 3f63d9db307ba5c1d7b9552515f96bd69cfe74f5 # Parent 467d7927a901586de48fa9d1f11e81d390d9b193 Removing smart references diff -r 467d7927a901 -r 3f63d9db307b lemon/graph_reader.h --- a/lemon/graph_reader.h Wed Oct 05 13:17:42 2005 +0000 +++ b/lemon/graph_reader.h Wed Oct 05 13:18:51 2005 +0000 @@ -122,8 +122,7 @@ /// /// Construct a new GraphReader. It reads into the given graph /// and it uses the given reader as the default skipper. - GraphReader(std::istream& _is, - typename SmartParameter<Graph>::Type _graph, + GraphReader(std::istream& _is, Graph& _graph, const DefaultSkipper& _skipper = DefaultSkipper()) : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper), nodeset_reader(*reader, _graph, std::string(), skipper), @@ -137,8 +136,7 @@ /// /// Construct a new GraphReader. It reads into the given graph /// and it uses the given reader as the default skipper. - GraphReader(const std::string& _filename, - typename SmartParameter<Graph>::Type _graph, + GraphReader(const std::string& _filename, Graph& _graph, const DefaultSkipper& _skipper = DefaultSkipper()) : reader(new LemonReader(_filename)), own_reader(true), skipper(_skipper), @@ -153,8 +151,7 @@ /// /// Construct a new GraphReader. It reads into the given graph /// and it uses the given reader as the default skipper. - GraphReader(LemonReader& _reader, - typename SmartParameter<Graph>::Type _graph, + GraphReader(LemonReader& _reader, Graph& _graph, const DefaultSkipper& _skipper = DefaultSkipper()) : reader(_reader), own_reader(false), skipper(_skipper), nodeset_reader(*reader, _graph, std::string(), skipper), diff -r 467d7927a901 -r 3f63d9db307b lemon/lemon_reader.h --- a/lemon/lemon_reader.h Wed Oct 05 13:17:42 2005 +0000 +++ b/lemon/lemon_reader.h Wed Oct 05 13:18:51 2005 +0000 @@ -36,6 +36,8 @@ #include <lemon/utility.h> #include <lemon/bits/item_reader.h> +#include <lemon/xy.h> + #include <lemon/concept_check.h> #include <lemon/concept/maps.h> @@ -94,38 +96,108 @@ } }; - template <typename M1, typename M2> - class WriteComposeMap { + template <typename Map> + struct Ref { typedef Map& Type; }; + template <typename Map> + struct Arg { typedef Map& Type; }; + + template <typename Graph, typename Map> + class ForwardComposeMap { public: - typedef True NeedCopy; + typedef typename Graph::UndirEdge Key; + typedef typename Map::Value Value; + + ForwardComposeMap(const Graph& _graph, typename Arg<Map>::Type _map) + : graph(_graph), map(_map) {} - typedef typename M2::Key Key; - typedef typename M1::Value Value; - - WriteComposeMap(typename SmartParameter<M1>::Type _m1, const M2& _m2) - : m1(_m1), m2(_m2) {} - - void set(const Key& key, const Value& value) { - m1.set(m2[key], value); + void set(const Key& key, const Value& val) { + map.set(graph.direct(key, true), val); } private: - - typename SmartReference<M1>::Type m1; - typename SmartConstReference<M2>::Type m2; - + typename Ref<Map>::Type map; + const Graph& graph; }; - template <typename M1, typename M2> - WriteComposeMap<M1, M2> writeComposeMap(M1& m1, const M2& m2) { - return WriteComposeMap<M1, M2>(m1, m2); + template <typename Graph, typename Map> + ForwardComposeMap<Graph, Map> + forwardComposeMap(const Graph& graph, const Map& map) { + return ForwardComposeMap<Graph, Map>(graph, map); } - template <typename M1, typename M2> - WriteComposeMap<M1, M2> writeComposeMap(const M1& m1, const M2& m2) { - return WriteComposeMap<M1, M2>(m1, m2); + template <typename Graph, typename Map> + ForwardComposeMap<Graph, Map> + forwardComposeMap(const Graph& graph, Map& map) { + return ForwardComposeMap<Graph, Map>(graph, map); } - + + template <typename Graph, typename Map> + class BackwardComposeMap { + public: + typedef typename Graph::UndirEdge Key; + typedef typename Map::Value Value; + + BackwardComposeMap(const Graph& _graph, typename Arg<Map>::Type _map) + : graph(_graph), map(_map) {} + + void set(const Key& key, const Value& val) { + map.set(graph.direct(key, false), val); + } + + private: + typename Ref<Map>::Type map; + const Graph& graph; + }; + + + template <typename Graph, typename Map> + BackwardComposeMap<Graph, Map> + backwardComposeMap(const Graph& graph, const Map& map) { + return BackwardComposeMap<Graph, Map>(graph, map); + } + + template <typename Graph, typename Map> + BackwardComposeMap<Graph, Map> + backwardComposeMap(const Graph& graph, Map& map) { + return BackwardComposeMap<Graph, Map>(graph, map); + } + + template <typename Graph, typename Map> + struct Ref<ForwardComposeMap<Graph, Map> > { + typedef ForwardComposeMap<Graph, Map> Type; + }; + template <typename Graph, typename Map> + struct Arg<ForwardComposeMap<Graph, Map> > { + typedef const ForwardComposeMap<Graph, Map>& Type; + }; + + template <typename Graph, typename Map> + struct Ref<BackwardComposeMap<Graph, Map> > { + typedef BackwardComposeMap<Graph, Map> Type; + }; + template <typename Graph, typename Map> + struct Arg<BackwardComposeMap<Graph, Map> > { + typedef const BackwardComposeMap<Graph, Map>& Type; + }; + + template <typename Map> + struct Ref<XMap<Map> > { + typedef XMap<Map> Type; + }; + template <typename Map> + struct Arg<XMap<Map> > { + typedef const XMap<Map>& Type; + }; + + template <typename Map> + struct Ref<YMap<Map> > { + typedef YMap<Map> Type; + }; + template <typename Map> + struct Arg<YMap<Map> > { + typedef const YMap<Map>& Type; + }; + } /// \ingroup io_group @@ -432,11 +504,11 @@ typedef _Map Map; typedef std::map<Value, Item, _reader_bits::Less<Value> > Inverse; - typename SmartReference<Map>::Type map; + typename _reader_bits::Ref<Map>::Type map; Reader reader; Inverse inverse; - MapReaderInverter(typename SmartParameter<Map>::Type _map, + MapReaderInverter(typename _reader_bits::Arg<Map>::Type _map, const Reader& _reader) : map(_map), reader(_reader) {} @@ -526,10 +598,10 @@ typedef typename Reader::Value Value; typedef _Item Item; - typename SmartReference<Map>::Type map; + typename _reader_bits::Ref<Map>::Type map; Reader reader; - MapReader(typename SmartParameter<Map>::Type _map, + MapReader(typename _reader_bits::Arg<Map>::Type _map, const Reader& _reader) : map(_map), reader(_reader) {} @@ -659,7 +731,7 @@ /// add the readed nodes to the given Graph. The reader will read /// the section when the \c section_id and the \c _id are the same. NodeSetReader(LemonReader& _reader, - typename SmartParameter<Graph>::Type _graph, + Graph& _graph, const std::string& _id = std::string(), const DefaultSkipper& _skipper = DefaultSkipper()) : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {} @@ -688,14 +760,14 @@ NodeSetReader& readNodeMap(std::string name, Map& map) { return _readMap< typename Traits::template Reader<typename Map::Value>, Map, - typename SmartParameter<Map>::Type>(name, map); + typename _reader_bits::Arg<Map>::Type>(name, map); } template <typename Map> NodeSetReader& readNodeMap(std::string name, const Map& map) { return _readMap< typename Traits::template Reader<typename Map::Value>, Map, - typename SmartParameter<Map>::Type>(name, map); + typename _reader_bits::Arg<Map>::Type>(name, map); } /// \brief Add a new node map reader command for the reader. @@ -704,14 +776,14 @@ template <typename Reader, typename Map> NodeSetReader& readNodeMap(std::string name, Map& map, const Reader& reader = Reader()) { - return _readMap<Reader, Map, typename SmartParameter<Map>::Type> + return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type> (name, map, reader); } template <typename Reader, typename Map> NodeSetReader& readNodeMap(std::string name, const Map& map, const Reader& reader = Reader()) { - return _readMap<Reader, Map, typename SmartParameter<Map>::Type> + return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type> (name, map, reader); } @@ -817,7 +889,7 @@ typedef std::map<std::string, ReaderBase<Node>*> MapReaders; MapReaders readers; - typename SmartReference<Graph>::Type graph; + Graph& graph; std::string id; SkipReader<Node, DefaultSkipper> skipper; @@ -867,7 +939,7 @@ /// \c edgset_id are the same. template <typename NodeIdReader> EdgeSetReader(LemonReader& _reader, - typename SmartParameter<Graph>::Type _graph, + Graph& _graph, const NodeIdReader& _nodeIdReader, const std::string& _id = std::string(), const DefaultSkipper& _skipper = DefaultSkipper()) @@ -898,14 +970,14 @@ EdgeSetReader& readEdgeMap(std::string name, Map& map) { return _readMap< typename Traits::template Reader<typename Map::Value>, Map, - typename SmartParameter<Map>::Type>(name, map); + typename _reader_bits::Arg<Map>::Type>(name, map); } template <typename Map> EdgeSetReader& readEdgeMap(std::string name, const Map& map) { return _readMap< typename Traits::template Reader<typename Map::Value>, Map, - typename SmartParameter<Map>::Type>(name, map); + typename _reader_bits::Arg<Map>::Type>(name, map); } /// \brief Add a new edge map reader command for the reader. @@ -915,14 +987,14 @@ EdgeSetReader& readEdgeMap(std::string name, Map& map, const Reader& reader = Reader()) { return _readMap<Reader, Map, - typename SmartParameter<Map>::Type>(name, map, reader); + typename _reader_bits::Arg<Map>::Type>(name, map, reader); } template <typename Reader, typename Map> EdgeSetReader& readEdgeMap(std::string name, const Map& map, const Reader& reader = Reader()) { return _readMap<Reader, Map, - typename SmartParameter<Map>::Type>(name, map, reader); + typename _reader_bits::Arg<Map>::Type>(name, map, reader); } private: @@ -1032,7 +1104,7 @@ typedef std::map<std::string, ReaderBase<Edge>*> MapReaders; MapReaders readers; - typename SmartReference<Graph>::Type graph; + Graph& graph; std::string id; SkipReader<Edge, DefaultSkipper> skipper; @@ -1089,7 +1161,7 @@ /// \c _id and the \c undiredgset_id are the same. template <typename NodeIdReader> UndirEdgeSetReader(LemonReader& _reader, - typename SmartParameter<Graph>::Type _graph, + Graph& _graph, const NodeIdReader& _nodeIdReader, const std::string& _id = std::string(), const DefaultSkipper& _skipper = DefaultSkipper()) @@ -1120,14 +1192,14 @@ UndirEdgeSetReader& readUndirEdgeMap(std::string name, Map& map) { return _readMap< typename Traits::template Reader<typename Map::Value>, Map, - typename SmartParameter<Map>::Type>(name, map); + typename _reader_bits::Arg<Map>::Type>(name, map); } template <typename Map> UndirEdgeSetReader& readUndirEdgeMap(std::string name, const Map& map) { return _readMap< typename Traits::template Reader<typename Map::Value>, Map, - typename SmartParameter<Map>::Type>(name, map); + typename _reader_bits::Arg<Map>::Type>(name, map); } /// \brief Add a new undirected edge map reader command for the reader. @@ -1136,14 +1208,14 @@ template <typename Reader, typename Map> UndirEdgeSetReader& readUndirEdgeMap(std::string name, Map& map, const Reader& reader = Reader()) { - return _readMap<Reader, Map, typename SmartParameter<Map>::Type> + return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type> (name, map, reader); } template <typename Reader, typename Map> UndirEdgeSetReader& readUndirEdgeMap(std::string name, const Map& map, const Reader& reader = Reader()) { - return _readMap<Reader, Map, typename SmartParameter<Map>::Type > + return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type > (name, map, reader); } @@ -1189,14 +1261,14 @@ UndirEdgeSetReader& readEdgeMap(std::string name, Map& map) { return _readDirMap< typename Traits::template Reader<typename Map::Value>, Map, - typename SmartParameter<Map>::Type>(name, map); + typename _reader_bits::Arg<Map>::Type>(name, map); } template <typename Map> UndirEdgeSetReader& readEdgeMap(std::string name, const Map& map) { return _readDirMap< typename Traits::template Reader<typename Map::Value>, Map, - typename SmartParameter<Map>::Type>(name, map); + typename _reader_bits::Arg<Map>::Type>(name, map); } /// \brief Add a new directed edge map reader command for the reader. @@ -1205,14 +1277,14 @@ template <typename Reader, typename Map> UndirEdgeSetReader& readEdgeMap(std::string name, Map& map, const Reader& reader = Reader()) { - return _readDirMap<Reader, Map, typename SmartParameter<Map>::Type> + return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type> (name, map, reader); } template <typename Reader, typename Map> UndirEdgeSetReader& readEdgeMap(std::string name, const Map& map, const Reader& reader = Reader()) { - return _readDirMap<Reader, Map, typename SmartParameter<Map>::Type> + return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type> (name, map, reader); } @@ -1224,9 +1296,9 @@ checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>(); checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>(); readMap("+" + name, - _reader_bits::writeComposeMap(map, forwardMap(graph)), reader); + _reader_bits::forwardComposeMap(graph, map), reader); readMap("-" + name, - _reader_bits::writeComposeMap(map, backwardMap(graph)), reader); + _reader_bits::backwardComposeMap(graph, map), reader); return *this; } @@ -1336,7 +1408,7 @@ typedef std::map<std::string, ReaderBase<UndirEdge>*> MapReaders; MapReaders readers; - typename SmartReference<Graph>::Type graph; + Graph& graph; std::string id; SkipReader<UndirEdge, DefaultSkipper> skipper; 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 <lemon/bits/item_writer.h> #include <lemon/utility.h> #include <lemon/maps.h> +#include <lemon/xy.h> #include <lemon/concept_check.h> #include <lemon/concept/maps.h> @@ -84,6 +85,85 @@ }; + template <typename Map> + struct Ref { typedef const Map& Type; }; + + template <typename Graph, typename Map> + 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<Map>::Type map; + const Graph& graph; + }; + + template <typename Graph, typename Map> + ForwardComposeMap<Graph, Map> + forwardComposeMap(const Graph& graph, const Map& map) { + return ForwardComposeMap<Graph, Map>(graph, map); + } + + template <typename Graph, typename Map> + 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<Map>::Type map; + const Graph& graph; + }; + + template <typename Graph, typename Map> + BackwardComposeMap<Graph, Map> + backwardComposeMap(const Graph& graph, const Map& map) { + return BackwardComposeMap<Graph, Map>(graph, map); + } + + template <typename Graph, typename Map> + struct Ref<ForwardComposeMap<Graph, Map> > { + typedef ForwardComposeMap<Graph, Map> Type; + }; + + template <typename Graph, typename Map> + struct Ref<BackwardComposeMap<Graph, Map> > { + typedef BackwardComposeMap<Graph, Map> Type; + }; + + template <typename Map> + struct Ref<XMap<Map> > { + typedef XMap<Map> Type; + }; + template <typename Map> + struct Ref<ConstXMap<Map> > { + typedef ConstXMap<Map> Type; + }; + + template <typename Map> + struct Ref<YMap<Map> > { + typedef YMap<Map> Type; + }; + template <typename Map> + struct Ref<ConstYMap<Map> > { + typedef ConstYMap<Map> Type; + }; + } /// \ingroup io_group @@ -234,7 +314,7 @@ typedef typename Writer::Value Value; typedef _Item Item; - typename SmartConstReference<Map>::Type map; + typename _writer_bits::Ref<Map>::Type map; Writer writer; MapWriter(const Map& _map, const Writer& _writer) @@ -453,7 +533,7 @@ WriterBase<Node>* idMap; bool forceIdMap; - typename SmartConstReference<Graph>::Type graph; + const Graph& graph; std::string id; }; @@ -627,7 +707,7 @@ WriterBase<Edge>* idMap; bool forceIdMap; - typename SmartConstReference<Graph>::Type graph; + const Graph& graph; std::string id; std::auto_ptr<IdWriterBase<Node> > nodeIdWriter; @@ -746,8 +826,10 @@ const Writer& writer = Writer()) { checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>(); checkConcept<_writer_bits::ItemWriter<typename Map::Value>, 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<UndirEdge>* idMap; bool forceIdMap; - typename SmartConstReference<Graph>::Type graph; + const Graph& graph; std::string id; std::auto_ptr<IdWriterBase<Node> > nodeIdWriter; diff -r 467d7927a901 -r 3f63d9db307b lemon/maps.h --- a/lemon/maps.h Wed Oct 05 13:17:42 2005 +0000 +++ b/lemon/maps.h Wed Oct 05 13:18:51 2005 +0000 @@ -38,11 +38,9 @@ /// Base class of maps. /// It provides the necessary <tt>typedef</tt>s required by the map concept. - template<typename K, typename T, typename _NeedCopy = False> + template<typename K, typename T> class MapBase { public: - /// \e - typedef _NeedCopy NeedCopy; ///\e typedef K Key; ///\e @@ -54,10 +52,10 @@ /// If you have to provide a map only for its type definitions, /// or if you have to provide a writable map, but /// data written to it will sent to <tt>/dev/null</tt>... - template<typename K, typename T, typename NC = False> - class NullMap : public MapBase<K, T, NC> { + template<typename K, typename T> + class NullMap : public MapBase<K, T> { public: - typedef MapBase<K, T, NC> Parent; + typedef MapBase<K, T> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -68,8 +66,8 @@ }; template <typename K, typename V> - NullMap<K, V, True> nullMap() { - return NullMap<K, V, True>(); + NullMap<K, V> nullMap() { + return NullMap<K, V>(); } @@ -78,13 +76,13 @@ /// This is a readable map which assigns a specified value to each key. /// In other aspects it is equivalent to the \ref NullMap. /// \todo set could be used to set the value. - template<typename K, typename T, typename NC = False> - class ConstMap : public MapBase<K, T, NC> { + template<typename K, typename T> + class ConstMap : public MapBase<K, T> { private: T v; public: - typedef MapBase<K, T, NC> Parent; + typedef MapBase<K, T> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -116,8 +114,8 @@ ///This function just returns a \ref ConstMap class. ///\relates ConstMap template<typename K, typename V> - inline ConstMap<K, V, True> constMap(const V &v) { - return ConstMap<K, V, True>(v); + inline ConstMap<K, V> constMap(const V &v) { + return ConstMap<K, V>(v); } @@ -126,10 +124,10 @@ struct Const { }; //\todo to document later - template<typename K, typename V, V v, typename NC> - class ConstMap<K, Const<V, v>, NC > : public MapBase<K, V, NC> { + template<typename K, typename V, V v> + class ConstMap<K, Const<V, v> > : public MapBase<K, V> { public: - typedef MapBase<K, V, False> Parent; + typedef MapBase<K, V> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -143,8 +141,8 @@ ///This function just returns a \ref ConstMap class. ///\relates ConstMap template<typename K, typename V, V v> - inline ConstMap<K, Const<V, v>, True> constMap() { - return ConstMap<K, Const<V, v>, True>(); + inline ConstMap<K, Const<V, v> > constMap() { + return ConstMap<K, Const<V, v> >(); } /// \c std::map wrapper @@ -225,10 +223,10 @@ /// /// This mapping gives back the given key as value without any /// modification. - template <typename T, typename NC = False> - class IdentityMap : public MapBase<T, T, NC> { + template <typename T> + class IdentityMap : public MapBase<T, T> { public: - typedef MapBase<T, T, NC> Parent; + typedef MapBase<T, T> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -242,8 +240,8 @@ ///This function just returns an \ref IdentityMap class. ///\relates IdentityMap template<typename T> - inline IdentityMap<T, True> identityMap() { - return IdentityMap<T, True>(); + inline IdentityMap<T> identityMap() { + return IdentityMap<T>(); } @@ -252,11 +250,11 @@ ///This \ref concept::ReadMap "read only map" ///converts the \c Value of a maps to type \c T. ///Its \c Key is inherited from \c M. - template <typename M, typename T, typename NC = False> - class ConvertMap : public MapBase<typename M::Key, T, NC> { - typename SmartConstReference<M>::Type m; + template <typename M, typename T> + class ConvertMap : public MapBase<typename M::Key, T> { + const M& m; public: - typedef MapBase<typename M::Key, T, NC> Parent; + typedef MapBase<typename M::Key, T> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -280,8 +278,8 @@ ///\relates ConvertMap ///\todo The order of the template parameters are changed. template<typename T, typename M> - inline ConvertMap<M, T, True> convertMap(const M &m) { - return ConvertMap<M, T, True>(m); + inline ConvertMap<M, T> convertMap(const M &m) { + return ConvertMap<M, T>(m); } ///Sum of two maps @@ -290,13 +288,13 @@ ///given maps. Its \c Key and \c Value will be inherited from \c M1. ///The \c Key and \c Value of M2 must be convertible to those of \c M1. - template<typename M1, typename M2, typename NC = False> - class AddMap : public MapBase<typename M1::Key, typename M1::Value, NC> { - typename SmartConstReference<M1>::Type m1; - typename SmartConstReference<M2>::Type m2; + template<typename M1, typename M2> + class AddMap : public MapBase<typename M1::Key, typename M1::Value> { + const M1& m1; + const M2& m2; public: - typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent; + typedef MapBase<typename M1::Key, typename M1::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -313,8 +311,8 @@ ///\relates AddMap ///\todo Wrong scope in Doxygen when \c \\relates is used template<typename M1, typename M2> - inline AddMap<M1, M2, True> addMap(const M1 &m1,const M2 &m2) { - return AddMap<M1, M2, True>(m1,m2); + inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) { + return AddMap<M1, M2>(m1,m2); } ///Shift a map with a constant. @@ -332,12 +330,12 @@ /// ConstMap<X::Key, X::Value> c_tmp(v); /// AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v); ///\endcode - template<typename M, typename C = typename M::Value, typename NC = False> - class ShiftMap : public MapBase<typename M::Key, typename M::Value, NC> { - typename SmartConstReference<M>::Type m; + template<typename M, typename C = typename M::Value> + class ShiftMap : public MapBase<typename M::Key, typename M::Value> { + const M& m; C v; public: - typedef MapBase<typename M::Key, typename M::Value, NC> Parent; + typedef MapBase<typename M::Key, typename M::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -356,8 +354,8 @@ ///\relates ShiftMap ///\todo A better name is required. template<typename M, typename C> - inline ShiftMap<M, C, True> shiftMap(const M &m,const C &v) { - return ShiftMap<M, C, True>(m,v); + inline ShiftMap<M, C> shiftMap(const M &m,const C &v) { + return ShiftMap<M, C>(m,v); } ///Difference of two maps @@ -367,12 +365,12 @@ ///given maps. Its \c Key and \c Value will be inherited from \c M1. ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. - template<typename M1, typename M2, typename NC = False> - class SubMap : public MapBase<typename M1::Key, typename M1::Value, NC> { - typename SmartConstReference<M1>::Type m1; - typename SmartConstReference<M2>::Type m2; + template<typename M1, typename M2> + class SubMap : public MapBase<typename M1::Key, typename M1::Value> { + const M1& m1; + const M2& m2; public: - typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent; + typedef MapBase<typename M1::Key, typename M1::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -387,8 +385,8 @@ /// ///\relates SubMap template<typename M1, typename M2> - inline SubMap<M1, M2, True> subMap(const M1 &m1, const M2 &m2) { - return SubMap<M1, M2, True>(m1, m2); + inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) { + return SubMap<M1, M2>(m1, m2); } ///Product of two maps @@ -399,12 +397,12 @@ ///maps. Its \c Key and \c Value will be inherited from \c M1. ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. - template<typename M1, typename M2, typename NC = False> - class MulMap : public MapBase<typename M1::Key, typename M1::Value, NC> { - typename SmartConstReference<M1>::Type m1; - typename SmartConstReference<M2>::Type m2; + template<typename M1, typename M2> + class MulMap : public MapBase<typename M1::Key, typename M1::Value> { + const M1& m1; + const M2& m2; public: - typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent; + typedef MapBase<typename M1::Key, typename M1::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -418,8 +416,8 @@ ///This function just returns a \ref MulMap class. ///\relates MulMap template<typename M1, typename M2> - inline MulMap<M1, M2, True> mulMap(const M1 &m1,const M2 &m2) { - return MulMap<M1, M2, True>(m1,m2); + inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) { + return MulMap<M1, M2>(m1,m2); } ///Scales a maps with a constant. @@ -437,12 +435,12 @@ /// ConstMap<X::Key, X::Value> c_tmp(v); /// MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v); ///\endcode - template<typename M, typename C = typename M::Value, typename NC = False> - class ScaleMap : public MapBase<typename M::Key, typename M::Value, NC> { - typename SmartConstReference<M>::Type m; + template<typename M, typename C = typename M::Value> + class ScaleMap : public MapBase<typename M::Key, typename M::Value> { + const M& m; C v; public: - typedef MapBase<typename M::Key, typename M::Value, NC> Parent; + typedef MapBase<typename M::Key, typename M::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -461,8 +459,8 @@ ///\relates ScaleMap ///\todo A better name is required. template<typename M, typename C> - inline ScaleMap<M, C, True> scaleMap(const M &m,const C &v) { - return ScaleMap<M, C, True>(m,v); + inline ScaleMap<M, C> scaleMap(const M &m,const C &v) { + return ScaleMap<M, C>(m,v); } ///Quotient of two maps @@ -472,12 +470,12 @@ ///given maps. Its \c Key and \c Value will be inherited from \c M1. ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. - template<typename M1, typename M2, typename NC = False> - class DivMap : public MapBase<typename M1::Key, typename M1::Value, NC> { - typename SmartConstReference<M1>::Type m1; - typename SmartConstReference<M2>::Type m2; + template<typename M1, typename M2> + class DivMap : public MapBase<typename M1::Key, typename M1::Value> { + const M1& m1; + const M2& m2; public: - typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent; + typedef MapBase<typename M1::Key, typename M1::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -491,8 +489,8 @@ ///This function just returns a \ref DivMap class. ///\relates DivMap template<typename M1, typename M2> - inline DivMap<M1, M2, True> divMap(const M1 &m1,const M2 &m2) { - return DivMap<M1, M2, True>(m1,m2); + inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) { + return DivMap<M1, M2>(m1,m2); } ///Composition of two maps @@ -512,12 +510,12 @@ ///The \c M2::Value must be convertible to \c M1::Key. ///\todo Check the requirements. - template <typename M1, typename M2, typename NC = False> - class ComposeMap : public MapBase<typename M2::Key, typename M1::Value, NC> { - typename SmartConstReference<M1>::Type m1; - typename SmartConstReference<M2>::Type m2; + template <typename M1, typename M2> + class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> { + const M1& m1; + const M2& m2; public: - typedef MapBase<typename M2::Key, typename M1::Value, NC> Parent; + typedef MapBase<typename M2::Key, typename M1::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -531,8 +529,8 @@ /// ///\relates ComposeMap template <typename M1, typename M2> - inline ComposeMap<M1, M2, True> composeMap(const M1 &m1,const M2 &m2) { - return ComposeMap<M1, M2, True>(m1,m2); + inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) { + return ComposeMap<M1, M2>(m1,m2); } ///Combines of two maps using an STL (binary) functor. @@ -561,12 +559,12 @@ template<typename M1, typename M2, typename F, typename V = typename F::result_type, typename NC = False> - class CombineMap : public MapBase<typename M1::Key, V, NC> { - typename SmartConstReference<M1>::Type m1; - typename SmartConstReference<M2>::Type m2; + class CombineMap : public MapBase<typename M1::Key, V> { + const M1& m1; + const M2& m2; F f; public: - typedef MapBase<typename M1::Key, V, NC> Parent; + typedef MapBase<typename M1::Key, V> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -593,19 +591,19 @@ /// ///\relates CombineMap template<typename M1, typename M2, typename F, typename V> - inline CombineMap<M1, M2, F, V, True> + inline CombineMap<M1, M2, F, V> combineMap(const M1& m1,const M2& m2, const F& f) { - return CombineMap<M1, M2, F, V, True>(m1,m2,f); + return CombineMap<M1, M2, F, V>(m1,m2,f); } template<typename M1, typename M2, typename F> - inline CombineMap<M1, M2, F, typename F::result_type, True> + inline CombineMap<M1, M2, F, typename F::result_type> combineMap(const M1& m1, const M2& m2, const F& f) { return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f); } template<typename M1, typename M2, typename K1, typename K2, typename V> - inline CombineMap<M1, M2, V (*)(K1, K2), V, True> + inline CombineMap<M1, M2, V (*)(K1, K2), V> combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) { return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f); } @@ -618,11 +616,11 @@ ///given map. Its \c Key and \c Value will be inherited from \c M. ///The unary \c - operator must be defined for \c Value, of course. - template<typename M, typename NC = False> - class NegMap : public MapBase<typename M::Key, typename M::Value, NC> { - typename SmartConstReference<M>::Type m; + template<typename M> + class NegMap : public MapBase<typename M::Key, typename M::Value> { + const M& m; public: - typedef MapBase<typename M::Key, typename M::Value, NC> Parent; + typedef MapBase<typename M::Key, typename M::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -636,8 +634,8 @@ ///This function just returns a \ref NegMap class. ///\relates NegMap template <typename M> - inline NegMap<M, True> negMap(const M &m) { - return NegMap<M, True>(m); + inline NegMap<M> negMap(const M &m) { + return NegMap<M>(m); } @@ -664,11 +662,11 @@ ///\endcode - template<typename M, typename NC = False> - class AbsMap : public MapBase<typename M::Key, typename M::Value, NC> { - typename SmartConstReference<M>::Type m; + template<typename M> + class AbsMap : public MapBase<typename M::Key, typename M::Value> { + const M& m; public: - typedef MapBase<typename M::Key, typename M::Value, NC> Parent; + typedef MapBase<typename M::Key, typename M::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -686,8 +684,8 @@ ///This function just returns a \ref AbsMap class. ///\relates AbsMap template<typename M> - inline AbsMap<M, True> absMap(const M &m) { - return AbsMap<M, True>(m); + inline AbsMap<M> absMap(const M &m) { + return AbsMap<M>(m); } ///Converts an STL style functor to a map @@ -707,10 +705,10 @@ typename K = typename F::argument_type, typename V = typename F::result_type, typename NC = False> - class FunctorMap : public MapBase<K, V, NC> { + class FunctorMap : public MapBase<K, V> { F f; public: - typedef MapBase<K, V, NC> Parent; + typedef MapBase<K, V> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -727,20 +725,20 @@ ///The third template parameter isn't necessary to be given. ///\relates FunctorMap template<typename K, typename V, typename F> inline - FunctorMap<F, K, V, True> functorMap(const F &f) { - return FunctorMap<F, K, V, True>(f); + FunctorMap<F, K, V> functorMap(const F &f) { + return FunctorMap<F, K, V>(f); } template <typename F> inline - FunctorMap<F, typename F::argument_type, typename F::result_type, True> + FunctorMap<F, typename F::argument_type, typename F::result_type> functorMap(const F &f) { return FunctorMap<F, typename F::argument_type, - typename F::result_type, True>(f); + typename F::result_type>(f); } template <typename K, typename V> inline - FunctorMap<V (*)(K), K, V, True> functorMap(V (*f)(K)) { - return FunctorMap<V (*)(K), K, V, True>(f); + FunctorMap<V (*)(K), K, V> functorMap(V (*f)(K)) { + return FunctorMap<V (*)(K), K, V>(f); } @@ -753,11 +751,11 @@ ///a ususal \ref concept::ReadMap "readable map", ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist. - template <typename M, typename NC = False> - class MapFunctor : public MapBase<typename M::Key, typename M::Value, NC> { - typename SmartConstReference<M>::Type m; + template <typename M> + class MapFunctor : public MapBase<typename M::Key, typename M::Value> { + const M& m; public: - typedef MapBase<typename M::Key, typename M::Value, NC> Parent; + typedef MapBase<typename M::Key, typename M::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -779,8 +777,8 @@ ///This function just returns a \ref MapFunctor class. ///\relates MapFunctor template<typename M> - inline MapFunctor<M, True> mapFunctor(const M &m) { - return MapFunctor<M, True>(m); + inline MapFunctor<M> mapFunctor(const M &m) { + return MapFunctor<M>(m); } @@ -795,12 +793,12 @@ ///The \c Key and \c Value will be inherited from \c M1. ///The \c Key and \c Value of M2 must be convertible from those of \c M1. - template<typename M1, typename M2, typename NC = False> - class ForkMap : public MapBase<typename M1::Key, typename M1::Value, NC> { - typename SmartConstReference<M1>::Type m1; - typename SmartConstReference<M2>::Type m2; + template<typename M1, typename M2> + class ForkMap : public MapBase<typename M1::Key, typename M1::Value> { + const M1& m1; + const M2& m2; public: - typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent; + typedef MapBase<typename M1::Key, typename M1::Value> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -818,8 +816,8 @@ ///\relates ForkMap ///\todo Wrong scope in Doxygen when \c \\relates is used template <typename M1, typename M2> - inline ForkMap<M1, M2, True> forkMap(const M1 &m1,const M2 &m2) { - return ForkMap<M1, M2, True>(m1,m2); + inline ForkMap<M1, M2> forkMap(const M1 &m1,const M2 &m2) { + return ForkMap<M1, M2>(m1,m2); } @@ -834,11 +832,11 @@ ///given map. Its \c Key and will be inherited from \c M, ///its Value is <tt>bool</tt>. - template <typename M, typename NC = False> - class NotMap : public MapBase<typename M::Key, bool, NC> { - typename SmartConstReference<M>::Type m; + template <typename M> + class NotMap : public MapBase<typename M::Key, bool> { + const M& m; public: - typedef MapBase<typename M::Key, bool, NC> Parent; + typedef MapBase<typename M::Key, bool> Parent; typedef typename Parent::Key Key; typedef typename Parent::Value Value; @@ -852,8 +850,8 @@ ///This function just returns a \ref NotMap class. ///\relates NotMap template <typename M> - inline NotMap<M, True> notMap(const M &m) { - return NotMap<M, True>(m); + inline NotMap<M> notMap(const M &m) { + return NotMap<M>(m); } /// @} diff -r 467d7927a901 -r 3f63d9db307b lemon/utility.h --- a/lemon/utility.h Wed Oct 05 13:17:42 2005 +0000 +++ b/lemon/utility.h Wed Oct 05 13:18:51 2005 +0000 @@ -139,47 +139,6 @@ template <class Cond, class T> struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {}; - // smart referencing - - template <typename _Type, typename Enable = void> - struct SmartReference { - typedef _Type& Type; - }; - - template <typename _Type> - struct SmartReference< - _Type, - typename enable_if<typename _Type::NeedCopy, void>::type - > { - typedef _Type Type; - }; - - template <typename _Type, typename Enable = void> - struct SmartConstReference { - typedef const _Type& Type; - }; - - template <typename _Type> - struct SmartConstReference< - _Type, - typename enable_if<typename _Type::NeedCopy, void>::type - > { - typedef const _Type Type; - }; - - template <typename _Type, typename Enable = void> - struct SmartParameter { - typedef _Type& Type; - }; - - template <typename _Type> - struct SmartParameter< - _Type, - typename enable_if<typename _Type::NeedCopy, void>::type - > { - typedef const _Type& Type; - }; - } // namespace lemon #endif