mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Several minor fixes to return types and return values.
([ReverseEnumerator -nextObject]): Pass pointer to enum_state. ([ConstantIndexedCollection -prevObjectWithEnumState:]): Method overhauled. ([ConstantIndexedCollection -nextObjectWithEnumState:]): Likewise. ([ConstantIndexedCollection -newEnumState]): New method. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1129 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2c829084eb
commit
f2ccdab2ce
1 changed files with 48 additions and 15 deletions
|
@ -26,12 +26,13 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <objects/Array.h>
|
#include <objects/Array.h>
|
||||||
#include <objects/NSString.h>
|
#include <objects/NSString.h>
|
||||||
|
#include <objects/behavior.h>
|
||||||
|
|
||||||
@implementation ReverseEnumerator
|
@implementation ReverseEnumerator
|
||||||
|
|
||||||
- nextObject
|
- nextObject
|
||||||
{
|
{
|
||||||
return [collection prevObjectWithEnumState: enum_state];
|
return [collection prevObjectWithEnumState: &enum_state];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -45,6 +46,7 @@
|
||||||
- objectAtIndex: (unsigned)index
|
- objectAtIndex: (unsigned)index
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- firstObject
|
- firstObject
|
||||||
|
@ -263,12 +265,24 @@
|
||||||
|
|
||||||
- prevObjectWithEnumState: (void**)enumState
|
- prevObjectWithEnumState: (void**)enumState
|
||||||
{
|
{
|
||||||
/* *(unsigned*)enumState-1 is the index of the element
|
/* *(int*)enumState is the index of the element that was returned
|
||||||
that will be returned */
|
last time -prevObjectWithEnumState: or -nextObjectWithEnumState
|
||||||
if (!(*enumState))
|
was called. In -newEnumState, *(int*)enumState is initialized to
|
||||||
*(unsigned*)enumState = [self count]-1;
|
-2; The implementation of -newEnumState can be found below. */
|
||||||
|
|
||||||
|
/* If there are not objects in this collection, or we are being
|
||||||
|
asked for the object before the first object, return nil. */
|
||||||
|
if ([self isEmpty] || (*(int*)enumState) == 0)
|
||||||
|
return NO_OBJECT;
|
||||||
|
|
||||||
|
if (*(int*)enumState == -2)
|
||||||
|
/* enumState was just initialized by -newEnumState, start
|
||||||
|
at the end of the sequence. */
|
||||||
|
*(int*)enumState = [self count]-1;
|
||||||
else
|
else
|
||||||
(*(unsigned*)enumState)--;
|
/* ...otherwise go to the previous index.*/
|
||||||
|
(*(int*)enumState)--;
|
||||||
|
|
||||||
return [self objectAtIndex:(*(unsigned*)enumState)];
|
return [self objectAtIndex:(*(unsigned*)enumState)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,31 +293,50 @@
|
||||||
- shallowCopyRange: (IndexRange)aRange
|
- shallowCopyRange: (IndexRange)aRange
|
||||||
{
|
{
|
||||||
[self notImplemented: _cmd];
|
[self notImplemented: _cmd];
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- shallowCopyInReverse
|
- shallowCopyInReverse
|
||||||
{
|
{
|
||||||
[self notImplemented: _cmd];
|
[self notImplemented: _cmd];
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- shallowCopyInReverseRange: (IndexRange)aRange
|
- shallowCopyInReverseRange: (IndexRange)aRange
|
||||||
{
|
{
|
||||||
[self notImplemented: _cmd];
|
[self notImplemented: _cmd];
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// OVERRIDE SOME COLLECTION METHODS;
|
// OVERRIDE SOME COLLECTION METHODS;
|
||||||
|
|
||||||
|
- (void*) newEnumState
|
||||||
|
{
|
||||||
|
return (void*) -2;
|
||||||
|
}
|
||||||
|
|
||||||
- nextObjectWithEnumState: (void**)enumState
|
- nextObjectWithEnumState: (void**)enumState
|
||||||
{
|
{
|
||||||
id ret;
|
/* *(int*)enumState is the index of the element that was returned
|
||||||
/* *(unsigned*)enumState is the index of the element that will be returned */
|
last time -prevObjectWithEnumState: or -nextObjectWithEnumState
|
||||||
if ([self isEmpty]
|
was called. In -newEnumState, *(int*)enumState is initialized to
|
||||||
|| (*(unsigned*)enumState) > [self count]-1)
|
-2. */
|
||||||
|
|
||||||
|
/* If there are not objects in this collection, or we are being
|
||||||
|
asked for the object after the last object, return nil. */
|
||||||
|
if ([self isEmpty] || (*(int*)enumState) > [self count]-1)
|
||||||
return NO_OBJECT;
|
return NO_OBJECT;
|
||||||
ret = [self objectAtIndex:(*(unsigned*)enumState)];
|
|
||||||
*(unsigned*)enumState = *(unsigned*)enumState + 1;
|
if (*(int*)enumState == -2)
|
||||||
return ret;
|
/* enumState was just initialized by -newEnumState, start
|
||||||
|
at the beginning of the sequence. */
|
||||||
|
*(int*)enumState = 0;
|
||||||
|
else
|
||||||
|
/* ...otherwise go the next index. */
|
||||||
|
(*(int*)enumState)++;
|
||||||
|
|
||||||
|
return [self objectAtIndex:(*(unsigned*)enumState)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is this what we want? */
|
/* is this what we want? */
|
||||||
|
@ -334,7 +367,7 @@
|
||||||
|
|
||||||
// REPLACING;
|
// REPLACING;
|
||||||
|
|
||||||
- replaceObjectAtIndex: (unsigned)index withObject: newObject
|
- (void) replaceObjectAtIndex: (unsigned)index withObject: newObject
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
@ -359,7 +392,7 @@
|
||||||
|
|
||||||
- (void) removeRange: (IndexRange)aRange
|
- (void) removeRange: (IndexRange)aRange
|
||||||
{
|
{
|
||||||
int count;
|
int count = aRange.length;
|
||||||
|
|
||||||
CHECK_INDEX_RANGE_ERROR(aRange.location, [self count]);
|
CHECK_INDEX_RANGE_ERROR(aRange.location, [self count]);
|
||||||
CHECK_INDEX_RANGE_ERROR(aRange.location+aRange.length-1, [self count]);
|
CHECK_INDEX_RANGE_ERROR(aRange.location+aRange.length-1, [self count]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue