]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/trackiter.h
Don't bother with creating intermediate steps for state updates
[r2c2.git] / source / libr2c2 / trackiter.h
1 #ifndef LIBR2C2_TRACKITER_H_
2 #define LIBR2C2_TRACKITER_H_
3
4 #include <set>
5 #include <msp/core/refptr.h>
6 #include "tracktype.h"
7
8 namespace R2C2 {
9
10 class BlockIter;
11 class Track;
12
13 /**
14 An iterator for traversing tracks.
15 */
16 class TrackIter
17 {
18 private:
19         Track *_track;
20         unsigned _entry;
21
22 public:
23         TrackIter();
24         TrackIter(Track *, unsigned);
25
26         Track *track() const { return _track; }
27         unsigned entry() const { return _entry; }
28         BlockIter block_iter() const;
29         const TrackType::Endpoint &endpoint() const;
30
31 private:
32         int get_exit(unsigned) const;
33 public:
34         TrackIter next() const;
35         TrackIter next(unsigned) const;
36         TrackIter reverse() const;
37         TrackIter reverse(unsigned) const;
38         TrackIter flip() const;
39
40         Track &operator*() const;
41         Track *operator->() const { return _track; }
42         bool operator==(const TrackIter &) const;
43         bool operator!=(const TrackIter &other) const { return !(*this==other); }
44         operator bool() const { return _track!=0; }
45 };
46
47
48 /**
49 A track iterator that detects looping.
50
51 A list of visited tracks is maintained internally to the iterator.  This list
52 is shared between iterators as long as next() is only called once per iterator.
53 Subsequent calls to next() cause the head of the list to be copied.
54 */
55 class TrackLoopIter: public TrackIter
56 {
57 private:
58         typedef std::list<Track *> TrackList;
59
60         Msp::RefPtr<TrackList> _visited;
61         TrackList::iterator _last;
62         bool _looped;
63
64 public:
65         TrackLoopIter();
66         TrackLoopIter(Track *, unsigned);
67         TrackLoopIter(const TrackIter &);
68 private:
69         TrackLoopIter(const TrackIter &, Msp::RefPtr<TrackList>, const TrackList::iterator &);
70
71 public:
72         bool looped() const { return _looped; }
73
74         TrackLoopIter next() const;
75         TrackLoopIter next(unsigned) const;
76 };
77
78 } // namespace R2C2
79
80 #endif