lemon/bits/traits.h
author deba
Mon, 06 Mar 2006 17:32:35 +0000
changeset 2000 ebcc93ead7da
parent 1993 2115143eceea
child 2039 dacc4ce9474d
permissions -rw-r--r--
Checking missing section reader
deba@1993
     1
/* -*- C++ -*-
deba@1993
     2
 *
deba@1993
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@1993
     4
 *
deba@1993
     5
 * Copyright (C) 2003-2006
deba@1993
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@1993
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1993
     8
 *
deba@1993
     9
 * Permission to use, modify and distribute this software is granted
deba@1993
    10
 * provided that this copyright notice appears in all copies. For
deba@1993
    11
 * precise terms see the accompanying LICENSE file.
deba@1993
    12
 *
deba@1993
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@1993
    14
 * express or implied, and with no claim as to its suitability for any
deba@1993
    15
 * purpose.
deba@1993
    16
 *
deba@1993
    17
 */
deba@1993
    18
deba@1993
    19
#ifndef LEMON_BITS_TRAITS_H
deba@1993
    20
#define LEMON_BITS_TRAITS_H
deba@1993
    21
deba@1993
    22
#include <lemon/bits/utility.h>
deba@1993
    23
deba@1993
    24
///\file
deba@1993
    25
///\brief Traits for graphs and maps
deba@1993
    26
///
deba@1993
    27
deba@1993
    28
