gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keyed decoding of geometry


From: Fred Kiefer
Subject: Re: Keyed decoding of geometry
Date: Mon, 26 Jan 2004 02:06:41 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030821

Richard Frith-Macdonald wrote:
On 24 Jan 2004, at 17:06, Fred Kiefer wrote:
And I also tried to write a few sample decoding methods based on that NIB file. I made specific methods out of them, so that it will be easier to keep them a bit apart from our current decoding code. Actually I would like to see some method like the follwoing on NSObject so we dont have to mix the different code in one method:


- (id) initWithCoder: (NSCoder*)aCoder
{
  if ([aCoder allowsKeyedCoding])
    {
    self = [self initWithKeyedCoder: aCoder];
    }
    else
    {
    // call old decoder code, for which I don't have a great name
    }
}


Maybe, on the other hand, keeping the two together might be considered a virtue ... certainly if the code involved is small.

We should try to get more opinions on this. The pros for a separate hierarxchy for each encoder type arethat the methods are shorter and cleaner and that calls to super may use the short cut, as they know what sort of archiver they are dealing with. For the cons I only see the additional method call.


And now to show you how easy some base classes could be decoded:

@implementation NSArray (NSKeyedCoding)

- (id) initWithKeyedCoder: (NSCoder*)aCoder
{
  NSArray *array = [aCoder decodeObjectForKey: @"NS.objects"];

  [self initWithArray: array];
  return self;
}

@end

@implementation NSSet (NSKeyedCoding)

- (id) initWithKeyedCoder: (NSCoder*)aCoder
{
  NSArray *array = [aCoder decodeObjectForKey: @"NS.objects"];

  [self initWithArray: array];
  return self;
}


I'm not sure this is right ... I think you are looking at something I've not impemented yet (and not even fully investigated). It appears that the keyed archiver implements -encodeArrayOfObjCType:length:at: by creating a temporary object of a private class in which to encapsulate the array, then encodes that temporary object. The temporary object encodes itsself
by writing various items with names like 'NS.objects'
To implement this properly, I need to figure out exactly how the private class (_NSKeyedCoderOldStyleArray) encodes itsself for arrays of different types of data. Quite possibly there are other things missed ... I haven't played with it to see how MacOS-X implements encodeValuesOfObjCTypes: for instance.



I did not say that my code is already usable. BUt as soon as your decoder is running it should work.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]