Runtime determination of object type

What it says on the tin: a place to discuss proposed new features.
Post Reply
Clive Jackson
Greenskin
Posts: 123
Joined: Mon Jan 03, 2005 3:16 am
Contact:

Runtime determination of object type

Post by Clive Jackson »

It would be extremely helpful if I could determine the type of Node that has been returned to me from a method. Similar to the way the MovableObject.getMovableType() method works, Could a getNodeType() method be added to the Node class? Then TagPoint, Bone, SceneNode etc would override it and return the appropriate name. In my application is it not always possible to know what type of node to expect returned from some methods. The Entity.getParent() method is a good example of a Node being returned that could be a TagPoint or a SceneNode.

In a similar vein I have the same problem with Camera.getReflectionPlane() which returns a Plane. Yet the reflection plane could be either a Plane or a Moveable plane. Could the same approach be used? Adding a getPlaneType() method to Plane which MoveablePlane then overrides.

I’m not aware of any other way to solve these issues. However if there are I’m all ears. :)
Thanks
Clive
User avatar
Clay
OGRE Community Helper
OGRE Community Helper
Posts: 518
Joined: Wed Mar 17, 2004 4:14 am
Contact:

Post by Clay »

It's rare that you should actually need to use that. While I do NOT recommend doing this, you can simply use RTTI to find the value. Under linux RTTI is already turned on, under windows you'll need to compile ogre from source, and turn in RTTI under "language options" for all the major Ogre projects.

Then use the typeid and dynamic_cast operators to find out the information you need. This can be done without changing the ogre source.

Again, I'd suggest looking at your design to see if there is a way to get away with not using this.

Edit: It's typeid, not typid. I dunno where that e went to.
Clive Jackson
Greenskin
Posts: 123
Joined: Mon Jan 03, 2005 3:16 am
Contact:

Post by Clive Jackson »

RTTI is an approach, but as you say not the best one.

I'm working on a language binding so there is not much I can do with the design.

The use of getType() style methods is failrly prevelant within Ogre. With a precedence already established I assumed, maybe wrongly that this would be a reasonable enhancement.

Thanks for your help anyway.
User avatar
Clay
OGRE Community Helper
OGRE Community Helper
Posts: 518
Joined: Wed Mar 17, 2004 4:14 am
Contact:

Post by Clay »

Actually language bindings are one of the places that RTTI is very useful for. What language?
Clive Jackson
Greenskin
Posts: 123
Joined: Mon Jan 03, 2005 3:16 am
Contact:

Post by Clive Jackson »

JavaScript
Thanks
Clive
Post Reply