|
1 /* -*- C++ -*- |
|
2 * lemon/traits.h - Part of LEMON, a generic C++ optimization library |
|
3 * |
|
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
5 * (Egervary Research Group on Combinatorial Optimization, 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 |
|
17 #ifndef LEMON_TRAITS_H |
|
18 #define LEMON_TRAITS_H |
|
19 |
|
20 #include <lemon/utility.h> |
|
21 |
|
22 ///\file |
|
23 ///\brief Traits for graphs and maps |
|
24 /// |
|
25 |
|
26 namespace lemon { |
|
27 template <typename _Graph, typename _Item> |
|
28 class ItemSetTraits {}; |
|
29 |
|
30 template <typename _Graph> |
|
31 class ItemSetTraits<_Graph, typename _Graph::Node> { |
|
32 public: |
|
33 |
|
34 typedef _Graph Graph; |
|
35 |
|
36 typedef typename Graph::Node Item; |
|
37 typedef typename Graph::NodeIt ItemIt; |
|
38 |
|
39 template <typename _Value> |
|
40 class Map : public Graph::template NodeMap<_Value> { |
|
41 public: |
|
42 typedef typename Graph::template NodeMap<_Value> Parent; |
|
43 typedef typename Parent::Value Value; |
|
44 |
|
45 Map(const Graph& _graph) : Parent(_graph) {} |
|
46 Map(const Graph& _graph, const Value& _value) |
|
47 : Parent(_graph, _value) {} |
|
48 }; |
|
49 |
|
50 }; |
|
51 |
|
52 template <typename _Graph> |
|
53 class ItemSetTraits<_Graph, typename _Graph::Edge> { |
|
54 public: |
|
55 |
|
56 typedef _Graph Graph; |
|
57 |
|
58 typedef typename Graph::Edge Item; |
|
59 typedef typename Graph::EdgeIt ItemIt; |
|
60 |
|
61 template <typename _Value> |
|
62 class Map : public Graph::template EdgeMap<_Value> { |
|
63 public: |
|
64 typedef typename Graph::template EdgeMap<_Value> Parent; |
|
65 typedef typename Parent::Value Value; |
|
66 |
|
67 Map(const Graph& _graph) : Parent(_graph) {} |
|
68 Map(const Graph& _graph, const Value& _value) |
|
69 : Parent(_graph, _value) {} |
|
70 }; |
|
71 |
|
72 }; |
|
73 |
|
74 template <typename _Graph> |
|
75 class ItemSetTraits<_Graph, typename _Graph::UndirEdge> { |
|
76 public: |
|
77 |
|
78 typedef _Graph Graph; |
|
79 |
|
80 typedef typename Graph::UndirEdge Item; |
|
81 typedef typename Graph::UndirEdgeIt ItemIt; |
|
82 |
|
83 template <typename _Value> |
|
84 class Map : public Graph::template UndirEdgeMap<_Value> { |
|
85 public: |
|
86 typedef typename Graph::template UndirEdgeMap<_Value> Parent; |
|
87 typedef typename Parent::Value Value; |
|
88 |
|
89 Map(const Graph& _graph) : Parent(_graph) {} |
|
90 Map(const Graph& _graph, const Value& _value) |
|
91 : Parent(_graph, _value) {} |
|
92 }; |
|
93 |
|
94 }; |
|
95 |
|
96 template <typename Map, typename Enable = void> |
|
97 struct MapTraits { |
|
98 typedef False ReferenceMapTag; |
|
99 |
|
100 typedef typename Map::Key Key; |
|
101 typedef typename Map::Value Value; |
|
102 |
|
103 typedef Value ConstReturnValue; |
|
104 typedef Value& ReturnValue; |
|
105 }; |
|
106 |
|
107 template <typename Map> |
|
108 struct MapTraits< |
|
109 Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > |
|
110 { |
|
111 typedef True ReferenceMapTag; |
|
112 |
|
113 typedef typename Map::Key Key; |
|
114 typedef typename Map::Value Value; |
|
115 |
|
116 typedef typename Map::ConstReference ConstReturnValue; |
|
117 typedef typename Map::Reference ReturnValue; |
|
118 |
|
119 typedef typename Map::ConstReference ConstReference; |
|
120 typedef typename Map::Reference Reference; |
|
121 }; |
|
122 |
|
123 // Indicators for the tags |
|
124 |
|
125 template <typename Graph, typename Enable = void> |
|
126 struct NodeNumTagIndicator { |
|
127 static const bool value = false; |
|
128 }; |
|
129 |
|
130 template <typename Graph> |
|
131 struct NodeNumTagIndicator< |
|
132 Graph, |
|
133 typename enable_if<typename Graph::NodeNumTag, void>::type |
|
134 > { |
|
135 static const bool value = true; |
|
136 }; |
|
137 |
|
138 template <typename Graph, typename Enable = void> |
|
139 struct EdgeNumTagIndicator { |
|
140 static const bool value = false; |
|
141 }; |
|
142 |
|
143 template <typename Graph> |
|
144 struct EdgeNumTagIndicator< |
|
145 Graph, |
|
146 typename enable_if<typename Graph::EdgeNumTag, void>::type |
|
147 > { |
|
148 static const bool value = true; |
|
149 }; |
|
150 |
|
151 template <typename Graph, typename Enable = void> |
|
152 struct FindEdgeTagIndicator { |
|
153 static const bool value = false; |
|
154 }; |
|
155 |
|
156 template <typename Graph> |
|
157 struct FindEdgeTagIndicator< |
|
158 Graph, |
|
159 typename enable_if<typename Graph::FindEdgeTag, void>::type |
|
160 > { |
|
161 static const bool value = true; |
|
162 }; |
|
163 |
|
164 |
|
165 |
|
166 } |
|
167 |
|
168 #endif // LEMON_MAPS_H |