Is there a way to check what the type_info of a superclass is? In my system objects are identified by a set of bits. Which is Identified by the type_info hashcode. I would like some of these types to enable polymorphism in a sense that my system thinks they are under the same bit. type_info creates a unique hashcode for every class type. Instead I want the derived classes to take the bit set of their superclass like so:
Component > ISomeInterfaceComponent -> bit = 00001
|
\ ComponentContextA -> bit = ISomeInterFaceComponent bit
|
\ ComponentContextB -> bit = ISomeInterFaceComponent bit
|
\ ComponentContextC -> bit = ISomeInterFaceComponent bit
This should add the object containing the components to one system for processing.
As of right now this is what happens:
Component > ISomeInterFaceComponent -> bit = 00001
|
\ ComponentContextA -> bit = 00010
|
\ ComponentContextB -> bit = 00100
|
\ ComponentContextC -> bit = 01000
Which demands that I create different systems for all components.
If anyone could give me pointers on how I could achieve this that would be great.
Edit: To prevent confusion to get a bit set for a type it goes as follows: ComponentTypeManager::getBit();
So I'm not working with instances. And I would love to keep the current system in lock.
There isn't any automatic way that I'm aware of. However, if I'm understanding you, it can be done via little additional effort.
For each of your 'base' classes, add a typedef that refers to itself, and use that instead in the
typeid()
. Note, subclasses could choose to override it. If they do so, then they will get their own ID, and their children will use their value.Note, another solution, if you don't want to use
typeid()
at all is to have a static member (or member function) on the base classes that returns the proper value for the base, and then invoke that directly in your getBit() function.http://ideone.com/6ad08