lemon/bits/traits.h
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 13 Jul 2008 19:51:02 +0100
changeset 209 765619b7cbb2
parent 184 716b220697a0
child 220 a5d8c039f218
permissions -rw-r--r--
Apply unify-sources.sh to the source tree
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@107
     5
 * Copyright (C) 2003-2008
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
deba@57
    22
#include <lemon/bits/utility.h>
deba@57
    23
deba@57
    24
///\file
deba@57
    25
///\brief Traits for graphs and maps
deba@57
    26
///
deba@57
    27
deba@57
    28
namespace lemon {
deba@57
    29
  template <typename _Graph, typename _Item>
deba@57
    30
  class ItemSetTraits {};
alpar@209
    31
deba@57
    32
deba@57
    33
  template <typename Graph, typename Enable = void>
deba@57
    34
  struct NodeNotifierIndicator {
deba@57
    35
    typedef InvalidType Type;
deba@57
    36
  };
deba@57
    37
  template <typename Graph>
deba@57
    38
  struct NodeNotifierIndicator<
alpar@209
    39
    Graph,
deba@57
    40
    typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
alpar@209
    41
  > {
deba@57
    42
    typedef typename Graph::NodeNotifier Type;
deba@57
    43
  };
deba@57
    44
deba@57
    45
  template <typename _Graph>
deba@57
    46
  class ItemSetTraits<_Graph, typename _Graph::Node> {
deba@57
    47
  public:
alpar@209
    48
deba@57
    49
    typedef _Graph Graph;
deba@57
    50
deba@57
    51
    typedef typename Graph::Node Item;
deba@57
    52
    typedef typename Graph::NodeIt ItemIt;
deba@57
    53
deba@57
    54
    typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@57
    55
deba@57
    56
    template <typename _Value>
deba@57
    57
    class Map : public Graph::template NodeMap<_Value> {
deba@57
    58
    public:
alpar@209
    59
      typedef typename Graph::template NodeMap<_Value> Parent;
alpar@209
    60
      typedef typename Graph::template NodeMap<_Value> Type;
deba@57
    61
      typedef typename Parent::Value Value;
deba@57
    62
deba@57
    63
      Map(const Graph& _digraph) : Parent(_digraph) {}
alpar@209
    64
      Map(const Graph& _digraph, const Value& _value)
alpar@209
    65
        : Parent(_digraph, _value) {}
deba@57
    66
deba@57
    67
     };
deba@57
    68
deba@57
    69
  };
deba@57
    70
deba@57
    71
  template <typename Graph, typename Enable = void>
deba@57
    72
  struct ArcNotifierIndicator {
deba@57
    73
    typedef InvalidType Type;
deba@57
    74
  };
deba@57
    75
  template <typename Graph>
deba@57
    76
  struct ArcNotifierIndicator<
alpar@209
    77
    Graph,
deba@57
    78
    typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
alpar@209
    79
  > {
deba@57
    80
    typedef typename Graph::ArcNotifier Type;
deba@57
    81
  };
deba@57
    82
deba@57
    83
  template <typename _Graph>
deba@57
    84
  class ItemSetTraits<_Graph, typename _Graph::Arc> {
deba@57
    85
  public:
alpar@209
    86
deba@57
    87
    typedef _Graph Graph;
deba@57
    88
deba@57
    89
    typedef typename Graph::Arc Item;
deba@57
    90
    typedef typename Graph::ArcIt ItemIt;
deba@57
    91
deba@57
    92
    typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier;
deba@57
    93
deba@57
    94
    template <typename _Value>
deba@57
    95
    class Map : public Graph::template ArcMap<_Value> {
deba@57
    96
    public:
alpar@209
    97
      typedef typename Graph::template ArcMap<_Value> Parent;
alpar@209
    98
      typedef typename Graph::template ArcMap<_Value> Type;
deba@57
    99
      typedef typename Parent::Value Value;
deba@57
   100
deba@57
   101
      Map(const Graph& _digraph) : Parent(_digraph) {}
alpar@209
   102
      Map(const Graph& _digraph, const Value& _value)
alpar@209
   103
        : Parent(_digraph, _value) {}
deba@57
   104
    };
deba@57
   105
deba@57
   106
  };
deba@57
   107
deba@57
   108
  template <typename Graph, typename Enable = void>
deba@57
   109
  struct EdgeNotifierIndicator {
deba@57
   110
    typedef InvalidType Type;
deba@57
   111
  };
deba@57
   112
  template <typename Graph>
deba@57
   113
  struct EdgeNotifierIndicator<
alpar@209
   114
    Graph,
deba@57
   115
    typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
alpar@209
   116
  > {
deba@57
   117
    typedef typename Graph::EdgeNotifier Type;
deba@57
   118
  };
deba@57
   119
deba@57
   120
  template <typename _Graph>
deba@57
   121
  class ItemSetTraits<_Graph, typename _Graph::Edge> {
deba@57
   122
  public:
alpar@209
   123
deba@57
   124
    typedef _Graph Graph;
deba@57
   125
deba@57
   126
    typedef typename Graph::Edge Item;
deba@57
   127
    typedef typename Graph::EdgeIt ItemIt;
deba@57
   128
deba@57
   129
    typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
deba@57
   130
deba@57
   131
    template <typename _Value>
deba@57
   132
    class Map : public Graph::template EdgeMap<_Value> {
deba@57
   133
    public:
alpar@209
   134
      typedef typename Graph::template EdgeMap<_Value> Parent;
alpar@209
   135
      typedef typename Graph::template EdgeMap<_Value> Type;
deba@57
   136
      typedef typename Parent::Value Value;
deba@57
   137
deba@57
   138
      Map(const Graph& _digraph) : Parent(_digraph) {}
alpar@209
   139
      Map(const Graph& _digraph, const Value& _value)
alpar@209
   140
        : Parent(_digraph, _value) {}
deba@57
   141
    };
deba@57
   142
deba@57
   143
  };
deba@57
   144
deba@57
   145
  template <typename Map, typename Enable = void>
deba@57
   146
  struct MapTraits {
deba@57
   147
    typedef False ReferenceMapTag;
deba@57
   148
deba@57
   149
    typedef typename Map::Key Key;
deba@57
   150
    typedef typename Map::Value Value;
deba@57
   151
alpar@184
   152
    typedef Value ConstReturnValue;
alpar@184
   153
    typedef Value ReturnValue;
deba@57
   154
  };
deba@57
   155
deba@57
   156
  template <typename Map>
deba@57
   157
  struct MapTraits<
alpar@209
   158
    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type >
deba@57
   159
  {
deba@57
   160
    typedef True ReferenceMapTag;
alpar@209
   161
deba@57
   162
    typedef typename Map::Key Key;
deba@57
   163
    typedef typename Map::Value Value;
deba@57
   164
deba@57
   165
    typedef typename Map::ConstReference ConstReturnValue;
deba@57
   166
    typedef typename Map::Reference ReturnValue;
deba@57
   167
alpar@209
   168
    typedef typename Map::ConstReference ConstReference;
deba@57
   169
    typedef typename Map::Reference Reference;
deba@57
   170
 };
deba@57
   171
deba@57
   172
  template <typename MatrixMap, typename Enable = void>
deba@57
   173
  struct MatrixMapTraits {
deba@57
   174
    typedef False ReferenceMapTag;
deba@57
   175
deba@57
   176
    typedef typename MatrixMap::FirstKey FirstKey;
deba@57
   177
    typedef typename MatrixMap::SecondKey SecondKey;
deba@57
   178
    typedef typename MatrixMap::Value Value;
deba@57
   179
alpar@184
   180
    typedef Value ConstReturnValue;
alpar@184
   181
    typedef Value ReturnValue;
deba@57
   182
  };
deba@57
   183
deba@57
   184
  template <typename MatrixMap>
deba@57
   185
  struct MatrixMapTraits<
alpar@209
   186
    MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
alpar@209
   187
                                  void>::type >
deba@57
   188
  {
deba@57
   189
    typedef True ReferenceMapTag;
alpar@209
   190
deba@57
   191
    typedef typename MatrixMap::FirstKey FirstKey;
deba@57
   192
    typedef typename MatrixMap::SecondKey SecondKey;
deba@57
   193
    typedef typename MatrixMap::Value Value;
deba@57
   194
deba@57
   195
    typedef typename MatrixMap::ConstReference ConstReturnValue;
deba@57
   196
    typedef typename MatrixMap::Reference ReturnValue;
deba@57
   197
alpar@209
   198
    typedef typename MatrixMap::ConstReference ConstReference;
deba@57
   199
    typedef typename MatrixMap::Reference Reference;
deba@57
   200
 };
deba@57
   201
deba@57
   202
  // Indicators for the tags
deba@57
   203
deba@57
   204
  template <typename Graph, typename Enable = void>
deba@57
   205
  struct NodeNumTagIndicator {
deba@57
   206
    static const bool value = false;
deba@57
   207
  };
deba@57
   208
deba@57
   209
  template <typename Graph>
deba@57
   210
  struct NodeNumTagIndicator<
alpar@209
   211
    Graph,
deba@57
   212
    typename enable_if<typename Graph::NodeNumTag, void>::type
deba@57
   213
  > {
deba@57
   214
    static const bool value = true;
deba@57
   215
  };
deba@57
   216
deba@57
   217
  template <typename Graph, typename Enable = void>
deba@139
   218
  struct EdgeNumTagIndicator {
deba@57
   219
    static const bool value = false;
deba@57
   220
  };
deba@57
   221
deba@57
   222
  template <typename Graph>
deba@139
   223
  struct EdgeNumTagIndicator<
alpar@209
   224
    Graph,
deba@139
   225
    typename enable_if<typename Graph::EdgeNumTag, void>::type
deba@57
   226
  > {
deba@57
   227
    static const bool value = true;
deba@57
   228
  };
deba@57
   229
deba@57
   230
  template <typename Graph, typename Enable = void>
deba@139
   231
  struct FindEdgeTagIndicator {
deba@57
   232
    static const bool value = false;
deba@57
   233
  };
deba@57
   234
deba@57
   235
  template <typename Graph>
deba@139
   236
  struct FindEdgeTagIndicator<
alpar@209
   237
    Graph,
deba@139
   238
    typename enable_if<typename Graph::FindEdgeTag, void>::type
deba@57
   239
  > {
deba@57
   240
    static const bool value = true;
deba@57
   241
  };
deba@57
   242
deba@57
   243
  template <typename Graph, typename Enable = void>
deba@57
   244
  struct UndirectedTagIndicator {
deba@57
   245
    static const bool value = false;
deba@57
   246
  };
deba@57
   247
deba@57
   248
  template <typename Graph>
deba@57
   249
  struct UndirectedTagIndicator<
alpar@209
   250
    Graph,
deba@57
   251
    typename enable_if<typename Graph::UndirectedTag, void>::type
deba@57
   252
  > {
deba@57
   253
    static const bool value = true;
deba@57
   254
  };
deba@57
   255
deba@57
   256
  template <typename Graph, typename Enable = void>
deba@57
   257
  struct BuildTagIndicator {
deba@57
   258
    static const bool value = false;
deba@57
   259
  };
deba@57
   260
deba@57
   261
  template <typename Graph>
deba@57
   262
  struct BuildTagIndicator<
alpar@209
   263
    Graph,
deba@57
   264
    typename enable_if<typename Graph::BuildTag, void>::type
deba@57
   265
  > {
deba@57
   266
    static const bool value = true;
deba@57
   267
  };
deba@57
   268
deba@57
   269
}
deba@57
   270
deba@57
   271
#endif