3 This file is part of R²C²
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #ifndef LIBR2C2_TRACKITER_H_
9 #define LIBR2C2_TRACKITER_H_
12 #include <msp/core/refptr.h>
13 #include "tracktype.h"
20 An iterator for traversing tracks.
30 TrackIter(Track *, unsigned);
32 Track *track() const { return _track; }
33 unsigned entry() const { return _entry; }
34 const TrackType::Endpoint &endpoint() const;
37 int get_exit(unsigned) const;
39 TrackIter next() const;
40 TrackIter next(unsigned) const;
41 TrackIter reverse() const;
42 TrackIter reverse(unsigned) const;
43 TrackIter flip() const;
45 Track &operator*() const;
46 Track *operator->() const { return _track; }
47 bool operator==(const TrackIter &) const;
48 bool operator!=(const TrackIter &other) const { return !(*this==other); }
49 operator bool() const { return _track!=0; }
54 A track iterator that detects looping.
56 A list of visited tracks is maintained internally to the iterator. This list
57 is shared between iterators as long as next() is only called once per iterator.
58 Subsequent calls to next() cause the head of the list to be copied.
60 class TrackLoopIter: public TrackIter
63 typedef std::list<Track *> TrackList;
65 Msp::RefPtr<TrackList> _visited;
66 TrackList::iterator _last;
71 TrackLoopIter(Track *, unsigned);
72 TrackLoopIter(const TrackIter &);
74 TrackLoopIter(const TrackIter &, Msp::RefPtr<TrackList>, const TrackList::iterator &);
77 bool looped() const { return _looped; }
79 TrackLoopIter next() const;
80 TrackLoopIter next(unsigned) const;