home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / EOKeyValueArchiver.h < prev    next >
Encoding:
Text File  |  1996-09-11  |  5.1 KB  |  158 lines

  1. // EOKeyValueArchiver
  2. // Copyright (c) 19965, NeXT Software, Inc. All rights reserved. 
  3.  
  4. // WEBScript Example: Archiving to file
  5. //
  6. // id archiver, name, pList, objectToArchive;
  7. //
  8. // archiver = [[EOKeyValueArchiver alloc] init];
  9. // name  = @"PATH.plist";
  10. //
  11. // [archiver encodeObject:objectToArchive forKey:@"ArchiveName"];
  12. // if (![[archiver dictionary] writeToFile:name atomically:NO]) {
  13. //     [WOApp logWithFormat:@"Unable to save file %@\n", name];
  14. // }
  15. //
  16.  
  17. #import <Foundation/Foundation.h>
  18.  
  19. @interface EOKeyValueArchiver : NSObject
  20. {
  21.     NSMutableDictionary *_propertyList;
  22.     id _delegate;
  23. }
  24.  
  25. - (void)encodeObject:(id)object forKey:(NSString *)key;
  26.         // archive an object in place
  27.         // calls object with encodeIntoArchiver:(EOKeyValueArchiver *)archiver;
  28.         // Set a new dictionary in the internal state and archives the class
  29.         // of the object under the key className
  30.  
  31. - (void)encodeReferenceToObject:(id)object forKey:(NSString *)key;
  32.         // Encodes a reference to the given object rather than embedding it.
  33.     // The delegate is responsible for providing the reference object
  34.     // in its archiver:referenceToEncodeForObject: method.
  35.     
  36. - (void)encodeBool:(BOOL)yn forKey:(NSString *)key;
  37.         // does YES, NO;
  38.         // skips archiving of NO values.
  39.  
  40. - (void)encodeInt:(int)intValue forKey:(NSString *)key;
  41.         // converts atring to int
  42.  
  43. - (NSDictionary *)dictionary;
  44.         // returns the builded property list
  45.  
  46. - (void)setDelegate:(id)delegate;
  47. - (id)delegate;
  48.  
  49. @end
  50.  
  51. @interface NSObject (EOKeyValueArchiverDelegation)
  52. - (id)archiver:(EOKeyValueArchiver *)archiver 
  53.         referenceToEncodeForObject:(id)object;
  54.     // delegate must implement this method to encode references if
  55.     // any of the objects it encodes call encodeReferenceToObject:forKey:.
  56.     // The delegate should return the object (perhaps a string)
  57.     // to encode in place of the referenced object.
  58. @end
  59.     
  60.     
  61.  
  62. // WEBScript Example: Unarchiving from file
  63. //
  64. // id decoder, name, pList;
  65. //
  66. // name = @"PATH.plist";
  67. //
  68. // pList          = [NSDictionary dictionaryWithContentsOfFile:name];
  69. // decoder        = [[EOKeyValueUnarchiver alloc] initWithDictionary:pList];
  70. // archivedObject = [decoder decodeObjectForKey:@"ArchiveName" withParent:nil];
  71. //
  72. // [coder finishInitializationOfObjects];
  73.  
  74.  
  75. @interface EOKeyValueUnarchiver : NSObject
  76. {
  77.     NSDictionary    *_propertyList;
  78.     id              _parent;
  79.     id            _nextParent;
  80.     NSMutableArray  *_allUnarchivedObjects;    
  81.     id _delegate;
  82.     NSHashTable *_awakenedObjects;
  83. }
  84.  
  85. - (id)initWithDictionary:(NSDictionary *)dictionary;
  86.  
  87. - (id)decodeObjectForKey:(NSString *)key;
  88.         // Unarchives an object that was archived in place
  89.  
  90. - (id)decodeObjectReferenceForKey:(NSString *)key;
  91.         // Unarchives an object that was archived as a reference.
  92.     // The delegate is responsible for supplying the object
  93.     // indentified by the reference its implementation of
  94.     // unarchiver:objectForReference:.
  95.  
  96. - (BOOL)decodeBoolForKey:(NSString *)key;
  97.         // returns NO if key not found
  98.  
  99. - (int)decodeIntForKey:(NSString *)key;
  100.         // returns int value in archive or 0 if none.
  101.  
  102. - (void)ensureObjectAwake:(id)object;
  103.         // The order that objects are sent awakeFromKeyValueUnarchiver:
  104.     // is not defined.  However, if in its implementation of
  105.     // awakeFromKeyValueUnarchiver: an object depends a related
  106.     // object already being awake, it can call ensureObjectAwake:
  107.     // passing the related object.
  108.  
  109. - (void)finishInitializationOfObjects;
  110.     // sends finishInitializationWithKeyValueUnarchiver: to all unarchived objects
  111.  
  112. - (void)awakeObjects;
  113.    // sends awakeFromKeyValueUnarchiver: to all unarchived objects
  114.  
  115. - (id)parent;
  116.     // can be called by an object in its initWithKeyValueUnarchiver: to
  117.    // get the pointer to the parent object that is unarchiving it.
  118.    // E.g. if an EOAttribute calls this it will get its EOEntity.
  119.  
  120. - (void)setDelegate:(id)delegate;
  121. - (id)delegate;
  122.  
  123. @end
  124.  
  125. @interface NSObject (EOKeyValueUnarchiverDelegation)
  126. - (id)unarchiver:(EOKeyValueUnarchiver *)archiver 
  127.         objectForReference:(id)object;
  128.     // delegate must implement this method to decode references if
  129.     // any of the objects it decodes call decodeObjectReferenceForKey:.
  130.     // The delegate should return the object identified by the
  131.     // reference (perhaps by looking up the reference in a table).
  132. @end
  133.  
  134.  
  135. @protocol EOKeyValueArchiving
  136.  
  137. - initWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)unarchiver;
  138.     // passes to an object to unarchive it.
  139.  
  140. - (void)encodeWithKeyValueArchiver:(EOKeyValueArchiver *)archiver;
  141.     // tells object to archive itself
  142.  
  143. @end
  144.  
  145. @interface NSObject(EOKeyValueArchivingAwakeMethods) 
  146.                     
  147. - (void)finishInitializationWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)unarchiver;
  148.     // passed to all unarchived objects after all objects have received
  149.     // initWithKeyValueUnarchiver:
  150.  
  151. - (void)awakeFromKeyValueUnarchiver:(EOKeyValueUnarchiver *)unarchiver;
  152.     // passed to all unarchived objects at application runtime to
  153.     // inform them to prepare to run.
  154.     // The unarchiver will not return parentObject or any archive
  155.     // preperties at this time. 
  156.  
  157. @end 
  158.