1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/lemon/bits/default_map.h Sun Jan 20 20:43:48 2008 +0100
1.3 @@ -0,0 +1,181 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2007
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#ifndef LEMON_BITS_DEFAULT_MAP_H
1.23 +#define LEMON_BITS_DEFAULT_MAP_H
1.24 +
1.25 +
1.26 +#include <lemon/bits/array_map.h>
1.27 +#include <lemon/bits/vector_map.h>
1.28 +//#include <lemon/bits/debug_map.h>
1.29 +
1.30 +///\ingroup graphbits
1.31 +///\file
1.32 +///\brief Graph maps that construct and destruct their elements dynamically.
1.33 +
1.34 +namespace lemon {
1.35 +
1.36 +
1.37 + //#ifndef LEMON_USE_DEBUG_MAP
1.38 +
1.39 + template <typename _Graph, typename _Item, typename _Value>
1.40 + struct DefaultMapSelector {
1.41 + typedef ArrayMap<_Graph, _Item, _Value> Map;
1.42 + };
1.43 +
1.44 + // bool
1.45 + template <typename _Graph, typename _Item>
1.46 + struct DefaultMapSelector<_Graph, _Item, bool> {
1.47 + typedef VectorMap<_Graph, _Item, bool> Map;
1.48 + };
1.49 +
1.50 + // char
1.51 + template <typename _Graph, typename _Item>
1.52 + struct DefaultMapSelector<_Graph, _Item, char> {
1.53 + typedef VectorMap<_Graph, _Item, char> Map;
1.54 + };
1.55 +
1.56 + template <typename _Graph, typename _Item>
1.57 + struct DefaultMapSelector<_Graph, _Item, signed char> {
1.58 + typedef VectorMap<_Graph, _Item, signed char> Map;
1.59 + };
1.60 +
1.61 + template <typename _Graph, typename _Item>
1.62 + struct DefaultMapSelector<_Graph, _Item, unsigned char> {
1.63 + typedef VectorMap<_Graph, _Item, unsigned char> Map;
1.64 + };
1.65 +
1.66 +
1.67 + // int
1.68 + template <typename _Graph, typename _Item>
1.69 + struct DefaultMapSelector<_Graph, _Item, signed int> {
1.70 + typedef VectorMap<_Graph, _Item, signed int> Map;
1.71 + };
1.72 +
1.73 + template <typename _Graph, typename _Item>
1.74 + struct DefaultMapSelector<_Graph, _Item, unsigned int> {
1.75 + typedef VectorMap<_Graph, _Item, unsigned int> Map;
1.76 + };
1.77 +
1.78 +
1.79 + // short
1.80 + template <typename _Graph, typename _Item>
1.81 + struct DefaultMapSelector<_Graph, _Item, signed short> {
1.82 + typedef VectorMap<_Graph, _Item, signed short> Map;
1.83 + };
1.84 +
1.85 + template <typename _Graph, typename _Item>
1.86 + struct DefaultMapSelector<_Graph, _Item, unsigned short> {
1.87 + typedef VectorMap<_Graph, _Item, unsigned short> Map;
1.88 + };
1.89 +
1.90 +
1.91 + // long
1.92 + template <typename _Graph, typename _Item>
1.93 + struct DefaultMapSelector<_Graph, _Item, signed long> {
1.94 + typedef VectorMap<_Graph, _Item, signed long> Map;
1.95 + };
1.96 +
1.97 + template <typename _Graph, typename _Item>
1.98 + struct DefaultMapSelector<_Graph, _Item, unsigned long> {
1.99 + typedef VectorMap<_Graph, _Item, unsigned long> Map;
1.100 + };
1.101 +
1.102 +
1.103 +#if defined __GNUC__ && !defined __STRICT_ANSI__
1.104 +
1.105 + // long long
1.106 + template <typename _Graph, typename _Item>
1.107 + struct DefaultMapSelector<_Graph, _Item, signed long long> {
1.108 + typedef VectorMap<_Graph, _Item, signed long long> Map;
1.109 + };
1.110 +
1.111 + template <typename _Graph, typename _Item>
1.112 + struct DefaultMapSelector<_Graph, _Item, unsigned long long> {
1.113 + typedef VectorMap<_Graph, _Item, unsigned long long> Map;
1.114 + };
1.115 +
1.116 +#endif
1.117 +
1.118 +
1.119 + // float
1.120 + template <typename _Graph, typename _Item>
1.121 + struct DefaultMapSelector<_Graph, _Item, float> {
1.122 + typedef VectorMap<_Graph, _Item, float> Map;
1.123 + };
1.124 +
1.125 +
1.126 + // double
1.127 + template <typename _Graph, typename _Item>
1.128 + struct DefaultMapSelector<_Graph, _Item, double> {
1.129 + typedef VectorMap<_Graph, _Item, double> Map;
1.130 + };
1.131 +
1.132 +
1.133 + // long double
1.134 + template <typename _Graph, typename _Item>
1.135 + struct DefaultMapSelector<_Graph, _Item, long double> {
1.136 + typedef VectorMap<_Graph, _Item, long double> Map;
1.137 + };
1.138 +
1.139 +
1.140 + // pointer
1.141 + template <typename _Graph, typename _Item, typename _Ptr>
1.142 + struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
1.143 + typedef VectorMap<_Graph, _Item, _Ptr*> Map;
1.144 + };
1.145 +
1.146 +// #else
1.147 +
1.148 +// template <typename _Graph, typename _Item, typename _Value>
1.149 +// struct DefaultMapSelector {
1.150 +// typedef DebugMap<_Graph, _Item, _Value> Map;
1.151 +// };
1.152 +
1.153 +// #endif
1.154 +
1.155 + /// \e
1.156 + template <typename _Graph, typename _Item, typename _Value>
1.157 + class DefaultMap
1.158 + : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
1.159 + public:
1.160 + typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
1.161 + typedef DefaultMap<_Graph, _Item, _Value> Map;
1.162 +
1.163 + typedef typename Parent::Graph Graph;
1.164 + typedef typename Parent::Value Value;
1.165 +
1.166 + explicit DefaultMap(const Graph& graph) : Parent(graph) {}
1.167 + DefaultMap(const Graph& graph, const Value& value)
1.168 + : Parent(graph, value) {}
1.169 +
1.170 + DefaultMap& operator=(const DefaultMap& cmap) {
1.171 + return operator=<DefaultMap>(cmap);
1.172 + }
1.173 +
1.174 + template <typename CMap>
1.175 + DefaultMap& operator=(const CMap& cmap) {
1.176 + Parent::operator=(cmap);
1.177 + return *this;
1.178 + }
1.179 +
1.180 + };
1.181 +
1.182 +}
1.183 +
1.184 +#endif