[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lispArchiver and superclass
From: |
Marcus G. Daniels |
Subject: |
Re: lispArchiver and superclass |
Date: |
17 Feb 2000 11:30:47 -0800 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "GO" == Gadi ORON <address@hidden> writes:
GO> How can you ask a superclass to be allocated through the
GO> lispArchiver?
By default, all the variables of the class and its superclasses
are collected and saved. The +createBegin: of the class named
by the argument of make-instance in the .scm file is the one that
runs.
When you have a class that requires some parameters to be create-time,
then that class needs to have a lispInCreate: method so that these are
set before -createEnd runs. If your Rectangle was a real GUI
rectangle, then you'd probably want that.
Here's an example (without the extra lispInCreate: method).
#import <simtools.h> // initSwarmBatch
#import <defobj/Create.h> // CreateDrop
#import <defobj.h> // lispAppArchvier
#import <collections.h> // OutputStream
@interface Shape: CreateDrop
{
unsigned scale;
int x, y;
}
+ createBegin: aZone;
- (void)describe: stream;
@end
@implementation Shape
+ createBegin: aZone
{
Shape *shape = [super createBegin: aZone];
shape->scale = 2;
shape->x = 100;
shape->y = 200;
return shape;
}
- (void)describe: (id <OutputStream>)stream
{
[stream catC: "+"];
[stream catInt: x];
[stream catC: "+"];
[stream catInt: y];
[stream catC: " *"];
[stream catUnsigned: scale];
}
@end
@interface Rect: Shape
{
unsigned width;
unsigned height;
}
+ createBegin: aZone;
- (void)describe: (id <OutputStream>)stream;
@end
@implementation Rect
+ createBegin: aZone
{
Rect *rectangle = [super createBegin: aZone];
rectangle->height = 10;
rectangle->width = 20;
return rectangle;
}
- (void)describe: (id <OutputStream>)stream
{
[stream catC: "["];
[stream catC: [self getName]];
[stream catC: "] "];
[stream catUnsigned: width];
[stream catC: "x"];
[stream catUnsigned: height];
[super describe: stream];
[stream catC: "\n"];
}
@end
int
main (int argc, const char **argv)
{
initSwarmBatch (argc, argv);
{
id rectangle;
if ((rectangle = [lispAppArchiver getObject: "rectangle"]))
xprint (rectangle);
else
{
rectangle = [Rect create: globalZone];
[lispAppArchiver putDeep: "rectangle" object: rectangle];
[lispAppArchiver sync];
}
}
return 0;
}
/*
Local Variables:
compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc
-DAPPNAME=archiveShape -o archiveShape -Wall -Werror -g -Wno-import
-I$SWARMHOME/include/swarm -L$SWARMHOME/lib/swarm archiveShape.m -lswarm -lobjc"
End:
*/
==================================
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.