# HG changeset patch # User deba # Date 1129286914 0 # Node ID 674182524bd9981626387c32e110f510d5f3c8fa # Parent 6a958ab38386e953039c92bdf2ca74b57b816e41 Traits moved to own file Tag for reference maps Possibility to handle proper the return type of the operator[]() const -- value or reference diff -r 6a958ab38386 -r 674182524bd9 lemon/bits/array_map.h --- a/lemon/bits/array_map.h Fri Oct 14 10:44:49 2005 +0000 +++ b/lemon/bits/array_map.h Fri Oct 14 10:48:34 2005 +0000 @@ -48,20 +48,29 @@ typedef _Item Item; public: - typedef True AdaptibleTag; - /// The graph type of the maps. typedef _Graph Graph; + /// The reference map tag. + typedef True ReferenceMapTag; + /// The key type of the maps. typedef _Item Key; + /// The value type of the map. + typedef _Value Value; + /// The const reference type of the map. + typedef const _Value& ConstReference; + /// The reference type of the map. + typedef _Value& Reference; + + typedef const Value ConstValue; + typedef Value* Pointer; + typedef const Value* ConstPointer; typedef AlterationNotifier<_Item> Registry; /// The MapBase of the Map which imlements the core regisitry function. typedef typename Registry::ObserverBase Parent; - /// The value type of the map. - typedef _Value Value; private: @@ -70,9 +79,9 @@ public: - /// \brief Graph and Registry initialized map constructor. + /// \brief Graph initialized map constructor. /// - /// Graph and Registry initialized map constructor. + /// Graph initialized map constructor. ArrayMap(const Graph& _g) : graph(&_g) { Item it; attach(_g.getNotifier(Item())); diff -r 6a958ab38386 -r 674182524bd9 lemon/bits/map_iterator.h --- a/lemon/bits/map_iterator.h Fri Oct 14 10:44:49 2005 +0000 +++ b/lemon/bits/map_iterator.h Fri Oct 14 10:48:34 2005 +0000 @@ -104,8 +104,8 @@ typedef typename Parent::ItemIt ItemIt; - typedef typename ReferenceMapTraits<_Map>::Value MapValue; - typedef typename ReferenceMapTraits<_Map>::Reference MapReference; + typedef typename _Map::Value MapValue; + typedef typename _Map::Reference MapReference; public: @@ -194,9 +194,8 @@ typedef typename Parent::ItemIt ItemIt; - typedef typename ReferenceMapTraits<_Map>::Value MapValue; - typedef typename ReferenceMapTraits<_Map>::ConstReference - MapReference; + typedef typename _Map::Value MapValue; + typedef typename _Map::ConstReference MapReference; public: @@ -353,11 +352,11 @@ typedef typename Parent::ItemIt ItemIt; /// The value type of the iterator. - typedef typename ReferenceMapTraits::Value MapValue; + typedef typename Map::Value MapValue; /// The reference type of the iterator. - typedef typename ReferenceMapTraits::Reference MapReference; + typedef typename Map::Reference MapReference; /// The pointer type of the iterator. - typedef typename ReferenceMapTraits::Pointer MapPointer; + typedef typename Map::Pointer MapPointer; public: @@ -433,11 +432,11 @@ typedef typename Parent::ItemIt ItemIt; /// The value type of the iterator. - typedef typename ReferenceMapTraits::Value MapValue; + typedef typename Map::Value MapValue; /// The reference type of the iterator. - typedef typename ReferenceMapTraits::ConstReference MapReference; + typedef typename Map::ConstReference MapReference; /// The pointer type of the iterator. - typedef typename ReferenceMapTraits::ConstPointer MapPointer; + typedef typename Map::ConstPointer MapPointer; public: diff -r 6a958ab38386 -r 674182524bd9 lemon/bits/static_map.h --- a/lemon/bits/static_map.h Fri Oct 14 10:44:49 2005 +0000 +++ b/lemon/bits/static_map.h Fri Oct 14 10:48:34 2005 +0000 @@ -62,28 +62,37 @@ } }; - typedef True AdaptibleTag; + private: + typedef std::vector<_Value> Container; + + public: + /// The graph type of the map. typedef _Graph Graph; + /// The reference map tag. + typedef True ReferenceMapTag; + /// The key type of the map. typedef _Item Key; - /// The id map type of the map. - typedef AlterationNotifier<_Item> Registry; /// The value type of the map. typedef _Value Value; + /// The const reference type of the map. + typedef typename Container::const_reference ConstReference; + /// The reference type of the map. + typedef typename Container::reference Reference; + + typedef const Value ConstValue; + typedef Value* Pointer; + typedef const Value* ConstPointer; + + typedef AlterationNotifier<_Item> Registry; /// The map type. typedef StaticMap Map; /// The base class of the map. typedef typename Registry::ObserverBase Parent; - private: - - typedef std::vector Container; - - public: - /// \brief Constructor to attach the new map into the registry. /// /// It constructs a map and attachs it into the registry. @@ -141,12 +150,6 @@ public: - typedef typename Container::reference Reference; - typedef typename Container::pointer Pointer; - typedef const Value ConstValue; - typedef typename Container::const_reference ConstReference; - typedef typename Container::const_pointer ConstPointer; - /// \brief The subcript operator. /// /// The subscript operator. The map can be subscripted by the diff -r 6a958ab38386 -r 674182524bd9 lemon/bits/vector_map.h --- a/lemon/bits/vector_map.h Fri Oct 14 10:44:49 2005 +0000 +++ b/lemon/bits/vector_map.h Fri Oct 14 10:48:34 2005 +0000 @@ -55,31 +55,38 @@ typename _Value > class VectorMap : public AlterationNotifier<_Item>::ObserverBase { + private: + + /// The container type of the map. + typedef std::vector<_Value> Container; + public: - typedef True AdaptibleTag; - /// The graph type of the map. typedef _Graph Graph; + /// The reference map tag. + typedef True ReferenceMapTag; + /// The key type of the map. typedef _Item Key; - /// The id map type of the map. - typedef AlterationNotifier<_Item> Registry; /// The value type of the map. typedef _Value Value; + /// The const reference type of the map. + typedef typename Container::const_reference ConstReference; + /// The reference type of the map. + typedef typename Container::reference Reference; + + typedef const Value ConstValue; + typedef Value* Pointer; + typedef const Value* ConstPointer; + + typedef AlterationNotifier<_Item> Registry; /// The map type. typedef VectorMap Map; /// The base class of the map. typedef typename Registry::ObserverBase Parent; - private: - - /// The container type of the map. - typedef std::vector Container; - - public: - /// The reference type of the map; typedef typename Container::reference Reference; /// The pointer type of the map; diff -r 6a958ab38386 -r 674182524bd9 lemon/concept/maps.h --- a/lemon/concept/maps.h Fri Oct 14 10:44:49 2005 +0000 +++ b/lemon/concept/maps.h Fri Oct 14 10:48:34 2005 +0000 @@ -17,6 +17,7 @@ #ifndef LEMON_CONCEPT_MAPS_H #define LEMON_CONCEPT_MAPS_H +#include #include ///\ingroup concept @@ -97,7 +98,7 @@ typename _WriteMap::Value own_val; Key& key; typename _WriteMap::Key& own_key; - WriteMap& m; + _WriteMap& m; }; }; @@ -122,7 +123,7 @@ struct Constraints { void constraints() { checkConcept, _ReadWriteMap >(); - checkConcept, _ReadWriteMap >(); + checkConcept, _ReadWriteMap >(); } }; }; @@ -133,6 +134,8 @@ class ReferenceMap : public ReadWriteMap { public: + /// Tag for reference maps. + typedef True ReferenceMapTag; /// Map's key type. typedef K Key; /// Map's value type. (The type of objects associated with the keys). @@ -176,7 +179,7 @@ Key& key; Value& val; Reference& ref; - ReferenceMap& m; + _ReferenceMap& m; }; }; diff -r 6a958ab38386 -r 674182524bd9 lemon/traits.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemon/traits.h Fri Oct 14 10:48:34 2005 +0000 @@ -0,0 +1,168 @@ +/* -*- C++ -*- + * lemon/traits.h - Part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#ifndef LEMON_TRAITS_H +#define LEMON_TRAITS_H + +#include + +///\file +///\brief Traits for graphs and maps +/// + +namespace lemon { + template + class ItemSetTraits {}; + + template + class ItemSetTraits<_Graph, typename _Graph::Node> { + public: + + typedef _Graph Graph; + + typedef typename Graph::Node Item; + typedef typename Graph::NodeIt ItemIt; + + template + class Map : public Graph::template NodeMap<_Value> { + public: + typedef typename Graph::template NodeMap<_Value> Parent; + typedef typename Parent::Value Value; + + Map(const Graph& _graph) : Parent(_graph) {} + Map(const Graph& _graph, const Value& _value) + : Parent(_graph, _value) {} + }; + + }; + + template + class ItemSetTraits<_Graph, typename _Graph::Edge> { + public: + + typedef _Graph Graph; + + typedef typename Graph::Edge Item; + typedef typename Graph::EdgeIt ItemIt; + + template + class Map : public Graph::template EdgeMap<_Value> { + public: + typedef typename Graph::template EdgeMap<_Value> Parent; + typedef typename Parent::Value Value; + + Map(const Graph& _graph) : Parent(_graph) {} + Map(const Graph& _graph, const Value& _value) + : Parent(_graph, _value) {} + }; + + }; + + template + class ItemSetTraits<_Graph, typename _Graph::UndirEdge> { + public: + + typedef _Graph Graph; + + typedef typename Graph::UndirEdge Item; + typedef typename Graph::UndirEdgeIt ItemIt; + + template + class Map : public Graph::template UndirEdgeMap<_Value> { + public: + typedef typename Graph::template UndirEdgeMap<_Value> Parent; + typedef typename Parent::Value Value; + + Map(const Graph& _graph) : Parent(_graph) {} + Map(const Graph& _graph, const Value& _value) + : Parent(_graph, _value) {} + }; + + }; + + template + struct MapTraits { + typedef False ReferenceMapTag; + + typedef typename Map::Key Key; + typedef typename Map::Value Value; + + typedef Value ConstReturnValue; + typedef Value& ReturnValue; + }; + + template + struct MapTraits< + Map, typename enable_if::type > + { + typedef True ReferenceMapTag; + + typedef typename Map::Key Key; + typedef typename Map::Value Value; + + typedef typename Map::ConstReference ConstReturnValue; + typedef typename Map::Reference ReturnValue; + + typedef typename Map::ConstReference ConstReference; + typedef typename Map::Reference Reference; + }; + + // Indicators for the tags + + template + struct NodeNumTagIndicator { + static const bool value = false; + }; + + template + struct NodeNumTagIndicator< + Graph, + typename enable_if::type + > { + static const bool value = true; + }; + + template + struct EdgeNumTagIndicator { + static const bool value = false; + }; + + template + struct EdgeNumTagIndicator< + Graph, + typename enable_if::type + > { + static const bool value = true; + }; + + template + struct FindEdgeTagIndicator { + static const bool value = false; + }; + + template + struct FindEdgeTagIndicator< + Graph, + typename enable_if::type + > { + static const bool value = true; + }; + + + +} + +#endif // LEMON_MAPS_H