COIN-OR::LEMON - Graph Library

source: lemon/lemon/bits/traits.h

Last change on this file was 1270:dceba191c00d, checked in by Alpar Juttner <alpar@…>, 11 years ago

Apply unify-sources.sh to the source tree

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