From: Mikko Rasa Date: Mon, 8 Jul 2013 22:10:23 +0000 (+0300) Subject: Move driver.add_sensor call where it belongs X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a4a6af55ad5a9bfa14067532b1d1c914ef4c6668;p=r2c2.git Move driver.add_sensor call where it belongs --- diff --git a/source/libr2c2/beamgate.cpp b/source/libr2c2/beamgate.cpp index 550c97c..614bce9 100644 --- a/source/libr2c2/beamgate.cpp +++ b/source/libr2c2/beamgate.cpp @@ -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; diff --git a/source/libr2c2/beamgate.h b/source/libr2c2/beamgate.h index c12afbf..8a3afe4 100644 --- a/source/libr2c2/beamgate.h +++ b/source/libr2c2/beamgate.h @@ -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 &) { } diff --git a/source/libr2c2/sensor.cpp b/source/libr2c2/sensor.cpp index 47e05f6..c31c795 100644 --- a/source/libr2c2/sensor.cpp +++ b/source/libr2c2/sensor.cpp @@ -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) diff --git a/source/libr2c2/sensor.h b/source/libr2c2/sensor.h index f1525bf..13aaca3 100644 --- a/source/libr2c2/sensor.h +++ b/source/libr2c2/sensor.h @@ -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; } diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 455cc88..2a7cc6a 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -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) diff --git a/source/libr2c2/trackcircuit.cpp b/source/libr2c2/trackcircuit.cpp index 2bdfe8b..7efe4d0 100644 --- a/source/libr2c2/trackcircuit.cpp +++ b/source/libr2c2/trackcircuit.cpp @@ -1,13 +1,21 @@ +#include #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 diff --git a/source/libr2c2/trackcircuit.h b/source/libr2c2/trackcircuit.h index 19c11c7..f7760bb 100644 --- a/source/libr2c2/trackcircuit.h +++ b/source/libr2c2/trackcircuit.h @@ -15,6 +15,7 @@ private: public: TrackCircuit(Layout &, Block &); + virtual void set_address(unsigned); virtual Block *get_block() const { return █ } };