lemon/bits/traits.h
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 13 Jul 2008 19:51:02 +0100
changeset 209 765619b7cbb2
parent 184 716b220697a0
child 220 a5d8c039f218
permissions -rw-r--r--
Apply unify-sources.sh to the source tree
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     5  * Copyright (C) 2003-2008
     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_BITS_TRAITS_H
    20 #define LEMON_BITS_TRAITS_H
    21 
    22 #include <lemon/bits/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 
    33   template <typename Graph, typename Enable = void>
    34   struct NodeNotifierIndicator {
    35     typedef InvalidType Type;
    36   };
    37   template <typename Graph>
    38   struct NodeNotifierIndicator<
    39     Graph,
    40     typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
    41   > {
    42     typedef typename Graph::NodeNotifier Type;
    43   };
    44 
    45   template <typename _Graph>
    46   class ItemSetTraits<_Graph, typename _Graph::Node> {
    47   public:
    48 
    49     typedef _Graph Graph;
    50 
    51     typedef typename Graph::Node Item;
    52     typedef typename Graph::NodeIt ItemIt;
    53 
    54     typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
    55 
    56     template <typename _Value>
    57     class Map : public Graph::template NodeMap<_Value> {
    58     public:
    59       typedef typename Graph::template NodeMap<_Value> Parent;
    60       typedef typename Graph::template NodeMap<_Value> Type;
    61       typedef typename Parent::Value Value;
    62 
    63       Map(const Graph& _digraph) : Parent(_digraph) {}
    64       Map(const Graph& _digraph, const Value& _value)
    65         : Parent(_digraph, _value) {}
    66 
    67      };
    68 
    69   };
    70 
    71   template <typename Graph, typename Enable = void>
    72   struct ArcNotifierIndicator {
    73     typedef InvalidType Type;
    74   };
    75   template <typename Graph>
    76   struct ArcNotifierIndicator<
    77     Graph,
    78     typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
    79   > {
    80     typedef typename Graph::ArcNotifier Type;
    81   };
    82 
    83   template <typename _Graph>
    84   class ItemSetTraits<_Graph, typename _Graph::Arc> {
    85   public:
    86 
    87     typedef _Graph Graph;
    88 
    89     typedef typename Graph::Arc Item;
    90     typedef typename Graph::ArcIt ItemIt;
    91 
    92     typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier;
    93 
    94     template <typename _Value>
    95     class Map : public Graph::template ArcMap<_Value> {
    96     public:
    97       typedef typename Graph::template ArcMap<_Value> Parent;
    98       typedef typename Graph::template ArcMap<_Value> Type;
    99       typedef typename Parent::Value Value;
   100 
   101       Map(const Graph& _digraph) : Parent(_digraph) {}
   102       Map(const Graph& _digraph, const Value& _value)
   103         : Parent(_digraph, _value) {}
   104     };
   105 
   106   };
   107 
   108   template <typename Graph, typename Enable = void>
   109   struct EdgeNotifierIndicator {
   110     typedef InvalidType Type;
   111   };
   112   template <typename Graph>
   113   struct EdgeNotifierIndicator<
   114     Graph,
   115     typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
   116   > {
   117     typedef typename Graph::EdgeNotifier Type;
   118   };
   119 
   120   template <typename _Graph>
   121   class ItemSetTraits<_Graph, typename _Graph::Edge> {
   122   public:
   123 
   124     typedef _Graph Graph;
   125 
   126     typedef typename Graph::Edge Item;
   127     typedef typename Graph::EdgeIt ItemIt;
   128 
   129     typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
   130 
   131     template <typename _Value>
   132     class Map : public Graph::template EdgeMap<_Value> {
   133     public:
   134       typedef typename Graph::template EdgeMap<_Value> Parent;
   135       typedef typename Graph::template EdgeMap<_Value> Type;
   136       typedef typename Parent::Value Value;
   137 
   138       Map(const Graph& _digraph) : Parent(_digraph) {}
   139       Map(const Graph& _digraph, const Value& _value)
   140         : Parent(_digraph, _value) {}
   141     };
   142 
   143   };
   144 
   145   template <typename Map, typename Enable = void>
   146   struct MapTraits {
   147     typedef False ReferenceMapTag;
   148 
   149     typedef typename Map::Key Key;
   150     typedef typename Map::Value Value;
   151 
   152     typedef Value ConstReturnValue;
   153     typedef Value ReturnValue;
   154   };
   155 
   156   template <typename Map>
   157   struct MapTraits<
   158     Map, typename enable_if<typename Map::ReferenceMapTag, void>::type >
   159   {
   160     typedef True ReferenceMapTag;
   161 
   162     typedef typename Map::Key Key;
   163     typedef typename Map::Value Value;
   164 
   165     typedef typename Map::ConstReference ConstReturnValue;
   166     typedef typename Map::Reference ReturnValue;
   167 
   168     typedef typename Map::ConstReference ConstReference;
   169     typedef typename Map::Reference Reference;
   170  };
   171 
   172   template <typename MatrixMap, typename Enable = void>
   173   struct MatrixMapTraits {
   174     typedef False ReferenceMapTag;
   175 
   176     typedef typename MatrixMap::FirstKey FirstKey;
   177     typedef typename MatrixMap::SecondKey SecondKey;
   178     typedef typename MatrixMap::Value Value;
   179 
   180     typedef Value ConstReturnValue;
   181     typedef Value ReturnValue;
   182   };
   183 
   184   template <typename MatrixMap>
   185   struct MatrixMapTraits<
   186     MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
   187                                   void>::type >
   188   {
   189     typedef True ReferenceMapTag;
   190 
   191     typedef typename MatrixMap::FirstKey FirstKey;
   192     typedef typename MatrixMap::SecondKey SecondKey;
   193     typedef typename MatrixMap::Value Value;
   194 
   195     typedef typename MatrixMap::ConstReference ConstReturnValue;
   196     typedef typename MatrixMap::Reference ReturnValue;
   197 
   198     typedef typename MatrixMap::ConstReference ConstReference;
   199     typedef typename MatrixMap::Reference Reference;
   200  };
   201 
   202   // Indicators for the tags
   203 
   204   template <typename Graph, typename Enable = void>
   205   struct NodeNumTagIndicator {
   206     static const bool value = false;
   207   };
   208 
   209   template <typename Graph>
   210   struct NodeNumTagIndicator<
   211     Graph,
   212     typename enable_if<typename Graph::NodeNumTag, void>::type
   213   > {
   214     static const bool value = true;
   215   };
   216 
   217   template <typename Graph, typename Enable = void>
   218   struct EdgeNumTagIndicator {
   219     static const bool value = false;
   220   };
   221 
   222   template <typename Graph>
   223   struct EdgeNumTagIndicator<
   224     Graph,
   225     typename enable_if<typename Graph::EdgeNumTag, void>::type
   226   > {
   227     static const bool value = true;
   228   };
   229 
   230   template <typename Graph, typename Enable = void>
   231   struct FindEdgeTagIndicator {
   232     static const bool value = false;
   233   };
   234 
   235   template <typename Graph>
   236   struct FindEdgeTagIndicator<
   237     Graph,
   238     typename enable_if<typename Graph::FindEdgeTag, void>::type
   239   > {
   240     static const bool value = true;
   241   };
   242 
   243   template <typename Graph, typename Enable = void>
   244   struct UndirectedTagIndicator {
   245     static const bool value = false;
   246   };
   247 
   248   template <typename Graph>
   249   struct UndirectedTagIndicator<
   250     Graph,
   251     typename enable_if<typename Graph::UndirectedTag, void>::type
   252   > {
   253     static const bool value = true;
   254   };
   255 
   256   template <typename Graph, typename Enable = void>
   257   struct BuildTagIndicator {
   258     static const bool value = false;
   259   };
   260 
   261   template <typename Graph>
   262   struct BuildTagIndicator<
   263     Graph,
   264     typename enable_if<typename Graph::BuildTag, void>::type
   265   > {
   266     static const bool value = true;
   267   };
   268 
   269 }
   270 
   271 #endif