mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
New file.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1233 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7650c0da16
commit
7bd4778592
3 changed files with 172 additions and 0 deletions
93
Testing/coder.m
Normal file
93
Testing/coder.m
Normal file
|
@ -0,0 +1,93 @@
|
|||
/* A demonstration of writing and reading GNU Objective C objects to a file. */
|
||||
|
||||
#include <objects/Archiver.h>
|
||||
#include <objects/BinaryCStream.h>
|
||||
#include <objects/Array.h>
|
||||
#include <objects/Dictionary.h>
|
||||
#include <objects/NSString.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
id array, dictionary;
|
||||
id archiver;
|
||||
id name;
|
||||
id arp;
|
||||
int i;
|
||||
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];
|
||||
|
||||
/* Create an Array and Dictionary */
|
||||
array = [Array new];
|
||||
dictionary = [Dictionary new];
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
[array addObject: [NSNumber numberWithInt: i]];
|
||||
[dictionary putObject: [NSNumber numberWithInt: i]
|
||||
atKey: [NSNumber numberWithInt: i*i]];
|
||||
}
|
||||
[array printForDebugger];
|
||||
[dictionary printForDebugger];
|
||||
|
||||
/* Write them to a file */
|
||||
|
||||
/* Create an instances of the Archiver class, specify that we
|
||||
want human-readable "Text"-style, instead of "Binary"-style
|
||||
coding. */
|
||||
archiver = [[Archiver alloc] initForWritingToFile: @"./coder.dat"
|
||||
withCStreamClass: cstream_class];
|
||||
[archiver encodeObject: array
|
||||
withName: @"Test Array"];
|
||||
[archiver encodeObject: dictionary
|
||||
withName: @"Test Dictionary"];
|
||||
|
||||
/* Release the objects that were coded */
|
||||
[array release];
|
||||
[dictionary release];
|
||||
|
||||
/* Close the archiver, (and thus flush the stream); then release it.
|
||||
We must separate the idea of "closing" a stream and
|
||||
"deallocating" a stream because of delays in deallocation due to
|
||||
-autorelease. */
|
||||
[archiver close];
|
||||
[archiver release];
|
||||
|
||||
|
||||
/* Read them back in from the file */
|
||||
|
||||
/* First create the unarchiver */
|
||||
archiver = [Unarchiver newReadingFromFile: @"./coder.dat"];
|
||||
|
||||
/* Read in the Array */
|
||||
[archiver decodeObjectAt: &array withName: &name];
|
||||
printf("got object named %@\n", name);
|
||||
|
||||
/* Read in the Dictionary */
|
||||
[archiver decodeObjectAt: &dictionary withName: &name];
|
||||
printf("got object named %@\n", name);
|
||||
|
||||
/* Display what we read, to make sure it matches what we wrote */
|
||||
[array printForDebugger];
|
||||
[dictionary printForDebugger];
|
||||
|
||||
/* Relase the objects we read */
|
||||
[array release];
|
||||
[dictionary release];
|
||||
|
||||
/* Release the unarchiver. */
|
||||
[archiver release];
|
||||
|
||||
/* Do the autorelease. */
|
||||
[arp release];
|
||||
|
||||
exit(0);
|
||||
}
|
55
Testing/cstream.m
Normal file
55
Testing/cstream.m
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* A demonstration of writing and reading GNU Objective C objects to a file. */
|
||||
|
||||
#include <objects/BinaryCStream.h>
|
||||
#include <objects/Array.h>
|
||||
#include <objects/Dictionary.h>
|
||||
#include <objects/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.1234;
|
||||
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 %g\n",
|
||||
(int)l, i, u, (int)s, (int)c, string, f, d);
|
||||
[[cstream stream] close];
|
||||
|
||||
cstream = [cstream_class cStreamReadingFromFile: @"cstream.dat"];
|
||||
[cstream decodeWithName: NULL
|
||||
valuesOfCTypes: "liIsc*",
|
||||
&l, &i, &u, &s, &c, &string, &f, &d];
|
||||
printf ("Read %d %d %u %d %d %s %g %g\n",
|
||||
(int)l, i, u, (int)s, (int)c, string, f, d);
|
||||
[[cstream stream] close];
|
||||
|
||||
/* Do the autorelease. */
|
||||
[arp release];
|
||||
|
||||
exit(0);
|
||||
}
|
24
Testing/float.c
Normal file
24
Testing/float.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <math.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int i = 0;
|
||||
double d = 0.123456789;
|
||||
|
||||
printf ("%f %d\n", d, i);
|
||||
d = frexp (d, &i);
|
||||
|
||||
d = ldexp (d, i);
|
||||
printf("%f\n", d);
|
||||
|
||||
printf ("%f %d\n", d, i);
|
||||
d = frexp (d, &i);
|
||||
|
||||
printf ("%f %d\n", d, i);
|
||||
d = frexp (d, &i);
|
||||
|
||||
printf ("%f %d\n", d, i);
|
||||
d = frexp (d, &i);
|
||||
|
||||
exit (0);
|
||||
}
|
Loading…
Reference in a new issue