ClassIDs are now actually typeinfo name pointers.

I'll see, next, about the `instanceOf` thing, and going with
more normal RTTI routes.
This commit is contained in:
2025-08-09 05:11:24 -04:00
parent abbb7fdbf9
commit c107600de6
26 changed files with 51 additions and 50 deletions

View File

@ -2,6 +2,7 @@
#define __LOUT_OBJECTX_HH__
#include <memory>
#include <typeindex>
#include <vector>
#include <map>
@ -106,22 +107,22 @@ private:
{
public:
Class *parent;
int id;
std::intptr_t id;
const char *className;
Class (Class *parent, int id, const char *className);
Class (Class *parent, std::type_index id, const char *className);
void intoStringBuffer(misc::StringBuffer *sb);
};
static std::map< std::string, std::unique_ptr< Class > > classesByName;
static std::vector< Class * > classesById;
static std::map< std::intptr_t, Class * > classesById;
static Class *currentlyConstructedClass;
int classId;
std::intptr_t classId;
protected:
void registerName (const char *className, int *classId);
void registerName (const char *className, std::type_index index, std::intptr_t *classId);
public:
IdentifiableObject ();
@ -134,7 +135,7 @@ public:
* This is rarely used, rather, tests with
* identity::IdentifiableObject::instanceOf are done.
*/
int getClassId () { return classId; }
std::intptr_t getClassId () { return classId; }
/**
* \brief Return the name, under which the class of this object was
@ -142,7 +143,7 @@ public:
*/
const char *getClassName() { return classesById.at( classId )->className; }
bool instanceOf (int otherClassId);
bool instanceOf (std::intptr_t otherClassId);
};
} // namespace identity