lemon/bits/default_map.h
author Balazs Dezso <deba@inf.elte.hu>
Thu, 27 Mar 2008 10:56:11 +0100
changeset 110 f2d66d810c88
parent 57 c1acf0018c0a
child 209 765619b7cbb2
permissions -rw-r--r--
Fix include files in random.h
deba@57
     1
/* -*- C++ -*-
deba@57
     2
 *
deba@57
     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_DEFAULT_MAP_H
deba@57
    20
#define LEMON_BITS_DEFAULT_MAP_H
deba@57
    21
deba@57
    22
deba@57
    23
#include <lemon/bits/array_map.h>
deba@57
    24
#include <lemon/bits/vector_map.h>
deba@57
    25
//#include <lemon/bits/debug_map.h>
deba@57
    26
deba@57
    27
///\ingroup graphbits
deba@57
    28
///\file
deba@57
    29
///\brief Graph maps that construct and destruct their elements dynamically.
deba@57
    30
deba@57
    31
namespace lemon {
deba@57
    32
  
deba@57
    33
  
deba@57
    34
  //#ifndef LEMON_USE_DEBUG_MAP
deba@57
    35
deba@57
    36
  template <typename _Graph, typename _Item, typename _Value>
deba@57
    37
  struct DefaultMapSelector {
deba@57
    38
    typedef ArrayMap<_Graph, _Item, _Value> Map;
deba@57
    39
  };
deba@57
    40
deba@57
    41
  // bool
deba@57
    42
  template <typename _Graph, typename _Item>
deba@57
    43
  struct DefaultMapSelector<_Graph, _Item, bool> {
deba@57
    44
    typedef VectorMap<_Graph, _Item, bool> Map;
deba@57
    45
  };
deba@57
    46
deba@57
    47
  // char
deba@57
    48
  template <typename _Graph, typename _Item>
deba@57
    49
  struct DefaultMapSelector<_Graph, _Item, char> {
deba@57
    50
    typedef VectorMap<_Graph, _Item, char> Map;
deba@57
    51
  };
deba@57
    52
deba@57
    53
  template <typename _Graph, typename _Item>
deba@57
    54
  struct DefaultMapSelector<_Graph, _Item, signed char> {
deba@57
    55
    typedef VectorMap<_Graph, _Item, signed char> Map;
deba@57
    56
  };
deba@57
    57
deba@57
    58
  template <typename _Graph, typename _Item>
deba@57
    59
  struct DefaultMapSelector<_Graph, _Item, unsigned char> {
deba@57
    60
    typedef VectorMap<_Graph, _Item, unsigned char> Map;
deba@57
    61
  };
deba@57
    62
deba@57
    63
deba@57
    64
  // int
deba@57
    65
  template <typename _Graph, typename _Item>
deba@57
    66
  struct DefaultMapSelector<_Graph, _Item, signed int> {
deba@57
    67
    typedef VectorMap<_Graph, _Item, signed int> Map;
deba@57
    68
  };
deba@57
    69
deba@57
    70
  template <typename _Graph, typename _Item>
deba@57
    71
  struct DefaultMapSelector<_Graph, _Item, unsigned int> {
deba@57
    72
    typedef VectorMap<_Graph, _Item, unsigned int> Map;
deba@57
    73
  };
deba@57
    74
deba@57
    75
deba@57
    76
  // short
deba@57
    77
  template <typename _Graph, typename _Item>
deba@57
    78
  struct DefaultMapSelector<_Graph, _Item, signed short> {
deba@57
    79
    typedef VectorMap<_Graph, _Item, signed short> Map;
deba@57
    80
  };
deba@57
    81
deba@57
    82
  template <typename _Graph, typename _Item>
deba@57
    83
  struct DefaultMapSelector<_Graph, _Item, unsigned short> {
deba@57
    84
    typedef VectorMap<_Graph, _Item, unsigned short> Map;
deba@57
    85
  };
deba@57
    86
deba@57
    87
deba@57
    88
  // long
deba@57
    89
  template <typename _Graph, typename _Item>
deba@57
    90
  struct DefaultMapSelector<_Graph, _Item, signed long> {
deba@57
    91
    typedef VectorMap<_Graph, _Item, signed long> Map;
deba@57
    92
  };
deba@57
    93
deba@57
    94
  template <typename _Graph, typename _Item>
deba@57
    95
  struct DefaultMapSelector<_Graph, _Item, unsigned long> {
deba@57
    96
    typedef VectorMap<_Graph, _Item, unsigned long> Map;
deba@57
    97
  };
deba@57
    98
deba@57
    99
deba@57
   100
#if defined __GNUC__ && !defined __STRICT_ANSI__
deba@57
   101
deba@57
   102
  // long long
deba@57
   103
  template <typename _Graph, typename _Item>
deba@57
   104
  struct DefaultMapSelector<_Graph, _Item, signed long long> {
deba@57
   105
    typedef VectorMap<_Graph, _Item, signed long long> Map;
deba@57
   106
  };
deba@57
   107
deba@57
   108
  template <typename _Graph, typename _Item>
deba@57
   109
  struct DefaultMapSelector<_Graph, _Item, unsigned long long> {
deba@57
   110
    typedef VectorMap<_Graph, _Item, unsigned long long> Map;
deba@57
   111
  };
deba@57
   112
deba@57
   113
#endif
deba@57
   114
deba@57
   115
deba@57
   116
  // float
deba@57
   117
  template <typename _Graph, typename _Item>
deba@57
   118
  struct DefaultMapSelector<_Graph, _Item, float> {
deba@57
   119
    typedef VectorMap<_Graph, _Item, float> Map;
deba@57
   120
  };
deba@57
   121
deba@57
   122
deba@57
   123
  // double
deba@57
   124
  template <typename _Graph, typename _Item>
deba@57
   125
  struct DefaultMapSelector<_Graph, _Item, double> {
deba@57
   126
    typedef VectorMap<_Graph, _Item,  double> Map;
deba@57
   127
  };
deba@57
   128
deba@57
   129
deba@57
   130
  // long double
deba@57
   131
  template <typename _Graph, typename _Item>
deba@57
   132
  struct DefaultMapSelector<_Graph, _Item, long double> {
deba@57
   133
    typedef VectorMap<_Graph, _Item, long double> Map;
deba@57
   134
  };
deba@57
   135
deba@57
   136
deba@57
   137
  // pointer
deba@57
   138
  template <typename _Graph, typename _Item, typename _Ptr>
deba@57
   139
  struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
deba@57
   140
    typedef VectorMap<_Graph, _Item, _Ptr*> Map;
deba@57
   141
  };
deba@57
   142
deba@57
   143
// #else 
deba@57
   144
deba@57
   145
//   template <typename _Graph, typename _Item, typename _Value>
deba@57
   146
//   struct DefaultMapSelector {
deba@57
   147
//     typedef DebugMap<_Graph, _Item, _Value> Map;
deba@57
   148
//   };
deba@57
   149
deba@57
   150
// #endif  
deba@57
   151
deba@57
   152
  /// \e
deba@57
   153
  template <typename _Graph, typename _Item, typename _Value>
deba@57
   154
  class DefaultMap 
deba@57
   155
    : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
deba@57
   156
  public:
deba@57
   157
    typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
deba@57
   158
    typedef DefaultMap<_Graph, _Item, _Value> Map;
deba@57
   159
    
deba@57
   160
    typedef typename Parent::Graph Graph;
deba@57
   161
    typedef typename Parent::Value Value;
deba@57
   162
deba@57
   163
    explicit DefaultMap(const Graph& graph) : Parent(graph) {}
deba@57
   164
    DefaultMap(const Graph& graph, const Value& value) 
deba@57
   165
      : Parent(graph, value) {}
deba@57
   166
deba@57
   167
    DefaultMap& operator=(const DefaultMap& cmap) {
deba@57
   168
      return operator=<DefaultMap>(cmap);
deba@57
   169
    }
deba@57
   170
deba@57
   171
    template <typename CMap>
deba@57
   172
    DefaultMap& operator=(const CMap& cmap) {
deba@57
   173
      Parent::operator=(cmap);
deba@57
   174
      return *this;
deba@57
   175
    }
deba@57
   176
deba@57
   177
  };
deba@57
   178
deba@57
   179
}
deba@57
   180
deba@57
   181
#endif