mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Reimplement some methods to fix some issues.
This commit is contained in:
parent
6ad1e47ab7
commit
0a2f885456
3 changed files with 64 additions and 12 deletions
|
@ -31,6 +31,8 @@
|
|||
#import "Foundation/NSPortCoder.h"
|
||||
#import "Foundation/NSIndexSet.h"
|
||||
#import "Foundation/NSKeyedArchiver.h"
|
||||
#import "Foundation/NSValue.h"
|
||||
#import "Foundation/NSDictionary.h"
|
||||
#import "GNUstepBase/GSObjCRuntime.h"
|
||||
#import "GSPrivate.h"
|
||||
#import "GSFastEnumeration.h"
|
||||
|
@ -309,8 +311,8 @@ static Class mutableSetClass;
|
|||
- (void) replaceObjectAtIndex: (NSUInteger)index
|
||||
withObject: (id)obj
|
||||
{
|
||||
[self _insertObject: obj atIndex: index];
|
||||
[self removeObjectAtIndex: index];
|
||||
[self insertObject: obj atIndex: index];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
|
||||
@class GSMutableOrderedSet;
|
||||
@interface GSMutableOrderedSet : NSObject // Help the compiler
|
||||
- (void) _raiseRangeExceptionWithIndex: (NSUInteger)index from: (SEL)sel;
|
||||
@end
|
||||
|
||||
@interface NSMutableOrderedSet (Private)
|
||||
|
@ -1306,6 +1307,28 @@ static SEL rlSel;
|
|||
return NSMutableOrderedSet_abstract_class;
|
||||
}
|
||||
|
||||
- (void) _raiseRangeExceptionWithIndex: (NSUInteger)index from: (SEL)sel
|
||||
{
|
||||
NSDictionary *info;
|
||||
NSException *exception;
|
||||
NSString *reason;
|
||||
NSUInteger count = [self count];
|
||||
|
||||
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithUnsignedInteger: index], @"Index",
|
||||
[NSNumber numberWithUnsignedInteger: count], @"Count",
|
||||
self, @"GSMutableSet", nil, nil];
|
||||
|
||||
reason = [NSString stringWithFormat:
|
||||
@"Index %"PRIuPTR" is out of range %d (in '%@')",
|
||||
index, count, NSStringFromSelector(sel)];
|
||||
|
||||
exception = [NSException exceptionWithName: NSRangeException
|
||||
reason: reason
|
||||
userInfo: info];
|
||||
[exception raise];
|
||||
}
|
||||
|
||||
- (instancetype)initWithCapacity: (NSUInteger)capacity
|
||||
{
|
||||
self = [self init];
|
||||
|
@ -1536,11 +1559,9 @@ static SEL rlSel;
|
|||
|
||||
if (c > 0)
|
||||
{
|
||||
IMP remLast = [self methodForSelector: rlSel];
|
||||
|
||||
while (c--)
|
||||
{
|
||||
(*remLast)(self, rlSel);
|
||||
[self removeObjectAtIndex: 0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1632,14 +1653,34 @@ static SEL rlSel;
|
|||
}
|
||||
}
|
||||
|
||||
- (void) exchangeObjectAtIndex:(NSUInteger)index withObjectAtIndex:(NSUInteger)otherIndex
|
||||
- (void) exchangeObjectAtIndex:(NSUInteger)index
|
||||
withObjectAtIndex:(NSUInteger)otherIndex
|
||||
{
|
||||
id tmp = [self objectAtIndex: index];
|
||||
|
||||
RETAIN(tmp);
|
||||
[self replaceObjectAtIndex: index withObject: [self objectAtIndex: otherIndex]];
|
||||
[self replaceObjectAtIndex: otherIndex withObject: tmp];
|
||||
RELEASE(tmp);
|
||||
NSUInteger count = [self count];
|
||||
|
||||
GS_BEGINIDBUF(objs, count);
|
||||
if (index >= count)
|
||||
{
|
||||
[self _raiseRangeExceptionWithIndex: index from: _cmd];
|
||||
}
|
||||
if (otherIndex >= count)
|
||||
{
|
||||
[self _raiseRangeExceptionWithIndex: otherIndex from: _cmd];
|
||||
}
|
||||
if (index != otherIndex)
|
||||
{
|
||||
id tmp = nil;
|
||||
NSRange range = NSMakeRange(0,[self count]);
|
||||
|
||||
[self getObjects: objs range: range];
|
||||
tmp = objs[index];
|
||||
objs[index] = objs[otherIndex];
|
||||
objs[otherIndex] = tmp;
|
||||
|
||||
[self removeAllObjects];
|
||||
[self addObjects: objs count: count];
|
||||
}
|
||||
GS_ENDIDBUF();
|
||||
}
|
||||
|
||||
- (void)filterUsingPredicate:(NSPredicate *)predicate
|
||||
|
|
|
@ -192,7 +192,16 @@ int main()
|
|||
PASS([[mutableTest4 objectAtIndex: 10] isEqual:@"time"] == YES,
|
||||
"Move to index moves to correct index");
|
||||
|
||||
NSLog(@"RESULT: %@",mutableTest4);
|
||||
NSMutableOrderedSet *mutableTest5 = [NSMutableOrderedSet orderedSet];
|
||||
[mutableTest5 addObject:@"Now"];
|
||||
[mutableTest5 addObject:@"is"];
|
||||
[mutableTest5 addObject:@"the"];
|
||||
[mutableTest5 exchangeObjectAtIndex:0 withObjectAtIndex:2];
|
||||
[testObjs addObject: mutableTest5];
|
||||
PASS([[mutableTest5 objectAtIndex: 0] isEqual:@"the"] == YES &&
|
||||
[[mutableTest5 objectAtIndex: 2] isEqual:@"Now"] == YES,
|
||||
"Exchanges indexes properly");
|
||||
//NSLog(@"RESULT: %@",mutableTest4);
|
||||
|
||||
test_NSObject(@"NSOrderedSet", testObjs);
|
||||
test_NSCoding(testObjs);
|
||||
|
|
Loading…
Reference in a new issue