[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 | * |
---|
[463] | 5 | * Copyright (C) 2003-2009 |
---|
[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] | 28 | namespace 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 | |
---|
| 154 | template <typename Map, typename Enable = void> |
---|
| 155 | struct MapTraits { |
---|
| 156 | typedef False ReferenceMapTag; |
---|
| 157 | |
---|
| 158 | typedef typename Map::Key Key; |
---|
| 159 | typedef typename Map::Value Value; |
---|
| 160 | |
---|
[184] | 161 | typedef Value ConstReturnValue; |
---|
| 162 | typedef Value ReturnValue; |
---|
[57] | 163 | }; |
---|
| 164 | |
---|
| 165 | template <typename Map> |
---|
| 166 | struct MapTraits< |
---|
[209] | 167 | Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > |
---|
[57] | 168 | { |
---|
| 169 | typedef True ReferenceMapTag; |
---|
[209] | 170 | |
---|
[57] | 171 | typedef typename Map::Key Key; |
---|
| 172 | typedef typename Map::Value Value; |
---|
| 173 | |
---|
| 174 | typedef typename Map::ConstReference ConstReturnValue; |
---|
| 175 | typedef typename Map::Reference ReturnValue; |
---|
| 176 | |
---|
[209] | 177 | typedef typename Map::ConstReference ConstReference; |
---|
[57] | 178 | typedef typename Map::Reference Reference; |
---|
| 179 | }; |
---|
| 180 | |
---|
| 181 | template <typename MatrixMap, typename Enable = void> |
---|
| 182 | struct MatrixMapTraits { |
---|
| 183 | typedef False ReferenceMapTag; |
---|
| 184 | |
---|
| 185 | typedef typename MatrixMap::FirstKey FirstKey; |
---|
| 186 | typedef typename MatrixMap::SecondKey SecondKey; |
---|
| 187 | typedef typename MatrixMap::Value Value; |
---|
| 188 | |
---|
[184] | 189 | typedef Value ConstReturnValue; |
---|
| 190 | typedef Value ReturnValue; |
---|
[57] | 191 | }; |
---|
| 192 | |
---|
| 193 | template <typename MatrixMap> |
---|
| 194 | struct MatrixMapTraits< |
---|
[209] | 195 | MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, |
---|
| 196 | void>::type > |
---|
[57] | 197 | { |
---|
| 198 | typedef True ReferenceMapTag; |
---|
[209] | 199 | |
---|
[57] | 200 | typedef typename MatrixMap::FirstKey FirstKey; |
---|
| 201 | typedef typename MatrixMap::SecondKey SecondKey; |
---|
| 202 | typedef typename MatrixMap::Value Value; |
---|
| 203 | |
---|
| 204 | typedef typename MatrixMap::ConstReference ConstReturnValue; |
---|
| 205 | typedef typename MatrixMap::Reference ReturnValue; |
---|
| 206 | |
---|
[209] | 207 | typedef typename MatrixMap::ConstReference ConstReference; |
---|
[57] | 208 | typedef typename MatrixMap::Reference Reference; |
---|
| 209 | }; |
---|
| 210 | |
---|
| 211 | // Indicators for the tags |
---|
| 212 | |
---|
[663] | 213 | template <typename GR, typename Enable = void> |
---|
[57] | 214 | struct NodeNumTagIndicator { |
---|
| 215 | static const bool value = false; |
---|
| 216 | }; |
---|
| 217 | |
---|
[663] | 218 | template <typename GR> |
---|
[57] | 219 | struct NodeNumTagIndicator< |
---|
[663] | 220 | GR, |
---|
| 221 | typename enable_if<typename GR::NodeNumTag, void>::type |
---|
[57] | 222 | > { |
---|
| 223 | static const bool value = true; |
---|
| 224 | }; |
---|
| 225 | |
---|
[663] | 226 | template <typename GR, typename Enable = void> |
---|
[372] | 227 | struct ArcNumTagIndicator { |
---|
| 228 | static const bool value = false; |
---|
| 229 | }; |
---|
| 230 | |
---|
[663] | 231 | template <typename GR> |
---|
[372] | 232 | struct ArcNumTagIndicator< |
---|
[663] | 233 | GR, |
---|
| 234 | typename enable_if<typename GR::ArcNumTag, void>::type |
---|
[372] | 235 | > { |
---|
| 236 | static const bool value = true; |
---|
| 237 | }; |
---|
| 238 | |
---|
[663] | 239 | template <typename GR, typename Enable = void> |
---|
[139] | 240 | struct EdgeNumTagIndicator { |
---|
[57] | 241 | static const bool value = false; |
---|
| 242 | }; |
---|
| 243 | |
---|
[663] | 244 | template <typename GR> |
---|
[139] | 245 | struct EdgeNumTagIndicator< |
---|
[663] | 246 | GR, |
---|
| 247 | typename enable_if<typename GR::EdgeNumTag, void>::type |
---|
[57] | 248 | > { |
---|
| 249 | static const bool value = true; |
---|
| 250 | }; |
---|
| 251 | |
---|
[663] | 252 | template <typename GR, typename Enable = void> |
---|
[372] | 253 | struct FindArcTagIndicator { |
---|
| 254 | static const bool value = false; |
---|
| 255 | }; |
---|
| 256 | |
---|
[663] | 257 | template <typename GR> |
---|
[372] | 258 | struct FindArcTagIndicator< |
---|
[663] | 259 | GR, |
---|
| 260 | typename enable_if<typename GR::FindArcTag, void>::type |
---|
[372] | 261 | > { |
---|
| 262 | static const bool value = true; |
---|
| 263 | }; |
---|
| 264 | |
---|
[663] | 265 | template <typename GR, typename Enable = void> |
---|
[139] | 266 | struct FindEdgeTagIndicator { |
---|
[57] | 267 | static const bool value = false; |
---|
| 268 | }; |
---|
| 269 | |
---|
[663] | 270 | template <typename GR> |
---|
[139] | 271 | struct FindEdgeTagIndicator< |
---|
[663] | 272 | GR, |
---|
| 273 | typename enable_if<typename GR::FindEdgeTag, void>::type |
---|
[57] | 274 | > { |
---|
| 275 | static const bool value = true; |
---|
| 276 | }; |
---|
| 277 | |
---|
[663] | 278 | template <typename GR, typename Enable = void> |
---|
[57] | 279 | struct UndirectedTagIndicator { |
---|
| 280 | static const bool value = false; |
---|
| 281 | }; |
---|
| 282 | |
---|
[663] | 283 | template <typename GR> |
---|
[57] | 284 | struct UndirectedTagIndicator< |
---|
[663] | 285 | GR, |
---|
| 286 | typename enable_if<typename GR::UndirectedTag, void>::type |
---|
[57] | 287 | > { |
---|
| 288 | static const bool value = true; |
---|
| 289 | }; |
---|
| 290 | |
---|
[663] | 291 | template <typename GR, typename Enable = void> |
---|
[57] | 292 | struct BuildTagIndicator { |
---|
| 293 | static const bool value = false; |
---|
| 294 | }; |
---|
| 295 | |
---|
[663] | 296 | template <typename GR> |
---|
[57] | 297 | struct BuildTagIndicator< |
---|
[663] | 298 | GR, |
---|
| 299 | typename enable_if<typename GR::BuildTag, void>::type |
---|
[57] | 300 | > { |
---|
| 301 | static const bool value = true; |
---|
| 302 | }; |
---|
| 303 | |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | #endif |
---|