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