From: Mikko Rasa Date: Tue, 26 Oct 2010 18:30:46 +0000 (+0000) Subject: Don't give out a turnout ID that's already in use X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=bd649cbc44e04f5e456ca19b7a32ebe479c130e1;p=r2c2.git Don't give out a turnout ID that's already in use --- diff --git a/source/libmarklin/layout.cpp b/source/libmarklin/layout.cpp index f1bc321..338612a 100644 --- a/source/libmarklin/layout.cpp +++ b/source/libmarklin/layout.cpp @@ -75,9 +75,16 @@ void Layout::remove_track(Track &t) unsigned Layout::allocate_turnout_id(bool dbl) { - unsigned result = next_turnout_id++; - if(dbl) - ++next_turnout_id; + set used_ids; + for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + if((*i)->get_turnout_id()) + used_ids.insert((*i)->get_turnout_id()); + + unsigned result = next_turnout_id; + while(used_ids.count(result) || (dbl && used_ids.count(result+1))) + ++result; + next_turnout_id = result+1+dbl; + return result; }