Extended use of CoreThing
This commit is contained in:
parent
66c4b4ca7a
commit
7bcd80087a
@ -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;
|
||||
}
|
@ -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
|
||||
|
10
Thing.cpp
10
Thing.cpp
@ -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; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user