lemon/bits/traits.h
author Alpar Juttner <alpar@cs.elte.hu>
Thu, 24 Apr 2008 20:26:14 +0100
changeset 151 4d79daa40e9b
parent 57 c1acf0018c0a
child 139 701c529ba737
permissions -rw-r--r--
Turn on built in Doxygen STL support
deba@57
     1
deba@57
     2
/* -*- C++ -*-
deba@57
     3
 *
deba@57
     4
 * This file is a part of LEMON, a generic C++ optimization library
deba@57
     5
 *
alpar@107
     6
 * Copyright (C) 2003-2008
deba@57
     7
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@57
     8
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@57
     9
 *
deba@57
    10
 * Permission to use, modify and distribute this software is granted
deba@57
    11
 * provided that this copyright notice appears in all copies. For
deba@57
    12
 * precise terms see the accompanying LICENSE file.
deba@57
    13
 *
deba@57
    14
 * This software is provided "AS IS" with no warranty of any kind,
deba@57
    15
 * express or implied, and with no claim as to its suitability for any
deba@57
    16
 * purpose.
deba@57
    17
 *
deba@57
    18
 */
deba@57
    19
deba@57
    20
#ifndef LEMON_BITS_TRAITS_H
deba@57
    21
#define LEMON_BITS_TRAITS_H
deba@57
    22
deba@57
    23
#include <lemon/bits/utility.h>
deba@57
    24
deba@57
    25
///\file
deba@57
    26
///\brief Traits for graphs and maps
deba@57
    27
///
deba@57
    28
deba@57
    29
