Distributed under the GPL
*/
+#include <algorithm>
#include <msp/core/except.h>
#include "track.h"
#include "trackiter.h"
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<Endpoint> &eps = _track->get_type().get_endpoints();
+ const vector<TrackType::Endpoint> &eps = _track->get_type().get_endpoints();
// Find an endpoint that's connected to the entry and has the requested path
for(unsigned i=0; i<eps.size(); ++i)
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