lemon/traits.h
author alpar
Fri, 04 Nov 2005 16:35:18 +0000
changeset 1773 ea5927cef15c
child 1790 c7dd9d8c770a
permissions -rw-r--r--
Bugfix
deba@1719
     1
/* -*- C++ -*-
deba@1719
     2
 * lemon/traits.h - Part of LEMON, a generic C++ optimization library
deba@1719
     3
 *
deba@1719
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@1719
     5
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1719
     6
 *
deba@1719
     7
 * Permission to use, modify and distribute this software is granted
deba@1719
     8
 * provided that this copyright notice appears in all copies. For
deba@1719
     9
 * precise terms see the accompanying LICENSE file.
deba@1719
    10
 *
deba@1719
    11
 * This software is provided "AS IS" with no warranty of any kind,
deba@1719
    12
 * express or implied, and with no claim as to its suitability for any
deba@1719
    13
 * purpose.
deba@1719
    14
 *
deba@1719
    15
 */
deba@1719
    16
deba@1719
    17
#ifndef LEMON_TRAITS_H
deba@1719
    18
#define LEMON_TRAITS_H
deba@1719
    19
deba@1719
    20
#include <lemon/utility.h>
deba@1719
    21
deba@1719
    22
///\file
deba@1719
    23
///\brief Traits for graphs and maps
deba@1719
    24
///
deba@1719
    25
deba@1719
    26
