From 57cf14b4871320574487b0fea90c6aad48f7f774 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 2 Jun 2025 12:35:53 +0200 Subject: [PATCH] Removed reconstruct thing and thingtype in constructor --- Thing.cpp | 11 ++--------- Thing.h | 7 +------ Things/DifferentialDrive.cpp | 7 ++++--- Things/DigitalSensor.cpp | 15 +++------------ Things/Motor.cpp | 4 +++- Things/RelativeEncoder.cpp | 5 +++-- Things/TemperatureSensor.cpp | 12 +++--------- Things/TouchSensor.cpp | 3 ++- 8 files changed, 21 insertions(+), 43 deletions(-) diff --git a/Thing.cpp b/Thing.cpp index 5fc4c72..29e4f95 100644 --- a/Thing.cpp +++ b/Thing.cpp @@ -47,9 +47,9 @@ namespace RoboidControl //std::cout << this->owner->name << ": New root thing " << std::endl; } - Thing::Thing(unsigned char thingType, Thing *parent) + Thing::Thing(Thing *parent) { - this->type = thingType; + this->type = Type::Undetermined; this->position = Spherical::zero; this->positionUpdated = true; @@ -73,13 +73,6 @@ namespace RoboidControl std::cout << "Destroy thing " << this->name << std::endl; } - Thing Thing::Reconstruct(Participant *owner, unsigned char thingType, unsigned char thingId) - { - Thing thing = Thing(thingType, owner->root); - thing.id = thingId; - return thing; - } - #pragma endregion Init void Thing::SetName(const char *name) diff --git a/Thing.h b/Thing.h index 5e8a5a8..bce0053 100644 --- a/Thing.h +++ b/Thing.h @@ -58,8 +58,7 @@ class Thing { /// The owner will be the same as the owner of the parent thing, it will /// be Participant::LocalParticipant if the parent is not specified. A thing /// without a parent will be a root thing. - Thing(unsigned char thingType = Thing::Type::Undetermined, - Thing* parent = LocalRoot()); + Thing(Thing* parent = LocalRoot()); /// @brief Create a new child thing /// @param parent The parent thing @@ -70,10 +69,6 @@ class Thing { ~Thing(); - static Thing Reconstruct(Participant* owner, - unsigned char thingType, - unsigned char thingId); - #pragma endregion Init public: diff --git a/Things/DifferentialDrive.cpp b/Things/DifferentialDrive.cpp index 14967ae..875b654 100644 --- a/Things/DifferentialDrive.cpp +++ b/Things/DifferentialDrive.cpp @@ -4,8 +4,8 @@ namespace RoboidControl { -DifferentialDrive::DifferentialDrive(Thing* parent) - : Thing(Type::DifferentialDrive, parent) { +DifferentialDrive::DifferentialDrive(Thing* parent) : Thing(parent) { + this->type = Type::DifferentialDrive; this->name = "Differential drive"; this->leftWheel = new Motor(this); @@ -18,7 +18,8 @@ DifferentialDrive::DifferentialDrive(Thing* parent) DifferentialDrive::DifferentialDrive(Motor* leftMotor, Motor* rightMotor, Thing* parent) - : Thing(Type::DifferentialDrive, parent) { + : Thing(parent) { + this->type = Type::DifferentialDrive; this->name = "Differential drive"; this->leftWheel = leftMotor; this->rightWheel = rightMotor; diff --git a/Things/DigitalSensor.cpp b/Things/DigitalSensor.cpp index ba0d859..35b9190 100644 --- a/Things/DigitalSensor.cpp +++ b/Things/DigitalSensor.cpp @@ -2,18 +2,9 @@ namespace RoboidControl { -//DigitalSensor::DigitalSensor() : Thing(Type::Switch) {} - -// DigitalSensor::DigitalSensor(Participant* owner, unsigned char thingId) -// : Thing(owner, Type::Switch, thingId) {} - -// DigitalSensor::DigitalSensor(Thing* parent, unsigned char thingId) -// : Thing(parent, Type::Switch) {} - -// DigitalSensor::DigitalSensor(Participant* owner) : Thing(owner, Type::Switch) {} - -// DigitalSensor::DigitalSensor(Thing* parent) : Thing(parent, Type::Switch) {} -DigitalSensor::DigitalSensor(Thing* parent) : Thing(Type::Switch, parent) {} +DigitalSensor::DigitalSensor(Thing* parent) : Thing(parent) { + this->type = Type::Switch; +} int DigitalSensor::GenerateBinary(char* bytes, unsigned char* ix) { bytes[(*ix)++] = state ? 1 : 0; diff --git a/Things/Motor.cpp b/Things/Motor.cpp index 12ab226..936d4ec 100644 --- a/Things/Motor.cpp +++ b/Things/Motor.cpp @@ -2,7 +2,9 @@ namespace RoboidControl { -Motor::Motor(Thing* parent) : Thing(Type::UncontrolledMotor, parent) {} +Motor::Motor(Thing* parent) : Thing(parent) { + this->type = Type::UncontrolledMotor; +} void Motor::SetTargetVelocity(float targetSpeed) { this->targetVelocity = targetSpeed; diff --git a/Things/RelativeEncoder.cpp b/Things/RelativeEncoder.cpp index 6e6a19c..573f84b 100644 --- a/Things/RelativeEncoder.cpp +++ b/Things/RelativeEncoder.cpp @@ -2,8 +2,9 @@ namespace RoboidControl { -RelativeEncoder::RelativeEncoder(Thing* parent) - : Thing(Type::IncrementalEncoder, parent) {} +RelativeEncoder::RelativeEncoder(Thing* parent) : Thing(parent) { + this->type = Type::IncrementalEncoder; +} float RelativeEncoder::GetRotationSpeed() { return rotationSpeed; diff --git a/Things/TemperatureSensor.cpp b/Things/TemperatureSensor.cpp index d67800b..39ecc41 100644 --- a/Things/TemperatureSensor.cpp +++ b/Things/TemperatureSensor.cpp @@ -4,15 +4,9 @@ namespace RoboidControl { -// TemperatureSensor::TemperatureSensor(Participant* participant, -// unsigned char thingId) -// : Thing(participant, Type::TemperatureSensor, thingId) {} - -// TemperatureSensor::TemperatureSensor(Participant* owner) : Thing(owner, Type::TemperatureSensor) {} - -TemperatureSensor::TemperatureSensor(Thing* parent) : Thing(Type::TemperatureSensor, parent) {} - -// TemperatureSensor::TemperatureSensor(Thing* parent) : Thing(parent, Type::TemperatureSensor) {} +TemperatureSensor::TemperatureSensor(Thing* parent) : Thing(parent) { + this->type = Type::TemperatureSensor; +} void TemperatureSensor::SetTemperature(float temp) { this->temperature = temp; diff --git a/Things/TouchSensor.cpp b/Things/TouchSensor.cpp index d1b9b41..85d9bbe 100644 --- a/Things/TouchSensor.cpp +++ b/Things/TouchSensor.cpp @@ -2,7 +2,8 @@ namespace RoboidControl { -TouchSensor::TouchSensor(Thing* parent) : Thing(Type::TouchSensor, parent) { +TouchSensor::TouchSensor(Thing* parent) : Thing(parent) { + this->type = Type::TouchSensor; this->name = "Touch sensor"; }