]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/blockiter.h
Add TrackIter and BlockIter classes
[r2c2.git] / source / libmarklin / blockiter.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_BLOCKITER_H_
9 #define LIBMARKLIN_BLOCKITER_H_
10
11 namespace Marklin {
12
13 class Block;
14 class Route;
15 class TrackIter;
16
17 /**
18 An iterator for traversing blocks.
19 */
20 class BlockIter
21 {
22 private:
23         Block *_block;
24         unsigned _entry;
25
26 public:
27         BlockIter();
28         BlockIter(Block *, unsigned);
29
30         Block *block() const { return _block; }
31         unsigned entry() const { return _entry; }
32         TrackIter track_iter() const;
33
34 private:
35         int get_exit(const Route *) const;
36 public:
37         BlockIter next(const Route * = 0) const;
38         BlockIter reverse(const Route * = 0) const;
39         BlockIter flip() const;
40
41         Block &operator*() const;
42         Block *operator->() const { return _block; }
43         bool operator==(const BlockIter &) const;
44         bool operator!=(const BlockIter &other) const { return !(*this==other); }
45         operator bool() const { return _block!=0; }
46 };
47
48 } // namespace Marklin
49
50 #endif