Start to simplify Identity.
It seems that this wants to be something like Java's `getClass` and `instanceof` feature. C++'s RTTI can do this too. For now, though, I'm just going to simplify this system to be more readable in "standard" C++ dialects. Then I can figure out what it's doing and how its used.
This commit is contained in:
@ -58,8 +58,9 @@ void IdentifiableObject::Class::intoStringBuffer(misc::StringBuffer *sb)
|
||||
HashTable <ConstString, IdentifiableObject::Class>
|
||||
*IdentifiableObject::classesByName =
|
||||
new HashTable<ConstString, IdentifiableObject::Class> (true, true);
|
||||
Vector <IdentifiableObject::Class> *IdentifiableObject::classesById =
|
||||
new Vector <IdentifiableObject::Class> (16, false);
|
||||
|
||||
std::vector< IdentifiableObject::Class * > IdentifiableObject::classesById;
|
||||
|
||||
IdentifiableObject::Class *IdentifiableObject::currentlyConstructedClass;
|
||||
|
||||
IdentifiableObject::IdentifiableObject ()
|
||||
@ -85,11 +86,11 @@ void IdentifiableObject::registerName (const char *className, int *classId)
|
||||
ConstString str (className);
|
||||
Class *klass = classesByName->get (&str);
|
||||
if (klass == NULL) {
|
||||
klass = new Class (currentlyConstructedClass, classesById->size (),
|
||||
klass = new Class (currentlyConstructedClass, classesById.size (),
|
||||
className);
|
||||
ConstString *key = new ConstString (className);
|
||||
classesByName->put (key, klass);
|
||||
classesById->put (klass);
|
||||
classesById.push_back (klass);
|
||||
*classId = klass->id;
|
||||
}
|
||||
|
||||
@ -109,7 +110,7 @@ bool IdentifiableObject::instanceOf (int otherClassId)
|
||||
// if this class is an instance of it or of a sub-class.
|
||||
return false;
|
||||
|
||||
Class *otherClass = classesById->get (otherClassId);
|
||||
Class *otherClass = classesById.at (otherClassId);
|
||||
|
||||
if (otherClass == NULL) {
|
||||
fprintf (stderr,
|
||||
@ -118,7 +119,7 @@ bool IdentifiableObject::instanceOf (int otherClassId)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Class *klass = classesById->get (classId); klass != NULL;
|
||||
for (Class *klass = classesById.at (classId); klass != NULL;
|
||||
klass = klass->parent) {
|
||||
if (klass == otherClass)
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user