Re: Persistance
Re: Persistance
- Subject: Re: Persistance
- From: Marcel Weiher <email@hidden>
- Date: Wed, 10 Oct 2001 09:13:02 +0200
Hi Chris,
good to hear that you guys are addressing this.
On Wednesday, October 10, 2001, at 02:43 AM, Chris Kane wrote:
At 10:59 AM +0200 10/9/01, Marcel Weiher wrote:
Objective-XML, for example, has an NSArchiver implementation that
generates XML files using NSCoding protocol. I am currently looking
at making the generated XML SOAP compatible (as much as feasible).
Apple also has a named-value encoder/decoder that generates XML,
waiting in the wings.
Great! It would be nice if we could coordinate at least the APIs
(possibly the default format as well) in order to make this stuff
plug-compatible. Do you have a copy of the MPWFoundation handy? The
additional API is in 'CodingAdditions.[hm]'
Here's the additional protocol:
@interface NSCoder(NamedCoding)
-(void)encodeObject:anObject withName:aName;
-decodeObjectWithName:aName;
-(void)encodeValueOfObjCType:(const unsigned char*)type at:(const
void*)var withName:(NSString*)name;
-(void)decodeValueOfObjCType:(const unsigned char*)type at:(void*)var
withName:(NSString*)name;
-(void)encodeArrayOfObjCType:(const unsigned char*)type
count:(unsigned)count at:(const void*)var withName:(NSString*)name;
-(void)decodeArrayOfObjCType:(const unsigned char*)type
count:(unsigned)count at:(void*)var withName:(NSString*)name;
@end
All this does is add a 'withName:' parameter to each of the
-encodeObject and encode{Value|Array}OfObjectType:... methods and their
corresponding decode methods.
I also find the
encodeVar( coder, varName )
decodeVar( coder, varName )
Macros extremely handy, because in about 99% of the cases, you simply
want to use the name of the instance variable.
We hope to introduce it in the next OS release. The bigger project is
converting AppKit and Foundation to take advantage of it (to achieve
the backwards AND forwards compatibility).
The best way is, of course, to update the code. However, the protocol
introduced in MPWFoundation achieves backwards and forwards
compatibility with the existing Foundation/AppKit code-base, obviously
without access to source. There are some areas that have to be
special-cased, but overall it works nicely.
For some, for example, using a technique like NSKeyValueCoding to do
limited "automatic" archiving has appeal (I pick that as one example,
since it's a suggestion that comes up every so often).
I've actually implemented that technique for a project where I needed
archiving only temporarily for testing purposes. It works very nicely
and is completely independent of the actual archiver used.
I would be interested in hearing from anyone who's written their own
coder that would like to share their solution to the 'half-initialized
object' problems during decoding, if they've solved them.
I am not quite sure which 'half-initialized object' problem you mean. I
have the problem that the XML-parser has the thread of control, and
cannot easily yield that thread of control to -initWithCoder: in an
interleaved fashion. My current solution is very simplistic: the
XML-parser creates a 'ValueHolder' object that is then read by the
Unarchiver during -initWithCoder: time. This isn't particularly costly
because the MPWObjectCache eliminates most of the actual object
allocations.
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Mad Scientist HOM, IDEAs, MetaAd and more