]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/trackiter.cpp
Make LCD output selectable at runtime through an extra I/O pin
[r2c2.git] / source / libmarklin / trackiter.cpp
index 6ee7231f924ebc9ab953f22c6ca922db81d010e4..b98022862dd903c25779c507f5f2dfc540199e5b 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2010  Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
+#include <algorithm>
 #include <msp/core/except.h>
 #include "track.h"
 #include "trackiter.h"
@@ -28,6 +29,14 @@ TrackIter::TrackIter(Track *t, unsigned e):
                throw InvalidParameterValue("Endpoint index not valid for track");
 }
 
+const TrackType::Endpoint &TrackIter::endpoint() const
+{
+       if(!_track)
+               throw InvalidState("TrackIter is null");
+
+       return _track->get_type().get_endpoint(_entry);
+}
+
 int TrackIter::get_exit(unsigned path) const
 {
        const vector<TrackType::Endpoint> &eps = _track->get_type().get_endpoints();
@@ -109,4 +118,54 @@ bool TrackIter::operator==(const TrackIter &other) const
        return _track==other._track && _entry==other._entry;
 }
 
+
+TrackLoopIter::TrackLoopIter():
+       _looped(false)
+{ }
+
+TrackLoopIter::TrackLoopIter(Track *t, unsigned e):
+       TrackIter(t, e),
+       _visited(new TrackList()),
+       _last(_visited->insert(_visited->end(), track())),
+       _looped(false)
+{ }
+
+TrackLoopIter::TrackLoopIter(const TrackIter &i):
+       TrackIter(i),
+       _visited(new TrackList()),
+       _last(_visited->insert(_visited->end(), track())),
+       _looped(false)
+{ }
+
+TrackLoopIter::TrackLoopIter(const TrackIter &i, RefPtr<TrackList> v, const TrackList::iterator &l):
+       TrackIter(i),
+       _looped(false)
+{
+       if(track())
+       {
+               _visited = v;
+               _last = l;
+               _looped = (_visited && find(_visited->begin(), _last, track())!=_last);
+
+               ++_last;
+               if(_last!=_visited->end())
+               {
+                       _visited = new TrackList(_visited->begin(), _last);
+                       _last = _visited->end();
+               }
+               _visited->push_back(track());
+               --_last;
+       }
+}
+
+TrackLoopIter TrackLoopIter::next() const
+{
+       return TrackLoopIter(TrackIter::next(), _visited, _last);
+}
+
+TrackLoopIter TrackLoopIter::next(unsigned path) const
+{
+       return TrackLoopIter(TrackIter::next(path), _visited, _last);
+}
+
 } // namespace Marklin