lemon/bits/traits.h
author Balazs Dezso <deba@inf.elte.hu>
Sun, 14 Nov 2010 20:06:23 +0100
changeset 1187 4c89e925cfe2
parent 663 f2d6d3446adf
child 1194 699c7eac2c6d
permissions -rw-r--r--
SmartBpGraph implementation (#69)
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@57
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@57
     4
 *
alpar@463
     5
 * Copyright (C) 2003-2009
deba@57
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@57
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@57
     8
 *
deba@57
     9
 * Permission to use, modify and distribute this software is granted
deba@57
    10
 * provided that this copyright notice appears in all copies. For
deba@57
    11
 * precise terms see the accompanying LICENSE file.
deba@57
    12
 *
deba@57
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@57
    14
 * express or implied, and with no claim as to its suitability for any
deba@57
    15
 * purpose.
deba@57
    16
 *
deba@57
    17
 */
deba@57
    18
deba@57
    19
#ifndef LEMON_BITS_TRAITS_H
deba@57
    20
#define LEMON_BITS_TRAITS_H
deba@57
    21
kpeter@314
    22
//\file
kpeter@314
    23
//\brief Traits for graphs and maps
kpeter@314
    24
//
deba@57
    25
deba@220
    26
#include <lemon/bits/enable_if.h>
deba@220
    27
deba@57
    28
namespace lemon {
deba@220
    29
deba@220
    30
  struct InvalidType {};
deba@220
    31
kpeter@663
    32
  template <typename GR, typename _Item>
deba@57
    33
  class ItemSetTraits {};
alpar@209
    34
deba@57
    35
kpeter@663
    36
  template <typename GR, typename Enable = void>
deba@57
    37
  struct NodeNotifierIndicator {
deba@57
    38
    typedef InvalidType Type;
deba@57
    39
  };
kpeter@663
    40
  template <typename GR>
deba@57
    41
  struct NodeNotifierIndicator<
kpeter@663
    42
    GR,
kpeter@663
    43
    typename enable_if<typename GR::NodeNotifier::Notifier, void>::type
alpar@209
    44
  > {
kpeter@663
    45
    typedef typename GR::NodeNotifier Type;
deba@57
    46
  };
deba@57
    47
kpeter@663
    48
  template <typename GR>
kpeter@663
    49
  class ItemSetTraits<GR, typename GR::Node> {
deba@57
    50
  public:
alpar@209
    51
kpeter@663
    52
    typedef GR Graph;
kpeter@663
    53
    typedef GR Digraph;
deba@57
    54
kpeter@663
    55
    typedef typename GR::Node Item;
kpeter@663
    56
    typedef typename GR::NodeIt ItemIt;
deba@57
    57
kpeter@663
    58
    typedef typename NodeNotifierIndicator<GR>::Type ItemNotifier;
deba@57
    59
kpeter@663
    60
    template <typename V>
kpeter@663
    61
    class Map : public GR::template NodeMap<V> {
kpeter@663
    62
      typedef typename GR::template NodeMap<V> Parent;
kpeter@663
    63
deba@57
    64
    public:
kpeter@663
    65
      typedef typename GR::template NodeMap<V> Type;
deba@57
    66
      typedef typename Parent::Value Value;
deba@57
    67
kpeter@663
    68
      Map(const GR& _digraph) : Parent(_digraph) {}
kpeter@663
    69
      Map(const GR& _digraph, const Value& _value)
alpar@209
    70
        : Parent(_digraph, _value) {}
deba@57
    71
deba@57
    72
     };
deba@57
    73
deba@57
    74
  };
deba@57
    75
kpeter@663
    76
  template <typename GR, typename Enable = void>
deba@57
    77
  struct ArcNotifierIndicator {
deba@57
    78
    typedef InvalidType Type;
deba@57
    79
  };
kpeter@663
    80
  template <typename GR>
deba@57
    81
  struct ArcNotifierIndicator<
kpeter@663
    82
    GR,
kpeter@663
    83
    typename enable_if<typename GR::ArcNotifier::Notifier, void>::type
alpar@209
    84
  > {
kpeter@663
    85
    typedef typename GR::ArcNotifier Type;
deba@57
    86
  };
deba@57
    87
kpeter@663
    88
  template <typename GR>
kpeter@663
    89
  class ItemSetTraits<GR, typename GR::Arc> {
deba@57
    90
  public:
alpar@209
    91
kpeter@663
    92
    typedef GR Graph;
kpeter@663
    93
    typedef GR Digraph;
deba@57
    94
kpeter@663
    95
    typedef typename GR::Arc Item;
kpeter@663
    96
    typedef typename GR::ArcIt ItemIt;
deba@57
    97
kpeter@663
    98
    typedef typename ArcNotifierIndicator<GR>::Type ItemNotifier;
deba@57
    99
kpeter@663
   100
    template <typename V>
kpeter@663
   101
    class Map : public GR::template ArcMap<V> {
kpeter@663
   102
      typedef typename GR::template ArcMap<V> Parent;
kpeter@663
   103
deba@57
   104
    public:
kpeter@663
   105
      typedef typename GR::template ArcMap<V> Type;
deba@57
   106
      typedef typename Parent::Value Value;
deba@57
   107
kpeter@663
   108
      Map(const GR& _digraph) : Parent(_digraph) {}
kpeter@663
   109
      Map(const GR& _digraph, const Value& _value)
alpar@209
   110
        : Parent(_digraph, _value) {}
deba@57
   111
    };
deba@57
   112
deba@57
   113
  };
deba@57
   114
kpeter@663
   115
  template <typename GR, typename Enable = void>
deba@57
   116
  struct EdgeNotifierIndicator {
deba@57
   117
    typedef InvalidType Type;
deba@57
   118
  };
kpeter@663
   119
  template <typename GR>
deba@57
   120
  struct EdgeNotifierIndicator<
kpeter@663
   121
    GR,
kpeter@663
   122
    typename enable_if<typename GR::EdgeNotifier::Notifier, void>::type
alpar@209
   123
  > {
kpeter@663
   124
    typedef typename GR::EdgeNotifier Type;
deba@57
   125
  };
deba@57
   126
kpeter@663
   127
  template <typename GR>
kpeter@663
   128
  class ItemSetTraits<GR, typename GR::Edge> {
deba@57
   129
  public:
alpar@209
   130
kpeter@663
   131
    typedef GR Graph;
kpeter@663
   132
    typedef GR Digraph;
deba@57
   133
kpeter@663
   134
    typedef typename GR::Edge Item;
kpeter@663
   135
    typedef typename GR::EdgeIt ItemIt;
deba@57
   136
kpeter@663
   137
    typedef typename EdgeNotifierIndicator<GR>::Type ItemNotifier;
deba@57
   138
kpeter@663
   139
    template <typename V>
kpeter@663
   140
    class Map : public GR::template EdgeMap<V> {
kpeter@663
   141
      typedef typename GR::template EdgeMap<V> Parent;
kpeter@663
   142
deba@57
   143
    public:
kpeter@663
   144
      typedef typename GR::template EdgeMap<V> Type;
deba@57
   145
      typedef typename Parent::Value Value;
deba@57
   146
kpeter@663
   147
      Map(const GR& _digraph) : Parent(_digraph) {}
kpeter@663
   148
      Map(const GR& _digraph, const Value& _value)
alpar@209
   149
        : Parent(_digraph, _value) {}
deba@57
   150
    };
deba@57
   151
deba@57
   152
  };
deba@57
   153
deba@1187
   154
  template <typename GR, typename Enable = void>
deba@1187
   155
  struct RedNodeNotifierIndicator {
deba@1187
   156
    typedef InvalidType Type;
deba@1187
   157
  };
deba@1187
   158
  template <typename GR>
deba@1187
   159
  struct RedNodeNotifierIndicator<
deba@1187
   160
    GR,
deba@1187
   161
    typename enable_if<typename GR::RedNodeNotifier::Notifier, void>::type
deba@1187
   162
  > {
deba@1187
   163
    typedef typename GR::RedNodeNotifier Type;
deba@1187
   164
  };
deba@1187
   165
deba@1187
   166
  template <typename GR>
deba@1187
   167
  class ItemSetTraits<GR, typename GR::RedNode> {
deba@1187
   168
  public:
deba@1187
   169
deba@1187
   170
    typedef GR BpGraph;
deba@1187
   171
    typedef GR Graph;
deba@1187
   172
    typedef GR Digraph;
deba@1187
   173
deba@1187
   174
    typedef typename GR::RedNode Item;
deba@1187
   175
    typedef typename GR::RedIt ItemIt;
deba@1187
   176
deba@1187
   177
    typedef typename RedNodeNotifierIndicator<GR>::Type ItemNotifier;
deba@1187
   178
deba@1187
   179
    template <typename V>
deba@1187
   180
    class Map : public GR::template RedMap<V> {
deba@1187
   181
      typedef typename GR::template RedMap<V> Parent;
deba@1187
   182
deba@1187
   183
    public:
deba@1187
   184
      typedef typename GR::template RedMap<V> Type;
deba@1187
   185
      typedef typename Parent::Value Value;
deba@1187
   186
deba@1187
   187
      Map(const GR& _bpgraph) : Parent(_bpgraph) {}
deba@1187
   188
      Map(const GR& _bpgraph, const Value& _value)
deba@1187
   189
        : Parent(_bpgraph, _value) {}
deba@1187
   190
deba@1187
   191
     };
deba@1187
   192
deba@1187
   193
  };
deba@1187
   194
deba@1187
   195
  template <typename GR, typename Enable = void>
deba@1187
   196
  struct BlueNodeNotifierIndicator {
deba@1187
   197
    typedef InvalidType Type;
deba@1187
   198
  };
deba@1187
   199
  template <typename GR>
deba@1187
   200
  struct BlueNodeNotifierIndicator<
deba@1187
   201
    GR,
deba@1187
   202
    typename enable_if<typename GR::BlueNodeNotifier::Notifier, void>::type
deba@1187
   203
  > {
deba@1187
   204
    typedef typename GR::BlueNodeNotifier Type;
deba@1187
   205
  };
deba@1187
   206
deba@1187
   207
  template <typename GR>
deba@1187
   208
  class ItemSetTraits<GR, typename GR::BlueNode> {
deba@1187
   209
  public:
deba@1187
   210
deba@1187
   211
    typedef GR BpGraph;
deba@1187
   212
    typedef GR Graph;
deba@1187
   213
    typedef GR Digraph;
deba@1187
   214
deba@1187
   215
    typedef typename GR::BlueNode Item;
deba@1187
   216
    typedef typename GR::BlueIt ItemIt;
deba@1187
   217
deba@1187
   218
    typedef typename BlueNodeNotifierIndicator<GR>::Type ItemNotifier;
deba@1187
   219
deba@1187
   220
    template <typename V>
deba@1187
   221
    class Map : public GR::template BlueMap<V> {
deba@1187
   222
      typedef typename GR::template BlueMap<V> Parent;
deba@1187
   223
deba@1187
   224
    public:
deba@1187
   225
      typedef typename GR::template BlueMap<V> Type;
deba@1187
   226
      typedef typename Parent::Value Value;
deba@1187
   227
deba@1187
   228
      Map(const GR& _bpgraph) : Parent(_bpgraph) {}
deba@1187
   229
      Map(const GR& _bpgraph, const Value& _value)
deba@1187
   230
        : Parent(_bpgraph, _value) {}
deba@1187
   231
deba@1187
   232
     };
deba@1187
   233
deba@1187
   234
  };
deba@1187
   235
deba@57
   236
  template <typename Map, typename Enable = void>
deba@57
   237
  struct MapTraits {
deba@57
   238
    typedef False ReferenceMapTag;
deba@57
   239
deba@57
   240
    typedef typename Map::Key Key;
deba@57
   241
    typedef typename Map::Value Value;
deba@57
   242
alpar@184
   243
    typedef Value ConstReturnValue;
alpar@184
   244
    typedef Value ReturnValue;
deba@57
   245
  };
deba@57
   246
deba@57
   247
  template <typename Map>
deba@57
   248
  struct MapTraits<
alpar@209
   249
    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type >
deba@57
   250
  {
deba@57
   251
    typedef True ReferenceMapTag;
alpar@209
   252
deba@57
   253
    typedef typename Map::Key Key;
deba@57
   254
    typedef typename Map::Value Value;
deba@57
   255
deba@57
   256
    typedef typename Map::ConstReference ConstReturnValue;
deba@57
   257
    typedef typename Map::Reference ReturnValue;
deba@57
   258
alpar@209
   259
    typedef typename Map::ConstReference ConstReference;
deba@57
   260
    typedef typename Map::Reference Reference;
deba@57
   261
 };
deba@57
   262
deba@57
   263
  template <typename MatrixMap, typename Enable = void>
deba@57
   264
  struct MatrixMapTraits {
deba@57
   265
    typedef False ReferenceMapTag;
deba@57
   266
deba@57
   267
    typedef typename MatrixMap::FirstKey FirstKey;
deba@57
   268
    typedef typename MatrixMap::SecondKey SecondKey;
deba@57
   269
    typedef typename MatrixMap::Value Value;
deba@57
   270
alpar@184
   271
    typedef Value ConstReturnValue;
alpar@184
   272
    typedef Value ReturnValue;
deba@57
   273
  };
deba@57
   274
deba@57
   275
  template <typename MatrixMap>
deba@57
   276
  struct MatrixMapTraits<
alpar@209
   277
    MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
alpar@209
   278
                                  void>::type >
deba@57
   279
  {
deba@57
   280
    typedef True ReferenceMapTag;
alpar@209
   281
deba@57
   282
    typedef typename MatrixMap::FirstKey FirstKey;
deba@57
   283
    typedef typename MatrixMap::SecondKey SecondKey;
deba@57
   284
    typedef typename MatrixMap::Value Value;
deba@57
   285
deba@57
   286
    typedef typename MatrixMap::ConstReference ConstReturnValue;
deba@57
   287
    typedef typename MatrixMap::Reference ReturnValue;
deba@57
   288
alpar@209
   289
    typedef typename MatrixMap::ConstReference ConstReference;
deba@57
   290
    typedef typename MatrixMap::Reference Reference;
deba@57
   291
 };
deba@57
   292
deba@57
   293
  // Indicators for the tags
deba@57
   294
kpeter@663
   295
  template <typename GR, typename Enable = void>
deba@57
   296
  struct NodeNumTagIndicator {
deba@57
   297
    static const bool value = false;
deba@57
   298
  };
deba@57
   299
kpeter@663
   300
  template <typename GR>
deba@57
   301
  struct NodeNumTagIndicator<
kpeter@663
   302
    GR,
kpeter@663
   303
    typename enable_if<typename GR::NodeNumTag, void>::type
deba@57
   304
  > {
deba@57
   305
    static const bool value = true;
deba@57
   306
  };
deba@57
   307
kpeter@663
   308
  template <typename GR, typename Enable = void>
kpeter@372
   309
  struct ArcNumTagIndicator {
kpeter@372
   310
    static const bool value = false;
kpeter@372
   311
  };
kpeter@372
   312
kpeter@663
   313
  template <typename GR>
kpeter@372
   314
  struct ArcNumTagIndicator<
kpeter@663
   315
    GR,
kpeter@663
   316
    typename enable_if<typename GR::ArcNumTag, void>::type
kpeter@372
   317
  > {
kpeter@372
   318
    static const bool value = true;
kpeter@372
   319
  };
kpeter@372
   320
kpeter@663
   321
  template <typename GR, typename Enable = void>
deba@139
   322
  struct EdgeNumTagIndicator {
deba@57
   323
    static const bool value = false;
deba@57
   324
  };
deba@57
   325
kpeter@663
   326
  template <typename GR>
deba@139
   327
  struct EdgeNumTagIndicator<
kpeter@663
   328
    GR,
kpeter@663
   329
    typename enable_if<typename GR::EdgeNumTag, void>::type
deba@57
   330
  > {
deba@57
   331
    static const bool value = true;
deba@57
   332
  };
deba@57
   333
kpeter@663
   334
  template <typename GR, typename Enable = void>
kpeter@372
   335
  struct FindArcTagIndicator {
kpeter@372
   336
    static const bool value = false;
kpeter@372
   337
  };
kpeter@372
   338
kpeter@663
   339
  template <typename GR>
kpeter@372
   340
  struct FindArcTagIndicator<
kpeter@663
   341
    GR,
kpeter@663
   342
    typename enable_if<typename GR::FindArcTag, void>::type
kpeter@372
   343
  > {
kpeter@372
   344
    static const bool value = true;
kpeter@372
   345
  };
kpeter@372
   346
kpeter@663
   347
  template <typename GR, typename Enable = void>
deba@139
   348
  struct FindEdgeTagIndicator {
deba@57
   349
    static const bool value = false;
deba@57
   350
  };
deba@57
   351
kpeter@663
   352
  template <typename GR>
deba@139
   353
  struct FindEdgeTagIndicator<
kpeter@663
   354
    GR,
kpeter@663
   355
    typename enable_if<typename GR::FindEdgeTag, void>::type
deba@57
   356
  > {
deba@57
   357
    static const bool value = true;
deba@57
   358
  };
deba@57
   359
kpeter@663
   360
  template <typename GR, typename Enable = void>
deba@57
   361
  struct UndirectedTagIndicator {
deba@57
   362
    static const bool value = false;
deba@57
   363
  };
deba@57
   364
kpeter@663
   365
  template <typename GR>
deba@57
   366
  struct UndirectedTagIndicator<
kpeter@663
   367
    GR,
kpeter@663
   368
    typename enable_if<typename GR::UndirectedTag, void>::type
deba@57
   369
  > {
deba@57
   370
    static const bool value = true;
deba@57
   371
  };
deba@57
   372
kpeter@663
   373
  template <typename GR, typename Enable = void>
deba@57
   374
  struct BuildTagIndicator {
deba@57
   375
    static const bool value = false;
deba@57
   376
  };
deba@57
   377
kpeter@663
   378
  template <typename GR>
deba@57
   379
  struct BuildTagIndicator<
kpeter@663
   380
    GR,
kpeter@663
   381
    typename enable_if<typename GR::BuildTag, void>::type
deba@57
   382
  > {
deba@57
   383
    static const bool value = true;
deba@57
   384
  };
deba@57
   385
deba@57
   386
}
deba@57
   387
deba@57
   388
#endif