lemon/bits/traits.h
author alpar
Thu, 30 Mar 2006 09:42:05 +0000
changeset 2022 0f3367da6104
parent 1993 2115143eceea
child 2039 dacc4ce9474d
permissions -rw-r--r--
docfix
     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_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 Parent::Value Value;
    61 
    62       Map(const Graph& _graph) : Parent(_graph) {}
    63       Map(const Graph& _graph, const Value& _value) 
    64 	: Parent(_graph, _value) {}
    65 
    66      };
    67 
    68   };
    69 
    70   template <typename Graph, typename Enable = void>
    71   struct EdgeNotifierIndicator {
    72     typedef InvalidType Type;
    73   };
    74   template <typename Graph>
    75   struct EdgeNotifierIndicator<
    76     Graph, 
    77     typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
    78   > { 
    79     typedef typename Graph::EdgeNotifier Type;
    80   };
    81 
    82   template <typename _Graph>
    83   class ItemSetTraits<_Graph, typename _Graph::Edge> {
    84   public:
    85     
    86     typedef _Graph Graph;
    87 
    88     typedef typename Graph::Edge Item;
    89     typedef typename Graph::EdgeIt ItemIt;
    90 
    91     typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
    92 
    93     template <typename _Value>
    94     class Map : public Graph::template EdgeMap<_Value> {
    95     public:
    96       typedef typename Graph::template EdgeMap<_Value> Parent; 
    97       typedef typename Parent::Value Value;
    98 
    99       Map(const Graph& _graph) : Parent(_graph) {}
   100       Map(const Graph& _graph, const Value& _value) 
   101 	: Parent(_graph, _value) {}
   102     };
   103 
   104   };
   105 
   106   template <typename Graph, typename Enable = void>
   107   struct UEdgeNotifierIndicator {
   108     typedef InvalidType Type;
   109   };
   110   template <typename Graph>
   111   struct UEdgeNotifierIndicator<
   112     Graph, 
   113     typename enable_if<typename Graph::UEdgeNotifier::Notifier, void>::type
   114   > { 
   115     typedef typename Graph::UEdgeNotifier Type;
   116   };
   117 
   118   template <typename _Graph>
   119   class ItemSetTraits<_Graph, typename _Graph::UEdge> {
   120   public:
   121     
   122     typedef _Graph Graph;
   123 
   124     typedef typename Graph::UEdge Item;
   125     typedef typename Graph::UEdgeIt ItemIt;
   126 
   127     typedef typename UEdgeNotifierIndicator<Graph>::Type ItemNotifier;
   128 
   129     template <typename _Value>
   130     class Map : public Graph::template UEdgeMap<_Value> {
   131     public:
   132       typedef typename Graph::template UEdgeMap<_Value> Parent; 
   133       typedef typename Parent::Value Value;
   134 
   135       Map(const Graph& _graph) : Parent(_graph) {}
   136       Map(const Graph& _graph, const Value& _value) 
   137 	: Parent(_graph, _value) {}
   138     };
   139 
   140   };
   141 
   142   template <typename Graph, typename Enable = void>
   143   struct ANodeNotifierIndicator {
   144     typedef InvalidType Type;
   145   };
   146   template <typename Graph>
   147   struct ANodeNotifierIndicator<
   148     Graph, 
   149     typename enable_if<typename Graph::ANodeNotifier::Notifier, void>::type
   150   > { 
   151     typedef typename Graph::ANodeNotifier Type;
   152   };
   153 
   154   template <typename _Graph>
   155   class ItemSetTraits<_Graph, typename _Graph::ANode> {
   156   public:
   157     
   158     typedef _Graph Graph;
   159 
   160     typedef typename Graph::ANode Item;
   161     typedef typename Graph::ANodeIt ItemIt;
   162 
   163     typedef typename ANodeNotifierIndicator<Graph>::Type ItemNotifier;
   164 
   165     template <typename _Value>
   166     class Map : public Graph::template ANodeMap<_Value> {
   167     public:
   168       typedef typename Graph::template ANodeMap<_Value> Parent; 
   169       typedef typename Parent::Value Value;
   170 
   171       Map(const Graph& _graph) : Parent(_graph) {}
   172       Map(const Graph& _graph, const Value& _value) 
   173 	: Parent(_graph, _value) {}
   174     };
   175 
   176   };
   177 
   178   template <typename Graph, typename Enable = void>
   179   struct BNodeNotifierIndicator {
   180     typedef InvalidType Type;
   181   };
   182   template <typename Graph>
   183   struct BNodeNotifierIndicator<
   184     Graph, 
   185     typename enable_if<typename Graph::BNodeNotifier::Notifier, void>::type
   186   > { 
   187     typedef typename Graph::BNodeNotifier Type;
   188   };
   189 
   190   template <typename _Graph>
   191   class ItemSetTraits<_Graph, typename _Graph::BNode> {
   192   public:
   193     
   194     typedef _Graph Graph;
   195 
   196     typedef typename Graph::BNode Item;
   197     typedef typename Graph::BNodeIt ItemIt;
   198 
   199     typedef typename BNodeNotifierIndicator<Graph>::Type ItemNotifier;
   200 
   201     template <typename _Value>
   202     class Map : public Graph::template BNodeMap<_Value> {
   203     public:
   204       typedef typename Graph::template BNodeMap<_Value> Parent; 
   205       typedef typename Parent::Value Value;
   206 
   207       Map(const Graph& _graph) : Parent(_graph) {}
   208       Map(const Graph& _graph, const Value& _value) 
   209 	: Parent(_graph, _value) {}
   210     };
   211 
   212   };
   213 
   214 
   215   template <typename Map, typename Enable = void>
   216   struct MapTraits {
   217     typedef False ReferenceMapTag;
   218 
   219     typedef typename Map::Key Key;
   220     typedef typename Map::Value Value;
   221 
   222     typedef const Value ConstReturnValue;
   223     typedef const Value ReturnValue;
   224   };
   225 
   226   template <typename Map>
   227   struct MapTraits<
   228     Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
   229   {
   230     typedef True ReferenceMapTag;
   231     
   232     typedef typename Map::Key Key;
   233     typedef typename Map::Value Value;
   234 
   235     typedef typename Map::ConstReference ConstReturnValue;
   236     typedef typename Map::Reference ReturnValue;
   237 
   238     typedef typename Map::ConstReference ConstReference; 
   239     typedef typename Map::Reference Reference;
   240  };
   241 
   242   // Indicators for the tags
   243 
   244   template <typename Graph, typename Enable = void>
   245   struct NodeNumTagIndicator {
   246     static const bool value = false;
   247   };
   248 
   249   template <typename Graph>
   250   struct NodeNumTagIndicator<
   251     Graph, 
   252     typename enable_if<typename Graph::NodeNumTag, void>::type
   253   > {
   254     static const bool value = true;
   255   };
   256 
   257   template <typename Graph, typename Enable = void>
   258   struct EdgeNumTagIndicator {
   259     static const bool value = false;
   260   };
   261 
   262   template <typename Graph>
   263   struct EdgeNumTagIndicator<
   264     Graph, 
   265     typename enable_if<typename Graph::EdgeNumTag, void>::type
   266   > {
   267     static const bool value = true;
   268   };
   269 
   270   template <typename Graph, typename Enable = void>
   271   struct FindEdgeTagIndicator {
   272     static const bool value = false;
   273   };
   274 
   275   template <typename Graph>
   276   struct FindEdgeTagIndicator<
   277     Graph, 
   278     typename enable_if<typename Graph::FindEdgeTag, void>::type
   279   > {
   280     static const bool value = true;
   281   };
   282 
   283   template <typename Graph, typename Enable = void>
   284   struct UndirectedTagIndicator {
   285     static const bool value = false;
   286   };
   287 
   288   template <typename Graph>
   289   struct UndirectedTagIndicator<
   290     Graph, 
   291     typename enable_if<typename Graph::UndirectedTag, void>::type
   292   > {
   293     static const bool value = true;
   294   };
   295 
   296 
   297 
   298 }
   299 
   300 #endif