swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: probes


From: Chimera
Subject: Re: probes
Date: Tue, 21 Jul 1998 03:25:25 -0700

Ken,

   Once I remembered to register my probe map !%#$, the method worked.

Thanks again,

D3

Ken Cline wrote:

> Doug,
>
> Did you solve this problem?  I didn't see a response on the
> mailing list... maybe I missed it?
>
> On Tue, 14 Jul 1998, Chimera wrote:
>
> > All right, a swarm programming question.
> >
> > I have a subclass of my basic Cell class.  The probe map for it (when I
> > right click on the 2-D grid display) only comes up with the variables in
> > the subclass.  I tried to make a custom probe map of the subclass, also
> > including the variables that I wanted from the superclass.  As I
> > suspected, it does not like including variables from its parent.
> > Perhaps it is in the midst of puberty?  Anyway, the quick fix is just to
> > redefine the variables in the subclass.  However, following the present
> > working environment of not sidestepping issues, I decided to ask if
> > there is a "correct" way of doing this.  Any suggestions?
> >
>
> I haven't done any Swarm/ObjC programming in ages, but in
> the old days ;)...
>
>    [ probeMap addProbe:
>        [ probeLibrary getProbeForVariable: "foo"
>                                   inClass: [self superClass] ] ];
>
> where "foo" is the variable defined in the super class.
> Does this no longer work?
>
> With custom probe maps you have to specify exactly which
> class in the hierarchy that defines the variable (correct me
> if I'm wrong, folks).  This adds a lot of flexibility but it
> can also cause some headaches: move a variable between your
> superclasses and you're forced to start picking though all
> the subclasses.  This also means that apps can become much
> more entangled with the libs they use.
>
> To make your subclass's code more robust, you might try
> "initializing" the probeLibrary with a CompleteProbeMap (see
> example code below). The CompleteProbeMap (still?) has code
> that climbs the super class tree probing all the variables
> and methods.  Alternatively, use a CompleteProbeMap as a
> (local) resource instead of probeLibrary.  I think either
> way would be valid, though I never tried it myself, of
> course. :)
>
> I hope that helps.
>
> Ken.
>
> PS: You shouldn't need to create the CompleteProbeMap
>     more than once, ie when the first instance of your
>     subclass is created.  For that reason you might
>     consider using a class method or class variable, as
>     appropriate.  Actually, it isn't necessary to create a
>     probe map for any class more that once since the probe
>     library stores the map by class.  However, if you
>     start to use some conditional method like probeLibrary's
>     "isProbeMapDefinedFor:", then you'll need to be careful
>     that some superclass method which gets executed first
>     (eg createBegin) doesn't end up taking credit for
>     defining the subclass's probe map.  (Hmmm.... maybe I'm
>     getting confused... like I said, its been awhile.  =;-)
>
> ---------------------------------------------------------
> Example code...
> (This was taken out of context => might not work as is...)
>
> /**
>  * Sets the class's probeMap with the char *'s provided in
>  * the variable argument list.  A ":" char * is used to
>  * divide the ivar names from the imethod names in the
>  * va_list.  That is, the usage is something like:
>  *
>  *   "var1", "var2", ..., ":", "method1", "method2",..., NULL
>  *
>  * This is the same syntax that CustomProbeMap uses.
>  *
>  */
> -setProbes: (char *) args, ...
> {
>    va_list  argptr  = NULL;
>    Class    class   = NULL;
>    id <ProbeMap> probeMap     = NULL;
>    char *        probeName    = NULL;
>    id <Probe>    probe        = NULL;
>    SEL           getProbeSEL  = NULL;
>
>    va_start( argptr, args );
>    class = [ self class ];
>
>    [ probeLibrary setProbeMap: [self getCompleteProbeMap] For: class ];
>    probeMap  = [ [ [ CustomProbeMap createBegin: [self getZone] ]
>                                  setProbedClass: class ] createEnd ];
>    probeName    = args;
>    getProbeSEL  = M(getProbeForVariable:inClass:);
>
>    while ( probeName && strlen( probeName ) ) {
>       if ( probeName[0] == ':' ) {
>          getProbeSEL  = M(getProbeForMessage:inClass:);
>          probeName    = va_arg( argptr, char * );
>          continue;
>       }
>       probe = [ probeLibrary perform: getProbeSEL with: (id)probeName
>                                                   with: (id)class     ];
>       // Should I copy the probe instead of passing it in directly?
>       if ( probe )
>          [ probeMap addProbe: probe ];
>       else
>          raiseEvent( WarningMessage, "\t> Probe does *NOT* exist in 
> `probeLibrary'.\n"  \
>                                      "\t> Unable to get probe `%s' for class 
> `%s'.\n",  \
>                                           probeName, [ class name ]           
>           );
>       probeName = va_arg( argptr, char * );
>    }
>
>    [ probeLibrary setProbeMap: probeMap For: class ];
>    va_end( argptr );
>
>    return self;
> }
>
>
> _________________________________________________________
> Ken Cline                             address@hidden
> SAIC                                 VOICE (410) 571-0413
> Annapolis, MD                          FAX (301) 261-8427
>
>                   ==================================
>    Swarm-Support is for discussion of the technical details of the day
>    to day usage of Swarm.  For list administration needs (esp.
>    [un]subscribing), please send a message to <address@hidden>
>    with "help" in the body of the message.
>                   ==================================



--
*********************************************************************
* Doug Donalson                 Office: (805) 893-2962
* Ecology, Evolution,           Home:   (805) 961-4447
* and Marine Biology            email address@hidden
* UC Santa Barbara
* Santa Barbara Ca. 93106
*********************************************************************
*
*   The most exciting phrase to hear in science, the one that
*   heralds new discoveries, is not "EUREKA" (I have found it) but
*   "That's funny ...?"
*
*       Isaac Asimov
*
*********************************************************************



                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]