From cf38d0a8208fab7ba7aaafc5eed9a86dfc3722a5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 31 Oct 2013 00:21:57 +0200 Subject: [PATCH] Detect conflicting blocks and avoid creating duplicate sensors --- source/libr2c2/block.cpp | 7 ++++++- source/libr2c2/block.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) 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; -- 2.45.2