home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / dec92.zip / 1012040A < prev    next >
Text File  |  1992-10-13  |  2KB  |  66 lines

  1. //-------------------------------------------------
  2. // Driver.m - Driver prog to demo the Person class.
  3. //-------------------------------------------------
  4.  
  5. #import <stdio.h>
  6. #import <objc/List.h>
  7.  
  8. #import "Person.h"
  9.  
  10. //-------------------------------------------------
  11. main()
  12. {
  13. int        i;
  14. id        personList;
  15. id        newPerson;
  16. NXTypedStream    *stream;
  17. id        newList;
  18.  
  19. personList = [[List alloc] init];
  20.  
  21. // Make a person and put them in the list.
  22. // (using discrete method calls).
  23. newPerson = [Person alloc];
  24. [newPerson initWithName:"Alan"
  25.        age:21];
  26. [personList addObject:newPerson];
  27.  
  28. // Make another person and put them in the list.
  29. // (using nested method calls).
  30. [personList addObject:
  31.         [[Person alloc] initWithName:"Bill"
  32.                    age:22]];
  33.  
  34. // Tell the objects in the list to -printInfo
  35. printf( "Original List:\n" );
  36. [personList makeObjectsPerform:@selector(printInfo)];
  37.  
  38. // Archive the list and its contents to a file.
  39. stream = NXOpenTypedStreamForFile( "listArchive",
  40.                    NX_WRITEONLY );
  41. printf( "Archiving List. \n" );
  42. NXWriteRootObject( stream, personList );
  43. NXCloseTypedStream( stream );
  44.  
  45. // Dispose of the list contents and then the list.
  46. [personList freeObjects];
  47. [personList free];
  48.  
  49. // Unarchive the list and its contents from the file.
  50. stream = NXOpenTypedStreamForFile( "listArchive",
  51.                    NX_READONLY );
  52. printf( "Unarchiving List. \n" );
  53. newList = NXReadObject( stream );
  54. NXCloseTypedStream( stream );
  55.  
  56. // Tell the objects in the new list to -printInfo
  57. printf( "New List:\n" );
  58. [newList makeObjectsPerform:@selector(printInfo)];
  59.  
  60. // Dispose of the new list and its contents.
  61. [newList free];
  62. }
  63.  
  64. //-------------------------------------------------
  65.  
  66.