Skip to main content
GameDev.net gamedev.net
🔒 Locked

Getting type information from class hierarchies without instances

Started by Dom77 Oct 15, 2007 at 4:35 AM 0 replies 950+ views
Original Post
Dom77
Dom77
I'd like to store Class information in some kind of registry, so I can use them at run-time (editor etc). My problem is, that I don't know how I could access my custom RTTI in the sub-classes without having instances. Basically I have a common base class (Object) and a ObjectFactory. An ID creates an instance of a specific class. For my RTTI stuff I have virtual member functions that do return the classID, baseClassID and static strings for names (like ClassNames etc). I could manually rrgister every aspect/info of a class, but I would love if it goes nearly automatic, by having a single 'register' call and then the registry class polls all the info it wants to store. To add a class to the factory, I've a templated method

register<MyClass>(ClassType_ID)

Inside I'd like to extend it in a simple way like this

ObjectRegistry::getSingleton().Register<MyClass>(unique_id);

and in there I'd like to have a bit like this:


           template<typename ClassType>
           void Register(ClassTypeID classTypeID)
           {
               ClassInfo newInfo;

               newInfo.classID = classTypeID;
               newInfo.baseClassID = ClassType::getBaseClassTypeID();
               // much more class infos added here, like names as strings, descriptions etc
               // (...)
                         // then adding it to different tables for different type of queries
               mRegisteredClassInfos[classTypeID] = newInfo;
               // (...)                       }

Now in the code example above, I use a static method - but in reality / in my implementations these are virtual methods .... and ... static virtual does not exist as virtual needs a this pointer but I don't want to deal with objects sat that level. Any idea how to have RTTI thats also works for class hierarchies without instances? As alternative I could - as said - register all infos manually or use something like GCC-XML to generate XML data what could be the base for automatic code generation (like for script bindings) thx Dom
_________________Dom's Blog
iMalc
iMalc
Have you considered using COM?
Or if that isn't an option, perhaps looking into how COM implements this stuff?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.