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;
|
||||
|
@ -98,7 +98,7 @@ namespace identity {
|
||||
class IdentifiableObject: public object::Object
|
||||
{
|
||||
private:
|
||||
class Class: public object::Object
|
||||
class Class final: public object::Object
|
||||
{
|
||||
public:
|
||||
Class *parent;
|
||||
@ -112,7 +112,7 @@ private:
|
||||
|
||||
static container::typed::HashTable <object::ConstString,
|
||||
Class> *classesByName;
|
||||
static container::typed::Vector <Class> *classesById;
|
||||
static std::vector< Class * > classesById;
|
||||
static Class *currentlyConstructedClass;
|
||||
|
||||
int classId;
|
||||
@ -137,7 +137,7 @@ public:
|
||||
* \brief Return the name, under which the class of this object was
|
||||
* registered.
|
||||
*/
|
||||
const char *getClassName() { return classesById->get(classId)->className; }
|
||||
const char *getClassName() { return classesById.at( classId )->className; }
|
||||
|
||||
bool instanceOf (int otherClassId);
|
||||
};
|
||||
|
Reference in New Issue
Block a user