1 #include <msp/strings/format.h>
6 #include "trackoffsetiter.h"
13 incompatible_path::incompatible_path(unsigned a, unsigned e):
14 logic_error(format("got %d, but %d already set", a, e))
18 TrackOffsetIter::TrackOffsetIter():
23 TrackOffsetIter::TrackOffsetIter(Track *t, unsigned e, float o):
25 _offset(_track ? o : 0),
26 _path((_track && _offset) ? _track->get_active_path() : -1)
31 TrackOffsetIter::TrackOffsetIter(Track *t, unsigned e, unsigned p, float o):
39 TrackOffsetIter::TrackOffsetIter(const TrackIter &t, float o):
41 _offset(_track ? o : 0),
42 _path((_track && _offset) ? _track->get_active_path() : -1)
47 TrackOffsetIter::TrackOffsetIter(const TrackIter &t, unsigned p, float o):
55 void TrackOffsetIter::validate()
61 throw invalid_argument("TrackOffsetIter::TrackOffsetIter");
65 if(!_track.endpoint().has_path(_path))
66 throw invalid_argument("TrackOffsetIter::TrackOffsetIter");
67 if(_offset>_track->get_type().get_path_length(_path))
68 throw invalid_argument("TrackOffsetIter::TrackOffsetIter");
72 BlockIter TrackOffsetIter::block_iter() const
74 return _track.block_iter();
77 OrientedPoint TrackOffsetIter::point() const
80 return OrientedPoint();
83 return _track->get_point(_track.entry(), _path, _offset);
85 return _track->get_point(_track.entry(), _offset);
88 TrackOffsetIter TrackOffsetIter::next() const
91 return _track.next(_path);
96 TrackOffsetIter TrackOffsetIter::next(unsigned p) const
98 if(_path>=0 && static_cast<unsigned>(_path)!=p)
99 throw incompatible_path(_path, p);
101 return _track.next(p);
104 TrackOffsetIter TrackOffsetIter::advance(float d, const Route *r) const
107 return TrackOffsetIter();
110 return reverse().advance(-d, r).reverse();
112 TrackIter t = _track;
119 p = (r ? r->get_path(*t) : t->get_active_path());
120 p = t->get_type().coerce_path(t.entry(), p);
122 float length = t->get_type().get_path_length(p);
124 return TrackOffsetIter(t, p, o);
131 return TrackOffsetIter();
134 TrackOffsetIter TrackOffsetIter::reverse() const
137 return TrackOffsetIter();
139 int p = (_path>=0 ? _path : _track->get_active_path());
140 TrackIter t = _track.reverse(p);
142 return TrackOffsetIter();
144 float o = t->get_type().get_path_length(p)-_offset;
146 return TrackOffsetIter(t, p, o);
149 bool TrackOffsetIter::operator==(const TrackOffsetIter &other) const
151 return _track==other._track && _offset==other._offset && _path==other._path;