Class CPKeyedArchiver

CPObject
    extended byCPCoder
        extended byCPKeyedArchiver

@implementation CPKeyedArchiver : CPCoder

Implements keyed archiving of object graphs. Archiving means to write data out in a format that be read in again later, or possibly stored in a file. To read the data back in, use a CPKeyedUnarchiver.


Method Summary
+(BOOL)allowsKeyedCoding
          Returns a flag indicating whether the receiver supports keyed coding.
+(CPData)archivedDataWithRootObject:(id)anObject
          Archives the specified object.
+(CPString)classNameForClass:(Class)aClass
          Returns the name of the substitute class used for encoding aClass by all keyed archivers.
+(void)setClassName:(CPString)aClassName forClass:(Class)aClass
          Allows substitution of class types for encoding.
-(id)initForWritingWithMutableData:(CPMutableData)data
          Initializes the keyed archiver with the specified CPMutableData for writing.
-(CPString)classNameForClass:(Class)aClass
          Returns the name of the substitute class used for encoding aClass by this keyed archiver.
-(id)delegate
          Returns the keyed archiver's delegate.
-(void)encodeBool:(BOOL)aBOOL forKey:(CPString)aKey
          Encodes a BOOL value.
-(void)encodeConditionalObject:(id)anObject forKey:(CPString)aKey
          Encodes an conditionally.
-(void)encodeDouble:(double)aDouble forKey:(CPString)aKey
          Encodes a double value.
-(void)encodeFloat:(float)aFloat forKey:(CPString)aKey
          Encodes a float value.
-(void)encodeInt:(float)anInt forKey:(CPString)aKey
          Encodes a int value.
-(void)encodeNumber:(CPNumber)aNumber forKey:(CPString)aKey
          Encodes a number.
-(void)encodeObject:(id)anObject forKey:(CPString)aKey
          Encdoes an object.
-(void)encodePoint:(CGPoint)aPoint forKey:(CPString)aKey
          Encodes a CGPoint.
-(void)encodeRect:(CGRect)aRect forKey:(CPString)aKey
          Encodes a CGRect.
-(void)encodeSize:(CGSize)aSize forKey:(CPString)aKey
          Encodes a CGSize.
-(void)finishEncoding
          Finishes up writing any left over data, and notifies delegates.
-(CPPropertyListFormat)outputFormat
          Returns the property list format used to archive objects.
-(void)setClassName:(CPString)aClassName forClass:(Class)aClass
          Allows substitution of class types for encoding.
-(void)setDelegate:(id)aDelegate
          Sets the keyed archiver's delegate.
-(void)setOutputFormat:(CPPropertyListFormat)aPropertyListFormat
          Sets the property list format the archiver should use to archive objects.

Methods inherited from class CPObject
initialize, alloc, class, instanceMethodForSelector, instancesRespondToSelector, isSubclassOfClass, load, new, setVersion, superclass, version, init, autorelease, awakeAfterUsingCoder, class, classForCoder, classForKeyedArchiver, className, copy, dealloc, description, doesNotRecognizeSelector, forwardInvocation, hash, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableCopy, performSelector, performSelector, performSelector, release, replacementObjectForArchiver, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, retain, self, superclass

Methods inherited from class CPCoder
allowsKeyedCoding, encodeBycopyObject, encodeConditionalObject, encodeDataObject, encodeObject, encodePoint, encodePropertyList, encodeRect, encodeRootObject, encodeSize, encodeValueOfObjCType

Delegate Method Summary
-(void)archiverWillFinish:(CPKeyedArchiver)archiver
          Called when the encoding is about to finish.
-(void)archiver:(CPKeyedArchiver)archiver didEncodeObject:(id)object
          Called when an object is encoded into the archiver.
-(void)archiverDidFinish:(CPKeyedArchiver)archiver
          Called when the archiver finishes encoding.
-(id)archiver:(CPKeyedArchiver)archiver willEncodeObject:(id)object
          Called when an object is about to be encoded.
-(void)archiver:(CPKeyedArchiver)archiver willReplaceObject:(id)object withObject:(id)newObject
          Called when an object is being replaced in the archiver.


Method Detail

allowsKeyedCoding

+(BOOL)allowsKeyedCoding
Returns a flag indicating whether the receiver supports keyed coding. The default implementation returns NO. Subclasses supporting keyed coding must override this to return YES.

archivedDataWithRootObject

+(CPData)archivedDataWithRootObject:(id)anObject
Archives the specified object.
Parameters:
anObject - the object to archive
Returns:
the archived object

classNameForClass

+(CPString)classNameForClass:(Class)aClass
Returns the name of the substitute class used for encoding aClass by all keyed archivers.
Parameters:
aClass - the class to substitute
Returns:
the name of the substitute class, or nil if there is no substitute class

setClassName

