[906] | 1 | /* -*- C++ -*- |
---|
[1435] | 2 | * lemon/default_map.h - Part of LEMON, a generic C++ optimization library |
---|
[906] | 3 | * |
---|
[1164] | 4 | * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
[1359] | 5 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
[906] | 6 | * |
---|
| 7 | * Permission to use, modify and distribute this software is granted |
---|
| 8 | * provided that this copyright notice appears in all copies. For |
---|
| 9 | * precise terms see the accompanying LICENSE file. |
---|
| 10 | * |
---|
| 11 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 12 | * express or implied, and with no claim as to its suitability for any |
---|
| 13 | * purpose. |
---|
| 14 | * |
---|
| 15 | */ |
---|
| 16 | |
---|
[921] | 17 | #ifndef LEMON_DEFAULT_MAP_H |
---|
| 18 | #define LEMON_DEFAULT_MAP_H |
---|
[822] | 19 | |
---|
| 20 | |
---|
[1307] | 21 | #include <lemon/bits/array_map.h> |
---|
| 22 | #include <lemon/bits/vector_map.h> |
---|
[822] | 23 | |
---|
| 24 | ///\ingroup graphmaps |
---|
| 25 | ///\file |
---|
[946] | 26 | ///\brief Graph maps that construct and destruct |
---|
[822] | 27 | ///their elements dynamically. |
---|
| 28 | |
---|
[921] | 29 | namespace lemon { |
---|
[822] | 30 | |
---|
| 31 | /// \addtogroup graphmaps |
---|
| 32 | /// @{ |
---|
| 33 | |
---|
| 34 | /** The ArrayMap template class is graph map structure what |
---|
| 35 | * automatically updates the map when a key is added to or erased from |
---|
[987] | 36 | * the map. This map uses the VectorMap if the Value is a primitive |
---|
[822] | 37 | * type and the ArrayMap for the other cases. |
---|
| 38 | * |
---|
| 39 | * The template parameter is the MapRegistry that the maps |
---|
[987] | 40 | * will belong to and the Value. |
---|
[822] | 41 | */ |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | |
---|
[1267] | 45 | template <typename _Graph, typename _Item, typename _Value> |
---|
[946] | 46 | struct DefaultMapSelector { |
---|
[1267] | 47 | typedef ArrayMap<_Graph, _Item, _Value> Map; |
---|
[946] | 48 | }; |
---|
[822] | 49 | |
---|
[946] | 50 | // bool |
---|
[1267] | 51 | template <typename _Graph, typename _Item> |
---|
| 52 | struct DefaultMapSelector<_Graph, _Item, bool> { |
---|
[980] | 53 | typedef VectorMap<_Graph, _Item, bool> Map; |
---|
[946] | 54 | }; |
---|
[822] | 55 | |
---|
[946] | 56 | // char |
---|
[1267] | 57 | template <typename _Graph, typename _Item> |
---|
| 58 | struct DefaultMapSelector<_Graph, _Item, char> { |
---|
[980] | 59 | typedef VectorMap<_Graph, _Item, char> Map; |
---|
[946] | 60 | }; |
---|
[822] | 61 | |
---|
[1267] | 62 | template <typename _Graph, typename _Item> |
---|
| 63 | struct DefaultMapSelector<_Graph, _Item, signed char> { |
---|
[980] | 64 | typedef VectorMap<_Graph, _Item, signed char> Map; |
---|
[946] | 65 | }; |
---|
[822] | 66 | |
---|
[1267] | 67 | template <typename _Graph, typename _Item> |
---|
| 68 | struct DefaultMapSelector<_Graph, _Item, unsigned char> { |
---|
[980] | 69 | typedef VectorMap<_Graph, _Item, unsigned char> Map; |
---|
[946] | 70 | }; |
---|
[822] | 71 | |
---|
| 72 | |
---|
[946] | 73 | // int |
---|
[1267] | 74 | template <typename _Graph, typename _Item> |
---|
| 75 | struct DefaultMapSelector<_Graph, _Item, signed int> { |
---|
[980] | 76 | typedef VectorMap<_Graph, _Item, signed int> Map; |
---|
[946] | 77 | }; |
---|
[822] | 78 | |
---|
[1267] | 79 | template <typename _Graph, typename _Item> |
---|
| 80 | struct DefaultMapSelector<_Graph, _Item, unsigned int> { |
---|
[980] | 81 | typedef VectorMap<_Graph, _Item, unsigned int> Map; |
---|
[946] | 82 | }; |
---|
[822] | 83 | |
---|
| 84 | |
---|
[946] | 85 | // short |
---|
[1267] | 86 | template <typename _Graph, typename _Item> |
---|
| 87 | struct DefaultMapSelector<_Graph, _Item, signed short> { |
---|
[980] | 88 | typedef VectorMap<_Graph, _Item, signed short> Map; |
---|
[946] | 89 | }; |
---|
[822] | 90 | |
---|
[1267] | 91 | template <typename _Graph, typename _Item> |
---|
| 92 | struct DefaultMapSelector<_Graph, _Item, unsigned short> { |
---|
[980] | 93 | typedef VectorMap<_Graph, _Item, unsigned short> Map; |
---|
[946] | 94 | }; |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | // long |
---|
[1267] | 98 | template <typename _Graph, typename _Item> |
---|
| 99 | struct DefaultMapSelector<_Graph, _Item, signed long> { |
---|
[980] | 100 | typedef VectorMap<_Graph, _Item, signed long> Map; |
---|
[946] | 101 | }; |
---|
| 102 | |
---|
[1267] | 103 | template <typename _Graph, typename _Item> |
---|
| 104 | struct DefaultMapSelector<_Graph, _Item, unsigned long> { |
---|
[980] | 105 | typedef VectorMap<_Graph, _Item, unsigned long> Map; |
---|
[946] | 106 | }; |
---|
| 107 | |
---|
| 108 | // \todo handling long long type |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | // float |
---|
[1267] | 112 | template <typename _Graph, typename _Item> |
---|
| 113 | struct DefaultMapSelector<_Graph, _Item, float> { |
---|
[980] | 114 | typedef VectorMap<_Graph, _Item, float> Map; |
---|
[946] | 115 | }; |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | // double |
---|
[1267] | 119 | template <typename _Graph, typename _Item> |
---|
| 120 | struct DefaultMapSelector<_Graph, _Item, double> { |
---|
[980] | 121 | typedef VectorMap<_Graph, _Item, double> Map; |
---|
[946] | 122 | }; |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | // long double |
---|
[1267] | 126 | template <typename _Graph, typename _Item> |
---|
| 127 | struct DefaultMapSelector<_Graph, _Item, long double> { |
---|
[980] | 128 | typedef VectorMap<_Graph, _Item, long double> Map; |
---|
[946] | 129 | }; |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | // pointer |
---|
[1267] | 133 | template <typename _Graph, typename _Item, typename _Ptr> |
---|
| 134 | struct DefaultMapSelector<_Graph, _Item, _Ptr*> { |
---|
[980] | 135 | typedef VectorMap<_Graph, _Item, _Ptr*> Map; |
---|
[946] | 136 | }; |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | |
---|
[1267] | 140 | template < |
---|
| 141 | typename _Graph, |
---|
| 142 | typename _Item, |
---|
| 143 | typename _Value> |
---|
| 144 | class DefaultMap |
---|
| 145 | : public DefaultMapSelector<_Graph, _Item, _Value>::Map { |
---|
[946] | 146 | public: |
---|
[1267] | 147 | typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent; |
---|
| 148 | typedef DefaultMap<_Graph, _Item, _Value> Map; |
---|
[946] | 149 | |
---|
| 150 | typedef typename Parent::Graph Graph; |
---|
[987] | 151 | typedef typename Parent::Value Value; |
---|
[946] | 152 | |
---|
[980] | 153 | DefaultMap(const Graph& _g) : Parent(_g) {} |
---|
[987] | 154 | DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {} |
---|
[946] | 155 | }; |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | template <typename _Base> |
---|
| 160 | class DefaultMappableGraphExtender : public _Base { |
---|
| 161 | public: |
---|
| 162 | |
---|
| 163 | typedef DefaultMappableGraphExtender<_Base> Graph; |
---|
| 164 | typedef _Base Parent; |
---|
| 165 | |
---|
| 166 | typedef typename Parent::Node Node; |
---|
| 167 | typedef typename Parent::NodeIt NodeIt; |
---|
| 168 | |
---|
| 169 | typedef typename Parent::Edge Edge; |
---|
| 170 | typedef typename Parent::EdgeIt EdgeIt; |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | template <typename _Value> |
---|
[1267] | 174 | class NodeMap |
---|
| 175 | : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > { |
---|
[946] | 176 | public: |
---|
[1022] | 177 | typedef DefaultMappableGraphExtender Graph; |
---|
[1267] | 178 | typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent; |
---|
[946] | 179 | |
---|
[980] | 180 | NodeMap(const Graph& _g) |
---|
| 181 | : Parent(_g) {} |
---|
[1022] | 182 | NodeMap(const Graph& _g, const _Value& _v) |
---|
[980] | 183 | : Parent(_g, _v) {} |
---|
[946] | 184 | }; |
---|
| 185 | |
---|
| 186 | template <typename _Value> |
---|
[1267] | 187 | class EdgeMap |
---|
| 188 | : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > { |
---|
[946] | 189 | public: |
---|
[1022] | 190 | typedef DefaultMappableGraphExtender Graph; |
---|
[1267] | 191 | typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent; |
---|
[946] | 192 | |
---|
[980] | 193 | EdgeMap(const Graph& _g) |
---|
| 194 | : Parent(_g) {} |
---|
[1022] | 195 | EdgeMap(const Graph& _g, const _Value& _v) |
---|
[980] | 196 | : Parent(_g, _v) {} |
---|
[946] | 197 | }; |
---|
| 198 | |
---|
| 199 | }; |
---|
| 200 | |
---|
[1022] | 201 | template <typename _Base> |
---|
| 202 | class MappableUndirGraphExtender : |
---|
| 203 | public DefaultMappableGraphExtender<_Base> { |
---|
| 204 | public: |
---|
| 205 | |
---|
| 206 | typedef MappableUndirGraphExtender Graph; |
---|
| 207 | typedef DefaultMappableGraphExtender<_Base> Parent; |
---|
| 208 | |
---|
| 209 | typedef typename Parent::UndirEdge UndirEdge; |
---|
| 210 | |
---|
| 211 | template <typename _Value> |
---|
[1267] | 212 | class UndirEdgeMap |
---|
| 213 | : public IterableMapExtender<DefaultMap<Graph, UndirEdge, _Value> > { |
---|
[1022] | 214 | public: |
---|
| 215 | typedef MappableUndirGraphExtender Graph; |
---|
[1267] | 216 | typedef IterableMapExtender< |
---|
| 217 | DefaultMap<Graph, UndirEdge, _Value> > Parent; |
---|
[1022] | 218 | |
---|
| 219 | UndirEdgeMap(const Graph& _g) |
---|
| 220 | : Parent(_g) {} |
---|
| 221 | UndirEdgeMap(const Graph& _g, const _Value& _v) |
---|
| 222 | : Parent(_g, _v) {} |
---|
| 223 | }; |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | }; |
---|
[822] | 227 | |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | #endif |
---|