1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/lemon/bits/default_map.h Tue Apr 05 12:30:46 2005 +0000
1.3 @@ -0,0 +1,230 @@
1.4 +/* -*- C++ -*-
1.5 + * src/lemon/default_map.h - Part of LEMON, a generic C++ optimization library
1.6 + *
1.7 + * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
1.9 + *
1.10 + * Permission to use, modify and distribute this software is granted
1.11 + * provided that this copyright notice appears in all copies. For
1.12 + * precise terms see the accompanying LICENSE file.
1.13 + *
1.14 + * This software is provided "AS IS" with no warranty of any kind,
1.15 + * express or implied, and with no claim as to its suitability for any
1.16 + * purpose.
1.17 + *
1.18 + */
1.19 +
1.20 +#ifndef LEMON_DEFAULT_MAP_H
1.21 +#define LEMON_DEFAULT_MAP_H
1.22 +
1.23 +
1.24 +#include <lemon/bits/array_map.h>
1.25 +#include <lemon/bits/vector_map.h>
1.26 +
1.27 +///\ingroup graphmaps
1.28 +///\file
1.29 +///\brief Graph maps that construct and destruct
1.30 +///their elements dynamically.
1.31 +
1.32 +namespace lemon {
1.33 +
1.34 +/// \addtogroup graphmaps
1.35 +/// @{
1.36 +
1.37 + /** The ArrayMap template class is graph map structure what
1.38 + * automatically updates the map when a key is added to or erased from
1.39 + * the map. This map uses the VectorMap if the Value is a primitive
1.40 + * type and the ArrayMap for the other cases.
1.41 + *
1.42 + * The template parameter is the MapRegistry that the maps
1.43 + * will belong to and the Value.
1.44 + */
1.45 +
1.46 +
1.47 +
1.48 + template <typename _Graph, typename _Item, typename _Value>
1.49 + struct DefaultMapSelector {
1.50 + typedef ArrayMap<_Graph, _Item, _Value> Map;
1.51 + };
1.52 +
1.53 + // bool
1.54 + template <typename _Graph, typename _Item>
1.55 + struct DefaultMapSelector<_Graph, _Item, bool> {
1.56 + typedef VectorMap<_Graph, _Item, bool> Map;
1.57 + };
1.58 +
1.59 + // char
1.60 + template <typename _Graph, typename _Item>
1.61 + struct DefaultMapSelector<_Graph, _Item, char> {
1.62 + typedef VectorMap<_Graph, _Item, char> Map;
1.63 + };
1.64 +
1.65 + template <typename _Graph, typename _Item>
1.66 + struct DefaultMapSelector<_Graph, _Item, signed char> {
1.67 + typedef VectorMap<_Graph, _Item, signed char> Map;
1.68 + };
1.69 +
1.70 + template <typename _Graph, typename _Item>
1.71 + struct DefaultMapSelector<_Graph, _Item, unsigned char> {
1.72 + typedef VectorMap<_Graph, _Item, unsigned char> Map;
1.73 + };
1.74 +
1.75 +
1.76 + // int
1.77 + template <typename _Graph, typename _Item>
1.78 + struct DefaultMapSelector<_Graph, _Item, signed int> {
1.79 + typedef VectorMap<_Graph, _Item, signed int> Map;
1.80 + };
1.81 +
1.82 + template <typename _Graph, typename _Item>
1.83 + struct DefaultMapSelector<_Graph, _Item, unsigned int> {
1.84 + typedef VectorMap<_Graph, _Item, unsigned int> Map;
1.85 + };
1.86 +
1.87 +
1.88 + // short
1.89 + template <typename _Graph, typename _Item>
1.90 + struct DefaultMapSelector<_Graph, _Item, signed short> {
1.91 + typedef VectorMap<_Graph, _Item, signed short> Map;
1.92 + };
1.93 +
1.94 + template <typename _Graph, typename _Item>
1.95 + struct DefaultMapSelector<_Graph, _Item, unsigned short> {
1.96 + typedef VectorMap<_Graph, _Item, unsigned short> Map;
1.97 + };
1.98 +
1.99 +
1.100 + // long
1.101 + template <typename _Graph, typename _Item>
1.102 + struct DefaultMapSelector<_Graph, _Item, signed long> {
1.103 + typedef VectorMap<_Graph, _Item, signed long> Map;
1.104 + };
1.105 +
1.106 + template <typename _Graph, typename _Item>
1.107 + struct DefaultMapSelector<_Graph, _Item, unsigned long> {
1.108 + typedef VectorMap<_Graph, _Item, unsigned long> Map;
1.109 + };
1.110 +
1.111 + // \todo handling long long type
1.112 +
1.113 +
1.114 + // float
1.115 + template <typename _Graph, typename _Item>
1.116 + struct DefaultMapSelector<_Graph, _Item, float> {
1.117 + typedef VectorMap<_Graph, _Item, float> Map;
1.118 + };
1.119 +
1.120 +
1.121 + // double
1.122 + template <typename _Graph, typename _Item>
1.123 + struct DefaultMapSelector<_Graph, _Item, double> {
1.124 + typedef VectorMap<_Graph, _Item, double> Map;
1.125 + };
1.126 +
1.127 +
1.128 + // long double
1.129 + template <typename _Graph, typename _Item>
1.130 + struct DefaultMapSelector<_Graph, _Item, long double> {
1.131 + typedef VectorMap<_Graph, _Item, long double> Map;
1.132 + };
1.133 +
1.134 +
1.135 + // pointer
1.136 + template <typename _Graph, typename _Item, typename _Ptr>
1.137 + struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
1.138 + typedef VectorMap<_Graph, _Item, _Ptr*> Map;
1.139 + };
1.140 +
1.141 +
1.142 +
1.143 + template <
1.144 + typename _Graph,
1.145 + typename _Item,
1.146 + typename _Value>
1.147 + class DefaultMap
1.148 + : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
1.149 + public:
1.150 + typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
1.151 + typedef DefaultMap<_Graph, _Item, _Value> Map;
1.152 +
1.153 + typedef typename Parent::Graph Graph;
1.154 + typedef typename Parent::Value Value;
1.155 +
1.156 + DefaultMap(const Graph& _g) : Parent(_g) {}
1.157 + DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {}
1.158 + };
1.159 +
1.160 +
1.161 +
1.162 + template <typename _Base>
1.163 + class DefaultMappableGraphExtender : public _Base {
1.164 + public:
1.165 +
1.166 + typedef DefaultMappableGraphExtender<_Base> Graph;
1.167 + typedef _Base Parent;
1.168 +
1.169 + typedef typename Parent::Node Node;
1.170 + typedef typename Parent::NodeIt NodeIt;
1.171 +
1.172 + typedef typename Parent::Edge Edge;
1.173 + typedef typename Parent::EdgeIt EdgeIt;
1.174 +
1.175 +
1.176 + template <typename _Value>
1.177 + class NodeMap
1.178 + : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
1.179 + public:
1.180 + typedef DefaultMappableGraphExtender Graph;
1.181 + typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
1.182 +
1.183 + NodeMap(const Graph& _g)
1.184 + : Parent(_g) {}
1.185 + NodeMap(const Graph& _g, const _Value& _v)
1.186 + : Parent(_g, _v) {}
1.187 + };
1.188 +
1.189 + template <typename _Value>
1.190 + class EdgeMap
1.191 + : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
1.192 + public:
1.193 + typedef DefaultMappableGraphExtender Graph;
1.194 + typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
1.195 +
1.196 + EdgeMap(const Graph& _g)
1.197 + : Parent(_g) {}
1.198 + EdgeMap(const Graph& _g, const _Value& _v)
1.199 + : Parent(_g, _v) {}
1.200 + };
1.201 +
1.202 + };
1.203 +
1.204 + template <typename _Base>
1.205 + class MappableUndirGraphExtender :
1.206 + public DefaultMappableGraphExtender<_Base> {
1.207 + public:
1.208 +
1.209 + typedef MappableUndirGraphExtender Graph;
1.210 + typedef DefaultMappableGraphExtender<_Base> Parent;
1.211 +
1.212 + typedef typename Parent::UndirEdge UndirEdge;
1.213 +
1.214 + template <typename _Value>
1.215 + class UndirEdgeMap
1.216 + : public IterableMapExtender<DefaultMap<Graph, UndirEdge, _Value> > {
1.217 + public:
1.218 + typedef MappableUndirGraphExtender Graph;
1.219 + typedef IterableMapExtender<
1.220 + DefaultMap<Graph, UndirEdge, _Value> > Parent;
1.221 +
1.222 + UndirEdgeMap(const Graph& _g)
1.223 + : Parent(_g) {}
1.224 + UndirEdgeMap(const Graph& _g, const _Value& _v)
1.225 + : Parent(_g, _v) {}
1.226 + };
1.227 +
1.228 +
1.229 + };
1.230 +
1.231 +}
1.232 +
1.233 +#endif