[209] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
[57] | 2 | * |
---|
[209] | 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
[57] | 4 | * |
---|
[440] | 5 | * Copyright (C) 2003-2009 |
---|
[57] | 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #ifndef LEMON_BITS_DEFAULT_MAP_H |
---|
| 20 | #define LEMON_BITS_DEFAULT_MAP_H |
---|
| 21 | |
---|
[491] | 22 | #include <lemon/config.h> |
---|
[57] | 23 | #include <lemon/bits/array_map.h> |
---|
| 24 | #include <lemon/bits/vector_map.h> |
---|
| 25 | //#include <lemon/bits/debug_map.h> |
---|
| 26 | |
---|
[314] | 27 | //\ingroup graphbits |
---|
| 28 | //\file |
---|
| 29 | //\brief Graph maps that construct and destruct their elements dynamically. |
---|
[57] | 30 | |
---|
| 31 | namespace lemon { |
---|
[209] | 32 | |
---|
| 33 | |
---|
[57] | 34 | //#ifndef LEMON_USE_DEBUG_MAP |
---|
| 35 | |
---|
| 36 | template <typename _Graph, typename _Item, typename _Value> |
---|
| 37 | struct DefaultMapSelector { |
---|
| 38 | typedef ArrayMap<_Graph, _Item, _Value> Map; |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | // bool |
---|
| 42 | template <typename _Graph, typename _Item> |
---|
| 43 | struct DefaultMapSelector<_Graph, _Item, bool> { |
---|
| 44 | typedef VectorMap<_Graph, _Item, bool> Map; |
---|
| 45 | }; |
---|
| 46 | |
---|
| 47 | // char |
---|
| 48 | template <typename _Graph, typename _Item> |
---|
| 49 | struct DefaultMapSelector<_Graph, _Item, char> { |
---|
| 50 | typedef VectorMap<_Graph, _Item, char> Map; |
---|
| 51 | }; |
---|
| 52 | |
---|
| 53 | template <typename _Graph, typename _Item> |
---|
| 54 | struct DefaultMapSelector<_Graph, _Item, signed char> { |
---|
| 55 | typedef VectorMap<_Graph, _Item, signed char> Map; |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | template <typename _Graph, typename _Item> |
---|
| 59 | struct DefaultMapSelector<_Graph, _Item, unsigned char> { |
---|
| 60 | typedef VectorMap<_Graph, _Item, unsigned char> Map; |
---|
| 61 | }; |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | // int |
---|
| 65 | template <typename _Graph, typename _Item> |
---|
| 66 | struct DefaultMapSelector<_Graph, _Item, signed int> { |
---|
| 67 | typedef VectorMap<_Graph, _Item, signed int> Map; |
---|
| 68 | }; |
---|
| 69 | |
---|
| 70 | template <typename _Graph, typename _Item> |
---|
| 71 | struct DefaultMapSelector<_Graph, _Item, unsigned int> { |
---|
| 72 | typedef VectorMap<_Graph, _Item, unsigned int> Map; |
---|
| 73 | }; |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | // short |
---|
| 77 | template <typename _Graph, typename _Item> |
---|
| 78 | struct DefaultMapSelector<_Graph, _Item, signed short> { |
---|
| 79 | typedef VectorMap<_Graph, _Item, signed short> Map; |
---|
| 80 | }; |
---|
| 81 | |
---|
| 82 | template <typename _Graph, typename _Item> |
---|
| 83 | struct DefaultMapSelector<_Graph, _Item, unsigned short> { |
---|
| 84 | typedef VectorMap<_Graph, _Item, unsigned short> Map; |
---|
| 85 | }; |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | // long |
---|
| 89 | template <typename _Graph, typename _Item> |
---|
| 90 | struct DefaultMapSelector<_Graph, _Item, signed long> { |
---|
| 91 | typedef VectorMap<_Graph, _Item, signed long> Map; |
---|
| 92 | }; |
---|
| 93 | |
---|
| 94 | template <typename _Graph, typename _Item> |
---|
| 95 | struct DefaultMapSelector<_Graph, _Item, unsigned long> { |
---|
| 96 | typedef VectorMap<_Graph, _Item, unsigned long> Map; |
---|
| 97 | }; |
---|
| 98 | |
---|
| 99 | |
---|
[485] | 100 | #if defined HAVE_LONG_LONG |
---|
[57] | 101 | |
---|
| 102 | // long long |
---|
| 103 | template <typename _Graph, typename _Item> |
---|
| 104 | struct DefaultMapSelector<_Graph, _Item, signed long long> { |
---|
| 105 | typedef VectorMap<_Graph, _Item, signed long long> Map; |
---|
| 106 | }; |
---|
| 107 | |
---|
| 108 | template <typename _Graph, typename _Item> |
---|
| 109 | struct DefaultMapSelector<_Graph, _Item, unsigned long long> { |
---|
| 110 | typedef VectorMap<_Graph, _Item, unsigned long long> Map; |
---|
| 111 | }; |
---|
| 112 | |
---|
| 113 | #endif |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | // float |
---|
| 117 | template <typename _Graph, typename _Item> |
---|
| 118 | struct DefaultMapSelector<_Graph, _Item, float> { |
---|
| 119 | typedef VectorMap<_Graph, _Item, float> Map; |
---|
| 120 | }; |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | // double |
---|
| 124 | template <typename _Graph, typename _Item> |
---|
| 125 | struct DefaultMapSelector<_Graph, _Item, double> { |
---|
| 126 | typedef VectorMap<_Graph, _Item, double> Map; |
---|
| 127 | }; |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | // long double |
---|
| 131 | template <typename _Graph, typename _Item> |
---|
| 132 | struct DefaultMapSelector<_Graph, _Item, long double> { |
---|
| 133 | typedef VectorMap<_Graph, _Item, long double> Map; |
---|
| 134 | }; |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | // pointer |
---|
| 138 | template <typename _Graph, typename _Item, typename _Ptr> |
---|
| 139 | struct DefaultMapSelector<_Graph, _Item, _Ptr*> { |
---|
| 140 | typedef VectorMap<_Graph, _Item, _Ptr*> Map; |
---|
| 141 | }; |
---|
| 142 | |
---|
[209] | 143 | // #else |
---|
[57] | 144 | |
---|
| 145 | // template <typename _Graph, typename _Item, typename _Value> |
---|
| 146 | // struct DefaultMapSelector { |
---|
| 147 | // typedef DebugMap<_Graph, _Item, _Value> Map; |
---|
| 148 | // }; |
---|
| 149 | |
---|
[209] | 150 | // #endif |
---|
[57] | 151 | |
---|
[314] | 152 | // DefaultMap class |
---|
[57] | 153 | template <typename _Graph, typename _Item, typename _Value> |
---|
[209] | 154 | class DefaultMap |
---|
[57] | 155 | : public DefaultMapSelector<_Graph, _Item, _Value>::Map { |
---|
[617] | 156 | typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent; |
---|
| 157 | |
---|
[57] | 158 | public: |
---|
| 159 | typedef DefaultMap<_Graph, _Item, _Value> Map; |
---|
[617] | 160 | |
---|
| 161 | typedef typename Parent::GraphType GraphType; |
---|
[57] | 162 | typedef typename Parent::Value Value; |
---|
| 163 | |
---|
[617] | 164 | explicit DefaultMap(const GraphType& graph) : Parent(graph) {} |
---|
| 165 | DefaultMap(const GraphType& graph, const Value& value) |
---|
[57] | 166 | : Parent(graph, value) {} |
---|
| 167 | |
---|
| 168 | DefaultMap& operator=(const DefaultMap& cmap) { |
---|
| 169 | return operator=<DefaultMap>(cmap); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | template <typename CMap> |
---|
| 173 | DefaultMap& operator=(const CMap& cmap) { |
---|
| 174 | Parent::operator=(cmap); |
---|
| 175 | return *this; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | }; |
---|
| 179 | |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | #endif |
---|