throw KeyError("Unknown block", lexical_cast(id));
}
-Block &Layout::get_block_by_track(const Track &t) const
-{
- for(set<Block *>::const_iterator i=blocks.begin(); i!=blocks.end(); ++i)
- if((*i)->get_tracks().count(const_cast<Track *>(&t)))
- return **i;
-
- throw InvalidParameterValue("No block found for track");
-}
-
void Layout::create_blocks()
{
set<Track *> used_tracks;
(*i)->check_link(**j);
}
-void Layout::create_blocks(const Track &track)
+void Layout::create_blocks(Track &track)
{
+ /* Must collect the blocks in a set first while all tracks are still
+ guaranteed to have blocks and to avoid duplicate deletes */
+ set<Block *> del_blocks;
+
+ del_blocks.insert(&track.get_block());
+
const vector<Track *> &links = track.get_links();
- for(set<Block *>::iterator i=blocks.begin(); i!=blocks.end();)
- {
- bool del = (*i)->get_tracks().count(const_cast<Track *>(&track));
- for(vector<Track *>::const_iterator j=links.begin(); (!del && j!=links.end()); ++j)
- del = (*i)->get_tracks().count(*j);
-
- if(del)
- delete *i++;
- else
- ++i;
- }
+ for(vector<Track *>::const_iterator i=links.begin(); i!=links.end(); ++i)
+ if(*i)
+ del_blocks.insert(&(*i)->get_block());
+
+ for(set<Block *>::iterator i=del_blocks.begin(); i!=del_blocks.end(); ++i)
+ delete *i;
create_blocks();
}