home *** CD-ROM | disk | FTP | other *** search
- // EOKeyValueArchiver
- // Copyright (c) 19965, NeXT Software, Inc. All rights reserved.
-
- // WEBScript Example: Archiving to file
- //
- // id archiver, name, pList, objectToArchive;
- //
- // archiver = [[EOKeyValueArchiver alloc] init];
- // name = @"PATH.plist";
- //
- // [archiver encodeObject:objectToArchive forKey:@"ArchiveName"];
- // if (![[archiver dictionary] writeToFile:name atomically:NO]) {
- // [WOApp logWithFormat:@"Unable to save file %@\n", name];
- // }
- //
-
- #import <Foundation/Foundation.h>
-
- @interface EOKeyValueArchiver : NSObject
- {
- NSMutableDictionary *_propertyList;
- id _delegate;
- }
-
- - (void)encodeObject:(id)object forKey:(NSString *)key;
- // archive an object in place
- // calls object with encodeIntoArchiver:(EOKeyValueArchiver *)archiver;
- // Set a new dictionary in the internal state and archives the class
- // of the object under the key className
-
- - (void)encodeReferenceToObject:(id)object forKey:(NSString *)key;
- // Encodes a reference to the given object rather than embedding it.
- // The delegate is responsible for providing the reference object
- // in its archiver:referenceToEncodeForObject: method.
-
- - (void)encodeBool:(BOOL)yn forKey:(NSString *)key;
- // does YES, NO;
- // skips archiving of NO values.
-
- - (void)encodeInt:(int)intValue forKey:(NSString *)key;
- // converts atring to int
-
- - (NSDictionary *)dictionary;
- // returns the builded property list
-
- - (void)setDelegate:(id)delegate;
- - (id)delegate;
-
- @end
-
- @interface NSObject (EOKeyValueArchiverDelegation)
- - (id)archiver:(EOKeyValueArchiver *)archiver
- referenceToEncodeForObject:(id)object;
- // delegate must implement this method to encode references if
- // any of the objects it encodes call encodeReferenceToObject:forKey:.
- // The delegate should return the object (perhaps a string)
- // to encode in place of the referenced object.
- @end
-
-
-
- // WEBScript Example: Unarchiving from file
- //
- // id decoder, name, pList;
- //
- // name = @"PATH.plist";
- //
- // pList = [NSDictionary dictionaryWithContentsOfFile:name];
- // decoder = [[EOKeyValueUnarchiver alloc] initWithDictionary:pList];
- // archivedObject = [decoder decodeObjectForKey:@"ArchiveName" withParent:nil];
- //
- // [coder finishInitializationOfObjects];
-
-
- @interface EOKeyValueUnarchiver : NSObject
- {
- NSDictionary *_propertyList;
- id _parent;
- id _nextParent;
- NSMutableArray *_allUnarchivedObjects;
- id _delegate;
- NSHashTable *_awakenedObjects;
- }
-
- - (id)initWithDictionary:(NSDictionary *)dictionary;
-
- - (id)decodeObjectForKey:(NSString *)key;
- // Unarchives an object that was archived in place
-
- - (id)decodeObjectReferenceForKey:(NSString *)key;
- // Unarchives an object that was archived as a reference.
- // The delegate is responsible for supplying the object
- // indentified by the reference its implementation of
- // unarchiver:objectForReference:.
-
- - (BOOL)decodeBoolForKey:(NSString *)key;
- // returns NO if key not found
-
- - (int)decodeIntForKey:(NSString *)key;
- // returns int value in archive or 0 if none.
-
- - (void)ensureObjectAwake:(id)object;
- // The order that objects are sent awakeFromKeyValueUnarchiver:
- // is not defined. However, if in its implementation of
- // awakeFromKeyValueUnarchiver: an object depends a related
- // object already being awake, it can call ensureObjectAwake:
- // passing the related object.
-
- - (void)finishInitializationOfObjects;
- // sends finishInitializationWithKeyValueUnarchiver: to all unarchived objects
-
- - (void)awakeObjects;
- // sends awakeFromKeyValueUnarchiver: to all unarchived objects
-
- - (id)parent;
- // can be called by an object in its initWithKeyValueUnarchiver: to
- // get the pointer to the parent object that is unarchiving it.
- // E.g. if an EOAttribute calls this it will get its EOEntity.
-
- - (void)setDelegate:(id)delegate;
- - (id)delegate;
-
- @end
-
- @interface NSObject (EOKeyValueUnarchiverDelegation)
- - (id)unarchiver:(EOKeyValueUnarchiver *)archiver
- objectForReference:(id)object;
- // delegate must implement this method to decode references if
- // any of the objects it decodes call decodeObjectReferenceForKey:.
- // The delegate should return the object identified by the
- // reference (perhaps by looking up the reference in a table).
- @end
-
-
- @protocol EOKeyValueArchiving
-
- - initWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)unarchiver;
- // passes to an object to unarchive it.
-
- - (void)encodeWithKeyValueArchiver:(EOKeyValueArchiver *)archiver;
- // tells object to archive itself
-
- @end
-
- @interface NSObject(EOKeyValueArchivingAwakeMethods)
-
- - (void)finishInitializationWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)unarchiver;
- // passed to all unarchived objects after all objects have received
- // initWithKeyValueUnarchiver:
-
- - (void)awakeFromKeyValueUnarchiver:(EOKeyValueUnarchiver *)unarchiver;
- // passed to all unarchived objects at application runtime to
- // inform them to prepare to run.
- // The unarchiver will not return parentObject or any archive
- // preperties at this time.
-
- @end
-