1 #include <msp/core/except.h>
12 BlockIter::BlockIter():
17 BlockIter::BlockIter(Block *b, unsigned e):
21 if(_block && _entry>_block->get_endpoints().size())
22 throw InvalidParameterValue("Endpoint index not valid for block");
25 TrackIter BlockIter::track_iter() const
30 const Block::Endpoint &ep = _block->get_endpoint(_entry);
31 return TrackIter(ep.track, ep.track_ep);
34 const Block::Endpoint &BlockIter::endpoint() const
37 throw InvalidState("BlockIter is null");
39 return _block->get_endpoint(_entry);
42 int BlockIter::get_exit(const Route *route) const
44 const vector<Block::Endpoint> &eps = _block->get_endpoints();
45 TrackIter t_iter = track_iter();
49 if(!_block->has_track(*t_iter))
50 throw LogicError("Block traversal strayed out of the block");
52 unsigned path = (route ? route->get_path(*t_iter) : t_iter->get_active_path());
53 TrackIter t_exit = t_iter.reverse(path);
55 for(unsigned i=0; i<eps.size(); ++i)
56 if(eps[i].track==t_exit.track() && eps[i].track_ep==t_exit.entry())
59 t_iter = t_exit.flip();
65 BlockIter BlockIter::next(const Route *route) const
70 int exit = get_exit(route);
75 result._block = _block->get_link(exit);
76 result._entry = (result._block ? result._block->get_endpoint_by_link(*_block) : 0);
81 BlockIter BlockIter::reverse(const Route *route) const
86 int exit = get_exit(route);
90 return BlockIter(_block, exit);
93 BlockIter BlockIter::flip() const
99 result._block = _block->get_link(_entry);
100 result._entry = (result._block ? result._block->get_endpoint_by_link(*_block) : 0);
105 Block &BlockIter::operator*() const
108 throw InvalidState("BlockIter is null");
113 bool BlockIter::operator==(const BlockIter &other) const
115 return _block==other._block && _entry==other._entry;