X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrackiter.h;h=e2f1d85dfde9e682cc0d3a7b2f555bdd0d0313d9;hb=9def58c4bbec8788430740a1e9afce64a496231f;hp=c91a7689b1ffa4bdd29303da46036d2c4659eee2;hpb=2bb6ce8ada216c0b2caa48f4639d03f2c581098e;p=r2c2.git diff --git a/source/libmarklin/trackiter.h b/source/libmarklin/trackiter.h index c91a768..e2f1d85 100644 --- a/source/libmarklin/trackiter.h +++ b/source/libmarklin/trackiter.h @@ -10,6 +10,7 @@ Distributed under the GPL #include #include +#include "tracktype.h" namespace Marklin { @@ -30,6 +31,7 @@ public: Track *track() const { return _track; } unsigned entry() const { return _entry; } + const TrackType::Endpoint &endpoint() const; private: int get_exit(unsigned) const; @@ -43,9 +45,41 @@ public: Track &operator*() const; Track *operator->() const { return _track; } bool operator==(const TrackIter &) const; + bool operator!=(const TrackIter &other) const { return !(*this==other); } operator bool() const { return _track!=0; } }; + +/** +A track iterator that detects looping. + +A list of visited tracks is maintained internally to the iterator. This list +is shared between iterators as long as next() is only called once per iterator. +Subsequent calls to next() cause the head of the list to be copied. +*/ +class TrackLoopIter: public TrackIter +{ +private: + typedef std::list TrackList; + + Msp::RefPtr _visited; + TrackList::iterator _last; + bool _looped; + +public: + TrackLoopIter(); + TrackLoopIter(Track *, unsigned); + TrackLoopIter(const TrackIter &); +private: + TrackLoopIter(const TrackIter &, Msp::RefPtr, const TrackList::iterator &); + +public: + bool looped() const { return _looped; } + + TrackLoopIter next() const; + TrackLoopIter next(unsigned) const; +}; + } // namespace Marklin #endif