]> git.tdb.fi Git - r2c2.git/commitdiff
Detect conflicting blocks and avoid creating duplicate sensors
authorMikko Rasa <tdb@tdb.fi>
Wed, 30 Oct 2013 22:21:57 +0000 (00:21 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 30 Oct 2013 22:21:57 +0000 (00:21 +0200)
source/libr2c2/block.cpp
source/libr2c2/block.h

index f02762c85a958e668b5b4e200c86bcbb877f0767..33627f8a7cf354afd006ace1b18436090d979441 100644 (file)
@@ -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<Block *> &blocks = layout.get_all<Block>();
+       for(set<Block *>::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);
index 558d425016ffe050a937ef47726536229b2b9eee..c3b7c8742fe8faa247b5af2948c885eea7c522a7 100644 (file)
@@ -34,6 +34,7 @@ private:
        unsigned id;
        unsigned sensor_id;
        unsigned turnout_id;
+       bool conflict;
        TrackCircuit *sensor;
        std::vector<Endpoint> endpoints;
        Train *train;