From: Mikko Rasa Date: Wed, 30 Oct 2013 22:21:57 +0000 (+0200) Subject: Detect conflicting blocks and avoid creating duplicate sensors X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=cf38d0a8208fab7ba7aaafc5eed9a86dfc3722a5;p=r2c2.git Detect conflicting blocks and avoid creating duplicate sensors --- diff --git a/source/libr2c2/block.cpp b/source/libr2c2/block.cpp index f02762c..33627f8 100644 --- a/source/libr2c2/block.cpp +++ b/source/libr2c2/block.cpp @@ -18,6 +18,7 @@ Block::Block(Layout &l, Track &start): id(0), sensor_id(start.get_sensor_id()), turnout_id(start.get_turnout_id()), + conflict(false), sensor(0), train(0) { @@ -44,7 +45,11 @@ Block::Block(Layout &l, Track &start): determine_id(); - if(sensor_id) + const set &blocks = layout.get_all(); + for(set::const_iterator i=blocks.begin(); (!conflict && i!=blocks.end()); ++i) + conflict = (id==(*i)->get_id()); + + if(!conflict && sensor_id) sensor = new TrackCircuit(layout, *this); layout.add(*this); diff --git a/source/libr2c2/block.h b/source/libr2c2/block.h index 558d425..c3b7c87 100644 --- a/source/libr2c2/block.h +++ b/source/libr2c2/block.h @@ -34,6 +34,7 @@ private: unsigned id; unsigned sensor_id; unsigned turnout_id; + bool conflict; TrackCircuit *sensor; std::vector endpoints; Train *train;