COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/lemon/default_map.h @ 1022:567f392d1d2e

Last change on this file since 1022:567f392d1d2e was 1022:567f392d1d2e, checked in by Mihaly Barasz, 15 years ago

UndirGraph? implementation nearly complete

File size: 6.4 KB
RevLine 
[906]1/* -*- C++ -*-
[921]2 * src/lemon/default_map.h - Part of LEMON, a generic C++ optimization library
[906]3 *
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
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
[921]21#include <lemon/array_map.h>
22#include <lemon/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]29namespace 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
[980]45  template <typename _Graph, typename _Item, typename _ItemIt, typename _Value>
[946]46  struct DefaultMapSelector {
[980]47    typedef ArrayMap<_Graph, _Item, _ItemIt, _Value> Map;
[946]48  };
[822]49
[946]50  // bool
[980]51  template <typename _Graph, typename _Item, typename _ItemIt>
52  struct DefaultMapSelector<_Graph, _Item, _ItemIt, bool> {
53    typedef VectorMap<_Graph, _Item, bool> Map;
[946]54  };
[822]55
[946]56  // char
[980]57  template <typename _Graph, typename _Item, typename _ItemIt>
58  struct DefaultMapSelector<_Graph, _Item, _ItemIt, char> {
59    typedef VectorMap<_Graph, _Item, char> Map;
[946]60  };
[822]61
[980]62  template <typename _Graph, typename _Item, typename _ItemIt>
63  struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed char> {
64    typedef VectorMap<_Graph, _Item, signed char> Map;
[946]65  };
[822]66
[980]67  template <typename _Graph, typename _Item, typename _ItemIt>
68  struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned char> {
69    typedef VectorMap<_Graph, _Item, unsigned char> Map;
[946]70  };
[822]71
72
[946]73  // int
[980]74  template <typename _Graph, typename _Item, typename _ItemIt>
75  struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed int> {
76    typedef VectorMap<_Graph, _Item, signed int> Map;
[946]77  };
[822]78
[980]79  template <typename _Graph, typename _Item, typename _ItemIt>
80  struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned int> {
81    typedef VectorMap<_Graph, _Item, unsigned int> Map;
[946]82  };
[822]83
84
[946]85  // short
[980]86  template <typename _Graph, typename _Item, typename _ItemIt>
87  struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed short> {
88    typedef VectorMap<_Graph, _Item, signed short> Map;
[946]89  };
[822]90
[980]91  template <typename _Graph, typename _Item, typename _ItemIt>
92  struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned short> {
93    typedef VectorMap<_Graph, _Item, unsigned short> Map;
[946]94  };
95
96
97  // long
[980]98  template <typename _Graph, typename _Item, typename _ItemIt>
99  struct DefaultMapSelector<_Graph, _Item, _ItemIt, signed long> {
100    typedef VectorMap<_Graph, _Item, signed long> Map;
[946]101  };
102
[980]103  template <typename _Graph, typename _Item, typename _ItemIt>
104  struct DefaultMapSelector<_Graph, _Item, _ItemIt, unsigned long> {
105    typedef VectorMap<_Graph, _Item, unsigned long> Map;
[946]106  };
107
108  // \todo handling long long type
109
110
111  // float
[980]112  template <typename _Graph, typename _Item, typename _ItemIt>
113  struct DefaultMapSelector<_Graph, _Item, _ItemIt, float> {
114    typedef VectorMap<_Graph, _Item, float> Map;
[946]115  };
116
117
118  // double
[980]119  template <typename _Graph, typename _Item, typename _ItemIt>
120  struct DefaultMapSelector<_Graph, _Item, _ItemIt, double> {
121    typedef VectorMap<_Graph, _Item,  double> Map;
[946]122  };
123
124
125  // long double
[980]126  template <typename _Graph, typename _Item, typename _ItemIt>
127  struct DefaultMapSelector<_Graph, _Item, _ItemIt, long double> {
128    typedef VectorMap<_Graph, _Item, long double> Map;
[946]129  };
130
131
132  // pointer
[980]133  template <typename _Graph, typename _Item, typename _ItemIt, typename _Ptr>
134  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _Ptr*> {
135    typedef VectorMap<_Graph, _Item, _Ptr*> Map;
[946]136  };
137
138
139
140  template <typename _Graph,
141            typename _Item,
142            typename _ItemIt,
143            typename _Value>
[980]144  class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _Value>::Map {
[946]145  public:
[980]146    typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _Value>::Map Parent;
147    typedef DefaultMap<_Graph, _Item, _ItemIt, _Value> Map;
[946]148   
149    typedef typename Parent::Graph Graph;
[987]150    typedef typename Parent::Value Value;
[946]151
[980]152    DefaultMap(const Graph& _g) : Parent(_g) {}
[987]153    DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {}
[946]154  };
155
156
157
158  template <typename _Base>
159  class DefaultMappableGraphExtender : public _Base {
160  public:
161
162    typedef DefaultMappableGraphExtender<_Base> Graph;
163    typedef _Base Parent;
164
165    typedef typename Parent::Node Node;
166    typedef typename Parent::NodeIt NodeIt;
167
168    typedef typename Parent::Edge Edge;
169    typedef typename Parent::EdgeIt EdgeIt;
170
171   
172    template <typename _Value>
[980]173    class NodeMap : public DefaultMap<Graph, Node, NodeIt, _Value> {
[946]174    public:
[1022]175      typedef DefaultMappableGraphExtender Graph;
[980]176      typedef DefaultMap<Graph, Node, NodeIt, _Value> Parent;
[946]177
[980]178      NodeMap(const Graph& _g)
179        : Parent(_g) {}
[1022]180      NodeMap(const Graph& _g, const _Value& _v)
[980]181        : Parent(_g, _v) {}
[946]182    };
183
184    template <typename _Value>
[980]185    class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, _Value> {
[946]186    public:
[1022]187      typedef DefaultMappableGraphExtender Graph;
[980]188      typedef DefaultMap<Graph, Edge, EdgeIt, _Value> Parent;
[946]189
[980]190      EdgeMap(const Graph& _g)
191        : Parent(_g) {}
[1022]192      EdgeMap(const Graph& _g, const _Value& _v)
[980]193        : Parent(_g, _v) {}
[946]194    };
195   
196  };
197
[1022]198  template <typename _Base>
199  class MappableUndirGraphExtender :
200    public DefaultMappableGraphExtender<_Base> {
201  public:
202
203    typedef MappableUndirGraphExtender Graph;
204    typedef DefaultMappableGraphExtender<_Base> Parent;
205
206    typedef typename Parent::UndirEdge UndirEdge;
207    typedef typename Parent::UndirEdgeIt UndirEdgeIt;
208
209    template <typename _Value>
210    class UndirEdgeMap :
211      public DefaultMap<Graph, UndirEdge, UndirEdgeIt, _Value> {
212    public:
213      typedef MappableUndirGraphExtender Graph;
214      typedef DefaultMap<Graph, UndirEdge, UndirEdgeIt, _Value> Parent;
215
216      UndirEdgeMap(const Graph& _g)
217        : Parent(_g) {}
218      UndirEdgeMap(const Graph& _g, const _Value& _v)
219        : Parent(_g, _v) {}
220    };
221
222
223  };
[822]224
225}
226
227#endif
Note: See TracBrowser for help on using the repository browser.