lemon/bits/traits.h
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 01 Feb 2012 06:43:50 +0100
changeset 983 fc1aa7c01c55
parent 440 88ed40ad0d4f
child 1019 4c89e925cfe2
permissions -rw-r--r--
Add dist target to CMAKE conf. (#434)
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@440
     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@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@57
   154
  template <typename Map, typename Enable = void>
deba@57
   155
  struct MapTraits {
deba@57
   156
    typedef False ReferenceMapTag;
deba@57
   157
deba@57
   158
    typedef typename Map::Key Key;
deba@57
   159
    typedef typename Map::Value Value;
deba@57
   160
alpar@184
   161
    typedef Value ConstReturnValue;
alpar@184
   162
    typedef Value ReturnValue;
deba@57
   163
  };
deba@57
   164
deba@57
   165
  template <typename Map>
deba@57
   166
  struct MapTraits<
alpar@209
   167
    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type >
deba@57
   168
  {
deba@57
   169
    typedef True ReferenceMapTag;
alpar@209
   170
deba@57
   171
    typedef typename Map::Key Key;
deba@57
   172
    typedef typename Map::Value Value;
deba@57
   173
deba@57
   174
    typedef typename Map::ConstReference ConstReturnValue;
deba@57
   175
    typedef typename Map::Reference ReturnValue;
deba@57
   176
alpar@209
   177
    typedef typename Map::ConstReference ConstReference;
deba@57
   178
    typedef typename Map::Reference Reference;
deba@57
   179
 };
deba@57
   180
deba@57
   181
  template <typename MatrixMap, typename Enable = void>
deba@57
   182
  struct MatrixMapTraits {
deba@57
   183
    typedef False ReferenceMapTag;
deba@57
   184
deba@57
   185
    typedef typename MatrixMap::FirstKey FirstKey;
deba@57
   186
    typedef typename MatrixMap::SecondKey SecondKey;
deba@57
   187
    typedef typename MatrixMap::Value Value;
deba@57
   188
alpar@184
   189
    typedef Value ConstReturnValue;
alpar@184
   190
    typedef Value ReturnValue;
deba@57
   191
  };
deba@57
   192
deba@57
   193
  template <typename MatrixMap>
deba@57
   194
  struct MatrixMapTraits<
alpar@209
   195
    MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
alpar@209
   196
                                  void>::type >
deba@57
   197
  {
deba@57
   198
    typedef True ReferenceMapTag;
alpar@209
   199
deba@57
   200
    typedef typename MatrixMap::FirstKey FirstKey;
deba@57
   201
    typedef typename MatrixMap::SecondKey SecondKey;
deba@57
   202
    typedef typename MatrixMap::Value Value;
deba@57
   203
deba@57
   204
    typedef typename MatrixMap::ConstReference ConstReturnValue;
deba@57
   205
    typedef typename MatrixMap::Reference ReturnValue;
deba@57
   206
alpar@209
   207
    typedef typename MatrixMap::ConstReference ConstReference;
deba@57
   208
    typedef typename MatrixMap::Reference Reference;
deba@57
   209
 };
deba@57
   210
deba@57
   211
  // Indicators for the tags
deba@57
   212
kpeter@616
   213
  template <typename GR, typename Enable = void>
deba@57
   214
  struct NodeNumTagIndicator {
deba@57
   215
    static const bool value = false;
deba@57
   216
  };
deba@57
   217
kpeter@616
   218
  template <typename GR>
deba@57
   219
  struct NodeNumTagIndicator<
kpeter@616
   220
    GR,
kpeter@616
   221
    typename enable_if<typename GR::NodeNumTag, void>::type
deba@57
   222
  > {
deba@57
   223
    static const bool value = true;
deba@57
   224
  };
deba@57
   225
kpeter@616
   226
  template <typename GR, typename Enable = void>
kpeter@360
   227
  struct ArcNumTagIndicator {
kpeter@360
   228
    static const bool value = false;
kpeter@360
   229
  };
kpeter@360
   230
kpeter@616
   231
  template <typename GR>
kpeter@360
   232
  struct ArcNumTagIndicator<
kpeter@616
   233
    GR,
kpeter@616
   234
    typename enable_if<typename GR::ArcNumTag, void>::type
kpeter@360
   235
  > {
kpeter@360
   236
    static const bool value = true;
kpeter@360
   237
  };
kpeter@360
   238
kpeter@616
   239
  template <typename GR, typename Enable = void>
deba@139
   240
  struct EdgeNumTagIndicator {
deba@57
   241
    static const bool value = false;
deba@57
   242
  };
deba@57
   243
kpeter@616
   244
  template <typename GR>
deba@139
   245
  struct EdgeNumTagIndicator<
kpeter@616
   246
    GR,
kpeter@616
   247
    typename enable_if<typename GR::EdgeNumTag, void>::type
deba@57
   248
  > {
deba@57
   249
    static const bool value = true;
deba@57
   250
  };
deba@57
   251
kpeter@616
   252
  template <typename GR, typename Enable = void>
kpeter@360
   253
  struct FindArcTagIndicator {
kpeter@360
   254
    static const bool value = false;
kpeter@360
   255
  };
kpeter@360
   256
kpeter@616
   257
  template <typename GR>
kpeter@360
   258
  struct FindArcTagIndicator<
kpeter@616
   259
    GR,
kpeter@616
   260
    typename enable_if<typename GR::FindArcTag, void>::type
kpeter@360
   261
  > {
kpeter@360
   262
    static const bool value = true;
kpeter@360
   263
  };
kpeter@360
   264
kpeter@616
   265
  template <typename GR, typename Enable = void>
deba@139
   266
  struct FindEdgeTagIndicator {
deba@57
   267
    static const bool value = false;
deba@57
   268
  };
deba@57
   269
kpeter@616
   270
  template <typename GR>
deba@139
   271
  struct FindEdgeTagIndicator<
kpeter@616
   272
    GR,
kpeter@616
   273
    typename enable_if<typename GR::FindEdgeTag, void>::type
deba@57
   274
  > {
deba@57
   275
    static const bool value = true;
deba@57
   276
  };
deba@57
   277
kpeter@616
   278
  template <typename GR, typename Enable = void>
deba@57
   279
  struct UndirectedTagIndicator {
deba@57
   280
    static const bool value = false;
deba@57
   281
  };
deba@57
   282
kpeter@616
   283
  template <typename GR>
deba@57
   284
  struct UndirectedTagIndicator<
kpeter@616
   285
    GR,
kpeter@616
   286
    typename enable_if<typename GR::UndirectedTag, void>::type
deba@57
   287
  > {
deba@57
   288
    static const bool value = true;
deba@57
   289
  };
deba@57
   290
kpeter@616
   291
  template <typename GR, typename Enable = void>
deba@57
   292
  struct BuildTagIndicator {
deba@57
   293
    static const bool value = false;
deba@57
   294
  };
deba@57
   295
kpeter@616
   296
  template <typename GR>
deba@57
   297
  struct BuildTagIndicator<
kpeter@616
   298
    GR,
kpeter@616
   299
    typename enable_if<typename GR::BuildTag, void>::type
deba@57
   300
  > {
deba@57
   301
    static const bool value = true;
deba@57
   302
  };
deba@57
   303
deba@57
   304
}
deba@57
   305
deba@57
   306
#endif