[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Avoiding runtime errors with CustomProbeMap
From: |
Benedikt Stefansson |
Subject: |
Avoiding runtime errors with CustomProbeMap |
Date: |
Mon, 02 Mar 1998 15:29:16 -0800 |
Hi,
This is a brief note on errors that may arise when you port an app to
1.0.5. Initially when I ported one of my sims to 1.0.5 I got the
following error messages for innocuous code that simply creates the
custom probe map for my ModelSwarm:
ModelSwarm.m: In function `_c_ModelSwarm__createBegin_':
ModelSwarm.m:35: warning: `CustomProbeMap' does not respond to
`setProbedClass:'
...<ton of warning deleted>
ModelSwarm.m:73: warning: `CustomProbeMap' does not respond to
`addProbe:'
ModelSwarm.m:76: warning: `CustomProbeMap' does not respond to
`addProbe:'
Although these were only warnings, the runtime would complain and refuse
to create a custom probe map for the ModelSwarm and pull up the default
(full) map instead in the GUI.
After fooling around with different things, casting variables
differently, using a ProbeMap instance instead of CustomProbeMap etc., I
finally realized that all that needed to be done was to change the
following line:
+createBegin: (id) aZone {
ModelSwarm * obj;
CustomProbeMap * probeMap; <---- THIS CAUSES THE WARNING
The solution is to define the variable in terms of the protocol,
CustomProbeMap, instead of using static typing:
+createBegin: (id) aZone {
ModelSwarm * obj;
id <CustomProbeMap> probeMap; <---- EVERYBODY HAPPY
Here is a shortened version of the +createBegin: method, for the record:
+createBegin: (id) aZone {
ModelSwarm * obj;
id <CustomProbeMap> probeMap;
// First, call our superclass createBegin
obj = [super createBegin: aZone];
obj->alpha=168.0;
obj->beta=0.667;
... <ton of instance variable declarations deleted>
obj->starting=9;
probeMap = [CustomProbeMap createBegin: aZone];
[probeMap setProbedClass: [self class]];
probeMap = [probeMap createEnd];
// Add in a bunch of variables, one per simulation parameter
[probeMap addProbe: [probeLibrary getProbeForVariable: "alpha"
inClass: [self class]]];
[probeMap addProbe: [probeLibrary getProbeForVariable: "beta"
inClass: [self class]]];
...<ton of probe declarations deleted>
[probeMap addProbe: [probeLibrary getProbeForVariable:
"startingPrice1"
inClass: [self class]]];
[probeLibrary setProbeMap: probeMap For: [self class]];
return obj;
}
-Benedikt
--
----------------
Benedikt Stefansson address@hidden
Department of Economics, UCLA Fax. (310) 825-9528
Los Angeles, CA 90095-1477 Tel. (310) 825-1777
==================================
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.
==================================
- Avoiding runtime errors with CustomProbeMap,
Benedikt Stefansson <=