]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/trackiter.h
Strip Id tags and copyright notices from files
[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 Track;
11
12 /**
13 An iterator for traversing tracks.
14 */
15 class TrackIter
16 {
17 private:
18         Track *_track;
19         unsigned _entry;
20
21 public:
22         TrackIter();
23         TrackIter(Track *, unsigned);
24
25         Track *track() const { return _track; }
26         unsigned entry() const { return _entry; }
27         const TrackType::Endpoint &endpoint() const;
28
29 private:
30         int get_exit(unsigned) const;
31 public:
32         TrackIter next() const;
33         TrackIter next(unsigned) const;
34         TrackIter reverse() const;
35         TrackIter reverse(unsigned) const;
36         TrackIter flip() const;
37
38         Track &operator*() const;
39         Track *operator->() const { return _track; }
40         bool operator==(const TrackIter &) const;
41         bool operator!=(const TrackIter &other) const { return !(*this==other); }
42         operator bool() const { return _track!=0; }
43 };
44
45
46 /**
47 A track iterator that detects looping.
48
49 A list of visited tracks is maintained internally to the iterator.  This list
50 is shared between iterators as long as next() is only called once per iterator.
51 Subsequent calls to next() cause the head of the list to be copied.
52 */
53 class TrackLoopIter: public TrackIter
54 {
55 private:
56         typedef std::list<Track *> TrackList;
57
58         Msp::RefPtr<TrackList> _visited;
59         TrackList::iterator _last;
60         bool _looped;
61
62 public:
63         TrackLoopIter();
64         TrackLoopIter(Track *, unsigned);
65         TrackLoopIter(const TrackIter &);
66 private:
67         TrackLoopIter(const TrackIter &, Msp::RefPtr<TrackList>, const TrackList::iterator &);
68
69 public:
70         bool looped() const { return _looped; }
71
72         TrackLoopIter next() const;
73         TrackLoopIter next(unsigned) const;
74 };
75
76 } // namespace R2C2
77
78 #endif