IsInstanceOf() and GetType() w/plugins
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 25/01/2006 at 17:15, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 8.503
Platform: Windows ; Mac ; Mac OSX ;
Language(s) :---------
IsInstanceOf() and GetType() don't seem to work at determining if one plugin object is derived from another (say a base myTag and derived thisTagExtendsMyTag).Now, I need to do general checks on type against existing tags whether BaseTags or other PluginTags. Is there an easy way to determine if a tag is of a basic plugin type?
For instance, let's say that I have a PluginTag, ATag, and several derived PluginTags, BTag and CTag. Since IsInstanceOf() and GetType() work on PLUGIN_IDs, the derived tags fail checks with these. Could super/SUPER() be used in this case? Solutions seem murky.
Thanks,
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/01/2006 at 11:16, xxxxxxxx wrote:
No, C4D has no such information. After all, the only thing that's registered by RegisterTagPlugin() is that DataAllocator will output a TagData derived class with a specific ID. It doesn't care if it's TagData->BTag or TagData->ATag->BTag.
You will have to implement a system of your own afaics if you need to keep track of those things, for example by storing stuff in the containers. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/01/2006 at 11:19, xxxxxxxx wrote:
Would you suggest some sort of self-implemented RTTI (I've seen several online)?
Thanks, Mikael.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/01/2006 at 12:26, xxxxxxxx wrote:
Yes, essentially. Or the built-in C++ one if you're really adventurous. Though I don't know how well that works neither with current compilers nor with any C4D expectations on class layout.
I have no experience with available RTTI implementations. If I were you I'd probably build my own quick-n-dirty one. Simply put a Bool=TRUE at the parent classes' IDs in the container, easy enough if you chain Init() calls to the parents (as you always should). Then it becomes very easy to see if a tag is-an ATag, just see if it has ATag's ID set to TRUE. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/01/2006 at 14:18, xxxxxxxx wrote:
Yes, essentially. Or the built-in C++ one if you're really adventurous. Though I don't know how well that works neither with current compilers nor with any C4D expectations on class layout.
I have no experience with available RTTI implementations. If I were you I'd probably build my own quick-n-dirty one. Simply put a Bool=TRUE at the parent classes' IDs in the container, easy enough if you chain Init() calls to the parents (as you always should). Then it becomes very easy to see if a tag is-an ATag, just see if it has ATag's ID set to TRUE. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/01/2007 at 12:43, xxxxxxxx wrote:
This thread is a little old, but I have a further question on the subject.
If I derive my own classes from c4d classes, could I make isinstanceof() work for my classes by overloading this function in my derived class? Or is this somehow a bad idea?
regards
/Filip -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/01/2007 at 12:57, xxxxxxxx wrote:
How would you work it?
For instance, you create a plugin object derived from ObjectData called MyObjectData. When an instance of your plugin object is created, you don't get back a MyObjectData*, you get back a BaseObject* (even a PluginObject* won't help). BaseObject and NodeData are separate entities being unified under the guise of an object. So, the only way to call your IsInstanceOf() override (which will be declared in MyObjectData) would be to first know that the BaseObject is of your type (defeating the purpose, eh?) so that you can get the correct NodeData (cast to MyObjectData) and call the IsInstaneOf(). See how this won't work?
The way it does work is this:
// ID from PluginCafe
MYPLUGIN_ID 1xxxxxxxxxBaseObject* obj;
// Get an object
...
// Check the type
if (obj->IsInstanceOf(MYPLUGIN_ID)) // this object's type is your plugin object -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/01/2007 at 05:09, xxxxxxxx wrote:
I was thinking that maybe isintanceof() is a virtual function, so that my overloaded function would get called automatically, using dynamic binding. Or does cinema handle this internally in some other way?
I have to try this out when I get home.
regards
/Filip -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/01/2007 at 05:25, xxxxxxxx wrote:
The problem is that IsInstanceOf() is a method in Atom (about as low-level in the system as you can get). But if you look at the Inheritance list, BaseData is nowhere to be found. All of the programmatic access for developers is through BaseData derived classes and not the related GeListNode (which is derived from Atom).
In saying that, I'm hoping that you aren't expecting to derive classes from, say, BaseObject. That won't work. You can't extend Cinema 4D's basic types - only extend Cinema 4D using Plugin types - all derived from BaseData. Check "Plugin Structure" in the SDK docs for verification.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/01/2007 at 12:38, xxxxxxxx wrote:
OK, thanks a lot for the clarification.
regards
/Filip