lemon/bits/traits.h
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 20 Jan 2021 16:17:21 +0100
changeset 1205 57abff252556
parent 1026 699c7eac2c6d
permissions -rw-r--r--
Bugfixes in CplexBase and ClpLp (#639)
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@1092
     5
 * Copyright (C) 2003-2013
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@616
    32
  template <typename GR, typename _Item>
deba@57
    33
  class ItemSetTraits {};
alpar@209
    34
deba@57
    35
kpeter@616
    36
  template <typename GR, typename Enable = void>
deba@57
    37
  struct NodeNotifierIndicator {
deba@57
    38
    typedef InvalidType Type;
deba@57
    39
  };
kpeter@616
    40
  template <typename GR>
deba@57
    41
  struct NodeNotifierIndicator<
kpeter@616
    42
    GR,
kpeter@616
    43
    typename enable_if<typename GR::NodeNotifier::Notifier, void>::type
alpar@209
    44
  > {
kpeter@616
    45
    typedef typename GR::NodeNotifier Type;
deba@57
    46
  };
deba@57
    47
kpeter@616
    48
  template <typename GR>
kpeter@616
    49
  class ItemSetTraits<GR, typename GR::Node> {
deba@57
    50
  public:
alpar@209
    51
kpeter@616
    52
    typedef GR Graph;
kpeter@616
    53
    typedef GR Digraph;
deba@57
    54
kpeter@616
    55
    typedef typename GR::Node Item;
kpeter@616
    56
    typedef typename GR::NodeIt ItemIt;
deba@57
    57
kpeter@616
    58
    typedef typename NodeNotifierIndicator<GR>::Type ItemNotifier;
deba@57
    59
kpeter@616
    60
    template <typename V>
kpeter@616
    61
    class Map : public GR::template NodeMap<V> {
kpeter@616
    62
      typedef typename GR::template NodeMap<V> Parent;
kpeter@616
    63
deba@57
    64
    public:
kpeter@616
    65
      typedef typename GR::template NodeMap<V> Type;
deba@57
    66
      typedef typename Parent::Value Value;
deba@57
    67
kpeter@616
    68
      Map(const GR& _digraph) : Parent(_digraph) {}
kpeter@616
    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@616
    76
  template <typename GR, typename Enable = void>
deba@57
    77
  struct ArcNotifierIndicator {
deba@57
    78
    typedef InvalidType Type;
deba@57
    79
  };
kpeter@616
    80
  template <typename GR>
deba@57
    81
  struct ArcNotifierIndicator<
kpeter@616
    82
    GR,
kpeter@616
    83
    typename enable_if<typename GR::ArcNotifier::Notifier, void>::type
alpar@209
    84
  > {
kpeter@616
    85
    typedef typename GR::ArcNotifier Type;
deba@57
    86
  };
deba@57
    87
kpeter@616
    88
  template <typename GR>
kpeter@616
    89
  class ItemSetTraits<GR, typename GR::Arc> {
deba@57
    90
  public:
alpar@209
    91
kpeter@616
    92
    typedef GR Graph;
kpeter@616
    93
    typedef GR Digraph;
deba@57
    94
kpeter@616
    95
    typedef typename GR::Arc Item;
kpeter@616
    96
    typedef typename GR::ArcIt ItemIt;
deba@57
    97
kpeter@616
    98
    typedef typename ArcNotifierIndicator<GR>::Type ItemNotifier;
deba@57
    99
kpeter@616
   100
    template <typename V>
kpeter@616
   101
    class Map : public GR::template ArcMap<V> {
kpeter@616
   102
      typedef typename GR::template ArcMap<V> Parent;
kpeter@616
   103
deba@57
   104
    public:
kpeter@616
   105
      typedef typename GR::template ArcMap<V> Type;
deba@57
   106
      typedef typename Parent::Value Value;
deba@57
   107
kpeter@616
   108
      Map(const GR& _digraph) : Parent(_digraph) {}
kpeter@616
   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@616
   115
  template <typename GR, typename Enable = void>
deba@57
   116
  struct EdgeNotifierIndicator {
deba@57
   117
    typedef InvalidType Type;
deba@57
   118
  };
kpeter@616
   119
  template <typename GR>
deba@57
   120
  struct EdgeNotifierIndicator<
kpeter@616
   121
    GR,
kpeter@616
   122
    typename enable_if<typename GR::EdgeNotifier::Notifier, void>::type
alpar@209
   123
  > {
kpeter@616
   124
    typedef typename GR::EdgeNotifier Type;
deba@57
   125
  };
deba@57
   126
kpeter@616
   127
  template <typename GR>
kpeter@616
   128
  class ItemSetTraits<GR, typename GR::Edge> {
deba@57
   129
  public:
alpar@209
   130
kpeter@616
   131
    typedef GR Graph;
kpeter@616
   132
    typedef GR Digraph;
deba@57
   133
kpeter@616
   134
    typedef typename GR::Edge Item;
kpeter@616
   135
    typedef typename GR::EdgeIt ItemIt;
deba@57
   136
kpeter@616
   137
    typedef typename EdgeNotifierIndicator<GR>::Type ItemNotifier;
deba@57
   138
kpeter@616
   139
    template <typename V>
kpeter@616
   140
    class Map : public GR::template EdgeMap<V> {
kpeter@616
   141
      typedef typename GR::template EdgeMap<V> Parent;
kpeter@616
   142
deba@57
   143
    public:
kpeter@616
   144
      typedef typename GR::template EdgeMap<V> Type;
deba@57
   145
      typedef typename Parent::Value Value;
deba@57
   146
kpeter@616
   147
      Map(const GR& _digraph) : Parent(_digraph) {}
kpeter@616
   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@1019
   154
  template <typename GR, typename Enable = void>
deba@1019
   155
  struct RedNodeNotifierIndicator {
deba@1019
   156
    typedef InvalidType Type;
deba@1019
   157
  };
deba@1019
   158
  template <typename GR>
deba@1019
   159
  struct RedNodeNotifierIndicator<
deba@1019
   160
    GR,
deba@1019
   161
    typename enable_if<typename GR::RedNodeNotifier::Notifier, void>::type
deba@1019
   162
  > {
deba@1019
   163
    typedef typename GR::RedNodeNotifier Type;
deba@1019
   164
  };
deba@1019
   165
deba@1019
   166
  template <typename GR>
deba@1019
   167
  class ItemSetTraits<GR, typename GR::RedNode> {
deba@1019
   168
  public:
deba@1019
   169
deba@1019
   170
    typedef GR BpGraph;
deba@1019
   171
    typedef GR Graph;
deba@1019
   172
    typedef GR Digraph;
deba@1019
   173
deba@1019
   174
    typedef typename GR::RedNode Item;
deba@1026
   175
    typedef typename GR::RedNodeIt ItemIt;
deba@1019
   176
deba@1019
   177
    typedef typename RedNodeNotifierIndicator<GR>::Type ItemNotifier;
deba@1019
   178
deba@1019
   179
    template <typename V>
deba@1026
   180
    class Map : public GR::template RedNodeMap<V> {
deba@1026
   181
      typedef typename GR::template RedNodeMap<V> Parent;
deba@1019
   182
deba@1019
   183
    public:
deba@1026
   184
      typedef typename GR::template RedNodeMap<V> Type;
deba@1019
   185
      typedef typename Parent::Value Value;
deba@1019
   186
deba@1019
   187
      Map(const GR& _bpgraph) : Parent(_bpgraph) {}
deba@1019
   188
      Map(const GR& _bpgraph, const Value& _value)
deba@1019
   189
        : Parent(_bpgraph, _value) {}
deba@1019
   190
deba@1019
   191
     };
deba@1019
   192
deba@1019
   193
  };
deba@1019
   194
deba@1019
   195
  template <typename GR, typename Enable = void>
deba@1019
   196
  struct BlueNodeNotifierIndicator {
deba@1019
   197
    typedef InvalidType Type;
deba@1019
   198
  };
deba@1019
   199
  template <typename GR>
deba@1019
   200
  struct BlueNodeNotifierIndicator<
deba@1019
   201
    GR,
deba@1019
   202
    typename enable_if<typename GR::BlueNodeNotifier::Notifier, void>::type
deba@1019
   203
  > {
deba@1019
   204
    typedef typename GR::BlueNodeNotifier Type;
deba@1019
   205
  };
deba@1019
   206
deba@1019
   207
  template <typename GR>
deba@1019
   208
  class ItemSetTraits<GR, typename GR::BlueNode> {
deba@1019
   209
  public:
deba@1019
   210
deba@1019
   211
    typedef GR BpGraph;
deba@1019
   212
    typedef GR Graph;
deba@1019
   213
    typedef GR Digraph;
deba@1019
   214
deba@1019
   215
    typedef typename GR::BlueNode Item;
deba@1026
   216
    typedef typename GR::BlueNodeIt ItemIt;
deba@1019
   217
deba@1019
   218
    typedef typename BlueNodeNotifierIndicator<GR>::Type ItemNotifier;
deba@1019
   219
deba@1019
   220
    template <typename V>
deba@1026
   221
    class Map : public GR::template BlueNodeMap<V> {
deba@1026
   222
      typedef typename GR::template BlueNodeMap<V> Parent;
deba@1019
   223
deba@1019
   224
    public:
deba@1026
   225
      typedef typename GR::template BlueNodeMap<V> Type;
deba@1019
   226
      typedef typename Parent::Value Value;
deba@1019
   227
deba@1019
   228
      Map(const GR& _bpgraph) : Parent(_bpgraph) {}
deba@1019
   229
      Map(const GR& _bpgraph, const Value& _value)
deba@1019
   230
        : Parent(_bpgraph, _value) {}
deba@1019
   231
deba@1019
   232
     };
deba@1019
   233
deba@1019
   234
  };
deba@1019
   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@616
   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@616
   300
  template <typename GR>
deba@57
   301
  struct NodeNumTagIndicator<
kpeter@616
   302
    GR,
kpeter@616
   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@616
   308
  template <typename GR, typename Enable = void>
kpeter@360
   309
  struct ArcNumTagIndicator {
kpeter@360
   310
    static const bool value = false;
kpeter@360
   311
  };
kpeter@360
   312
kpeter@616
   313
  template <typename GR>
kpeter@360
   314
  struct ArcNumTagIndicator<
kpeter@616
   315
    GR,
kpeter@616
   316
    typename enable_if<typename GR::ArcNumTag, void>::type
kpeter@360
   317
  > {
kpeter@360
   318
    static const bool value = true;
kpeter@360
   319
  };
kpeter@360
   320
kpeter@616
   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@616
   326
  template <typename GR>
deba@139
   327
  struct EdgeNumTagIndicator<
kpeter@616
   328
    GR,
kpeter@616
   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@616
   334
  template <typename GR, typename Enable = void>
kpeter@360
   335
  struct FindArcTagIndicator {
kpeter@360
   336
    static const bool value = false;
kpeter@360
   337
  };
kpeter@360
   338
kpeter@616
   339
  template <typename GR>
kpeter@360
   340
  struct FindArcTagIndicator<
kpeter@616
   341
    GR,
kpeter@616
   342
    typename enable_if<typename GR::FindArcTag, void>::type
kpeter@360
   343
  > {
kpeter@360
   344
    static const bool value = true;
kpeter@360
   345
  };
kpeter@360
   346
kpeter@616
   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@616
   352
  template <typename GR>
deba@139
   353
  struct FindEdgeTagIndicator<
kpeter@616
   354
    GR,
kpeter@616
   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@616
   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@616
   365
  template <typename GR>
deba@57
   366
  struct UndirectedTagIndicator<
kpeter@616
   367
    GR,
kpeter@616
   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@616
   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@616
   378
  template <typename GR>
deba@57
   379
  struct BuildTagIndicator<
kpeter@616
   380
    GR,
kpeter@616
   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