+(void)setClassName:(CPString)aClassName forClass:(Class)aClass
Allows substitution of class types for encoding. Specifically classes of type aClass encountered by all keyed archivers will instead be archived as a class of type aClassName.
Parameters:
aClassName - the substitute class name
aClass - the class to substitute

initForWritingWithMutableData

-(id)initForWritingWithMutableData:(CPMutableData)data
Initializes the keyed archiver with the specified CPMutableData for writing.
Parameters:
data - the object to archive to
Returns:
the initialized keyed archiver

classNameForClass

-(CPString)classNameForClass:(Class)aClass
Returns the name of the substitute class used for encoding aClass by this keyed archiver.
Parameters:
aClass - the class to substitute
Returns:
the name of the substitute class, or nil if there is no substitute class

delegate

-(id)delegate
Returns the keyed archiver's delegate

encodeBool

-(void)encodeBool:(BOOL)aBOOL forKey:(CPString)aKey
Encodes a BOOL value
Parameters:
aBOOL
aKey - the key to associate with the BOOL

encodeConditionalObject

-(void)encodeConditionalObject:(id)anObject forKey:(CPString)aKey
Encodes an conditionally. The method checks if the object has already been coded into this data stream before. If so, it will only encode a reference to that first object to save memory.
Parameters:
anObject - the object to to conditionally encode
aKey - the key to associate with the object

encodeDouble

-(void)encodeDouble:(double)aDouble forKey:(CPString)aKey
Encodes a double value
Parameters:
aDouble - the double value
aKey - the key to associate with the double

encodeFloat

-(void)encodeFloat:(float)aFloat forKey:(CPString)aKey
Encodes a float value
Parameters:
aFloat - the float value
aKey - the key to associate with the float

encodeInt

-(void)encodeInt:(float)anInt forKey:(CPString)aKey
Encodes a int value
Parameters:
anInt - the int value
aKey - the key to associate with the int

encodeNumber

-(void)encodeNumber:(CPNumber)aNumber forKey:(CPString)aKey
Encodes a number
Parameters:
aNumber - the number to encode
aKey - the key to associate with the object

encodeObject

-(void)encodeObject:(id)anObject forKey:(CPString)aKey
Encdoes an object
Parameters:
anObject - the object to encode
aKey - the key to associate with the object

encodePoint

-(void)encodePoint:(CGPoint)aPoint forKey:(CPString)aKey
Encodes a CGPoint
Parameters:
aPoint - the point to encode
aKey - the key to associate with the point

encodeRect

-(void)encodeRect:(CGRect)aRect forKey:(CPString)aKey
Encodes a CGRect
Parameters:
aRect - the rectangle to encode
aKey - the key to associate with the rectangle

encodeSize

-(void)encodeSize:(CGSize)aSize forKey:(CPString)aKey
Encodes a CGSize
Parameters:
aSize - the size to encode
aKey - the key to associate with the size

finishEncoding

-(void)finishEncoding
Finishes up writing any left over data, and notifies delegates. After calling this method, the archiver can not encode anymore objects.

outputFormat

-(CPPropertyListFormat)outputFormat
Returns the property list format used to archive objects.

setClassName

-(void)setClassName:(CPString)aClassName forClass:(Class)aClass
Allows substitution of class types for encoding. Specifically classes of type aClass encountered by this keyed archiver will instead be archived as a class of type aClassName.
Parameters:
aClassName - the substitute class name
aClass - the class to substitute

setDelegate

-(void)setDelegate:(id)aDelegate
Sets the keyed archiver's delegate
Parameters:
aDelegate

setOutputFormat

-(void)setOutputFormat:(CPPropertyListFormat)aPropertyListFormat
Sets the property list format the archiver should use to archive objects.
Parameters:
aPropertyListFormat - the format to use

Delegate Method Detail

archiverWillFinish

-(void)archiverWillFinish:(CPKeyedArchiver)archiver
Called when the encoding is about to finish.
Parameters:
archiver - the archiver that's about to finish

archiver

-(void)archiver:(CPKeyedArchiver)archiver didEncodeObject:(id)object
Called when an object is encoded into the archiver.
Parameters:
archiver - the archiver that encoded the object
object - the object that was encoded

archiverDidFinish

-(void)archiverDidFinish:(CPKeyedArchiver)archiver
Called when the archiver finishes encoding.
Parameters:
archiver - the arhiver that finished encoding

archiver

-(id)archiver:(CPKeyedArchiver)archiver willEncodeObject:(id)object
Called when an object is about to be encoded. Allows the delegate to replace the object that gets encoded with a substitute or nil.
Parameters:
archiver - the archiver encoding the object
object - the candidate object for encoding
Returns:
the object to encode

archiver

-(void)archiver:(CPKeyedArchiver)archiver willReplaceObject:(id)object withObject:(id)newObject
Called when an object is being replaced in the archiver.
Parameters:
archiver - the archiver encoding the object
object - the object to be replaced
newObject - the replacement object

Created on Sat Sep 13 14:15:43 PDT 2008