# HG changeset patch # User deba # Date 1125494972 0 # Node ID 66ae78d29f1eaa2b258a010722aada363b006155 # Parent d5a7d6bc0f006594f0dd9243fc08b98369d96cb7 Template assign operator for graph maps. Some naming and coding conventions. diff -r d5a7d6bc0f00 -r 66ae78d29f1e lemon/bits/array_map.h --- a/lemon/bits/array_map.h Tue Aug 30 21:19:07 2005 +0000 +++ b/lemon/bits/array_map.h Wed Aug 31 13:29:32 2005 +0000 @@ -19,26 +19,27 @@ #include #include +#include +#include -///\ingroup graphmapfactory -///\file -///\brief Graph maps that construates and destruates -///their elements dynamically. +/// \ingroup graphmapfactory +/// \file +/// \brief Graph maps that construct and destruct +/// their elements dynamically. namespace lemon { - - /// \addtogroup graphmapfactory - /// @{ - + /// \ingroup graphmapfactory + /// + /// \brief Graph map based on the array storage. + /// /// The ArrayMap template class is graph map structure what /// automatically updates the map when a key is added to or erased from - /// the map. This map factory uses the allocators to implement + /// the map. This map uses the allocators to implement /// the container functionality. /// /// The template parameter is the AlterationNotifier that the maps /// will belong to and the Value. - template first(it); it != INVALID; graph->next(it)) { - int id = graph->id(it);; - allocator.construct(&(values[id]), copy.values[id]); - } - - return *this; - } - + /// \brief The destructor of the map. + /// /// The destructor of the map. - virtual ~ArrayMap() { if (attached()) { clear(); detach(); } } - - + + private: + + ArrayMap& operator=(const ArrayMap&); + + protected: + + using Parent::attach; + using Parent::detach; + using Parent::attached; + + const Graph* getGraph() { + return graph; + } + + + public: + ///The subscript operator. The map can be subscripted by the ///actual keys of the graph. @@ -174,7 +160,9 @@ void set(const Key& key, const Value& val) { (*this)[key] = val; } - + + protected: + /// Add a new key to the map. It called by the map registry. void add(const Key& key) { @@ -274,10 +262,6 @@ } } - const Graph* getGraph() { - return graph; - } - private: void allocate_memory() { @@ -301,69 +285,6 @@ }; - template - class ArrayMappableGraphExtender : public _Base { - public: - - typedef ArrayMappableGraphExtender<_Base> Graph; - typedef _Base Parent; - - typedef typename Parent::Node Node; - typedef typename Parent::NodeIt NodeIt; - typedef typename Parent::NodeNotifier NodeObserverRegistry; - - typedef typename Parent::Edge Edge; - typedef typename Parent::EdgeIt EdgeIt; - typedef typename Parent::EdgeNotifier EdgeObserverRegistry; - - - - template - class NodeMap - : public IterableMapExtender > { - public: - typedef ArrayMappableGraphExtender<_Base> Graph; - - typedef typename Graph::Node Node; - typedef typename Graph::NodeIt NodeIt; - - typedef IterableMapExtender > Parent; - - //typedef typename Parent::Graph Graph; - typedef typename Parent::Value Value; - - NodeMap(const Graph& g) - : Parent(g) {} - NodeMap(const Graph& g, const Value& v) - : Parent(g, v) {} - - }; - - template - class EdgeMap - : public IterableMapExtender > { - public: - typedef ArrayMappableGraphExtender<_Base> Graph; - - typedef typename Graph::Edge Edge; - typedef typename Graph::EdgeIt EdgeIt; - - typedef IterableMapExtender > Parent; - - //typedef typename Parent::Graph Graph; - typedef typename Parent::Value Value; - - EdgeMap(const Graph& g) - : Parent(g) {} - EdgeMap(const Graph& g, const Value& v) - : Parent(g, v) {} - - }; - - }; - -/// @} - } #endif //LEMON_ARRAY_MAP_H diff -r d5a7d6bc0f00 -r 66ae78d29f1e lemon/bits/default_map.h --- a/lemon/bits/default_map.h Tue Aug 30 21:19:07 2005 +0000 +++ b/lemon/bits/default_map.h Wed Aug 31 13:29:32 2005 +0000 @@ -28,19 +28,8 @@ namespace lemon { -/// \addtogroup graphmapfactory -/// @{ - - /** The ArrayMap template class is graph map structure what - * automatically updates the map when a key is added to or erased from - * the map. This map uses the VectorMap if the Value is a primitive - * type and the ArrayMap for the other cases. - * - * The template parameter is the MapRegistry that the maps - * will belong to and the Value. - */ - - + /// \addtogroup graphmapfactory + /// @{ template struct DefaultMapSelector { @@ -135,8 +124,7 @@ typedef VectorMap<_Graph, _Item, _Ptr*> Map; }; - - + /// \e template < typename _Graph, typename _Item, @@ -152,15 +140,16 @@ DefaultMap(const Graph& _g) : Parent(_g) {} DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {} + }; - + /// \e template - class DefaultMappableGraphExtender : public _Base { + class MappableGraphExtender : public _Base { public: - typedef DefaultMappableGraphExtender<_Base> Graph; + typedef MappableGraphExtender<_Base> Graph; typedef _Base Parent; typedef typename Parent::Node Node; @@ -174,37 +163,67 @@ class NodeMap : public IterableMapExtender > { public: - typedef DefaultMappableGraphExtender Graph; + typedef MappableGraphExtender Graph; typedef IterableMapExtender > Parent; NodeMap(const Graph& _g) : Parent(_g) {} NodeMap(const Graph& _g, const _Value& _v) : Parent(_g, _v) {} + + /// \brief Template assign operator. + /// + /// The given parameter should be conform to the ReadMap + /// concecpt and could be indiced by the current item set of + /// the NodeMap. In this case the value for each item + /// is assigned by the value of the given ReadMap. + template + NodeMap& operator=(const CMap& cmap) { + checkConcept, CMap>(); + const typename Parent::Graph* graph = Parent::getGraph(); + Node it; + for (graph->first(it); it != INVALID; graph->next(it)) { + Parent::set(it, cmap[it]); + } + return *this; + } + }; template class EdgeMap : public IterableMapExtender > { public: - typedef DefaultMappableGraphExtender Graph; + typedef MappableGraphExtender Graph; typedef IterableMapExtender > Parent; EdgeMap(const Graph& _g) : Parent(_g) {} EdgeMap(const Graph& _g, const _Value& _v) : Parent(_g, _v) {} + + template + EdgeMap& operator=(const CMap& cmap) { + checkConcept, CMap>(); + const typename Parent::Graph* graph = Parent::getGraph(); + Edge it; + for (graph->first(it); it != INVALID; graph->next(it)) { + Parent::set(it, cmap[it]); + } + return *this; + } }; }; + /// \e template class MappableUndirGraphExtender : - public DefaultMappableGraphExtender<_Base> { + public MappableGraphExtender<_Base> { public: typedef MappableUndirGraphExtender Graph; - typedef DefaultMappableGraphExtender<_Base> Parent; + typedef MappableGraphExtender<_Base> Parent; typedef typename Parent::UndirEdge UndirEdge; @@ -220,11 +239,23 @@ : Parent(_g) {} UndirEdgeMap(const Graph& _g, const _Value& _v) : Parent(_g, _v) {} + + template + UndirEdgeMap& operator=(const CMap& cmap) { + checkConcept, CMap>(); + const typename Parent::Graph* graph = Parent::getGraph(); + UndirEdge it; + for (graph->first(it); it != INVALID; graph->next(it)) { + Parent::set(it, cmap[it]); + } + return *this; + } }; }; + /// @} } #endif diff -r d5a7d6bc0f00 -r 66ae78d29f1e lemon/bits/vector_map.h --- a/lemon/bits/vector_map.h Tue Aug 30 21:19:07 2005 +0000 +++ b/lemon/bits/vector_map.h Wed Aug 31 13:29:32 2005 +0000 @@ -23,16 +23,20 @@ #include #include #include +#include +#include -///\ingroup graphmapfactory +/// \ingroup graphmapfactory +/// ///\file ///\brief Vector based graph maps. namespace lemon { - - /// \addtogroup graphmapfactory - /// @{ - + + /// \ingroup graphmapfactory + /// + /// \brief Graph map based on the std::vector storage. + /// /// The VectorMap template class is graph map structure what /// automatically updates the map when a key is added to or erased from /// the map. This map factory uses the allocators to implement @@ -117,39 +121,29 @@ } } - using Parent::attach; - using Parent::detach; - using Parent::attached; - - /** Assign operator to copy a map of the same map type. - */ - VectorMap& operator=(const VectorMap& copy) { - if (© == this) return *this; - - if (graph != copy.graph) { - if (attached()) { - detach(); - } - if (copy.attached()) { - attach(*copy.getRegistry()); - } - } - container = copy.container; - - return *this; - } - - virtual ~VectorMap() { if (attached()) { detach(); } } + + private: + + VectorMap& operator=(const VectorMap&); + + protected: + + using Parent::attach; + using Parent::detach; + using Parent::attached; + const Graph* getGraph() const { return graph; } + public: + /// The subcript operator. /// The subscript operator. The map can be subscripted by the @@ -173,13 +167,14 @@ /// It the same as operator[](key) = value expression. /// - void set(const Key& key, const Value& value) { (*this)[key] = value; } - /// Adds a new key to the map. - + protected: + + /// \brief Adds a new key to the map. + /// /// It adds a new key to the map. It called by the observer registry /// and it overrides the add() member function of the observer base. @@ -220,69 +215,6 @@ }; - - template - class VectorMappableGraphExtender : public _Base { - public: - - typedef VectorMappableGraphExtender<_Base> Graph; - typedef _Base Parent; - - typedef typename Parent::Node Node; - typedef typename Parent::NodeIt NodeIt; - typedef typename Parent::NodeIdMap NodeIdMap; - typedef typename Parent::NodeNotifier NodeObserverRegistry; - - typedef typename Parent::Edge Edge; - typedef typename Parent::EdgeIt EdgeIt; - typedef typename Parent::EdgeIdMap EdgeIdMap; - typedef typename Parent::EdgeNotifier EdgeObserverRegistry; - - - template - class NodeMap : - public IterableMapExtender > { - public: - typedef VectorMappableGraphExtender<_Base> Graph; - - typedef typename Graph::Node Node; - - typedef IterableMapExtender > Parent; - - //typedef typename Parent::Graph Graph; - typedef typename Parent::Value Value; - - NodeMap(const Graph& g) - : Parent(g) {} - NodeMap(const Graph& g, const Value& v) - : Parent(g, v) {} - - }; - - template - class EdgeMap - : public IterableMapExtender > { - public: - typedef VectorMappableGraphExtender<_Base> Graph; - - typedef typename Graph::Edge Edge; - - typedef IterableMapExtender > Parent; - - //typedef typename Parent::Graph Graph; - typedef typename Parent::Value Value; - - EdgeMap(const Graph& g) - : Parent(g) {} - EdgeMap(const Graph& g, const Value& v) - : Parent(g, v) {} - - }; - - }; - - /// @} - } #endif diff -r d5a7d6bc0f00 -r 66ae78d29f1e lemon/concept/graph_component.h --- a/lemon/concept/graph_component.h Tue Aug 30 21:19:07 2005 +0000 +++ b/lemon/concept/graph_component.h Wed Aug 31 13:29:32 2005 +0000 @@ -798,8 +798,6 @@ _Map a2(g,t); // Copy constructor. Do we need it? _Map b=c; - // Copy operator. Do we need it? - a=b; ignore_unused_variable_warning(a2); } diff -r d5a7d6bc0f00 -r 66ae78d29f1e lemon/concept/undir_graph.h --- a/lemon/concept/undir_graph.h Tue Aug 30 21:19:07 2005 +0000 +++ b/lemon/concept/undir_graph.h Wed Aug 31 13:29:32 2005 +0000 @@ -248,9 +248,9 @@ /// typedef True UndirTag; - /// The base type of node iterators, + /// \brief The base type of node iterators, /// or in other words, the trivial node iterator. - + /// /// This is the base type of each node iterator, /// thus each kind of node iterator converts to this. /// More precisely each kind of node iterator should be inherited diff -r d5a7d6bc0f00 -r 66ae78d29f1e lemon/full_graph.h --- a/lemon/full_graph.h Tue Aug 30 21:19:07 2005 +0000 +++ b/lemon/full_graph.h Wed Aug 31 13:29:32 2005 +0000 @@ -195,8 +195,9 @@ AlterableFullGraphBase; typedef IterableGraphExtender IterableFullGraphBase; - typedef DefaultMappableGraphExtender - MappableFullGraphBase; + typedef MappableGraphExtender< + IterableGraphExtender< + AlterableGraphExtender > > ExtendedFullGraphBase; /// \ingroup graphs /// @@ -210,7 +211,7 @@ /// \sa concept::StaticGraph. /// /// \author Alpar Juttner - class FullGraph : public MappableFullGraphBase { + class FullGraph : public ExtendedFullGraphBase { public: FullGraph(int n) { construct(n); } @@ -378,14 +379,10 @@ }; - typedef UndirGraphExtender - UndirUndirFullGraphBase; - typedef AlterableUndirGraphExtender - AlterableUndirFullGraphBase; - typedef IterableUndirGraphExtender - IterableUndirFullGraphBase; - typedef MappableUndirGraphExtender - MappableUndirFullGraphBase; + typedef MappableUndirGraphExtender< + IterableUndirGraphExtender< + AlterableUndirGraphExtender< + UndirGraphExtender > > > ExtendedUndirFullGraphBase; /// \ingroup graphs /// @@ -402,7 +399,7 @@ /// \sa FullGraph /// /// \author Balazs Dezso - class UndirFullGraph : public MappableUndirFullGraphBase { + class UndirFullGraph : public ExtendedUndirFullGraphBase { public: UndirFullGraph(int n) { construct(n); } }; diff -r d5a7d6bc0f00 -r 66ae78d29f1e lemon/graph_adaptor.h --- a/lemon/graph_adaptor.h Tue Aug 30 21:19:07 2005 +0000 +++ b/lemon/graph_adaptor.h Wed Aug 31 13:29:32 2005 +0000 @@ -1430,7 +1430,7 @@ public ErasableGraphExtender< ClearableGraphExtender< ExtendableGraphExtender< - DefaultMappableGraphExtender< + MappableGraphExtender< IterableGraphExtender< AlterableGraphExtender< NewEdgeSetAdaptorBase<_Graph> > > > > > > { @@ -1440,7 +1440,7 @@ typedef ErasableGraphExtender< ClearableGraphExtender< ExtendableGraphExtender< - DefaultMappableGraphExtender< + MappableGraphExtender< IterableGraphExtender< AlterableGraphExtender< NewEdgeSetAdaptorBase<_Graph> > > > > > > Parent; diff -r d5a7d6bc0f00 -r 66ae78d29f1e lemon/list_graph.h --- a/lemon/list_graph.h Tue Aug 30 21:19:07 2005 +0000 +++ b/lemon/list_graph.h Wed Aug 31 13:29:32 2005 +0000 @@ -304,10 +304,15 @@ typedef AlterableGraphExtender AlterableListGraphBase; typedef IterableGraphExtender IterableListGraphBase; - typedef DefaultMappableGraphExtender MappableListGraphBase; + typedef MappableGraphExtender MappableListGraphBase; typedef ExtendableGraphExtender ExtendableListGraphBase; typedef ClearableGraphExtender ClearableListGraphBase; - typedef ErasableGraphExtender ErasableListGraphBase; + typedef ErasableGraphExtender< + ClearableGraphExtender< + ExtendableGraphExtender< + MappableGraphExtender< + IterableGraphExtender< + AlterableGraphExtender > > > > > ExtendedListGraphBase; /// \addtogroup graphs /// @{ @@ -321,7 +326,7 @@ ///it also provides several additional useful extra functionalities. ///\sa concept::ErasableGraph. - class ListGraph : public ErasableListGraphBase + class ListGraph : public ExtendedListGraphBase { public: /// Changes the target of \c e to \c n @@ -549,7 +554,7 @@ MappableUndirGraphExtender< IterableUndirGraphExtender< AlterableUndirGraphExtender< - UndirGraphExtender > > > > > > ErasableUndirListGraphBase; + UndirGraphExtender > > > > > > ExtendedUndirListGraphBase; /// \addtogroup graphs /// @{ @@ -566,7 +571,7 @@ ///\todo SnapShot, reverseEdge(), changeTarget(), changeSource(), contract() ///haven't been implemented yet. /// - class UndirListGraph : public ErasableUndirListGraphBase { + class UndirListGraph : public ExtendedUndirListGraphBase { }; diff -r d5a7d6bc0f00 -r 66ae78d29f1e lemon/maps.h --- a/lemon/maps.h Tue Aug 30 21:19:07 2005 +0000 +++ b/lemon/maps.h Wed Aug 31 13:29:32 2005 +0000 @@ -113,10 +113,10 @@ ///This function just returns a \ref ConstMap class. ///\relates ConstMap - template - inline ConstMap constMap(const K &k) + template + inline ConstMap constMap(const V &v) { - return ConstMap(k); + return ConstMap(v); } diff -r d5a7d6bc0f00 -r 66ae78d29f1e lemon/smart_graph.h --- a/lemon/smart_graph.h Tue Aug 30 21:19:07 2005 +0000 +++ b/lemon/smart_graph.h Wed Aug 31 13:29:32 2005 +0000 @@ -233,11 +233,11 @@ }; - typedef AlterableGraphExtender AlterableSmartGraphBase; - typedef IterableGraphExtender IterableSmartGraphBase; - typedef DefaultMappableGraphExtender MappableSmartGraphBase; - typedef ExtendableGraphExtender ExtendableSmartGraphBase; - typedef ClearableGraphExtender ClearableSmartGraphBase; + typedef ClearableGraphExtender< + ExtendableGraphExtender< + MappableGraphExtender< + IterableGraphExtender< + AlterableGraphExtender > > > > ExtendedSmartGraphBase; /// \addtogroup graphs /// @{ @@ -253,7 +253,7 @@ ///\sa concept::ExtendableGraph. /// ///\author Alpar Juttner - class SmartGraph : public ClearableSmartGraphBase { + class SmartGraph : public ExtendedSmartGraphBase { public: /// Finds an edge between two nodes. @@ -390,7 +390,7 @@ MappableUndirGraphExtender< IterableUndirGraphExtender< AlterableUndirGraphExtender< - UndirGraphExtender > > > > > UndirSmartGraphBase; + UndirGraphExtender > > > > > ExtendedUndirSmartGraphBase; ///A smart undirected graph class. @@ -404,7 +404,7 @@ /// ///\todo SnapShot hasn't been implemented yet. /// - class UndirSmartGraph : public UndirSmartGraphBase { + class UndirSmartGraph : public ExtendedUndirSmartGraphBase { };