lemon/traits.h
author alpar
Tue, 21 Feb 2006 12:37:00 +0000
changeset 1977 8ef02f0c4245
parent 1915 f1f523d39d32
child 1979 c2992fd74dad
permissions -rw-r--r--
RefPtr: a reference counted pointer class
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #ifndef LEMON_TRAITS_H
    20 #define LEMON_TRAITS_H
    21 
    22 #include <lemon/utility.h>
    23 
    24 ///\file
    25 ///\brief Traits for graphs and maps
    26 ///
    27 
    28 namespace lemon {
    29   template <typename _Graph, typename _Item>
    30   class ItemSetTraits {};
    31   
    32   template <typename _Graph>
    33   class ItemSetTraits<_Graph, typename _Graph::Node> {
    34   public:
    35     
    36     typedef _Graph Graph;
    37 
    38     typedef typename Graph::Node Item;
    39     typedef typename Graph::NodeIt ItemIt;
    40 
    41     template <typename _Value>
    42     class Map : public Graph::template NodeMap<_Value> {
    43     public:
    44       typedef typename Graph::template NodeMap<_Value> Parent; 
    45       typedef typename Parent::Value Value;
    46 
    47       Map(const Graph& _graph) : Parent(_graph) {}
    48       Map(const Graph& _graph, const Value& _value) 
    49 	: Parent(_graph, _value) {}
    50     };
    51 
    52   };
    53 
    54   template <typename _Graph>
    55   class ItemSetTraits<_Graph, typename _Graph::Edge> {
    56   public:
    57     
    58     typedef _Graph Graph;
    59 
    60     typedef typename Graph::Edge Item;
    61     typedef typename Graph::EdgeIt ItemIt;
    62 
    63     template <typename _Value>
    64     class Map : public Graph::template EdgeMap<_Value> {
    65     public:
    66       typedef typename Graph::template EdgeMap<_Value> Parent; 
    67       typedef typename Parent::Value Value;
    68 
    69       Map(const Graph& _graph) : Parent(_graph) {}
    70       Map(const Graph& _graph, const Value& _value) 
    71 	: Parent(_graph, _value) {}
    72     };
    73 
    74   };
    75 
    76   template <typename _Graph>
    77   class ItemSetTraits<_Graph, typename _Graph::UEdge> {
    78   public:
    79     
    80     typedef _Graph Graph;
    81 
    82     typedef typename Graph::UEdge Item;
    83     typedef typename Graph::UEdgeIt ItemIt;
    84 
    85     template <typename _Value>
    86     class Map : public Graph::template UEdgeMap<_Value> {
    87     public:
    88       typedef typename Graph::template UEdgeMap<_Value> Parent; 
    89       typedef typename Parent::Value Value;
    90 
    91       Map(const Graph& _graph) : Parent(_graph) {}
    92       Map(const Graph& _graph, const Value& _value) 
    93 	: Parent(_graph, _value) {}
    94     };
    95 
    96   };
    97 
    98 
    99   template <typename _Graph>
   100   class ItemSetTraits<_Graph, typename _Graph::ANode> {
   101   public:
   102     
   103     typedef _Graph Graph;
   104 
   105     typedef typename Graph::ANode Item;
   106     typedef typename Graph::ANodeIt ItemIt;
   107 
   108     template <typename _Value>
   109     class Map : public Graph::template ANodeMap<_Value> {
   110     public:
   111       typedef typename Graph::template ANodeMap<_Value> Parent; 
   112       typedef typename Parent::Value Value;
   113 
   114       Map(const Graph& _graph) : Parent(_graph) {}
   115       Map(const Graph& _graph, const Value& _value) 
   116 	: Parent(_graph, _value) {}
   117     };
   118 
   119   };
   120 
   121   template <typename _Graph>
   122   class ItemSetTraits<_Graph, typename _Graph::BNode> {
   123   public:
   124     
   125     typedef _Graph Graph;
   126 
   127     typedef typename Graph::BNode Item;
   128     typedef typename Graph::BNodeIt ItemIt;
   129 
   130     template <typename _Value>
   131     class Map : public Graph::template BNodeMap<_Value> {
   132     public:
   133       typedef typename Graph::template BNodeMap<_Value> Parent; 
   134       typedef typename Parent::Value Value;
   135 
   136       Map(const Graph& _graph) : Parent(_graph) {}
   137       Map(const Graph& _graph, const Value& _value) 
   138 	: Parent(_graph, _value) {}
   139     };
   140 
   141   };
   142 
   143 
   144   template <typename Map, typename Enable = void>
   145   struct MapTraits {
   146     typedef False ReferenceMapTag;
   147 
   148     typedef typename Map::Key Key;
   149     typedef typename Map::Value Value;
   150 
   151     typedef const Value ConstReturnValue;
   152     typedef const Value ReturnValue;
   153   };
   154 
   155   template <typename Map>
   156   struct MapTraits<
   157     Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
   158   {
   159     typedef True ReferenceMapTag;
   160     
   161     typedef typename Map::Key Key;
   162     typedef typename Map::Value Value;
   163 
   164     typedef typename Map::ConstReference ConstReturnValue;
   165     typedef typename Map::Reference ReturnValue;
   166 
   167     typedef typename Map::ConstReference ConstReference; 
   168     typedef typename Map::Reference Reference;
   169  };
   170 
   171   // Indicators for the tags
   172 
   173   template <typename Graph, typename Enable = void>
   174   struct NodeNumTagIndicator {
   175     static const bool value = false;
   176   };
   177 
   178   template <typename Graph>
   179   struct NodeNumTagIndicator<
   180     Graph, 
   181     typename enable_if<typename Graph::NodeNumTag, void>::type
   182   > {
   183     static const bool value = true;
   184   };
   185 
   186   template <typename Graph, typename Enable = void>
   187   struct EdgeNumTagIndicator {
   188     static const bool value = false;
   189   };
   190 
   191   template <typename Graph>
   192   struct EdgeNumTagIndicator<
   193     Graph, 
   194     typename enable_if<typename Graph::EdgeNumTag, void>::type
   195   > {
   196     static const bool value = true;
   197   };
   198 
   199   template <typename Graph, typename Enable = void>
   200   struct FindEdgeTagIndicator {
   201     static const bool value = false;
   202   };
   203 
   204   template <typename Graph>
   205   struct FindEdgeTagIndicator<
   206     Graph, 
   207     typename enable_if<typename Graph::FindEdgeTag, void>::type
   208   > {
   209     static const bool value = true;
   210   };
   211 
   212 
   213 
   214 }
   215 
   216 #endif // LEMON_MAPS_H