lemon/bits/traits.h
author ladanyi
Sat, 01 Mar 2008 20:09:40 +0000
changeset 2591 3b4d5bc3b4fb
parent 2512 371cf309fc3c
child 2618 6aa6fcaeaea5
permissions -rw-r--r--
In C++98 array size shall be an integral constant expression. Fixes
ticket 12.
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
 *
alpar@2553
     5
 * Copyright (C) 2003-2008
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@2512
    60
      typedef typename Graph::template NodeMap<_Value> Type; 
deba@1993
    61
      typedef typename Parent::Value Value;
deba@1993
    62
deba@1993
    63
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
    64
      Map(const Graph& _graph, const Value& _value) 
deba@1993
    65
	: Parent(_graph, _value) {}
deba@1993
    66
deba@1993
    67
     };
deba@1993
    68
deba@1993
    69
  };
deba@1993
    70
deba@1993
    71
  template <typename Graph, typename Enable = void>
deba@1993
    72
  struct EdgeNotifierIndicator {
deba@1993
    73
    typedef InvalidType Type;
deba@1993
    74
  };
deba@1993
    75
  template <typename Graph>
deba@1993
    76
  struct EdgeNotifierIndicator<
deba@1993
    77
    Graph, 
deba@1993
    78
    typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
deba@1993
    79
  > { 
deba@1993
    80
    typedef typename Graph::EdgeNotifier Type;
deba@1993
    81
  };
deba@1993
    82
deba@1993
    83
  template <typename _Graph>
deba@1993
    84
  class ItemSetTraits<_Graph, typename _Graph::Edge> {
deba@1993
    85
  public:
deba@1993
    86
    
deba@1993
    87
    typedef _Graph Graph;
deba@1993
    88
deba@1993
    89
    typedef typename Graph::Edge Item;
deba@1993
    90
    typedef typename Graph::EdgeIt ItemIt;
deba@1993
    91
deba@1993
    92
    typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
    93
deba@1993
    94
    template <typename _Value>
deba@1993
    95
    class Map : public Graph::template EdgeMap<_Value> {
deba@1993
    96
    public:
deba@1993
    97
      typedef typename Graph::template EdgeMap<_Value> Parent; 
deba@2512
    98
      typedef typename Graph::template EdgeMap<_Value> Type; 
deba@1993
    99
      typedef typename Parent::Value Value;
deba@1993
   100
deba@1993
   101
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   102
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   103
	: Parent(_graph, _value) {}
deba@1993
   104
    };
deba@1993
   105
deba@1993
   106
  };
deba@1993
   107
deba@1993
   108
  template <typename Graph, typename Enable = void>
deba@1993
   109
  struct UEdgeNotifierIndicator {
deba@1993
   110
    typedef InvalidType Type;
deba@1993
   111
  };
deba@1993
   112
  template <typename Graph>
deba@1993
   113
  struct UEdgeNotifierIndicator<
deba@1993
   114
    Graph, 
deba@1993
   115
    typename enable_if<typename Graph::UEdgeNotifier::Notifier, void>::type
deba@1993
   116
  > { 
deba@1993
   117
    typedef typename Graph::UEdgeNotifier Type;
deba@1993
   118
  };
deba@1993
   119
deba@1993
   120
  template <typename _Graph>
deba@1993
   121
  class ItemSetTraits<_Graph, typename _Graph::UEdge> {
deba@1993
   122
  public:
deba@1993
   123
    
deba@1993
   124
    typedef _Graph Graph;
deba@1993
   125
deba@1993
   126
    typedef typename Graph::UEdge Item;
deba@1993
   127
    typedef typename Graph::UEdgeIt ItemIt;
deba@1993
   128
deba@1993
   129
    typedef typename UEdgeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
   130
deba@1993
   131
    template <typename _Value>
deba@1993
   132
    class Map : public Graph::template UEdgeMap<_Value> {
deba@1993
   133
    public:
deba@1993
   134
      typedef typename Graph::template UEdgeMap<_Value> Parent; 
deba@2512
   135
      typedef typename Graph::template UEdgeMap<_Value> Type; 
deba@1993
   136
      typedef typename Parent::Value Value;
deba@1993
   137
deba@1993
   138
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   139
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   140
	: Parent(_graph, _value) {}
deba@1993
   141
    };
deba@1993
   142
deba@1993
   143
  };
deba@1993
   144
deba@1993
   145
  template <typename Graph, typename Enable = void>
deba@1993
   146
  struct ANodeNotifierIndicator {
deba@1993
   147
    typedef InvalidType Type;
deba@1993
   148
  };
deba@1993
   149
  template <typename Graph>
deba@1993
   150
  struct ANodeNotifierIndicator<
