COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/bits/traits.h @ 2553:bfced05fa852

Last change on this file since 2553:bfced05fa852 was 2553:bfced05fa852, checked in by Alpar Juttner, 12 years ago

Happy New Year to LEMON (+ better update-copyright-header script)

File size: 9.0 KB
Line 
1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2008
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_TRAITS_H
20#define LEMON_BITS_TRAITS_H
21
22#include <lemon/bits/utility.h>
23
24///\file
25///\brief Traits for graphs and maps
26///
27
28namespace lemon {
29  template <typename _Graph, typename _Item>
30  class ItemSetTraits {};
31 
32
33  template <typename Graph, typename Enable = void>
34  struct NodeNotifierIndicator {
35    typedef InvalidType Type;
36  };
37  template <typename Graph>
38  struct NodeNotifierIndicator<
39    Graph,
40    typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
41  > {
42    typedef typename Graph::NodeNotifier Type;
43  };
44
45  template <typename _Graph>
46  class ItemSetTraits<_Graph, typename _Graph::Node> {
47  public:
48   
49    typedef _Graph Graph;
50
51    typedef typename Graph::Node Item;
52    typedef typename Graph::NodeIt ItemIt;
53
54    typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
55
56    template <typename _Value>
57    class Map : public Graph::template NodeMap<_Value> {
58    public:
59      typedef typename Graph::template NodeMap<_Value> Parent;
60      typedef typename Graph::template NodeMap<_Value> Type;
61      typedef typename Parent::Value Value;
62
63      Map(const Graph& _graph) : Parent(_graph) {}
64      Map(const Graph& _graph, const Value& _value)
65        : Parent(_graph, _value) {}
66
67     };
68
69  };
70
71  template <typename Graph, typename Enable = void>
72  struct EdgeNotifierIndicator {
73    typedef InvalidType Type;
74  };
75  template <typename Graph>
76  struct EdgeNotifierIndicator<
77    Graph,
78    typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
79  > {
80    typedef typename Graph::EdgeNotifier Type;
81  };
82
83  template <typename _Graph>
84  class ItemSetTraits<_Graph, typename _Graph::Edge> {
85  public:
86   
87    typedef _Graph Graph;
88
89    typedef typename Graph::Edge Item;
90    typedef typename Graph::EdgeIt ItemIt;
91
92    typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
93
94    template <typename _Value>
95    class Map : public Graph::template EdgeMap<_Value> {
96    public:
97      typedef typename Graph::template EdgeMap<_Value> Parent;
98      typedef typename Graph::template EdgeMap<_Value> Type;
99      typedef typename Parent::Value Value;
100
101      Map(const Graph& _graph) : Parent(_graph) {}
102      Map(const Graph& _graph, const Value& _value)
103        : Parent(_graph, _value) {}
104    };
105
106  };
107
108  template <typename Graph, typename Enable = void>
109  struct UEdgeNotifierIndicator {
110    typedef InvalidType Type;
111  };
112  template <typename Graph>
113  struct UEdgeNotifierIndicator<
114    Graph,
115    typename enable_if<typename Graph::UEdgeNotifier::Notifier, void>::type
116  > {
117    typedef typename Graph::UEdgeNotifier Type;
118  };
119
120  template <typename _Graph>
121  class ItemSetTraits<_Graph, typename _Graph::UEdge> {
122  public:
123   
124    typedef _Graph Graph;
125
126    typedef typename Graph::UEdge Item;
127    typedef typename Graph::UEdgeIt ItemIt;
128
129    typedef typename UEdgeNotifierIndicator<Graph>::Type ItemNotifier;
130
131    template <typename _Value>
132    class Map : public Graph::template UEdgeMap<_Value> {
133    public:
134      typedef typename Graph::template UEdgeMap<_Value> Parent;
135      typedef typename Graph::template UEdgeMap<_Value> Type;
136      typedef typename Parent::Value Value;
137
138      Map(const Graph& _graph) : Parent(_graph) {}
139      Map(const Graph& _graph, const Value& _value)
140        : Parent(_graph, _value) {}
141    };
142
143  };
144
145  template <typename Graph, typename Enable = void>
146  struct ANodeNotifierIndicator {
147    typedef InvalidType Type;
148  };
149  template <typename Graph>
150  struct ANodeNotifierIndicator<
151    Graph,
152    typename enable_if<typename Graph::ANodeNotifier::Notifier, void>::type
153  > {
154    typedef typename Graph::ANodeNotifier Type;
155  };
156
157  template <typename _Graph>
158  class ItemSetTraits<_Graph, typename _Graph::ANode> {
159  public:
160   
161    typedef _Graph Graph;
162
163    typedef typename Graph::ANode Item;
164    typedef typename Graph::ANodeIt ItemIt;
165
166    typedef typename ANodeNotifierIndicator<Graph>::Type ItemNotifier;
167
168    template <typename _Value>
169    class Map : public Graph::template ANodeMap<_Value> {
170    public:
171      typedef typename Graph::template ANodeMap<_Value> Parent;
172      typedef typename Graph::template ANodeMap<_Value> Type;
173      typedef typename Parent::Value Value;
174
175      Map(const Graph& _graph) : Parent(_graph) {}
176      Map(const Graph& _graph, const Value& _value)
177        : Parent(_graph, _value) {}
178    };
179
180  };
181
182  template <typename Graph, typename Enable = void>
183  struct BNodeNotifierIndicator {
184    typedef InvalidType Type;
185  };
186  template <typename Graph>
187  struct BNodeNotifierIndicator<
188    Graph,
189    typename enable_if<typename Graph::BNodeNotifier::Notifier, void>::type
190  > {
191    typedef typename Graph::BNodeNotifier Type;
192  };
193
194  template <typename _Graph>
195  class ItemSetTraits<_Graph, typename _Graph::BNode> {
196  public:
197   
198    typedef _Graph Graph;
199
200    typedef typename Graph::BNode Item;
201    typedef typename Graph::BNodeIt ItemIt;
202
203    typedef typename BNodeNotifierIndicator<Graph>::Type ItemNotifier;
204
205    template <typename _Value>
206    class Map : public Graph::template BNodeMap<_Value> {
207    public:
208      typedef typename Graph::template BNodeMap<_Value> Parent;
209      typedef typename Graph::template BNodeMap<_Value> Type;
210      typedef typename Parent::Value Value;
211
212      Map(const Graph& _graph) : Parent(_graph) {}
213      Map(const Graph& _graph, const Value& _value)
214        : Parent(_graph, _value) {}
215    };
216
217  };
218
219
220  template <typename Map, typename Enable = void>
221  struct MapTraits {
222    typedef False ReferenceMapTag;
223
224    typedef typename Map::Key Key;
225    typedef typename Map::Value Value;
226
227    typedef const Value ConstReturnValue;
228    typedef const Value ReturnValue;
229  };
230
231  template <typename Map>
232  struct MapTraits<
233    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type >
234  {
235    typedef True ReferenceMapTag;
236   
237    typedef typename Map::Key Key;
238    typedef typename Map::Value Value;
239
240    typedef typename Map::ConstReference ConstReturnValue;
241    typedef typename Map::Reference ReturnValue;
242
243    typedef typename Map::ConstReference ConstReference;
244    typedef typename Map::Reference Reference;
245 };
246
247  template <typename MatrixMap, typename Enable = void>
248  struct MatrixMapTraits {
249    typedef False ReferenceMapTag;
250
251    typedef typename MatrixMap::FirstKey FirstKey;
252    typedef typename MatrixMap::SecondKey SecondKey;
253    typedef typename MatrixMap::Value Value;
254
255    typedef const Value ConstReturnValue;
256    typedef const Value ReturnValue;
257  };
258
259  template <typename MatrixMap>
260  struct MatrixMapTraits<
261    MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
262                                  void>::type >
263  {
264    typedef True ReferenceMapTag;
265   
266    typedef typename MatrixMap::FirstKey FirstKey;
267    typedef typename MatrixMap::SecondKey SecondKey;
268    typedef typename MatrixMap::Value Value;
269
270    typedef typename MatrixMap::ConstReference ConstReturnValue;
271    typedef typename MatrixMap::Reference ReturnValue;
272
273    typedef typename MatrixMap::ConstReference ConstReference;
274    typedef typename MatrixMap::Reference Reference;
275 };
276
277  // Indicators for the tags
278
279  template <typename Graph, typename Enable = void>
280  struct NodeNumTagIndicator {
281    static const bool value = false;
282  };
283
284  template <typename Graph>
285  struct NodeNumTagIndicator<
286    Graph,
287    typename enable_if<typename Graph::NodeNumTag, void>::type
288  > {
289    static const bool value = true;
290  };
291
292  template <typename Graph, typename Enable = void>
293  struct EdgeNumTagIndicator {
294    static const bool value = false;
295  };
296
297  template <typename Graph>
298  struct EdgeNumTagIndicator<
299    Graph,
300    typename enable_if<typename Graph::EdgeNumTag, void>::type
301  > {
302    static const bool value = true;
303  };
304
305  template <typename Graph, typename Enable = void>
306  struct FindEdgeTagIndicator {
307    static const bool value = false;
308  };
309
310  template <typename Graph>
311  struct FindEdgeTagIndicator<
312    Graph,
313    typename enable_if<typename Graph::FindEdgeTag, void>::type
314  > {
315    static const bool value = true;
316  };
317
318  template <typename Graph, typename Enable = void>
319  struct UndirectedTagIndicator {
320    static const bool value = false;
321  };
322
323  template <typename Graph>
324  struct UndirectedTagIndicator<
325    Graph,
326    typename enable_if<typename Graph::UndirectedTag, void>::type
327  > {
328    static const bool value = true;
329  };
330
331  template <typename Graph, typename Enable = void>
332  struct BuildTagIndicator {
333    static const bool value = false;
334  };
335
336  template <typename Graph>
337  struct BuildTagIndicator<
338    Graph,
339    typename enable_if<typename Graph::BuildTag, void>::type
340  > {
341    static const bool value = true;
342  };
343
344}
345
346#endif
Note: See TracBrowser for help on using the repository browser.