1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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.
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
19 #ifndef LEMON_BITS_TRAITS_H
20 #define LEMON_BITS_TRAITS_H
22 #include <lemon/bits/utility.h>
25 ///\brief Traits for graphs and maps
29 template <typename _Graph, typename _Item>
30 class ItemSetTraits {};
33 template <typename Graph, typename Enable = void>
34 struct NodeNotifierIndicator {
35 typedef InvalidType Type;
37 template <typename Graph>
38 struct NodeNotifierIndicator<
40 typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
42 typedef typename Graph::NodeNotifier Type;
45 template <typename _Graph>
46 class ItemSetTraits<_Graph, typename _Graph::Node> {
51 typedef typename Graph::Node Item;
52 typedef typename Graph::NodeIt ItemIt;
54 typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier;
56 template <typename _Value>
57 class Map : public Graph::template NodeMap<_Value> {
59 typedef typename Graph::template NodeMap<_Value> Parent;
60 typedef typename Graph::template NodeMap<_Value> Type;
61 typedef typename Parent::Value Value;
63 Map(const Graph& _digraph) : Parent(_digraph) {}
64 Map(const Graph& _digraph, const Value& _value)
65 : Parent(_digraph, _value) {}
71 template <typename Graph, typename Enable = void>
72 struct ArcNotifierIndicator {
73 typedef InvalidType Type;
75 template <typename Graph>
76 struct ArcNotifierIndicator<
78 typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
80 typedef typename Graph::ArcNotifier Type;
83 template <typename _Graph>
84 class ItemSetTraits<_Graph, typename _Graph::Arc> {
89 typedef typename Graph::Arc Item;
90 typedef typename Graph::ArcIt ItemIt;
92 typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier;
94 template <typename _Value>
95 class Map : public Graph::template ArcMap<_Value> {
97 typedef typename Graph::template ArcMap<_Value> Parent;
98 typedef typename Graph::template ArcMap<_Value> Type;
99 typedef typename Parent::Value Value;
101 Map(const Graph& _digraph) : Parent(_digraph) {}
102 Map(const Graph& _digraph, const Value& _value)
103 : Parent(_digraph, _value) {}
108 template <typename Graph, typename Enable = void>
109 struct EdgeNotifierIndicator {
110 typedef InvalidType Type;
112 template <typename Graph>
113 struct EdgeNotifierIndicator<
115 typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
117 typedef typename Graph::EdgeNotifier Type;
120 template <typename _Graph>
121 class ItemSetTraits<_Graph, typename _Graph::Edge> {
124 typedef _Graph Graph;
126 typedef typename Graph::Edge Item;
127 typedef typename Graph::EdgeIt ItemIt;
129 typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier;
131 template <typename _Value>
132 class Map : public Graph::template EdgeMap<_Value> {
134 typedef typename Graph::template EdgeMap<_Value> Parent;
135 typedef typename Graph::template EdgeMap<_Value> Type;
136 typedef typename Parent::Value Value;
138 Map(const Graph& _digraph) : Parent(_digraph) {}
139 Map(const Graph& _digraph, const Value& _value)
140 : Parent(_digraph, _value) {}
145 template <typename Map, typename Enable = void>
147 typedef False ReferenceMapTag;
149 typedef typename Map::Key Key;
150 typedef typename Map::Value Value;
152 typedef Value ConstReturnValue;
153 typedef Value ReturnValue;
156 template <typename Map>
158 Map, typename enable_if<typename Map::ReferenceMapTag, void>::type >
160 typedef True ReferenceMapTag;
162 typedef typename Map::Key Key;
163 typedef typename Map::Value Value;
165 typedef typename Map::ConstReference ConstReturnValue;
166 typedef typename Map::Reference ReturnValue;
168 typedef typename Map::ConstReference ConstReference;
169 typedef typename Map::Reference Reference;
172 template <typename MatrixMap, typename Enable = void>
173 struct MatrixMapTraits {
174 typedef False ReferenceMapTag;
176 typedef typename MatrixMap::FirstKey FirstKey;
177 typedef typename MatrixMap::SecondKey SecondKey;
178 typedef typename MatrixMap::Value Value;
180 typedef Value ConstReturnValue;
181 typedef Value ReturnValue;
184 template <typename MatrixMap>
185 struct MatrixMapTraits<
186 MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
189 typedef True ReferenceMapTag;
191 typedef typename MatrixMap::FirstKey FirstKey;
192 typedef typename MatrixMap::SecondKey SecondKey;
193 typedef typename MatrixMap::Value Value;
195 typedef typename MatrixMap::ConstReference ConstReturnValue;
196 typedef typename MatrixMap::Reference ReturnValue;
198 typedef typename MatrixMap::ConstReference ConstReference;
199 typedef typename MatrixMap::Reference Reference;
202 // Indicators for the tags
204 template <typename Graph, typename Enable = void>
205 struct NodeNumTagIndicator {
206 static const bool value = false;
209 template <typename Graph>
210 struct NodeNumTagIndicator<
212 typename enable_if<typename Graph::NodeNumTag, void>::type
214 static const bool value = true;
217 template <typename Graph, typename Enable = void>
218 struct EdgeNumTagIndicator {
219 static const bool value = false;
222 template <typename Graph>
223 struct EdgeNumTagIndicator<
225 typename enable_if<typename Graph::EdgeNumTag, void>::type
227 static const bool value = true;
230 template <typename Graph, typename Enable = void>
231 struct FindEdgeTagIndicator {
232 static const bool value = false;
235 template <typename Graph>
236 struct FindEdgeTagIndicator<
238 typename enable_if<typename Graph::FindEdgeTag, void>::type
240 static const bool value = true;
243 template <typename Graph, typename Enable = void>
244 struct UndirectedTagIndicator {
245 static const bool value = false;
248 template <typename Graph>
249 struct UndirectedTagIndicator<
251 typename enable_if<typename Graph::UndirectedTag, void>::type
253 static const bool value = true;
256 template <typename Graph, typename Enable = void>
257 struct BuildTagIndicator {
258 static const bool value = false;
261 template <typename Graph>
262 struct BuildTagIndicator<
264 typename enable_if<typename Graph::BuildTag, void>::type
266 static const bool value = true;