libs-base/Testing/cstream.m
netc c30836a60c Convert to the GNUstep makefile package.
The installation of the header files was modified slightly
to correspond with the GNUstep makefile package.  All OpenStep
headers go into Foundation while the gnustep-base specific
headers go into gnustep/base.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2437 72102866-910b-0410-8b05-ffd578937521
1997-09-23 21:00:33 +00:00

57 lines
1.4 KiB
Objective-C

/* A demonstration of writing and reading GNU Objective C objects to a file. */
#include <gnustep/base/BinaryCStream.h>
#include <gnustep/base/Array.h>
#include <gnustep/base/Dictionary.h>
#include <Foundation/NSString.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSValue.h>
int main(int argc, char *argv[])
{
id arp;
long l = 0x6543;
int i = 0x1234;
unsigned u = 2;
short s = 0x987;
char c = 0x12;
char *string = "Testing";
float f = 0.1234F;
double d = 0.987654321;
id cstream;
Class cstream_class;
if (argc > 1)
cstream_class = objc_get_class (argv[1]);
else
cstream_class = [BinaryCStream class];
[NSObject enableDoubleReleaseCheck: YES];
arp = [[NSAutoreleasePool alloc] init];
cstream = [[cstream_class alloc]
initForWritingToFile: @"cstream.dat"];
/* Write an integer to a file */
[cstream encodeWithName: @"some values"
valuesOfCTypes: "liIsc*fd",
&l, &i, &u, &s, &c, &string, &f, &d];
printf ("Wrote %d %d %u %d %d %s %g %.15g\n",
(int)l, i, u, (int)s, (int)c, string, f, d);
[[cstream stream] close];
f = d = 0;
cstream = [cstream_class cStreamReadingFromFile: @"cstream.dat"];
[cstream decodeWithName: NULL
valuesOfCTypes: "liIsc*fd",
&l, &i, &u, &s, &c, &string, &f, &d];
printf ("Read %d %d %u %d %d %s %g %.15g\n",
(int)l, i, u, (int)s, (int)c, string, f, d);
[[cstream stream] close];
/* Do the autorelease. */
[arp release];
exit(0);
}