namespace lemon {
deba@57
    30
  template <typename _Graph, typename _Item>
deba@57
    31
  class ItemSetTraits {};
deba@57
    32
  
deba@57
    33
deba@57
    34
  template <typename Graph, typename Enable = void>
deba@57
    35
  struct NodeNotifierIndicator {
deba@57
    36
    typedef InvalidType Type;
deba@57
    37
  };
deba@57
    38
  template <typename Graph>
deba@57
    39
  struct NodeNotifierIndicator<
deba@57
    40
    Graph, 
deba@57
    41
    typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
deba@57
    42
  > { 
deba@57
    43
    typedef typename Graph::NodeNotifier Type;
deba@57
    44
  };
deba@57
    45
deba@57
    46
  template <typename _Graph>
deba@57
    47
  class ItemSetTraits<_Graph, typename _Graph::Node> {
deba@57
    48
  public:
deba@57
    49
    
deba@57
    50
    typedef _Graph Graph;
deba@57
    51
deba@57
    52
    typedef typename Graph::Node Item;
deba@57
    53
    typedef typename Graph::NodeIt ItemIt;
deba@57
    54
deba@57
    55
    typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
deba@57
    56
deba@57
    57
    template <typename _Value>
deba@57
    58
    class Map : public Graph::template NodeMap<_Value> {
deba@57
    59
    public:
deba@57
    60
      typedef typename Graph::template NodeMap<_Value> Parent; 
deba@57
    61
      typedef typename Graph::template NodeMap<_Value> Type; 
deba@57
    62
      typedef typename Parent::Value Value;
deba@57
    63
deba@57
    64
      Map(const Graph& _digraph) : Parent(_digraph) {}
deba@57
    65
      Map(const Graph& _digraph, const Value& _value) 
deba@57
    66
	: Parent(_digraph, _value) {}
deba@57
    67
deba@57
    68
     };
deba@57
    69
deba@57
    70
  };
deba@57
    71
deba@57
    72
  template <typename Graph, typename Enable = void>
deba@57
    73
  struct ArcNotifierIndicator {
deba@57
    74
    typedef InvalidType Type;
deba@57
    75
  };
deba@57
    76
  template <typename Graph>
deba@57
    77
  struct ArcNotifierIndicator<
deba@57
    78
    Graph, 
deba@57
    79
    typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
deba@57
    80
  > { 
deba@57
    81
    typedef typename Graph::ArcNotifier Type;
deba@57
    82
  };
deba@57
    83
deba@57
    84
  template <typename _Graph>
deba@57
    85
  class ItemSetTraits<_Graph, typename _Graph::Arc> {
deba@57
    86
  public:
deba@57
    87
    
deba@57
    88
    typedef _Graph Graph;
deba@57
    89
deba@57
    90
    typedef typename Graph::Arc Item;
deba@57
    91
    typedef typename Graph::ArcIt ItemIt;
deba@57
    92
deba@57
    93
    typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier;
deba@57
    94
deba@57
    95
    template <typename _Value>
deba@57
    96
    class Map : public Graph::template ArcMap<_Value> {
deba@57
    97
    public:
deba@57
    98
      typedef typename Graph::template ArcMap<_Value> Parent; 
deba@57
    99
      typedef typename Graph::template ArcMap<_Value> Type; 
deba@57
   100
      typedef typename Parent::Value Value;
deba@57
   101
deba@57
   102
      Map(const Graph& _digraph) : Parent(_digraph) {}
deba@57
   103
      Map(const Graph& _digraph, const Value& _value) 
deba@57
   104
	: Parent(_digraph, _value) {}
deba@57
   105
    };
deba@57
   106
deba@57
   107
  };
deba@57
   108
deba@57
   109
  template <typename Graph, typename Enable = void>
deba@57
   110
  struct EdgeNotifierIndicator {
deba@57
   111
    typedef InvalidType Type;
deba@57
   112
  };
deba@57
   113
  template <typename Graph>
deba@57
   114
  struct EdgeNotifierIndicator<
deba@57
   115
    Graph, 
deba@57
   116
    typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
deba@57
   117
  > { 
deba@57
   118
    typedef typename Graph::EdgeNotifier Type;
deba@57
   119
  };
deba@57
   120
deba@57
   121
  template <typename _Graph>
deba@57
   122
  class ItemSetTraits<_Graph, typename _Graph::Edge> {
deba@57
   123
  public:
deba@57
   124
    
deba@57
   125
    typedef _Graph Graph;
deba@57
   126
deba@57
   127
    typedef typename Graph::Edge Item;
deba@57
   128
    typedef typename Graph::EdgeIt ItemIt;
deba@57
   129
deba@57
   130
    typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
deba@57
   131
deba@57
   132
    template <typename _Value>
deba@57
   133
    class Map : public Graph::template EdgeMap<_Value> {
deba@57
   134
    public:
deba@57
   135
      typedef typename Graph::template EdgeMap<_Value> Parent; 
deba@57
   136
      typedef typename Graph::template EdgeMap<_Value> Type; 
deba@57
   137
      typedef typename Parent::Value Value;
deba@57
   138
deba@57
   139
      Map(const Graph& _digraph) : Parent(_digraph) {}
deba@57
   140
      Map(const Graph& _digraph, const Value& _value) 
deba@57
   141
	: Parent(_digraph, _value) {}
deba@57
   142
    };
deba@57
   143
deba@57
   144
  };
deba@57
   145
deba@57
   146
  template <typename Map, typename Enable = void>
deba@57
   147
  struct MapTraits {
deba@57
   148
    typedef False ReferenceMapTag;
deba@57
   149
deba@57
   150
    typedef typename Map::Key Key;
deba@57
   151
    typedef typename Map::Value Value;
deba@57
   152
deba@57
   153
    typedef const Value ConstReturnValue;
deba@57
   154
    typedef const Value ReturnValue;
deba@57
   155
  };
deba@57
   156
deba@57
   157
  template <typename Map>
deba@57
   158
  struct MapTraits<
deba@57
   159
    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
deba@57
   160
  {
deba@57
   161
    typedef True ReferenceMapTag;
deba@57
   162
    
deba@57
   163
    typedef typename Map::Key Key;
deba@57
   164
    typedef typename Map::Value Value;
deba@57
   165
deba@57
   166
    typedef typename Map::ConstReference ConstReturnValue;
deba@57
   167
    typedef typename Map::Reference ReturnValue;
deba@57
   168
deba@57
   169
    typedef typename Map::ConstReference ConstReference; 
deba@57
   170
    typedef typename Map::Reference Reference;
deba@57
   171
 };
deba@57
   172
deba@57
   173
  template <typename MatrixMap, typename Enable = void>
deba@57
   174
  struct MatrixMapTraits {
deba@57
   175
    typedef False ReferenceMapTag;
deba@57
   176
deba@57
   177
    typedef typename MatrixMap::FirstKey FirstKey;
deba@57
   178
    typedef typename MatrixMap::SecondKey SecondKey;
deba@57
   179
    typedef typename MatrixMap::Value Value;
deba@57
   180
deba@57
   181
    typedef const Value ConstReturnValue;
deba@57
   182
    typedef const Value ReturnValue;
deba@57
   183
  };
deba@57
   184
deba@57
   185
  template <typename MatrixMap>
deba@57
   186
  struct MatrixMapTraits<
deba@57
   187
    MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, 
deba@57
   188
                                  void>::type > 
deba@57
   189
  {
deba@57
   190
    typedef True ReferenceMapTag;
deba@57
   191
    
deba@57
   192
    typedef typename MatrixMap::FirstKey FirstKey;
deba@57
   193
    typedef typename MatrixMap::SecondKey SecondKey;
deba@57
   194
    typedef typename MatrixMap::Value Value;
deba@57
   195
deba@57
   196
    typedef typename MatrixMap::ConstReference ConstReturnValue;
deba@57
   197
    typedef typename MatrixMap::Reference ReturnValue;
deba@57
   198
deba@57
   199
    typedef typename MatrixMap::ConstReference ConstReference; 
deba@57
   200
    typedef typename MatrixMap::Reference Reference;
deba@57
   201
 };
deba@57
   202
deba@57
   203
  // Indicators for the tags
deba@57
   204
deba@57
   205
  template <typename Graph, typename Enable = void>
deba@57
   206
  struct NodeNumTagIndicator {
deba@57
   207
    static const bool value = false;
deba@57
   208
  };
deba@57
   209
deba@57
   210
  template <typename Graph>
deba@57
   211
  struct NodeNumTagIndicator<
deba@57
   212
    Graph, 
deba@57
   213
    typename enable_if<typename Graph::NodeNumTag, void>::type
deba@57
   214
  > {
deba@57
   215
    static const bool value = true;
deba@57
   216
  };
deba@57
   217
deba@57
   218
  template <typename Graph, typename Enable = void>
deba@57
   219
  struct ArcNumTagIndicator {
deba@57
   220
    static const bool value = false;
deba@57
   221
  };
deba@57
   222
deba@57
   223
  template <typename Graph>
deba@57
   224
  struct ArcNumTagIndicator<
deba@57
   225
    Graph, 
deba@57
   226
    typename enable_if<typename Graph::ArcNumTag, void>::type
deba@57
   227
  > {
deba@57
   228
    static const bool value = true;
deba@57
   229
  };
deba@57
   230
deba@57
   231
  template <typename Graph, typename Enable = void>
deba@57
   232
  struct FindArcTagIndicator {
deba@57
   233
    static const bool value = false;
deba@57
   234
  };
deba@57
   235
deba@57
   236
  template <typename Graph>
deba@57
   237
  struct FindArcTagIndicator<
deba@57
   238
    Graph, 
deba@57
   239
    typename enable_if<typename Graph::FindArcTag, void>::type
deba@57
   240
  > {
deba@57
   241
    static const bool value = true;
deba@57
   242
  };
deba@57
   243
deba@57
   244
  template <typename Graph, typename Enable = void>
deba@57
   245
  struct UndirectedTagIndicator {
deba@57
   246
    static const bool value = false;
deba@57
   247
  };
deba@57
   248
deba@57
   249
  template <typename Graph>
deba@57
   250
  struct UndirectedTagIndicator<
deba@57
   251
    Graph, 
deba@57
   252
    typename enable_if<typename Graph::UndirectedTag, void>::type
deba@57
   253
  > {
deba@57
   254
    static const bool value = true;
deba@57
   255
  };
deba@57
   256
deba@57
   257
  template <typename Graph, typename Enable = void>
deba@57
   258
  struct BuildTagIndicator {
deba@57
   259
    static const bool value = false;
deba@57
   260
  };
deba@57
   261
deba@57
   262
  template <typename Graph>
deba@57
   263
  struct BuildTagIndicator<
deba@57
   264
    Graph, 
deba@57
   265
    typename enable_if<typename Graph::BuildTag, void>::type
deba@57
   266
  > {
deba@57
   267
    static const bool value = true;
deba@57
   268
  };
deba@57
   269
deba@57
   270
}
deba@57
   271
deba@57
   272
#endif