[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 | * |
---|
[107] | 5 | * Copyright (C) 2003-2008 |
---|
[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 | |
---|
| 22 | #include <lemon/bits/utility.h> |
---|
| 23 | |
---|
| 24 | ///\file |
---|
| 25 | ///\brief Traits for graphs and maps |
---|
| 26 | /// |
---|
| 27 | |
---|
| 28 | namespace lemon { |
---|
| 29 | template <typename _Graph, typename _Item> |
---|
| 30 | class ItemSetTraits {}; |
---|
[209] | 31 | |
---|
[57] | 32 | |
---|
| 33 | template <typename Graph, typename Enable = void> |
---|
| 34 | struct NodeNotifierIndicator { |
---|
| 35 | typedef InvalidType Type; |
---|
| 36 | }; |
---|
| 37 | template <typename Graph> |
---|
| 38 | struct NodeNotifierIndicator< |
---|
[209] | 39 | Graph, |
---|
[57] | 40 | typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type |
---|
[209] | 41 | > { |
---|
[57] | 42 | typedef typename Graph::NodeNotifier Type; |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | template <typename _Graph> |
---|
| 46 | class ItemSetTraits<_Graph, typename _Graph::Node> { |
---|
| 47 | public: |
---|
[209] | 48 | |
---|
[57] | 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: |
---|
[209] | 59 | typedef typename Graph::template NodeMap<_Value> Parent; |
---|
| 60 | typedef typename Graph::template NodeMap<_Value> Type; |
---|
[57] | 61 | typedef typename Parent::Value Value; |
---|
| 62 | |
---|
| 63 | Map(const Graph& _digraph) : Parent(_digraph) {} |
---|
[209] | 64 | Map(const Graph& _digraph, const Value& _value) |
---|
| 65 | : Parent(_digraph, _value) {} |
---|
[57] | 66 | |
---|
| 67 | }; |
---|
| 68 | |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | template <typename Graph, typename Enable = void> |
---|
| 72 | struct ArcNotifierIndicator { |
---|
| 73 | typedef InvalidType Type; |
---|
| 74 | }; |
---|
| 75 | template <typename Graph> |
---|
| 76 | struct ArcNotifierIndicator< |
---|
[209] | 77 | Graph, |
---|
[57] | 78 | typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type |
---|
[209] | 79 | > { |
---|
[57] | 80 | typedef typename Graph::ArcNotifier Type; |
---|
| 81 | }; |
---|
| 82 | |
---|
| 83 | template <typename _Graph> |
---|
| 84 | class ItemSetTraits<_Graph, typename _Graph::Arc> { |
---|
| 85 | public: |
---|
[209] | 86 | |
---|
[57] | 87 | typedef _Graph Graph; |
---|
| 88 | |
---|
| 89 | typedef typename Graph::Arc Item; |
---|
| 90 | typedef typename Graph::ArcIt ItemIt; |
---|
| 91 | |
---|
| 92 | typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier; |
---|
| 93 | |
---|
| 94 | template <typename _Value> |
---|
| 95 | class Map : public Graph::template ArcMap<_Value> { |
---|
| 96 | public: |
---|
[209] | 97 | typedef typename Graph::template ArcMap<_Value> Parent; |
---|
| 98 | typedef typename Graph::template ArcMap<_Value> Type; |
---|
[57] | 99 | typedef typename Parent::Value Value; |
---|
| 100 | |
---|
| 101 | Map(const Graph& _digraph) : Parent(_digraph) {} |
---|
[209] | 102 | Map(const Graph& _digraph, const Value& _value) |
---|
| 103 | : Parent(_digraph, _value) {} |
---|
[57] | 104 | }; |
---|
| 105 | |
---|
| 106 | }; |
---|
| 107 | |
---|
| 108 | template <typename Graph, typename Enable = void> |
---|
| 109 | struct EdgeNotifierIndicator { |
---|
| 110 | typedef InvalidType Type; |
---|
| 111 | }; |
---|
| 112 | template <typename Graph> |
---|
| 113 | struct EdgeNotifierIndicator< |
---|
[209] | 114 | Graph, |
---|
[57] | 115 | typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type |
---|
[209] | 116 | > { |
---|
[57] | 117 | typedef typename Graph::EdgeNotifier Type; |
---|
| 118 | }; |
---|
| 119 | |
---|
| 120 | template <typename _Graph> |
---|
| 121 | class ItemSetTraits<_Graph, typename _Graph::Edge> { |
---|
| 122 | public: |
---|
[209] | 123 | |
---|
[57] | 124 | typedef _Graph Graph; |
---|
| 125 | |
---|
| 126 | typedef typename Graph::Edge Item; |
---|
| 127 | typedef typename Graph::EdgeIt ItemIt; |
---|
| 128 | |
---|
| 129 | typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier; |
---|
| 130 | |
---|
| 131 | template <typename _Value> |
---|
| 132 | class Map : public Graph::template EdgeMap<_Value> { |
---|
| 133 | public: |
---|
[209] | 134 | typedef typename Graph::template EdgeMap<_Value> Parent; |
---|
| 135 | typedef typename Graph::template EdgeMap<_Value> Type; |
---|
[57] | 136 | typedef typename Parent::Value Value; |
---|
| 137 | |
---|
| 138 | Map(const Graph& _digraph) : Parent(_digraph) {} |
---|
[209] | 139 | Map(const Graph& _digraph, const Value& _value) |
---|
| 140 | : Parent(_digraph, _value) {} |
---|
[57] | 141 | }; |
---|
| 142 | |
---|
| 143 | }; |
---|
| 144 | |
---|
| 145 | template <typename Map, typename Enable = void> |
---|
| 146 | struct MapTraits { |
---|
| 147 | typedef False ReferenceMapTag; |
---|
| 148 | |
---|
| 149 | typedef typename Map::Key Key; |
---|
| 150 | typedef typename Map::Value Value; |
---|
| 151 | |
---|
[184] | 152 | typedef Value ConstReturnValue; |
---|
| 153 | typedef Value ReturnValue; |
---|
[57] | 154 | }; |
---|
| 155 | |
---|
| 156 | template <typename Map> |
---|
| 157 | struct MapTraits< |
---|
[209] | 158 | Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > |
---|
[57] | 159 | { |
---|
| 160 | typedef True ReferenceMapTag; |
---|
[209] | 161 | |
---|
[57] | 162 | typedef typename Map::Key Key; |
---|
| 163 | typedef typename Map::Value Value; |
---|
| 164 | |
---|
| 165 | typedef typename Map::ConstReference ConstReturnValue; |
---|
| 166 | typedef typename Map::Reference ReturnValue; |
---|
| 167 | |
---|
[209] | 168 | typedef typename Map::ConstReference ConstReference; |
---|
[57] | 169 | typedef typename Map::Reference Reference; |
---|
| 170 | }; |
---|
| 171 | |
---|
| 172 | template <typename MatrixMap, typename Enable = void> |
---|
| 173 | struct MatrixMapTraits { |
---|
| 174 | typedef False ReferenceMapTag; |
---|
| 175 | |
---|
| 176 | typedef typename MatrixMap::FirstKey FirstKey; |
---|
| 177 | typedef typename MatrixMap::SecondKey SecondKey; |
---|
| 178 | typedef typename MatrixMap::Value Value; |
---|
| 179 | |
---|
[184] | 180 | typedef Value ConstReturnValue; |
---|
| 181 | typedef Value ReturnValue; |
---|
[57] | 182 | }; |
---|
| 183 | |
---|
| 184 | template <typename MatrixMap> |
---|
| 185 | struct MatrixMapTraits< |
---|
[209] | 186 | MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, |
---|
| 187 | void>::type > |
---|
[57] | 188 | { |
---|
| 189 | typedef True ReferenceMapTag; |
---|
[209] | 190 | |
---|
[57] | 191 | typedef typename MatrixMap::FirstKey FirstKey; |
---|
| 192 | typedef typename MatrixMap::SecondKey SecondKey; |
---|
| 193 | typedef typename MatrixMap::Value Value; |
---|
| 194 | |
---|
| 195 | typedef typename MatrixMap::ConstReference ConstReturnValue; |
---|
| 196 | typedef typename MatrixMap::Reference ReturnValue; |
---|
| 197 | |
---|
[209] | 198 | typedef typename MatrixMap::ConstReference ConstReference; |
---|
[57] | 199 | typedef typename MatrixMap::Reference Reference; |
---|
| 200 | }; |
---|
| 201 | |
---|
| 202 | // Indicators for the tags |
---|
| 203 | |
---|
| 204 | template <typename Graph, typename Enable = void> |
---|
| 205 | struct NodeNumTagIndicator { |
---|
| 206 | static const bool value = false; |
---|
| 207 | }; |
---|
| 208 | |
---|
| 209 | template <typename Graph> |
---|
| 210 | struct NodeNumTagIndicator< |
---|
[209] | 211 | Graph, |
---|
[57] | 212 | typename enable_if<typename Graph::NodeNumTag, void>::type |
---|
| 213 | > { |
---|
| 214 | static const bool value = true; |
---|
| 215 | }; |
---|
| 216 | |
---|
| 217 | template <typename Graph, typename Enable = void> |
---|
[139] | 218 | struct EdgeNumTagIndicator { |
---|
[57] | 219 | static const bool value = false; |
---|
| 220 | }; |
---|
| 221 | |
---|
| 222 | template <typename Graph> |
---|
[139] | 223 | struct EdgeNumTagIndicator< |
---|
[209] | 224 | Graph, |
---|
[139] | 225 | typename enable_if<typename Graph::EdgeNumTag, void>::type |
---|
[57] | 226 | > { |
---|
| 227 | static const bool value = true; |
---|
| 228 | }; |
---|
| 229 | |
---|
| 230 | template <typename Graph, typename Enable = void> |
---|
[139] | 231 | struct FindEdgeTagIndicator { |
---|
[57] | 232 | static const bool value = false; |
---|
| 233 | }; |
---|
| 234 | |
---|
| 235 | template <typename Graph> |
---|
[139] | 236 | struct FindEdgeTagIndicator< |
---|
[209] | 237 | Graph, |
---|
[139] | 238 | typename enable_if<typename Graph::FindEdgeTag, void>::type |
---|
[57] | 239 | > { |
---|
| 240 | static const bool value = true; |
---|
| 241 | }; |
---|
| 242 | |
---|
| 243 | template <typename Graph, typename Enable = void> |
---|
| 244 | struct UndirectedTagIndicator { |
---|
| 245 | static const bool value = false; |
---|
| 246 | }; |
---|
| 247 | |
---|
| 248 | template <typename Graph> |
---|
| 249 | struct UndirectedTagIndicator< |
---|
[209] | 250 | Graph, |
---|
[57] | 251 | typename enable_if<typename Graph::UndirectedTag, void>::type |
---|
| 252 | > { |
---|
| 253 | static const bool value = true; |
---|
| 254 | }; |
---|
| 255 | |
---|
| 256 | template <typename Graph, typename Enable = void> |
---|
| 257 | struct BuildTagIndicator { |
---|
| 258 | static const bool value = false; |
---|
| 259 | }; |
---|
| 260 | |
---|
| 261 | template <typename Graph> |
---|
| 262 | struct BuildTagIndicator< |
---|
[209] | 263 | Graph, |
---|
[57] | 264 | typename enable_if<typename Graph::BuildTag, void>::type |
---|
| 265 | > { |
---|
| 266 | static const bool value = true; |
---|
| 267 | }; |
---|
| 268 | |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | #endif |
---|