]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/blockiter.h
Use max/min for range capping
[r2c2.git] / source / libr2c2 / blockiter.h
1 #ifndef LIBR2C2_BLOCKITER_H_
2 #define LIBR2C2_BLOCKITER_H_
3
4 #include "block.h"
5
6 namespace R2C2 {
7
8 class Route;
9 class TrackIter;
10
11 /**
12 An iterator for traversing blocks.
13 */
14 class BlockIter
15 {
16 private:
17         Block *_block;
18         unsigned _entry;
19
20 public:
21         BlockIter();
22         BlockIter(Block *, unsigned);
23
24         Block *block() const { return _block; }
25         unsigned entry() const { return _entry; }
26         TrackIter track_iter() const;
27         const Block::Endpoint &endpoint() const;
28
29 private:
30         int get_exit(const Route *) const;
31 public:
32         BlockIter next(const Route * = 0) const;
33         BlockIter reverse(const Route * = 0) const;
34         BlockIter flip() const;
35
36         Block &operator*() const;
37         Block *operator->() const { return _block; }
38         bool operator==(const BlockIter &) const;
39         bool operator!=(const BlockIter &other) const { return !(*this==other); }
40         operator bool() const { return _block!=0; }
41 };
42
43 } // namespace R2C2
44
45 #endif