mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Guessed implementation for keyed archiving.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25684 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b31f78629e
commit
c4fa37544f
2 changed files with 106 additions and 9 deletions
|
@ -1,3 +1,8 @@
|
|||
2007-12-06 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSIndexSet.m (-initWithCoder:): Implement guessed algorithm
|
||||
for keyed archiving of sets with multiple index ranges.
|
||||
|
||||
2007-12-06 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSIndexSet.m (-initWithCoder:): Fix wrong method in last
|
||||
|
|
|
@ -23,10 +23,11 @@
|
|||
|
||||
*/
|
||||
|
||||
#include "Foundation/NSCoder.h"
|
||||
#include <Foundation/NSIndexSet.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSZone.h>
|
||||
#include "Foundation/NSCoder.h"
|
||||
#include "Foundation/NSData.h"
|
||||
#include "Foundation/NSIndexSet.h"
|
||||
#include "Foundation/NSException.h"
|
||||
#include "Foundation/NSZone.h"
|
||||
|
||||
#define GSI_ARRAY_TYPE NSRange
|
||||
#define GSI_ARRAY_TYPES GSI_ARRAY_EXTRA
|
||||
|
@ -298,8 +299,48 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
|||
}
|
||||
else
|
||||
{
|
||||
// FIXME
|
||||
[self notImplemented:_cmd];
|
||||
NSMutableData *m = [NSMutableData dataWithCapacity: rangeCount*2];
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < rangeCount; i++)
|
||||
{
|
||||
NSRange r;
|
||||
unsigned v;
|
||||
uint8_t b;
|
||||
|
||||
r = GSIArrayItemAtIndex(_array, 0).ext;
|
||||
v = r.location;
|
||||
do
|
||||
{
|
||||
if (v > 0x7f)
|
||||
{
|
||||
b = (v & 0x7f) | 0x80;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = v;
|
||||
}
|
||||
v >>= 7;
|
||||
[m appendBytes: &b length: 1];
|
||||
}
|
||||
while (v > 0);
|
||||
v = r.length;
|
||||
do
|
||||
{
|
||||
if (v > 0x7f)
|
||||
{
|
||||
b = (v & 0x7f) | 0x80;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = v;
|
||||
}
|
||||
v >>= 7;
|
||||
[m appendBytes: &b length: 1];
|
||||
}
|
||||
while (v > 0);
|
||||
[aCoder encodeObject: m forKey: @"NSRangeData"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,13 +551,65 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
|||
}
|
||||
else
|
||||
{
|
||||
NSData * data = nil;
|
||||
NSMutableIndexSet *other = [NSMutableIndexSet new];
|
||||
NSData *data = nil;
|
||||
const uint8_t *bytes;
|
||||
unsigned length;
|
||||
unsigned index;
|
||||
|
||||
if ([aCoder containsValueForKey: @"NSRangeData"])
|
||||
{
|
||||
data = [aCoder decodeObjectForKey: @"NSRangeData"];
|
||||
}
|
||||
|
||||
bytes = (const uint8_t*)[data bytes];
|
||||
length = [data length];
|
||||
while (index < length)
|
||||
{
|
||||
NSRange range;
|
||||
unsigned offset;
|
||||
unsigned value;
|
||||
unsigned next;
|
||||
|
||||
for (offset = 0; index + offset < length; offset++)
|
||||
{
|
||||
if (bytes[index + offset] < 0x80)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
NSAssert(index + offset < length && bytes[index + offset] < 0x80,
|
||||
NSInternalInconsistencyException);
|
||||
next = index + offset + 1;
|
||||
value = bytes[index + offset];
|
||||
while (offset-- > 0)
|
||||
{
|
||||
value <<= 7;
|
||||
value += (bytes[index + offset] & 0x7f);
|
||||
}
|
||||
range.location = value;
|
||||
index = next;
|
||||
for (offset = 0; index + offset < length; offset++)
|
||||
{
|
||||
if (bytes[index + offset] < 0x80)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
NSAssert(index + offset < length && bytes[index + offset] < 0x80,
|
||||
NSInternalInconsistencyException);
|
||||
next = index + offset + 1;
|
||||
value = bytes[index + offset];
|
||||
while (offset-- > 0)
|
||||
{
|
||||
value <<= 7;
|
||||
value += (bytes[index + offset] & 0x7f);
|
||||
}
|
||||
range.length = value;
|
||||
index = next;
|
||||
[other addIndexesInRange: range];
|
||||
}
|
||||
self = [self initWithIndexSet: other];
|
||||
RELEASE(other);
|
||||
/*
|
||||
FIXME:
|
||||
NSLog(@"Decoded count %d, data %@", rangeCount, data);
|
||||
|
@ -526,7 +619,6 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
|||
5 + 6 + 23 gives <05021701>
|
||||
155 + 156 + 223 gives <9b0102df 0101>
|
||||
*/
|
||||
[self notImplemented:_cmd];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
|
Loading…
Reference in a new issue