COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/bits/default_map.h @ 2041:28df5272df99

Last change on this file since 2041:28df5272df99 was 2031:080d51024ac5, checked in by Balazs Dezso, 18 years ago

Correcting the structure of the graph's and adaptor's map.
The template assign operators and map iterators can be used for adaptors also.

Some bugfix in the adaptors

New class SwapBpUGraphAdaptor which swaps the two nodeset of the graph.

File size: 4.6 KB
Line 
1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
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
22
23#include <lemon/bits/array_map.h>
24#include <lemon/bits/vector_map.h>
25
26///\ingroup graphbits
27///\file
28///\brief Graph maps that construct and destruct their elements dynamically.
29
30namespace lemon {
31 
32 
33#ifndef _GLIBCXX_DEBUG
34
35  template <typename _Graph, typename _Item, typename _Value>
36  struct DefaultMapSelector {
37    typedef ArrayMap<_Graph, _Item, _Value> Map;
38  };
39
40#else
41
42  template <typename _Graph, typename _Item, typename _Value>
43  struct DefaultMapSelector {
44    typedef VectorMap<_Graph, _Item, _Value> Map;
45  };
46
47#endif
48
49  // bool
50  template <typename _Graph, typename _Item>
51  struct DefaultMapSelector<_Graph, _Item, bool> {
52    typedef VectorMap<_Graph, _Item, bool> Map;
53  };
54
55  // char
56  template <typename _Graph, typename _Item>
57  struct DefaultMapSelector<_Graph, _Item, char> {
58    typedef VectorMap<_Graph, _Item, char> Map;
59  };
60
61  template <typename _Graph, typename _Item>
62  struct DefaultMapSelector<_Graph, _Item, signed char> {
63    typedef VectorMap<_Graph, _Item, signed char> Map;
64  };
65
66  template <typename _Graph, typename _Item>
67  struct DefaultMapSelector<_Graph, _Item, unsigned char> {
68    typedef VectorMap<_Graph, _Item, unsigned char> Map;
69  };
70
71
72  // int
73  template <typename _Graph, typename _Item>
74  struct DefaultMapSelector<_Graph, _Item, signed int> {
75    typedef VectorMap<_Graph, _Item, signed int> Map;
76  };
77
78  template <typename _Graph, typename _Item>
79  struct DefaultMapSelector<_Graph, _Item, unsigned int> {
80    typedef VectorMap<_Graph, _Item, unsigned int> Map;
81  };
82
83
84  // short
85  template <typename _Graph, typename _Item>
86  struct DefaultMapSelector<_Graph, _Item, signed short> {
87    typedef VectorMap<_Graph, _Item, signed short> Map;
88  };
89
90  template <typename _Graph, typename _Item>
91  struct DefaultMapSelector<_Graph, _Item, unsigned short> {
92    typedef VectorMap<_Graph, _Item, unsigned short> Map;
93  };
94
95
96  // long
97  template <typename _Graph, typename _Item>
98  struct DefaultMapSelector<_Graph, _Item, signed long> {
99    typedef VectorMap<_Graph, _Item, signed long> Map;
100  };
101
102  template <typename _Graph, typename _Item>
103  struct DefaultMapSelector<_Graph, _Item, unsigned long> {
104    typedef VectorMap<_Graph, _Item, unsigned long> Map;
105  };
106
107
108#ifndef __STRICT_ANSI__
109
110  // long long
111  template <typename _Graph, typename _Item>
112  struct DefaultMapSelector<_Graph, _Item, signed long long> {
113    typedef VectorMap<_Graph, _Item, signed long long> Map;
114  };
115
116  template <typename _Graph, typename _Item>
117  struct DefaultMapSelector<_Graph, _Item, unsigned long long> {
118    typedef VectorMap<_Graph, _Item, unsigned long long> Map;
119  };
120
121#endif
122
123
124  // float
125  template <typename _Graph, typename _Item>
126  struct DefaultMapSelector<_Graph, _Item, float> {
127    typedef VectorMap<_Graph, _Item, float> Map;
128  };
129
130
131  // double
132  template <typename _Graph, typename _Item>
133  struct DefaultMapSelector<_Graph, _Item, double> {
134    typedef VectorMap<_Graph, _Item,  double> Map;
135  };
136
137
138  // long double
139  template <typename _Graph, typename _Item>
140  struct DefaultMapSelector<_Graph, _Item, long double> {
141    typedef VectorMap<_Graph, _Item, long double> Map;
142  };
143
144
145  // pointer
146  template <typename _Graph, typename _Item, typename _Ptr>
147  struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
148    typedef VectorMap<_Graph, _Item, _Ptr*> Map;
149  };
150
151  /// \e
152  template <typename _Graph, typename _Item, typename _Value>
153  class DefaultMap
154    : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
155  public:
156    typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
157    typedef DefaultMap<_Graph, _Item, _Value> Map;
158   
159    typedef typename Parent::Graph Graph;
160    typedef typename Parent::Value Value;
161
162    DefaultMap(const Graph& graph) : Parent(graph) {}
163    DefaultMap(const Graph& graph, const Value& value)
164      : Parent(graph, value) {}
165
166    DefaultMap& operator=(const DefaultMap& cmap) {
167      return operator=<DefaultMap>(cmap);
168    }
169
170    template <typename CMap>
171    DefaultMap& operator=(const CMap& cmap) {
172      Parent::operator=(cmap);
173      return *this;
174    }
175
176  };
177
178}
179
180#endif
Note: See TracBrowser for help on using the repository browser.