deba@1993
   151
    Graph, 
deba@1993
   152
    typename enable_if<typename Graph::ANodeNotifier::Notifier, void>::type
deba@1993
   153
  > { 
deba@1993
   154
    typedef typename Graph::ANodeNotifier Type;
deba@1993
   155
  };
deba@1993
   156
deba@1993
   157
  template <typename _Graph>
deba@1993
   158
  class ItemSetTraits<_Graph, typename _Graph::ANode> {
deba@1993
   159
  public:
deba@1993
   160
    
deba@1993
   161
    typedef _Graph Graph;
deba@1993
   162
deba@1993
   163
    typedef typename Graph::ANode Item;
deba@1993
   164
    typedef typename Graph::ANodeIt ItemIt;
deba@1993
   165
deba@1993
   166
    typedef typename ANodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
   167
deba@1993
   168
    template <typename _Value>
deba@1993
   169
    class Map : public Graph::template ANodeMap<_Value> {
deba@1993
   170
    public:
deba@1993
   171
      typedef typename Graph::template ANodeMap<_Value> Parent; 
deba@2512
   172
      typedef typename Graph::template ANodeMap<_Value> Type; 
deba@1993
   173
      typedef typename Parent::Value Value;
deba@1993
   174
deba@1993
   175
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   176
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   177
	: Parent(_graph, _value) {}
deba@1993
   178
    };
deba@1993
   179
deba@1993
   180
  };
deba@1993
   181
deba@1993
   182
  template <typename Graph, typename Enable = void>
deba@1993
   183
  struct BNodeNotifierIndicator {
deba@1993
   184
    typedef InvalidType Type;
deba@1993
   185
  };
deba@1993
   186
  template <typename Graph>
deba@1993
   187
  struct BNodeNotifierIndicator<
deba@1993
   188
    Graph, 
deba@1993
   189
    typename enable_if<typename Graph::BNodeNotifier::Notifier, void>::type
deba@1993
   190
  > { 
deba@1993
   191
    typedef typename Graph::BNodeNotifier Type;
deba@1993
   192
  };
deba@1993
   193
deba@1993
   194
  template <typename _Graph>
deba@1993
   195
  class ItemSetTraits<_Graph, typename _Graph::BNode> {
deba@1993
   196
  public:
deba@1993
   197
    
deba@1993
   198
    typedef _Graph Graph;
deba@1993
   199
deba@1993
   200
    typedef typename Graph::BNode Item;
deba@1993
   201
    typedef typename Graph::BNodeIt ItemIt;
deba@1993
   202
deba@1993
   203
    typedef typename BNodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@1993
   204
deba@1993
   205
    template <typename _Value>
deba@1993
   206
    class Map : public Graph::template BNodeMap<_Value> {
deba@1993
   207
    public:
deba@1993
   208
      typedef typename Graph::template BNodeMap<_Value> Parent; 
deba@2512
   209
      typedef typename Graph::template BNodeMap<_Value> Type; 
deba@1993
   210
      typedef typename Parent::Value Value;
deba@1993
   211
deba@1993
   212
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1993
   213
      Map(const Graph& _graph, const Value& _value) 
deba@1993
   214
	: Parent(_graph, _value) {}
deba@1993
   215
    };
deba@1993
   216
deba@1993
   217
  };
deba@1993
   218
deba@1993
   219
deba@1993
   220
  template <typename Map, typename Enable = void>
deba@1993
   221
  struct MapTraits {
deba@1993
   222
    typedef False ReferenceMapTag;
deba@1993
   223
deba@1993
   224
    typedef typename Map::Key Key;
deba@1993
   225
    typedef typename Map::Value Value;
deba@1993
   226
deba@1993
   227
    typedef const Value ConstReturnValue;
deba@1993
   228
    typedef const Value ReturnValue;
deba@1993
   229
  };
deba@1993
   230
deba@1993
   231
  template <typename Map>
deba@1993
   232
  struct MapTraits<
deba@1993
   233
    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
deba@1993
   234
  {
deba@1993
   235
    typedef True ReferenceMapTag;
deba@1993
   236
    
deba@1993
   237
    typedef typename Map::Key Key;
deba@1993
   238
    typedef typename Map::Value Value;
deba@1993
   239
deba@1993
   240
    typedef typename Map::ConstReference ConstReturnValue;
deba@1993
   241
    typedef typename Map::Reference ReturnValue;
deba@1993
   242
deba@1993
   243
    typedef typename Map::ConstReference ConstReference; 
deba@1993
   244
    typedef typename Map::Reference Reference;
deba@1993
   245
 };
deba@1993
   246
deba@2039
   247
  template <typename MatrixMap, typename Enable = void>
