]> git.tdb.fi Git - r2c2.git/commitdiff
Move driver.add_sensor call where it belongs
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Jul 2013 22:10:23 +0000 (01:10 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Jul 2013 23:45:18 +0000 (02:45 +0300)
source/libr2c2/beamgate.cpp
source/libr2c2/beamgate.h
source/libr2c2/sensor.cpp
source/libr2c2/sensor.h
source/libr2c2/track.cpp
source/libr2c2/trackcircuit.cpp
source/libr2c2/trackcircuit.h

index 550c97c4ca457ace5deed6f5c9fdec7ae8fe8562..614bce9657916152431cda52c1ce0853ba76c318 100644 (file)
@@ -34,11 +34,6 @@ const BeamGateType &BeamGate::get_type() const
        return BeamGateType::instance();
 }
 
-void BeamGate::set_address(unsigned a)
-{
-       address = a;
-}
-
 void BeamGate::set_position(const Vector &p)
 {
        position = p;
index c12afbf9964786eb2f69b81a403d90ee5d194434..8a3afe404680f08875101aba407bb3f1ef30233f 100644 (file)
@@ -30,7 +30,6 @@ public:
        virtual BeamGate *clone(Layout * = 0) const;
        virtual const BeamGateType &get_type() const;
 
-       void set_address(unsigned);
        virtual void set_position(const Vector &);
        virtual void set_rotation(const Angle &);
        virtual void set_tilt(const Angle &) { }
index 47e05f6068076063acc1e711fd97b480e66e406d..c31c795f12986e32fbd4f23e95c885e03d1aff2f 100644 (file)
@@ -23,6 +23,13 @@ Sensor::~Sensor()
        layout.remove(*this);
 }
 
+void Sensor::set_address(unsigned a)
+{
+       address = a;
+       if(layout.has_driver())
+               layout.get_driver().add_sensor(address);
+}
+
 void Sensor::tick(const Time::TimeDelta &dt)
 {
        if(state_confirm_timeout)
index f1525bf4d6a377d7e2b3fd6c1e07d462a9982ebf..13aaca3fe8e9a060e94db659372ecfc3433cf13e 100644 (file)
@@ -33,6 +33,7 @@ protected:
 public:
        virtual ~Sensor();
 
+       virtual void set_address(unsigned);
        unsigned get_address() const { return address; }
        State get_state() const { return state; }
        virtual Block *get_block() const { return 0; }
index 455cc88055c6301a8b7d53d29998a5d98cea8eb1..2a7cc6adc4b8ccc4c7c66ab8e8c5a9e037db9073 100644 (file)
@@ -169,8 +169,6 @@ void Track::set_sensor_id(unsigned i)
 
        sensor_id = i;
        layout.create_blocks(*this);
-       if(layout.has_driver() && sensor_id)
-               layout.get_driver().add_sensor(sensor_id);
 }
 
 void Track::set_active_path(unsigned p)
index 2bdfe8b2fe4ba63666472f71a1888fac015c5d94..7efe4d094cae020a88e7e154e2ecd38f105f2b09 100644 (file)
@@ -1,13 +1,21 @@
+#include <stdexcept>
 #include "block.h"
 #include "trackcircuit.h"
 
+using namespace std;
+
 namespace R2C2 {
 
 TrackCircuit::TrackCircuit(Layout &l, Block &b):
        Sensor(l),
        block(b)
 {
-       address = block.get_sensor_id();
+       Sensor::set_address(block.get_sensor_id());
+}
+
+void TrackCircuit::set_address(unsigned)
+{
+       throw logic_error("use Track::set_sensor_id");
 }
 
 } // namespace R2C2
index 19c11c7e40991f293dc145d40c8a1a5494f3d77c..f7760bbc73d93e7fac7b7d752b35ff12eac44a8a 100644 (file)
@@ -15,6 +15,7 @@ private:
 public:
        TrackCircuit(Layout &, Block &);
 
+       virtual void set_address(unsigned);
        virtual Block *get_block() const { return &block; }
 };