namespace lemon {
deba@1719
    27
  template <typename _Graph, typename _Item>
deba@1719
    28
  class ItemSetTraits {};
deba@1719
    29
  
deba@1719
    30
  template <typename _Graph>
deba@1719
    31
  class ItemSetTraits<_Graph, typename _Graph::Node> {
deba@1719
    32
  public:
deba@1719
    33
    
deba@1719
    34
    typedef _Graph Graph;
deba@1719
    35
deba@1719
    36
    typedef typename Graph::Node Item;
deba@1719
    37
    typedef typename Graph::NodeIt ItemIt;
deba@1719
    38
deba@1719
    39
    template <typename _Value>
deba@1719
    40
    class Map : public Graph::template NodeMap<_Value> {
deba@1719
    41
    public:
deba@1719
    42
      typedef typename Graph::template NodeMap<_Value> Parent; 
deba@1719
    43
      typedef typename Parent::Value Value;
deba@1719
    44
deba@1719
    45
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1719
    46
      Map(const Graph& _graph, const Value& _value) 
deba@1719
    47
	: Parent(_graph, _value) {}
deba@1719
    48
    };
deba@1719
    49
deba@1719
    50
  };
deba@1719
    51
deba@1719
    52
  template <typename _Graph>
deba@1719
    53
  class ItemSetTraits<_Graph, typename _Graph::Edge> {
deba@1719
    54
  public:
deba@1719
    55
    
deba@1719
    56
    typedef _Graph Graph;
deba@1719
    57
deba@1719
    58
    typedef typename Graph::Edge Item;
deba@1719
    59
    typedef typename Graph::EdgeIt ItemIt;
deba@1719
    60
deba@1719
    61
    template <typename _Value>
deba@1719
    62
    class Map : public Graph::template EdgeMap<_Value> {
deba@1719
    63
    public:
deba@1719
    64
      typedef typename Graph::template EdgeMap<_Value> Parent; 
deba@1719
    65
      typedef typename Parent::Value Value;
deba@1719
    66
deba@1719
    67
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1719
    68
      Map(const Graph& _graph, const Value& _value) 
deba@1719
    69
	: Parent(_graph, _value) {}
deba@1719
    70
    };
deba@1719
    71
deba@1719
    72
  };
deba@1719
    73
deba@1719
    74
  template <typename _Graph>
deba@1719
    75
  class ItemSetTraits<_Graph, typename _Graph::UndirEdge> {
deba@1719
    76
  public:
deba@1719
    77
    
deba@1719
    78
    typedef _Graph Graph;
deba@1719
    79
deba@1719
    80
    typedef typename Graph::UndirEdge Item;
deba@1719
    81
    typedef typename Graph::UndirEdgeIt ItemIt;
deba@1719
    82
deba@1719
    83
    template <typename _Value>
deba@1719
    84
    class Map : public Graph::template UndirEdgeMap<_Value> {
deba@1719
    85
    public:
deba@1719
    86
      typedef typename Graph::template UndirEdgeMap<_Value> Parent; 
deba@1719
    87
      typedef typename Parent::Value Value;
deba@1719
    88
deba@1719
    89
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1719
    90
      Map(const Graph& _graph, const Value& _value) 
deba@1719
    91
	: Parent(_graph, _value) {}
deba@1719
    92
    };
deba@1719
    93
deba@1719
    94
  };
deba@1719
    95
deba@1719
    96
  template <typename Map, typename Enable = void>
deba@1719
    97
  struct MapTraits {
deba@1719
    98
    typedef False ReferenceMapTag;
deba@1719
    99
deba@1719
   100
    typedef typename Map::Key Key;
deba@1719
   101
    typedef typename Map::Value Value;
deba@1719
   102
deba@1719
   103
    typedef Value ConstReturnValue;
deba@1719
   104
    typedef Value& ReturnValue;
deba@1719
   105
  };
deba@1719
   106
deba@1719
   107
  template <typename Map>
deba@1719
   108
  struct MapTraits<
deba@1719
   109
    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
deba@1719
   110
  {
deba@1719
   111
    typedef True ReferenceMapTag;
deba@1719
   112
    
deba@1719
   113
    typedef typename Map::Key Key;
deba@1719
   114
    typedef typename Map::Value Value;
deba@1719
   115
deba@1719
   116
    typedef typename Map::ConstReference ConstReturnValue;
deba@1719
   117
    typedef typename Map::Reference ReturnValue;
deba@1719
   118
deba@1719
   119
    typedef typename Map::ConstReference ConstReference; 
deba@1719
   120
    typedef typename Map::Reference Reference;
deba@1719
   121
 };
deba@1719
   122
deba@1719
   123
  // Indicators for the tags
deba@1719
   124
deba@1719
   125
  template <typename Graph, typename Enable = void>
deba@1719
   126
  struct NodeNumTagIndicator {
deba@1719
   127
    static const bool value = false;
deba@1719
   128
  };
deba@1719
   129
deba@1719
   130
  template <typename Graph>
deba@1719
   131
  struct NodeNumTagIndicator<
deba@1719
   132
    Graph, 
deba@1719
   133
    typename enable_if<typename Graph::NodeNumTag, void>::type
deba@1719
   134
  > {
deba@1719
   135
    static const bool value = true;
deba@1719
   136
  };
deba@1719
   137
deba@1719
   138
  template <typename Graph, typename Enable = void>
deba@1719
   139
  struct EdgeNumTagIndicator {
deba@1719
   140
    static const bool value = false;
deba@1719
   141
  };
deba@1719
   142
deba@1719
   143
  template <typename Graph>
deba@1719
   144
  struct EdgeNumTagIndicator<
deba@1719
   145
    Graph, 
deba@1719
   146
    typename enable_if<typename Graph::EdgeNumTag, void>::type
deba@1719
   147
  > {
deba@1719
   148
    static const bool value = true;
deba@1719
   149
  };
deba@1719
   150
deba@1719
   151
  template <typename Graph, typename Enable = void>
deba@1719
   152
  struct FindEdgeTagIndicator {
deba@1719
   153
    static const bool value = false;
deba@1719
   154
  };
deba@1719
   155
deba@1719
   156
  template <typename Graph>
deba@1719
   157
  struct FindEdgeTagIndicator<
deba@1719
   158
    Graph, 
deba@1719
   159
    typename enable_if<typename Graph::FindEdgeTag, void>::type
deba@1719
   160
  > {
deba@1719
   161
    static const bool value = true;
deba@1719
   162
  };
deba@1719
   163
deba@1719
   164
deba@1719
   165
deba@1719
   166
}
deba@1719
   167
deba@1719
   168
#endif // LEMON_MAPS_H