From ba2940682253a16c0c3a00d35d8756f02fe69253 Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 11 Dec 2007 07:52:45 +0000 Subject: [PATCH] Implement old style encoding/decoding git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25720 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 1 + Source/NSIndexSet.m | 80 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa5bc2fa9..b56d79998 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * Source/NSIndexSet.m: Test and debug ([-initWithCoder:]) and ([-encodeWithCoder:]) methods for keyed archiving of sets with multiple index ranges. + Implement old-style coding/decoding as well. 2007-12-10 Chris Farber diff --git a/Source/NSIndexSet.m b/Source/NSIndexSet.m index 4a35d4d5f..1f323d25c 100644 --- a/Source/NSIndexSet.m +++ b/Source/NSIndexSet.m @@ -276,14 +276,22 @@ static unsigned posForIndex(GSIArray array, unsigned index) - (void) encodeWithCoder: (NSCoder*)aCoder { - int rangeCount = 0; + unsigned rangeCount = 0; if (_array != 0) { rangeCount = GSIArrayCount(_array); } - - [aCoder encodeInt: rangeCount forKey: @"NSRangeCount"]; + + if ([aCoder allowsKeyedCoding]) + { + [aCoder encodeInt: rangeCount forKey: @"NSRangeCount"]; + } + else + { + [aCoder encodeValueOfObjCType: @encode(unsigned int) + at: &rangeCount]; + } if (rangeCount == 0) { @@ -294,8 +302,18 @@ static unsigned posForIndex(GSIArray array, unsigned index) NSRange r; r = GSIArrayItemAtIndex(_array, 0).ext; - [aCoder encodeInt: r.location forKey: @"NSLocation"]; - [aCoder encodeInt: r.length forKey: @"NSLength"]; + if ([aCoder allowsKeyedCoding]) + { + [aCoder encodeInt: r.location forKey: @"NSLocation"]; + [aCoder encodeInt: r.length forKey: @"NSLength"]; + } + else + { + [aCoder encodeValueOfObjCType: @encode(unsigned int) + at: &r.location]; + [aCoder encodeValueOfObjCType: @encode(unsigned int) + at: &r.length]; + } } else { @@ -340,7 +358,14 @@ static unsigned posForIndex(GSIArray array, unsigned index) } while (v > 0); } - [aCoder encodeObject: m forKey: @"NSRangeData"]; + if ([aCoder allowsKeyedCoding]) + { + [aCoder encodeObject: m forKey: @"NSRangeData"]; + } + else + { + [aCoder encodeObject: m]; + } } } @@ -523,11 +548,19 @@ static unsigned posForIndex(GSIArray array, unsigned index) - (id) initWithCoder: (NSCoder*)aCoder { - int rangeCount = 0; + unsigned rangeCount = 0; - if ([aCoder containsValueForKey: @"NSRangeCount"]) + if ([aCoder allowsKeyedCoding]) { - rangeCount = [aCoder decodeIntForKey: @"NSRangeCount"]; + if ([aCoder containsValueForKey: @"NSRangeCount"]) + { + rangeCount = [aCoder decodeIntForKey: @"NSRangeCount"]; + } + } + else + { + [aCoder decodeValueOfObjCType: @encode(unsigned int) + at: &rangeCount]; } if (rangeCount == 0) @@ -539,13 +572,23 @@ static unsigned posForIndex(GSIArray array, unsigned index) unsigned len = 0; unsigned loc = 0; - if ([aCoder containsValueForKey: @"NSLocation"]) + if ([aCoder allowsKeyedCoding]) { - loc = [aCoder decodeIntForKey: @"NSLocation"]; + if ([aCoder containsValueForKey: @"NSLocation"]) + { + loc = [aCoder decodeIntForKey: @"NSLocation"]; + } + if ([aCoder containsValueForKey: @"NSLength"]) + { + len = [aCoder decodeIntForKey: @"NSLength"]; + } } - if ([aCoder containsValueForKey: @"NSLength"]) + else { - len = [aCoder decodeIntForKey: @"NSLength"]; + [aCoder decodeValueOfObjCType: @encode(unsigned int) + at: &loc]; + [aCoder decodeValueOfObjCType: @encode(unsigned int) + at: &len]; } self = [self initWithIndexesInRange: NSMakeRange(loc, len)]; } @@ -557,9 +600,16 @@ static unsigned posForIndex(GSIArray array, unsigned index) unsigned length; unsigned index = 0; - if ([aCoder containsValueForKey: @"NSRangeData"]) + if ([aCoder allowsKeyedCoding]) { - data = [aCoder decodeObjectForKey: @"NSRangeData"]; + if ([aCoder containsValueForKey: @"NSRangeData"]) + { + data = [aCoder decodeObjectForKey: @"NSRangeData"]; + } + } + else + { + data = [aCoder decodeObject]; } bytes = (const uint8_t*)[data bytes]; length = [data length];