[Lemon-commits] [lemon_svn] deba: r2246 - in hugo/trunk/lemon: . bits concept

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:51:13 CET 2006


Author: deba
Date: Fri Oct 14 12:48:34 2005
New Revision: 2246

Added:
   hugo/trunk/lemon/traits.h
Modified:
   hugo/trunk/lemon/bits/array_map.h
   hugo/trunk/lemon/bits/map_iterator.h
   hugo/trunk/lemon/bits/static_map.h
   hugo/trunk/lemon/bits/vector_map.h
   hugo/trunk/lemon/concept/maps.h

Log:
Traits moved to own file
Tag for reference maps
Possibility to handle proper the return type
of the operator[]() const -- value or reference



Modified: hugo/trunk/lemon/bits/array_map.h
==============================================================================
--- hugo/trunk/lemon/bits/array_map.h	(original)
+++ hugo/trunk/lemon/bits/array_map.h	Fri Oct 14 12:48:34 2005
@@ -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()));

Modified: hugo/trunk/lemon/bits/map_iterator.h
==============================================================================
--- hugo/trunk/lemon/bits/map_iterator.h	(original)
+++ hugo/trunk/lemon/bits/map_iterator.h	Fri Oct 14 12:48:34 2005
@@ -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<Map>::Value MapValue;
+    typedef typename Map::Value MapValue;
     /// The reference type of the iterator.
-    typedef typename ReferenceMapTraits<Map>::Reference MapReference;
+    typedef typename Map::Reference MapReference;
     /// The pointer type of the iterator.
-    typedef typename ReferenceMapTraits<Map>::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<Map>::Value MapValue;
+    typedef typename Map::Value MapValue;
     /// The reference type of the iterator.
-    typedef typename ReferenceMapTraits<Map>::ConstReference MapReference;
+    typedef typename Map::ConstReference MapReference;
     /// The pointer type of the iterator.
-    typedef typename ReferenceMapTraits<Map>::ConstPointer MapPointer;
+    typedef typename Map::ConstPointer MapPointer;
 
   public:
 

Modified: hugo/trunk/lemon/bits/static_map.h
==============================================================================
--- hugo/trunk/lemon/bits/static_map.h	(original)
+++ hugo/trunk/lemon/bits/static_map.h	Fri Oct 14 12:48:34 2005
@@ -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<Value> 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

Modified: hugo/trunk/lemon/bits/vector_map.h
==============================================================================
--- hugo/trunk/lemon/bits/vector_map.h	(original)
+++ hugo/trunk/lemon/bits/vector_map.h	Fri Oct 14 12:48:34 2005
@@ -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<Value> Container;	
-
-  public:
-
     /// The reference type of the map;
     typedef typename Container::reference Reference;
     /// The pointer type of the map;

Modified: hugo/trunk/lemon/concept/maps.h
==============================================================================
--- hugo/trunk/lemon/concept/maps.h	(original)
+++ hugo/trunk/lemon/concept/maps.h	Fri Oct 14 12:48:34 2005
@@ -17,6 +17,7 @@
 #ifndef LEMON_CONCEPT_MAPS_H
 #define LEMON_CONCEPT_MAPS_H
 
+#include <lemon/utility.h>
 #include <lemon/concept_check.h>
 
 ///\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<ReadMap<K, T>, _ReadWriteMap >();
-	  checkConcept<ReadMap<K, T>, _ReadWriteMap >();
+	  checkConcept<WriteMap<K, T>, _ReadWriteMap >();
 	}
       };
     };
@@ -133,6 +134,8 @@
     class ReferenceMap : public ReadWriteMap<K,T>
     {
     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;
       };
     };
 

Added: hugo/trunk/lemon/traits.h
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/traits.h	Fri Oct 14 12:48:34 2005
@@ -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 <lemon/utility.h>
+
+///\file
+///\brief Traits for graphs and maps
+///
+
+namespace lemon {
+  template <typename _Graph, typename _Item>
+  class ItemSetTraits {};
+  
+  template <typename _Graph>
+  class ItemSetTraits<_Graph, typename _Graph::Node> {
+  public:
+    
+    typedef _Graph Graph;
+
+    typedef typename Graph::Node Item;
+    typedef typename Graph::NodeIt ItemIt;
+
+    template <typename _Value>
+    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 <typename _Graph>
+  class ItemSetTraits<_Graph, typename _Graph::Edge> {
+  public:
+    
+    typedef _Graph Graph;
+
+    typedef typename Graph::Edge Item;
+    typedef typename Graph::EdgeIt ItemIt;
+
+    template <typename _Value>
+    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 <typename _Graph>
+  class ItemSetTraits<_Graph, typename _Graph::UndirEdge> {
+  public:
+    
+    typedef _Graph Graph;
+
+    typedef typename Graph::UndirEdge Item;
+    typedef typename Graph::UndirEdgeIt ItemIt;
+
+    template <typename _Value>
+    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 <typename Map, typename Enable = void>
+  struct MapTraits {
+    typedef False ReferenceMapTag;
+
+    typedef typename Map::Key Key;
+    typedef typename Map::Value Value;
+
+    typedef Value ConstReturnValue;
+    typedef Value& ReturnValue;
+  };
+
+  template <typename Map>
+  struct MapTraits<
+    Map, typename enable_if<typename Map::ReferenceMapTag, void>::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 <typename Graph, typename Enable = void>
+  struct NodeNumTagIndicator {
+    static const bool value = false;
+  };
+
+  template <typename Graph>
+  struct NodeNumTagIndicator<
+    Graph, 
+    typename enable_if<typename Graph::NodeNumTag, void>::type
+  > {
+    static const bool value = true;
+  };
+
+  template <typename Graph, typename Enable = void>
+  struct EdgeNumTagIndicator {
+    static const bool value = false;
+  };
+
+  template <typename Graph>
+  struct EdgeNumTagIndicator<
+    Graph, 
+    typename enable_if<typename Graph::EdgeNumTag, void>::type
+  > {
+    static const bool value = true;
+  };
+
+  template <typename Graph, typename Enable = void>
+  struct FindEdgeTagIndicator {
+    static const bool value = false;
+  };
+
+  template <typename Graph>
+  struct FindEdgeTagIndicator<
+    Graph, 
+    typename enable_if<typename Graph::FindEdgeTag, void>::type
+  > {
+    static const bool value = true;
+  };
+
+
+
+}
+
+#endif // LEMON_MAPS_H



More information about the Lemon-commits mailing list