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