lemon/traits.h
author alpar
Thu, 02 Feb 2006 08:52:20 +0000
changeset 1941 9fe177e0437d
parent 1909 2d806130e700
child 1956 a055123339d5
permissions -rw-r--r--
The version tag of the trunk is svn-head
deba@1719
     1
/* -*- C++ -*-
deba@1719
     2
 * lemon/traits.h - Part of LEMON, a generic C++ optimization library
deba@1719
     3
 *
alpar@1875
     4
 * Copyright (C) 2006 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>
klao@1909
    75
  class ItemSetTraits<_Graph, typename _Graph::UEdge> {
deba@1719
    76
  public:
deba@1719
    77
    
deba@1719
    78
    typedef _Graph Graph;
deba@1719
    79
klao@1909
    80
    typedef typename Graph::UEdge Item;
klao@1909
    81
    typedef typename Graph::UEdgeIt ItemIt;
deba@1719
    82
deba@1719
    83
    template <typename _Value>
klao@1909
    84
    class Map : public Graph::template UEdgeMap<_Value> {
deba@1719
    85
    public:
klao@1909
    86
      typedef typename Graph::template UEdgeMap<_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@1915
    96
deba@1915
    97
  template <typename _Graph>
deba@1915
    98
  class ItemSetTraits<_Graph, typename _Graph::ANode> {
deba@1915
    99
  public:
deba@1915
   100
    
deba@1915
   101
    typedef _Graph Graph;
deba@1915
   102
deba@1915
   103
    typedef typename Graph::ANode Item;
deba@1915
   104
    typedef typename Graph::ANodeIt ItemIt;
deba@1915
   105
deba@1915
   106
    template <typename _Value>
deba@1915
   107
    class Map : public Graph::template ANodeMap<_Value> {
deba@1915
   108
    public:
deba@1915
   109
      typedef typename Graph::template ANodeMap<_Value> Parent; 
deba@1915
   110
      typedef typename Parent::Value Value;
deba@1915
   111
deba@1915
   112
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1915
   113
      Map(const Graph& _graph, const Value& _value) 
deba@1915
   114
	: Parent(_graph, _value) {}
deba@1915
   115
    };
deba@1915
   116
deba@1915
   117
  };
deba@1915
   118
deba@1915
   119
  template <typename _Graph>
deba@1915
   120
  class ItemSetTraits<_Graph, typename _Graph::BNode> {
deba@1915
   121
  public:
deba@1915
   122
    
deba@1915
   123
    typedef _Graph Graph;
deba@1915
   124
deba@1915
   125
    typedef typename Graph::BNode Item;
deba@1915
   126
    typedef typename Graph::BNodeIt ItemIt;
deba@1915
   127
deba@1915
   128
    template <typename _Value>
deba@1915
   129
    class Map : public Graph::template BNodeMap<_Value> {
deba@1915
   130
    public:
deba@1915
   131
      typedef typename Graph::template BNodeMap<_Value> Parent; 
deba@1915
   132
      typedef typename Parent::Value Value;
deba@1915
   133
deba@1915
   134
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1915
   135
      Map(const Graph& _graph, const Value& _value) 
deba@1915
   136
	: Parent(_graph, _value) {}
deba@1915
   137
    };
deba@1915
   138
deba@1915
   139
  };
deba@1915
   140
deba@1915
   141
deba@1719
   142
  template <typename Map, typename Enable = void>
deba@1719
   143
  struct MapTraits {
deba@1719
   144
    typedef False ReferenceMapTag;
deba@1719
   145
deba@1719
   146
    typedef typename Map::Key Key;
deba@1719
   147
    typedef typename Map::Value Value;
deba@1719
   148
deba@1790
   149
    typedef const Value ConstReturnValue;
deba@1790
   150
    typedef const Value ReturnValue;
deba@1719
   151
  };
deba@1719
   152
deba@1719
   153
  template <typename Map>
deba@1719
   154
  struct MapTraits<
deba@1719
   155
    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
deba@1719
   156
  {
deba@1719
   157
    typedef True ReferenceMapTag;
deba@1719
   158
    
deba@1719
   159
    typedef typename Map::Key Key;
deba@1719
   160
    typedef typename Map::Value Value;
deba@1719
   161
deba@1719
   162
    typedef typename Map::ConstReference ConstReturnValue;
deba@1719
   163
    typedef typename Map::Reference ReturnValue;
deba@1719
   164
deba@1719
   165
    typedef typename Map::ConstReference ConstReference; 
deba@1719
   166
    typedef typename Map::Reference Reference;
deba@1719
   167
 };
deba@1719
   168
deba@1719
   169
  // Indicators for the tags
deba@1719
   170
deba@1719
   171
  template <typename Graph, typename Enable = void>
deba@1719
   172
  struct NodeNumTagIndicator {
deba@1719
   173
    static const bool value = false;
deba@1719
   174
  };
deba@1719
   175
deba@1719
   176
  template <typename Graph>
deba@1719
   177
  struct NodeNumTagIndicator<
deba@1719
   178
    Graph, 
deba@1719
   179
    typename enable_if<typename Graph::NodeNumTag, void>::type
deba@1719
   180
  > {
deba@1719
   181
    static const bool value = true;
deba@1719
   182
  };
deba@1719
   183
deba@1719
   184
  template <typename Graph, typename Enable = void>
deba@1719
   185
  struct EdgeNumTagIndicator {
deba@1719
   186
    static const bool value = false;
deba@1719
   187
  };
deba@1719
   188
deba@1719
   189
  template <typename Graph>
deba@1719
   190
  struct EdgeNumTagIndicator<
deba@1719
   191
    Graph, 
deba@1719
   192
    typename enable_if<typename Graph::EdgeNumTag, void>::type
deba@1719
   193
  > {
deba@1719
   194
    static const bool value = true;
deba@1719
   195
  };
deba@1719
   196
deba@1719
   197
  template <typename Graph, typename Enable = void>
deba@1719
   198
  struct FindEdgeTagIndicator {
deba@1719
   199
    static const bool value = false;
deba@1719
   200
  };
deba@1719
   201
deba@1719
   202
  template <typename Graph>
deba@1719
   203
  struct FindEdgeTagIndicator<
deba@1719
   204
    Graph, 
deba@1719
   205
    typename enable_if<typename Graph::FindEdgeTag, void>::type
deba@1719
   206
  > {
deba@1719
   207
    static const bool value = true;
deba@1719
   208
  };
deba@1719
   209
deba@1719
   210
deba@1719
   211
deba@1719
   212
}
deba@1719
   213
deba@1719
   214
#endif // LEMON_MAPS_H