]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/trackiter.h
Move the fitting part of Manipulator::connect to a separate function
[r2c2.git] / source / libmarklin / trackiter.h
index c91a7689b1ffa4bdd29303da46036d2c4659eee2..e7560611277ea06c7a45a9fa68fa93327ea3e8f6 100644 (file)
@@ -43,9 +43,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<Track *> TrackList;
+
+       Msp::RefPtr<TrackList> _visited;
+       TrackList::iterator _last;
+       bool _looped;
+
+public:
+       TrackLoopIter();
+       TrackLoopIter(Track *, unsigned);
+       TrackLoopIter(const TrackIter &);
+private:
+       TrackLoopIter(const TrackIter &, Msp::RefPtr<TrackList>, const TrackList::iterator &);
+
+public:
+       bool looped() const { return _looped; }
+
+       TrackLoopIter next() const;
+       TrackLoopIter next(unsigned) const;
+};
+
 } // namespace Marklin
 
 #endif