Extended use of CoreThing

This commit is contained in:
Pascal Serrarens 2024-12-14 10:45:43 +01:00
parent 66c4b4ca7a
commit 7bcd80087a
4 changed files with 33 additions and 41 deletions

View File

@ -8,31 +8,31 @@ CoreThing::CoreThing(
this->type = thingType;
this->networkId = networkId;
this->Init();
// CoreThings::Add(this);
CoreThing::Add(this);
}
void CoreThing::Init() {}
// CoreThing *CoreThings::allThings[256] = {nullptr};
CoreThing *CoreThing::allThings[256] = {nullptr};
// CoreThing *CoreThings::Get(unsigned char networkId, unsigned char thingId) {
// for (unsigned char ix = 0; ix < 256; ix++) {
// CoreThing *thing = allThings[ix];
// if (thing == nullptr)
// continue;
// if (thing->networkId == networkId && thing->id == thingId)
// return thing;
// }
// return nullptr;
// }
CoreThing *CoreThing::Get(unsigned char networkId, unsigned char thingId) {
for (unsigned char ix = 0; ix < 256; ix++) {
CoreThing *thing = allThings[ix];
if (thing == nullptr)
continue;
if (thing->networkId == networkId && thing->id == thingId)
return thing;
}
return nullptr;
}
// bool CoreThings::Add(CoreThing *newThing) {
// for (unsigned char ix = 0; ix < 256; ix++) {
// CoreThing *thing = allThings[ix];
// if (thing == nullptr) {
// allThings[ix] = newThing;
// return true;
// }
// }
// return false;
// }
bool CoreThing::Add(CoreThing *newThing) {
for (unsigned char ix = 0; ix < 256; ix++) {
CoreThing *thing = allThings[ix];
if (thing == nullptr) {
allThings[ix] = newThing;
return true;
}
}
return false;
}

View File

@ -15,27 +15,19 @@ public:
const char *modelUrl;
// protected Sensor sensor;
static CoreThing *allThings[];
public:
CoreThing(
// Participant *client,
unsigned char networkId, unsigned char thingId,
unsigned char thingType = 0);
static CoreThing *Get(unsigned char networkId, unsigned char thingId);
static bool Add(CoreThing *thing);
protected:
virtual void Init();
// Things
};
// class CoreThings {
// friend class CoreThing;
// public:
// static CoreThing *allThings[];
// public:
// static CoreThing *Get(unsigned char networkId, unsigned char thingId);
// static bool Add(CoreThing *thing);
// };
} // namespace Passer::Control

View File

@ -6,8 +6,8 @@ using namespace Passer::RoboidControl;
int Thing::lastThingId = 1;
Thing::Thing() {
//: CoreThing(0, lastThingId++, (unsigned char)Type::Undetermined) {
Thing::Thing()
: CoreThing(0, lastThingId++, (unsigned char)Type::Undetermined) {
this->id = lastThingId++;
this->type = (unsigned int)Type::Undetermined;
this->childCount = 0;
@ -15,14 +15,14 @@ Thing::Thing() {
this->children = nullptr;
}
Thing::Thing(unsigned char id) {
//: CoreThing(0, id, (unsigned char)Type::Undetermined) {
Thing::Thing(unsigned char id)
: CoreThing(0, id, (unsigned char)Type::Undetermined) {
this->id = id;
// this->position = SphericalOf<signed short>::zero;
this->type = (unsigned int)Type::Undetermined;
this->childCount = 0;
this->parent = nullptr;
this->children = nullptr;
// this->position = SphericalOf<signed short>::zero;
}
void Thing::SetName(const char *name) { this->name = name; }

View File

@ -10,7 +10,7 @@ namespace Passer {
namespace RoboidControl {
/// @brief A thing is a functional component on a robot
class Thing { //: public CoreThing {
class Thing : public CoreThing {
public:
Thing();
/// @brief Default constructor for a Thing