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>
|
HashTable <ConstString, IdentifiableObject::Class>
|
||||||
*IdentifiableObject::classesByName =
|
*IdentifiableObject::classesByName =
|
||||||
new HashTable<ConstString, IdentifiableObject::Class> (true, true);
|
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::Class *IdentifiableObject::currentlyConstructedClass;
|
||||||
|
|
||||||
IdentifiableObject::IdentifiableObject ()
|
IdentifiableObject::IdentifiableObject ()
|
||||||
@ -85,11 +86,11 @@ void IdentifiableObject::registerName (const char *className, int *classId)
|
|||||||
ConstString str (className);
|
ConstString str (className);
|
||||||
Class *klass = classesByName->get (&str);
|
Class *klass = classesByName->get (&str);
|
||||||
if (klass == NULL) {
|
if (klass == NULL) {
|
||||||
klass = new Class (currentlyConstructedClass, classesById->size (),
|
klass = new Class (currentlyConstructedClass, classesById.size (),
|
||||||
className);
|
className);
|
||||||
ConstString *key = new ConstString (className);
|
ConstString *key = new ConstString (className);
|
||||||
classesByName->put (key, klass);
|
classesByName->put (key, klass);
|
||||||
classesById->put (klass);
|
classesById.push_back (klass);
|
||||||
*classId = klass->id;
|
*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.
|
// if this class is an instance of it or of a sub-class.
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Class *otherClass = classesById->get (otherClassId);
|
Class *otherClass = classesById.at (otherClassId);
|
||||||
|
|
||||||
if (otherClass == NULL) {
|
if (otherClass == NULL) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
@ -118,7 +119,7 @@ bool IdentifiableObject::instanceOf (int otherClassId)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Class *klass = classesById->get (classId); klass != NULL;
|
for (Class *klass = classesById.at (classId); klass != NULL;
|
||||||
klass = klass->parent) {
|
klass = klass->parent) {
|
||||||
if (klass == otherClass)
|
if (klass == otherClass)
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -98,7 +98,7 @@ namespace identity {
|
|||||||
class IdentifiableObject: public object::Object
|
class IdentifiableObject: public object::Object
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
class Class: public object::Object
|
class Class final: public object::Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Class *parent;
|
Class *parent;
|
||||||
@ -112,7 +112,7 @@ private:
|
|||||||
|
|
||||||
static container::typed::HashTable <object::ConstString,
|
static container::typed::HashTable <object::ConstString,
|
||||||
Class> *classesByName;
|
Class> *classesByName;
|
||||||
static container::typed::Vector <Class> *classesById;
|
static std::vector< Class * > classesById;
|
||||||
static Class *currentlyConstructedClass;
|
static Class *currentlyConstructedClass;
|
||||||
|
|
||||||
int classId;
|
int classId;
|
||||||
@ -137,7 +137,7 @@ public:
|
|||||||
* \brief Return the name, under which the class of this object was
|
* \brief Return the name, under which the class of this object was
|
||||||
* registered.
|
* registered.
|
||||||
*/
|
*/
|
||||||
const char *getClassName() { return classesById->get(classId)->className; }
|
const char *getClassName() { return classesById.at( classId )->className; }
|
||||||
|
|
||||||
bool instanceOf (int otherClassId);
|
bool instanceOf (int otherClassId);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user