deba@2039
   248
  struct MatrixMapTraits {
deba@2039
   249
    typedef False ReferenceMapTag;
deba@2039
   250
deba@2039
   251
    typedef typename MatrixMap::FirstKey FirstKey;
deba@2039
   252
    typedef typename MatrixMap::SecondKey SecondKey;
deba@2039
   253
    typedef typename MatrixMap::Value Value;
deba@2039
   254
deba@2039
   255
    typedef const Value ConstReturnValue;
deba@2039
   256
    typedef const Value ReturnValue;
deba@2039
   257
  };
deba@2039
   258
deba@2039
   259
  template <typename MatrixMap>
deba@2039
   260
  struct MatrixMapTraits<
deba@2039
   261
    MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, 
deba@2039
   262
                                  void>::type > 
deba@2039
   263
  {
deba@2039
   264
    typedef True ReferenceMapTag;
deba@2039
   265
    
deba@2039
   266
    typedef typename MatrixMap::FirstKey FirstKey;
deba@2039
   267
    typedef typename MatrixMap::SecondKey SecondKey;
deba@2039
   268
    typedef typename MatrixMap::Value Value;
deba@2039
   269
deba@2039
   270
    typedef typename MatrixMap::ConstReference ConstReturnValue;
deba@2039
   271
    typedef typename MatrixMap::Reference ReturnValue;
deba@2039
   272
deba@2039
   273
    typedef typename MatrixMap::ConstReference ConstReference; 
deba@2039
   274
    typedef typename MatrixMap::Reference Reference;
deba@2039
   275
 };
deba@2039
   276
deba@1993
   277
  // Indicators for the tags
deba@1993
   278
deba@1993
   279
  template <typename Graph, typename Enable = void>
deba@1993
   280
  struct NodeNumTagIndicator {
deba@1993
   281
    static const bool value = false;
deba@1993
   282
  };
deba@1993
   283
deba@1993
   284
  template <typename Graph>
deba@1993
   285
  struct NodeNumTagIndicator<
deba@1993
   286
    Graph, 
deba@1993
   287
    typename enable_if<typename Graph::NodeNumTag, void>::type
deba@1993
   288
  > {
deba@1993
   289
    static const bool value = true;
deba@1993
   290
  };
deba@1993
   291
deba@1993
   292
  template <typename Graph, typename Enable = void>
deba@1993
   293
  struct EdgeNumTagIndicator {
deba@1993
   294
    static const bool value = false;
deba@1993
   295
  };
deba@1993
   296
deba@1993
   297
  template <typename Graph>
deba@1993
   298
  struct EdgeNumTagIndicator<
deba@1993
   299
    Graph, 
deba@1993
   300
    typename enable_if<typename Graph::EdgeNumTag, void>::type
deba@1993
   301
  > {
deba@1993
   302
    static const bool value = true;
deba@1993
   303
  };
deba@1993
   304
deba@1993
   305
  template <typename Graph, typename Enable = void>
deba@1993
   306
  struct FindEdgeTagIndicator {
deba@1993
   307
    static const bool value = false;
deba@1993
   308
  };
deba@1993
   309
deba@1993
   310
  template <typename Graph>
deba@1993
   311
  struct FindEdgeTagIndicator<
deba@1993
   312
    Graph, 
deba@1993
   313
    typename enable_if<typename Graph::FindEdgeTag, void>::type
deba@1993
   314
  > {
deba@1993
   315
    static const bool value = true;
deba@1993
   316
  };
deba@1993
   317
deba@1993
   318
  template <typename Graph, typename Enable = void>
deba@1993
   319
  struct UndirectedTagIndicator {
deba@1993
   320
    static const bool value = false;
deba@1993
   321
  };
deba@1993
   322
deba@1993
   323
  template <typename Graph>
deba@1993
   324
  struct UndirectedTagIndicator<
deba@1993
   325
    Graph, 
deba@1993
   326
    typename enable_if<typename Graph::UndirectedTag, void>::type
deba@1993
   327
  > {
deba@1993
   328
    static const bool value = true;
deba@1993
   329
  };
deba@1993
   330
deba@2290
   331
  template <typename Graph, typename Enable = void>
deba@2329
   332
  struct BuildTagIndicator {
deba@2290
   333
    static const bool value = false;
deba@2290
   334
  };
deba@1993
   335
deba@2290
   336
  template <typename Graph>
deba@2329
   337
  struct BuildTagIndicator<
deba@2290
   338
    Graph, 
deba@2329
   339
    typename enable_if<typename Graph::BuildTag, void>::type
deba@2290
   340
  > {
deba@2290
   341
    static const bool value = true;
deba@2290
   342
  };
deba@1993
   343
deba@1993
   344
}
deba@1993
   345
deba@1996
   346
#endif