namespace lemon {
deba@1993
    29
  template <typename _Graph, typename _Item>
deba@1993
    30
  class ItemSetTraits {};
deba@1993
    31
  
deba@1993
    32
deba@1993
    33
  template <typename Graph, typename Enable = void>
deba@1993
    34
  struct NodeNotifierIndicator {
deba@1993
    35
    typedef InvalidType Type;
deba@1993
    36
  };
deba@1993
    37
  template <typename Graph>
deba@1993
    38
  struct NodeNotifierIndicator<
deba@1993
    39
    Graph, 
deba@1993
    40
    typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
deba@1993
    41
  > { 
deba@1993
    42
    typedef typename Graph::NodeNotifier Type;
deba@1993
    43
  };
deba@1993
    44
deba@1993
    45
  template <typename _Graph>
deba@1993
    46
  class ItemSetTraits<_Graph, typename _Graph::Node> {
deba@1993
    47
  public:
deba@1993
    48
    
deba@1993
    49
    typedef _Graph Graph;
deba@1993
    50
deba@1993
    51
    typedef typename Graph::Node Item;
deba@1993
    52
    typedef typename Graph::NodeIt ItemIt;
deba@1993
    53
deba@1993
    54
    typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
    55
deba@1993
    56
    template <typename _Value>
deba@1993
    57
    class Map : public Graph::template NodeMap<_Value> {
deba@1993
    58
    public:
deba@1993
    59
      typedef typename Graph::template NodeMap<_Value> Parent; 
deba@1993
    60
      typedef typename Parent::Value Value;
deba@1993
    61
deba@1993
    62
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
    63
      Map(const Graph& _graph, const Value& _value) 
deba@1993
    64
	: Parent(_graph, _value) {}
deba@1993
    65
deba@1993
    66
     };
deba@1993
    67
deba@1993
    68
  };
deba@1993
    69
deba@1993
    70
  template <typename Graph, typename Enable = void>
deba@1993
    71
  struct EdgeNotifierIndicator {
deba@1993
    72
    typedef InvalidType Type;
deba@1993
    73
  };
deba@1993
    74
  template <typename Graph>
deba@1993
    75
  struct EdgeNotifierIndicator<
deba@1993
    76
    Graph, 
deba@1993
    77
    typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
deba@1993
    78
  > { 
deba@1993
    79
    typedef typename Graph::EdgeNotifier Type;
deba@1993
    80
  };
deba@1993
    81
deba@1993
    82
  template <typename _Graph>
deba@1993
    83
  class ItemSetTraits<_Graph, typename _Graph::Edge> {
deba@1993
    84
  public:
deba@1993
    85
    
deba@1993
    86
    typedef _Graph Graph;
deba@1993
    87
deba@1993
    88
    typedef typename Graph::Edge Item;
deba@1993
    89
    typedef typename Graph::EdgeIt ItemIt;
deba@1993
    90
deba@1993
    91
    typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
    92
deba@1993
    93
    template <typename _Value>
deba@1993
    94
    class Map : public Graph::template EdgeMap<_Value> {
deba@1993
    95
    public:
deba@1993
    96
      typedef typename Graph::template EdgeMap<_Value> Parent; 
deba@1993
    97
      typedef typename Parent::Value Value;
deba@1993
    98
deba@1993
    99
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   100
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   101
	: Parent(_graph, _value) {}
deba@1993
   102
    };
deba@1993
   103
deba@1993
   104
  };
deba@1993
   105
deba@1993
   106
  template <typename Graph, typename Enable = void>
deba@1993
   107
  struct UEdgeNotifierIndicator {
deba@1993
   108
    typedef InvalidType Type;
deba@1993
   109
  };
deba@1993
   110
  template <typename Graph>
deba@1993
   111
  struct UEdgeNotifierIndicator<
deba@1993
   112
    Graph, 
deba@1993
   113
    typename enable_if<typename Graph::UEdgeNotifier::Notifier, void>::type
deba@1993
   114
  > { 
deba@1993
   115
    typedef typename Graph::UEdgeNotifier Type;
deba@1993
   116
  };
deba@1993
   117
deba@1993
   118
  template <typename _Graph>
deba@1993
   119
  class ItemSetTraits<_Graph, typename _Graph::UEdge> {
deba@1993
   120
  public:
deba@1993
   121
    
deba@1993
   122
    typedef _Graph Graph;
deba@1993
   123
deba@1993
   124
    typedef typename Graph::UEdge Item;
deba@1993
   125
    typedef typename Graph::UEdgeIt ItemIt;
deba@1993
   126
deba@1993
   127
    typedef typename UEdgeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
   128
deba@1993
   129
    template <typename _Value>
deba@1993
   130
    class Map : public Graph::template UEdgeMap<_Value> {
deba@1993
   131
    public:
deba@1993
   132
      typedef typename Graph::template UEdgeMap<_Value> Parent; 
deba@1993
   133
      typedef typename Parent::Value Value;
deba@1993
   134
deba@1993
   135
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   136
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   137
	: Parent(_graph, _value) {}
deba@1993
   138
    };
deba@1993
   139
deba@1993
   140
  };
deba@1993
   141
deba@1993
   142
  template <typename Graph, typename Enable = void>
deba@1993
   143
  struct ANodeNotifierIndicator {
deba@1993
   144
    typedef InvalidType Type;
deba@1993
   145
  };
deba@1993
   146
  template <typename Graph>
deba@1993
   147
  struct ANodeNotifierIndicator<
deba@1993
   148
    Graph, 
deba@1993
   149
    typename enable_if<typename Graph::ANodeNotifier::Notifier, void>::type
deba@1993
   150
  > { 
deba@1993
   151
    typedef typename Graph::ANodeNotifier Type;
deba@1993
   152
  };
deba@1993
   153
deba@1993
   154
  template <typename _Graph>
deba@1993
   155
  class ItemSetTraits<_Graph, typename _Graph::ANode> {
deba@1993
   156
  public:
deba@1993
   157
    
deba@1993
   158
    typedef _Graph Graph;
deba@1993
   159
deba@1993
   160
    typedef typename Graph::ANode Item;
deba@1993
   161
    typedef typename Graph::ANodeIt ItemIt;
deba@1993
   162
deba@1993
   163
    typedef typename ANodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
   164
deba@1993
   165
    template <typename _Value>
deba@1993
   166
    class Map : public Graph::template ANodeMap<_Value> {
deba@1993
   167
    public:
deba@1993
   168
      typedef typename Graph::template ANodeMap<_Value> Parent; 
deba@1993
   169
      typedef typename Parent::Value Value;
deba@1993
   170
deba@1993
   171
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   172
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   173
	: Parent(_graph, _value) {}
deba@1993
   174
    };
deba@1993
   175
deba@1993
   176
  };
deba@1993
   177
deba@1993
   178
  template <typename Graph, typename Enable = void>
deba@1993
   179
  struct BNodeNotifierIndicator {
deba@1993
   180
    typedef InvalidType Type;
deba@1993
   181
  };
deba@1993
   182
  template <typename Graph>
deba@1993
   183
  struct BNodeNotifierIndicator<
deba@1993
   184
    Graph, 
deba@1993
   185
    typename enable_if<typename Graph::BNodeNotifier::Notifier, void>::type
deba@1993
   186
  > { 
deba@1993
   187
    typedef typename Graph::BNodeNotifier Type;
deba@1993
   188
  };
deba@1993
   189
deba@1993
   190
  template <typename _Graph>
deba@1993
   191
  class ItemSetTraits<_Graph, typename _Graph::BNode> {
deba@1993
   192
  public:
deba@1993
   193
    
deba@1993
   194
    typedef _Graph Graph;
deba@1993
   195
deba@1993
   196
    typedef typename Graph::BNode Item;
deba@1993
   197
    typedef typename Graph::BNodeIt ItemIt;
deba@1993
   198
deba@1993
   199
    typedef typename BNodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
   200
deba@1993
   201
    template <typename _Value>
deba@1993
   202
    class Map : public Graph::template BNodeMap<_Value> {
deba@1993
   203
    public:
deba@1993
   204
      typedef typename Graph::template BNodeMap<_Value> Parent; 
deba@1993
   205
      typedef typename Parent::Value Value;
deba@1993
   206
deba@1993
   207
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   208
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   209
	: Parent(_graph, _value) {}
deba@1993
   210
    };
deba@1993
   211
deba@1993
   212
  };
deba@1993
   213
deba@1993
   214
deba@1993
   215
  template <typename Map, typename Enable = void>
deba@1993
   216
  struct MapTraits {
deba@1993
   217
    typedef False ReferenceMapTag;
deba@1993
   218
deba@1993
   219
    typedef typename Map::Key Key;
deba@1993
   220
    typedef typename Map::Value Value;
deba@1993
   221
deba@1993
   222
    typedef const Value ConstReturnValue;
deba@1993
   223
    typedef const Value ReturnValue;
deba@1993
   224
  };
deba@1993
   225
deba@1993
   226
  template <typename Map>
deba@1993
   227
  struct MapTraits<
deba@1993
   228
    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
deba@1993
   229
  {
deba@1993
   230
    typedef True ReferenceMapTag;
deba@1993
   231
    
deba@1993
   232
    typedef typename Map::Key Key;
deba@1993
   233
    typedef typename Map::Value Value;
deba@1993
   234
deba@1993
   235
    typedef typename Map::ConstReference ConstReturnValue;
deba@1993
   236
    typedef typename Map::Reference ReturnValue;
deba@1993
   237
deba@1993
   238
    typedef typename Map::ConstReference ConstReference; 
deba@1993
   239
    typedef typename Map::Reference Reference;
deba@1993
   240
 };
deba@1993
   241
deba@1993
   242
  // Indicators for the tags
deba@1993
   243
deba@1993
   244
  template <typename Graph, typename Enable = void>
deba@1993
   245
  struct NodeNumTagIndicator {
deba@1993
   246
    static const bool value = false;
deba@1993
   247
  };
deba@1993
   248
deba@1993
   249
  template <typename Graph>
deba@1993
   250
  struct NodeNumTagIndicator<
deba@1993
   251
    Graph, 
deba@1993
   252
    typename enable_if<typename Graph::NodeNumTag, void>::type
deba@1993
   253
  > {
deba@1993
   254
    static const bool value = true;
deba@1993
   255
  };
deba@1993
   256
deba@1993
   257
  template <typename Graph, typename Enable = void>
deba@1993
   258
  struct EdgeNumTagIndicator {
deba@1993
   259
    static const bool value = false;
deba@1993
   260
  };
deba@1993
   261
deba@1993
   262
  template <typename Graph>
deba@1993
   263
  struct EdgeNumTagIndicator<
deba@1993
   264
    Graph, 
deba@1993
   265
    typename enable_if<typename Graph::EdgeNumTag, void>::type
deba@1993
   266
  > {
deba@1993
   267
    static const bool value = true;
deba@1993
   268
  };
deba@1993
   269
deba@1993
   270
  template <typename Graph, typename Enable = void>
deba@1993
   271
  struct FindEdgeTagIndicator {
deba@1993
   272
    static const bool value = false;
deba@1993
   273
  };
deba@1993
   274
deba@1993
   275
  template <typename Graph>
deba@1993
   276
  struct FindEdgeTagIndicator<
deba@1993
   277
    Graph, 
deba@1993
   278
    typename enable_if<typename Graph::FindEdgeTag, void>::type
deba@1993
   279
  > {
deba@1993
   280
    static const bool value = true;
deba@1993
   281
  };
deba@1993
   282
deba@1993
   283
  template <typename Graph, typename Enable = void>
deba@1993
   284
  struct UndirectedTagIndicator {
deba@1993
   285
    static const bool value = false;
deba@1993
   286
  };
deba@1993
   287
deba@1993
   288
  template <typename Graph>
deba@1993
   289
  struct UndirectedTagIndicator<
deba@1993
   290
    Graph, 
deba@1993
   291
    typename enable_if<typename Graph::UndirectedTag, void>::type
deba@1993
   292
  > {
deba@1993
   293
    static const bool value = true;
deba@1993
   294
  };
deba@1993
   295
deba@1993
   296
deba@1993
   297
deba@1993
   298
}
deba@1993
   299
deba@1996
   300
#endif