/*swarm-support mgd@swarm.org (Marcus G. Daniels) 02/28/2000 JB> Can it easily be used to make a deep JB> copy of an object? My swarm agents contain a binary tree, and I JB> was looking for a quick and dirty deep copy of agents (several JB> objects including the tree). In 2.1 (e.g. approx. the latest snapshot), the Lisp Archiver caches expressions until an explicit `sync' is done. With HDF5 there really is a HDF5 transaction made. The idea is to get rid of the need for registerClient: and updateArchiver: -- both Lisp and HDF5 transactions can be considered immediate. For example, the code below creates no file, yet the object is copied by deep-serialization. */ #import // initSwarmBatch #import // CreateDrop @interface Node: CreateDrop { unsigned sn; } + create: aZone setSn: (unsigned)sn; - (void)describe: stream; @end @implementation Node + create: aZone setSn: (unsigned)theSn { Node *node = [super createBegin: aZone]; node->sn = theSn; return node; } - (void)describe: stream { [stream catC: "[Node sn: "]; [stream catUnsigned: sn]; [stream catC: "]"]; } @end @interface Tree: CreateDrop { id left, right; } + createBegin: aZone; - (void)describe: stream; @end @implementation Tree + createBegin: aZone { Tree *obj = [super createBegin: aZone]; obj->left = [Node create: aZone setSn: 1]; obj->right = [Node create: aZone setSn: 2]; return obj; } - (void)describe: stream { [stream catC: "Tree: ["]; [stream catC: "left: "]; xprint (left); [stream catC: " right: "]; xprint (right); [stream catC: "]"]; } @end @interface Agent: CreateDrop { id tree; } @end @implementation Agent + createBegin: aZone { Agent *obj = [super createBegin: aZone]; obj->tree = [Tree create: aZone]; return obj; } - (void)describe: stream { [stream catC: "Agent: ["]; [stream catPointer: self]; [stream catC: " "]; xprint (tree); [stream catC: "]\n"]; } @end int main (int argc, const char **argv) { initSwarmBatch (argc, argv); { id agent; agent = [Agent create: globalZone]; xprint (agent); [lispAppArchiver putDeep: "agent" object: agent]; agent = [lispAppArchiver getObject: "agent"]; xprint (agent); } return 0; } /* Local Variables: compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc -DAPPNAME=archiveTree -o archiveTree -Wall -Werror -g -Wno-import -I$SWARMHOME/include/swarm -L$SWARMHOME/lib/swarm archiveTree.m -lswarm -lobjc" End: */