Changeset 432:76287c8caa26 in lemon for lemon/bits
- Timestamp:
- 11/30/08 19:18:32 (16 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- lemon/bits
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/graph_adaptor_extender.h
r430 r432 1 /* -*- C++-*-1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 2 * 3 * This file is a part of LEMON, a generic C++ optimization library 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 25 25 #include <lemon/bits/default_map.h> 26 26 27 28 ///\ingroup digraphbits29 ///\file30 ///\brief Extenders for the digraph adaptor types31 27 namespace lemon { 32 28 33 /// \ingroup digraphbits34 ///35 /// \brief Extender for the DigraphAdaptors36 29 template <typename _Digraph> 37 30 class DigraphAdaptorExtender : public _Digraph { … … 65 58 Node oppositeNode(const Node &n, const Arc &e) const { 66 59 if (n == Parent::source(e)) 67 60 return Parent::target(e); 68 61 else if(n==Parent::target(e)) 69 62 return Parent::source(e); 70 63 else 71 72 } 73 74 class NodeIt : public Node { 64 return INVALID; 65 } 66 67 class NodeIt : public Node { 75 68 const Adaptor* _adaptor; 76 69 public: … … 81 74 82 75 explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) { 83 84 } 85 86 NodeIt(const Adaptor& adaptor, const Node& node) 87 88 89 NodeIt& operator++() { 90 91 return *this; 92 } 93 94 }; 95 96 97 class ArcIt : public Arc { 76 _adaptor->first(static_cast<Node&>(*this)); 77 } 78 79 NodeIt(const Adaptor& adaptor, const Node& node) 80 : Node(node), _adaptor(&adaptor) {} 81 82 NodeIt& operator++() { 83 _adaptor->next(*this); 84 return *this; 85 } 86 87 }; 88 89 90 class ArcIt : public Arc { 98 91 const Adaptor* _adaptor; 99 92 public: … … 104 97 105 98 explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) { 106 107 } 108 109 ArcIt(const Adaptor& adaptor, const Arc& e) : 110 111 112 ArcIt& operator++() { 113 114 return *this; 115 } 116 117 }; 118 119 120 class OutArcIt : public Arc { 99 _adaptor->first(static_cast<Arc&>(*this)); 100 } 101 102 ArcIt(const Adaptor& adaptor, const Arc& e) : 103 Arc(e), _adaptor(&adaptor) { } 104 105 ArcIt& operator++() { 106 _adaptor->next(*this); 107 return *this; 108 } 109 110 }; 111 112 113 class OutArcIt : public Arc { 121 114 const Adaptor* _adaptor; 122 115 public: … … 126 119 OutArcIt(Invalid i) : Arc(i) { } 127 120 128 OutArcIt(const Adaptor& adaptor, const Node& node) 129 130 131 } 132 133 OutArcIt(const Adaptor& adaptor, const Arc& arc) 134 135 136 OutArcIt& operator++() { 137 138 return *this; 139 } 140 141 }; 142 143 144 class InArcIt : public Arc { 121 OutArcIt(const Adaptor& adaptor, const Node& node) 122 : _adaptor(&adaptor) { 123 _adaptor->firstOut(*this, node); 124 } 125 126 OutArcIt(const Adaptor& adaptor, const Arc& arc) 127 : Arc(arc), _adaptor(&adaptor) {} 128 129 OutArcIt& operator++() { 130 _adaptor->nextOut(*this); 131 return *this; 132 } 133 134 }; 135 136 137 class InArcIt : public Arc { 145 138 const Adaptor* _adaptor; 146 139 public: … … 150 143 InArcIt(Invalid i) : Arc(i) { } 151 144 152 InArcIt(const Adaptor& adaptor, const Node& node) 153 : _adaptor(&adaptor) { 154 _adaptor->firstIn(*this, node); 155 } 156 157 InArcIt(const Adaptor& adaptor, const Arc& arc) : 158 Arc(arc), _adaptor(&adaptor) {} 159 160 InArcIt& operator++() { 161 _adaptor->nextIn(*this); 162 return *this; 163 } 164 165 }; 166 167 /// \brief Base node of the iterator 168 /// 169 /// Returns the base node (ie. the source in this case) of the iterator 145 InArcIt(const Adaptor& adaptor, const Node& node) 146 : _adaptor(&adaptor) { 147 _adaptor->firstIn(*this, node); 148 } 149 150 InArcIt(const Adaptor& adaptor, const Arc& arc) : 151 Arc(arc), _adaptor(&adaptor) {} 152 153 InArcIt& operator++() { 154 _adaptor->nextIn(*this); 155 return *this; 156 } 157 158 }; 159 170 160 Node baseNode(const OutArcIt &e) const { 171 161 return Parent::source(e); 172 162 } 173 /// \brief Running node of the iterator174 ///175 /// Returns the running node (ie. the target in this case) of the176 /// iterator177 163 Node runningNode(const OutArcIt &e) const { 178 164 return Parent::target(e); 179 165 } 180 166 181 /// \brief Base node of the iterator182 ///183 /// Returns the base node (ie. the target in this case) of the iterator184 167 Node baseNode(const InArcIt &e) const { 185 168 return Parent::target(e); 186 169 } 187 /// \brief Running node of the iterator188 ///189 /// Returns the running node (ie. the source in this case) of the190 /// iterator191 170 Node runningNode(const InArcIt &e) const { 192 171 return Parent::source(e); … … 199 178 /// 200 179 /// \brief Extender for the GraphAdaptors 201 template <typename _Graph> 180 template <typename _Graph> 202 181 class GraphAdaptorExtender : public _Graph { 203 182 public: 204 183 205 184 typedef _Graph Parent; 206 185 typedef _Graph Graph; … … 211 190 typedef typename Parent::Edge Edge; 212 191 213 // Graph extension 192 // Graph extension 214 193 215 194 int maxId(Node) const { … … 239 218 Node oppositeNode(const Node &n, const Edge &e) const { 240 219 if( n == Parent::u(e)) 241 220 return Parent::v(e); 242 221 else if( n == Parent::v(e)) 243 222 return Parent::u(e); 244 223 else 245 224 return INVALID; 246 225 } 247 226 … … 256 235 257 236 258 class NodeIt : public Node { 237 class NodeIt : public Node { 259 238 const Adaptor* _adaptor; 260 239 public: … … 265 244 266 245 explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) { 267 268 } 269 270 NodeIt(const Adaptor& adaptor, const Node& node) 271 272 273 NodeIt& operator++() { 274 275 return *this; 276 } 277 278 }; 279 280 281 class ArcIt : public Arc { 246 _adaptor->first(static_cast<Node&>(*this)); 247 } 248 249 NodeIt(const Adaptor& adaptor, const Node& node) 250 : Node(node), _adaptor(&adaptor) {} 251 252 NodeIt& operator++() { 253 _adaptor->next(*this); 254 return *this; 255 } 256 257 }; 258 259 260 class ArcIt : public Arc { 282 261 const Adaptor* _adaptor; 283 262 public: … … 288 267 289 268 explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) { 290 291 } 292 293 ArcIt(const Adaptor& adaptor, const Arc& e) : 294 295 296 ArcIt& operator++() { 297 298 return *this; 299 } 300 301 }; 302 303 304 class OutArcIt : public Arc { 269 _adaptor->first(static_cast<Arc&>(*this)); 270 } 271 272 ArcIt(const Adaptor& adaptor, const Arc& e) : 273 Arc(e), _adaptor(&adaptor) { } 274 275 ArcIt& operator++() { 276 _adaptor->next(*this); 277 return *this; 278 } 279 280 }; 281 282 283 class OutArcIt : public Arc { 305 284 const Adaptor* _adaptor; 306 285 public: … … 310 289 OutArcIt(Invalid i) : Arc(i) { } 311 290 312 OutArcIt(const Adaptor& adaptor, const Node& node) 313 314 315 } 316 317 OutArcIt(const Adaptor& adaptor, const Arc& arc) 318 319 320 OutArcIt& operator++() { 321 322 return *this; 323 } 324 325 }; 326 327 328 class InArcIt : public Arc { 291 OutArcIt(const Adaptor& adaptor, const Node& node) 292 : _adaptor(&adaptor) { 293 _adaptor->firstOut(*this, node); 294 } 295 296 OutArcIt(const Adaptor& adaptor, const Arc& arc) 297 : Arc(arc), _adaptor(&adaptor) {} 298 299 OutArcIt& operator++() { 300 _adaptor->nextOut(*this); 301 return *this; 302 } 303 304 }; 305 306 307 class InArcIt : public Arc { 329 308 const Adaptor* _adaptor; 330 309 public: … … 334 313 InArcIt(Invalid i) : Arc(i) { } 335 314 336 InArcIt(const Adaptor& adaptor, const Node& node) 337 338 339 } 340 341 InArcIt(const Adaptor& adaptor, const Arc& arc) : 342 343 344 InArcIt& operator++() { 345 346 return *this; 347 } 348 349 }; 350 351 class EdgeIt : public Parent::Edge { 315 InArcIt(const Adaptor& adaptor, const Node& node) 316 : _adaptor(&adaptor) { 317 _adaptor->firstIn(*this, node); 318 } 319 320 InArcIt(const Adaptor& adaptor, const Arc& arc) : 321 Arc(arc), _adaptor(&adaptor) {} 322 323 InArcIt& operator++() { 324 _adaptor->nextIn(*this); 325 return *this; 326 } 327 328 }; 329 330 class EdgeIt : public Parent::Edge { 352 331 const Adaptor* _adaptor; 353 332 public: … … 358 337 359 338 explicit EdgeIt(const Adaptor& adaptor) : _adaptor(&adaptor) { 360 361 } 362 363 EdgeIt(const Adaptor& adaptor, const Edge& e) : 364 365 366 EdgeIt& operator++() { 367 368 return *this; 369 } 370 371 }; 372 373 class IncEdgeIt : public Edge { 339 _adaptor->first(static_cast<Edge&>(*this)); 340 } 341 342 EdgeIt(const Adaptor& adaptor, const Edge& e) : 343 Edge(e), _adaptor(&adaptor) { } 344 345 EdgeIt& operator++() { 346 _adaptor->next(*this); 347 return *this; 348 } 349 350 }; 351 352 class IncEdgeIt : public Edge { 374 353 friend class GraphAdaptorExtender; 375 354 const Adaptor* _adaptor; … … 382 361 383 362 IncEdgeIt(const Adaptor& adaptor, const Node &n) : _adaptor(&adaptor) { 384 363 _adaptor->firstInc(static_cast<Edge&>(*this), direction, n); 385 364 } 386 365 387 366 IncEdgeIt(const Adaptor& adaptor, const Edge &e, const Node &n) 388 389 367 : _adaptor(&adaptor), Edge(e) { 368 direction = (_adaptor->u(e) == n); 390 369 } 391 370 392 371 IncEdgeIt& operator++() { 393 _adaptor->nextInc(*this, direction); 394 return *this; 395 } 396 }; 397 398 /// \brief Base node of the iterator 399 /// 400 /// Returns the base node (ie. the source in this case) of the iterator 372 _adaptor->nextInc(*this, direction); 373 return *this; 374 } 375 }; 376 401 377 Node baseNode(const OutArcIt &a) const { 402 378 return Parent::source(a); 403 379 } 404 /// \brief Running node of the iterator405 ///406 /// Returns the running node (ie. the target in this case) of the407 /// iterator408 380 Node runningNode(const OutArcIt &a) const { 409 381 return Parent::target(a); 410 382 } 411 383 412 /// \brief Base node of the iterator413 ///414 /// Returns the base node (ie. the target in this case) of the iterator415 384 Node baseNode(const InArcIt &a) const { 416 385 return Parent::target(a); 417 386 } 418 /// \brief Running node of the iterator419 ///420 /// Returns the running node (ie. the source in this case) of the421 /// iterator422 387 Node runningNode(const InArcIt &a) const { 423 388 return Parent::source(a); 424 389 } 425 390 426 /// Base node of the iterator427 ///428 /// Returns the base node of the iterator429 391 Node baseNode(const IncEdgeIt &e) const { 430 392 return e.direction ? Parent::u(e) : Parent::v(e); 431 393 } 432 /// Running node of the iterator433 ///434 /// Returns the running node of the iterator435 394 Node runningNode(const IncEdgeIt &e) const { 436 395 return e.direction ? Parent::v(e) : Parent::u(e); -
lemon/bits/variant.h
r430 r432 1 /* -*- C++-*-1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 2 * 3 * This file is a part of LEMON, a generic C++ optimization library 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 28 28 29 29 namespace _variant_bits { 30 30 31 31 template <int left, int right> 32 32 struct CTMax { … … 87 87 flag = bivariant.flag; 88 88 if (flag) { 89 new(reinterpret_cast<First*>(data)) First(bivariant.first()); 89 new(reinterpret_cast<First*>(data)) First(bivariant.first()); 90 90 } else { 91 new(reinterpret_cast<Second*>(data)) Second(bivariant.second()); 91 new(reinterpret_cast<Second*>(data)) Second(bivariant.second()); 92 92 } 93 93 } … … 107 107 destroy(); 108 108 flag = true; 109 new(reinterpret_cast<First*>(data)) First(); 109 new(reinterpret_cast<First*>(data)) First(); 110 110 return *this; 111 111 } … … 118 118 destroy(); 119 119 flag = true; 120 new(reinterpret_cast<First*>(data)) First(f); 120 new(reinterpret_cast<First*>(data)) First(f); 121 121 return *this; 122 122 } … … 129 129 destroy(); 130 130 flag = false; 131 new(reinterpret_cast<Second*>(data)) Second(); 131 new(reinterpret_cast<Second*>(data)) Second(); 132 132 return *this; 133 133 } … … 140 140 destroy(); 141 141 flag = false; 142 new(reinterpret_cast<Second*>(data)) Second(s); 142 new(reinterpret_cast<Second*>(data)) Second(s); 143 143 return *this; 144 144 } … … 160 160 flag = bivariant.flag; 161 161 if (flag) { 162 new(reinterpret_cast<First*>(data)) First(bivariant.first()); 162 new(reinterpret_cast<First*>(data)) First(bivariant.first()); 163 163 } else { 164 new(reinterpret_cast<Second*>(data)) Second(bivariant.second()); 164 new(reinterpret_cast<Second*>(data)) Second(bivariant.second()); 165 165 } 166 166 return *this; … … 232 232 } 233 233 } 234 234 235 235 char data[_variant_bits::CTMax<sizeof(First), sizeof(Second)>::value]; 236 236 bool flag; … … 238 238 239 239 namespace _variant_bits { 240 240 241 241 template <int _idx, typename _TypeMap> 242 242 struct Memory { … … 277 277 template <int _idx, typename _TypeMap> 278 278 struct Size { 279 static const int value = 280 CTMax<sizeof(typename _TypeMap::template Map<_idx>::Type), 279 static const int value = 280 CTMax<sizeof(typename _TypeMap::template Map<_idx>::Type), 281 281 Size<_idx - 1, _TypeMap>::value>::value; 282 282 }; … … 284 284 template <typename _TypeMap> 285 285 struct Size<0, _TypeMap> { 286 static const int value = 286 static const int value = 287 287 sizeof(typename _TypeMap::template Map<0>::Type); 288 288 }; … … 302 302 /// variant type. 303 303 /// \param _TypeMap This class describes the types of the Variant. The 304 /// _TypeMap::Map<index>::Type should be a valid type for each index 304 /// _TypeMap::Map<index>::Type should be a valid type for each index 305 305 /// in the range {0, 1, ..., _num - 1}. The \c VariantTypeMap is helper 306 306 /// class to define such type mappings up to 10 types. … … 338 338 Variant() { 339 339 flag = 0; 340 new(reinterpret_cast<typename TypeMap::template Map<0>::Type*>(data)) 340 new(reinterpret_cast<typename TypeMap::template Map<0>::Type*>(data)) 341 341 typename TypeMap::template Map<0>::Type(); 342 342 } … … 379 379 _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data); 380 380 flag = _idx; 381 new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data)) 381 new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data)) 382 382 typename TypeMap::template Map<_idx>::Type(); 383 383 return *this; … … 392 392 _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data); 393 393 flag = _idx; 394 new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data)) 394 new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data)) 395 395 typename TypeMap::template Map<_idx>::Type(init); 396 396 return *this; … … 404 404 LEMON_DEBUG(_idx == flag, "Variant wrong index"); 405 405 return *reinterpret_cast<const typename TypeMap:: 406 template Map<_idx>::Type*>(data); 406 template Map<_idx>::Type*>(data); 407 407 } 408 408 … … 414 414 LEMON_DEBUG(_idx == flag, "Variant wrong index"); 415 415 return *reinterpret_cast<typename TypeMap::template Map<_idx>::Type*> 416 (data); 416 (data); 417 417 } 418 418 … … 425 425 426 426 private: 427 427 428 428 char data[_variant_bits::Size<num - 1, TypeMap>::value]; 429 429 int flag; … … 443 443 444 444 struct List {}; 445 445 446 446 template <typename _Type, typename _List> 447 447 struct Insert { … … 450 450 }; 451 451 452 template <int _idx, typename _T0, typename _T1, typename _T2, 452 template <int _idx, typename _T0, typename _T1, typename _T2, 453 453 typename _T3, typename _T5, typename _T4, typename _T6, 454 454 typename _T7, typename _T8, typename _T9> … … 467 467 typedef typename Get<_idx, L0>::Type Type; 468 468 }; 469 469 470 470 } 471 471 … … 476 476 /// \see Variant 477 477 template < 478 typename _T0, 478 typename _T0, 479 479 typename _T1 = void, typename _T2 = void, typename _T3 = void, 480 480 typename _T5 = void, typename _T4 = void, typename _T6 = void, … … 488 488 }; 489 489 }; 490 490 491 491 } 492 492
Note: See TracChangeset
for help on using the changeset viewer.