Update for new Coder organization.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@792 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mccallum 1996-01-24 03:24:06 +00:00
parent 5070e6640c
commit 55112e3931

View file

@ -4,19 +4,18 @@
text archive format. text archive format.
*/ */
#include <objects/TextCoder.h> #include <objects/Coder.h>
#include <objects/StdioStream.h>
#include <objects/Set.h> #include <objects/Set.h>
#include <objects/EltNodeCollector.h> #include <objects/EltNodeCollector.h>
#include <objects/LinkedList.h> #include <objects/LinkedList.h>
#include <objects/LinkedListEltNode.h> #include <objects/LinkedListEltNode.h>
#include <objects/NSString.h>
int main() int main()
{ {
id set, ll; id set, ll;
id stream;
id coder; id coder;
const char *n; id name;
/* Create a Set of int's /* Create a Set of int's
and a LinkedList of float's */ and a LinkedList of float's */
@ -42,59 +41,33 @@ int main()
[ll printForDebugger]; [ll printForDebugger];
/* Write them to a file */ /* Write them to a file */
stream = [[StdioStream alloc] coder = [Coder coderWritingToFile: @"./textcoding.txt"];
initWithFilename:"./textcoding.txt" [coder encodeObject:set withName:@"Test Set"];
fmode:"w"]; [coder encodeObject:ll withName:@"Test EltNodeCollector LinkedList"];
coder = [[TextCoder alloc] initEncodingOnStream:stream];
[coder encodeObject:set withName:"Test Set"];
[coder encodeObject:ll withName:"Test EltNodeCollector LinkedList"];
/* Free the objects */ /* Release the objects that were coded */
[coder release];
[set release]; [set release];
[ll release]; [ll release];
/* Read them back in from the file */ /* Read them back in from the file */
/* First init the stream and coder */ /* First init the stream and coder */
stream = [[StdioStream alloc] coder = [Coder coderReadingFromFile: @"./textcoding.txt"];
initWithFilename:"./textcoding.txt"
fmode:"r"];
coder = [[TextCoder alloc] initDecodingOnStream:stream];
/* Read in the Set */ /* Read in the Set */
[coder decodeObjectAt:&set withName:&n]; [coder decodeObjectAt:&set withName:&name];
printf("got object named %s\n", n); printf("got object named %@\n", name);
/* The name was malloc'ed by the Stream, free it */
(*objc_free)((void*)n);
/* Read in the LinkedList */ /* Read in the LinkedList */
[coder decodeObjectAt:&ll withName:&n]; [coder decodeObjectAt:&ll withName:&name];
printf("got object named %s\n", n); printf("got object named %@\n", name);
/* The name was malloc'ed by the Stream, free it */
(*objc_free)((void*)n);
/* Display what we read, to make sure it matches what we wrote */ /* Display what we read, to make sure it matches what we wrote */
[set printForDebugger]; [set printForDebugger];
[ll printForDebugger]; [ll printForDebugger];
/* Free the objects */ /* Relase the objects we read */
[coder release];
[set release]; [set release];
[ll release]; [ll release];
exit(0); exit(0);
} }
/* Some notes:
This program is a great example of how allocating and freeing
memory is very screwed up:
* The Stream allocates the name, we have to free it.
* The Coder free's its Stream when the Coder is free'd, but we
were the ones to create it.
These difficult and ad-hoc rules will be fixed in the future.
*/