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