3 This file is part of R²C²
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/core/except.h>
10 #include "blockiter.h"
12 #include "trackiter.h"
19 BlockIter::BlockIter():
24 BlockIter::BlockIter(Block *b, unsigned e):
28 if(_block && _entry>_block->get_endpoints().size())
29 throw InvalidParameterValue("Endpoint index not valid for block");
32 TrackIter BlockIter::track_iter() const
37 const Block::Endpoint &ep = _block->get_endpoint(_entry);
38 return TrackIter(ep.track, ep.track_ep);
41 const Block::Endpoint &BlockIter::endpoint() const
44 throw InvalidState("BlockIter is null");
46 return _block->get_endpoint(_entry);
49 int BlockIter::get_exit(const Route *route) const
51 const vector<Block::Endpoint> &eps = _block->get_endpoints();
52 TrackIter t_iter = track_iter();
56 if(!_block->has_track(*t_iter))
57 throw LogicError("Block traversal strayed out of the block");
59 unsigned path = (route ? route->get_path(*t_iter) : t_iter->get_active_path());
60 TrackIter t_exit = t_iter.reverse(path);
62 for(unsigned i=0; i<eps.size(); ++i)
63 if(eps[i].track==t_exit.track() && eps[i].track_ep==t_exit.entry())
66 t_iter = t_exit.flip();
72 BlockIter BlockIter::next(const Route *route) const
77 int exit = get_exit(route);
82 result._block = _block->get_link(exit);
83 result._entry = (result._block ? result._block->get_endpoint_by_link(*_block) : 0);
88 BlockIter BlockIter::reverse(const Route *route) const
93 int exit = get_exit(route);
97 return BlockIter(_block, exit);
100 BlockIter BlockIter::flip() const
106 result._block = _block->get_link(_entry);
107 result._entry = (result._block ? result._block->get_endpoint_by_link(*_block) : 0);
112 Block &BlockIter::operator*() const
115 throw InvalidState("BlockIter is null");
120 bool BlockIter::operator==(const BlockIter &other) const
122 return _block==other._block && _entry==other._entry;