//-------------------------------------------------
// Driver.m - Driver prog to demo the Person class.
//-------------------------------------------------

#import <stdio.h>
#import <objc/List.h>

#import "Person.h"

//-------------------------------------------------
main()
{
int		i;
id		personList;
id		newPerson;
NXTypedStream	*stream;
id		newList;

personList = [[List alloc] init];

// Make a person and put them in the list.
// (using discrete method calls).
newPerson = [Person alloc];
[newPerson initWithName:"Alan"
	   age:21];
[personList addObject:newPerson];

// Make another person and put them in the list.
// (using nested method calls).
[personList addObject:
		[[Person alloc] initWithName:"Bill"
			   	age:22]];

// Tell the objects in the list to -printInfo
printf( "Original List:\n" );
[personList makeObjectsPerform:@selector(printInfo)];

// Archive the list and its contents to a file.
stream = NXOpenTypedStreamForFile( "listArchive",
				   NX_WRITEONLY );
printf( "Archiving List. \n" );
NXWriteRootObject( stream, personList );
NXCloseTypedStream( stream );

// Dispose of the list contents and then the list.
[personList freeObjects];
[personList free];

// Unarchive the list and its contents from the file.
stream = NXOpenTypedStreamForFile( "listArchive",
				   NX_READONLY );
printf( "Unarchiving List. \n" );
newList = NXReadObject( stream );
NXCloseTypedStream( stream );

// Tell the objects in the new list to -printInfo
printf( "New List:\n" );
[newList makeObjectsPerform:@selector(printInfo)];

// Dispose of the new list and its contents.
[newList free];
}

//-------------------------------------------------

