Re: Getting a list of all classes, etc...
Re: Getting a list of all classes, etc...
- Subject: Re: Getting a list of all classes, etc...
- From: "Sherm Pendley" <email@hidden>
- Date: Thu, 27 Mar 2008 01:11:08 -0400
On Thu, Mar 27, 2008 at 12:43 AM, Graham Cox <email@hidden> wrote:
I have a class that can contain different objects which all derive
> from a class R. The container can accept instances of any subclass of R.
>
> Each subclass of R implements a CLASS method for a particular feature,
> returning an array. The container needs to build an array which is the
> union of all the arrays returned by each subclass. Thus it needs to
> iterate through a list of all possible subclasses of R, combining the
> arrays as it goes. Problem is that not all possible subclasses of R
> are known until runtime, so I need a way to be able to get hold of
> such a list, based on the fact that they all inherit from R. Note that
> these are not instances of R, but classes. (I can get a list of
> instances I have right now, but that doesn't cover the possibility of
> another object instance derived from R being added after I already
> built the array).
>
> Hope this makes sense - any ideas?
You're on the right track, IMHO. What I would do is climb the inheritance
tree for each registered class. If you find an ancestor with the name of R,
the class you're checking is a subclass. If you get to a root class (i.e. a
class whose super_class member is NULL), then it's not.
while( NULL != aClass->super_class && 0 != strncmp(aClass->name, "R", 1) )
aClass = aClass->super_class;
BOOL isSubclassOfR = (NULL != aClass->super_class) ? YES : NO;
Keep in mind that this is for the ObjC 1 runtime. I haven't yet looked at
the ObjC 2 runtime in any detail, so if you're targeting 64-bit Leopard,
YMMV.
sherm--
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden