From a4a6af55ad5a9bfa14067532b1d1c914ef4c6668 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 9 Jul 2013 01:10:23 +0300 Subject: [PATCH] Move driver.add_sensor call where it belongs --- source/libr2c2/beamgate.cpp | 5 ----- source/libr2c2/beamgate.h | 1 - source/libr2c2/sensor.cpp | 7 +++++++ source/libr2c2/sensor.h | 1 + source/libr2c2/track.cpp | 2 -- source/libr2c2/trackcircuit.cpp | 10 +++++++++- source/libr2c2/trackcircuit.h | 1 + 7 files changed, 18 insertions(+), 9 deletions(-) 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 █ } }; -- 2.43.0