1994-11-04 16:29:24 +00:00
|
|
|
/* A demonstration of writing and reading GNU Objective C objects to a file,
|
|
|
|
in human-readable text format.
|
|
|
|
Look at the file "textcoding.txt" after running this program to see the
|
|
|
|
text archive format.
|
|
|
|
*/
|
|
|
|
|
1996-01-24 03:24:06 +00:00
|
|
|
#include <objects/Coder.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
#include <objects/Set.h>
|
|
|
|
#include <objects/EltNodeCollector.h>
|
|
|
|
#include <objects/LinkedList.h>
|
|
|
|
#include <objects/LinkedListEltNode.h>
|
1996-01-24 03:24:06 +00:00
|
|
|
#include <objects/NSString.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
id set, ll;
|
|
|
|
id coder;
|
1996-01-24 03:24:06 +00:00
|
|
|
id name;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Create a Set of int's
|
|
|
|
and a LinkedList of float's */
|
|
|
|
set = [[Set alloc] initWithType:@encode(int)];
|
|
|
|
ll = [[EltNodeCollector alloc] initWithType:@encode(float)
|
|
|
|
nodeCollector:[[LinkedList alloc] init]
|
|
|
|
nodeClass:[LinkedListEltNode class]];
|
|
|
|
|
|
|
|
/* Populate the Set and display it */
|
|
|
|
[set addElement:1234567];
|
|
|
|
[set addElement:2345678];
|
|
|
|
[set addElement:3456789];
|
|
|
|
[set addElement:4567891];
|
|
|
|
[set addElement:5678912];
|
|
|
|
[set printForDebugger];
|
|
|
|
|
|
|
|
/* Populate the LinkedList and display it */
|
|
|
|
[ll addElement:1.2f];
|
|
|
|
[ll addElement:(float)3.4];
|
|
|
|
[ll addElement:(float)5.6];
|
|
|
|
[ll addElement:(float)7.8];
|
|
|
|
[ll addElement:(float)9.0];
|
|
|
|
[ll printForDebugger];
|
|
|
|
|
|
|
|
/* Write them to a file */
|
1996-01-24 03:24:06 +00:00
|
|
|
coder = [Coder coderWritingToFile: @"./textcoding.txt"];
|
|
|
|
[coder encodeObject:set withName:@"Test Set"];
|
|
|
|
[coder encodeObject:ll withName:@"Test EltNodeCollector LinkedList"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-01-24 03:24:06 +00:00
|
|
|
/* Release the objects that were coded */
|
1995-06-30 20:28:51 +00:00
|
|
|
[set release];
|
|
|
|
[ll release];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Read them back in from the file */
|
|
|
|
/* First init the stream and coder */
|
1996-01-24 03:24:06 +00:00
|
|
|
coder = [Coder coderReadingFromFile: @"./textcoding.txt"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Read in the Set */
|
1996-01-24 03:24:06 +00:00
|
|
|
[coder decodeObjectAt:&set withName:&name];
|
|
|
|
printf("got object named %@\n", name);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Read in the LinkedList */
|
1996-01-24 03:24:06 +00:00
|
|
|
[coder decodeObjectAt:&ll withName:&name];
|
|
|
|
printf("got object named %@\n", name);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Display what we read, to make sure it matches what we wrote */
|
|
|
|
[set printForDebugger];
|
|
|
|
[ll printForDebugger];
|
|
|
|
|
1996-01-24 03:24:06 +00:00
|
|
|
/* Relase the objects we read */
|
1995-06-30 20:28:51 +00:00
|
|
|
[set release];
|
|
|
|
[ll release];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|