mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Overhaul for new collection class scheme to improve distributed
objects and NeXT-compatibility. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@966 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a867a5e028
commit
ee361e59f8
2 changed files with 17 additions and 50 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <objects/IndexedCollection.h>
|
||||
#include <objects/IndexedCollectionPrivate.h>
|
||||
#include <objects/MallocAddress.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
/* memcpy(), strlen(), strcmp() are gcc builtin's */
|
||||
|
||||
@implementation NSGCString
|
||||
|
@ -43,11 +44,15 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
- (void) _collectionReleaseContents
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
- (void) _collectionDealloc
|
||||
{
|
||||
if (_free_contents)
|
||||
OBJC_FREE(_contents_chars);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (Class) classForConnectedCoder: aRmc
|
||||
|
@ -124,12 +129,10 @@
|
|||
|
||||
// FOR IndexedCollection SUPPORT;
|
||||
|
||||
- (elt) elementAtIndex: (unsigned)index
|
||||
- objectAtIndex: (unsigned)index
|
||||
{
|
||||
elt ret_elt;
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
ret_elt.char_u = _contents_chars[index];
|
||||
return ret_elt;
|
||||
return [NSNumber numberWithChar: _contents_chars[index]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -246,11 +249,10 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
|
|||
|
||||
/* xxx This should be made to return void, but we need to change
|
||||
IndexedCollecting and its conformers */
|
||||
- removeRange: (IndexRange)range
|
||||
- (void) removeRange: (IndexRange)range
|
||||
{
|
||||
stringDecrementCountAndFillHoleAt((NSGMutableCStringStruct*)self,
|
||||
range.location, range.length);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: aCoder
|
||||
|
@ -292,7 +294,10 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
|
|||
return _contents_chars[index];
|
||||
}
|
||||
|
||||
- insertElement: (elt)newElement atIndex: (unsigned)index
|
||||
|
||||
// FOR IndexedCollection and OrderedCollection SUPPORT;
|
||||
|
||||
- (void) insertObject: newObject atIndex: (unsigned)index
|
||||
{
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count+1);
|
||||
// one for the next char, one for the '\0';
|
||||
|
@ -302,28 +307,15 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
|
|||
OBJC_REALLOC(_contents_chars, char, _capacity);
|
||||
}
|
||||
stringIncrementCountAndMakeHoleAt((NSGMutableCStringStruct*)self, index, 1);
|
||||
_contents_chars[index] = newElement.char_u;
|
||||
_contents_chars[index] = [newObject charValue];
|
||||
_contents_chars[_count] = '\0';
|
||||
return self;
|
||||
}
|
||||
|
||||
- (elt) removeElementAtIndex: (unsigned)index
|
||||
- (void) removeObjectAtIndex: (unsigned)index
|
||||
{
|
||||
elt ret;
|
||||
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
ret = _contents_chars[index];
|
||||
stringDecrementCountAndFillHoleAt((NSGMutableCStringStruct*)self, index, 1);
|
||||
_contents_chars[_count] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (elt) elementAtIndex: (unsigned)index
|
||||
{
|
||||
elt ret_elt;
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
ret_elt.char_u = _contents_chars[index];
|
||||
return ret_elt;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -75,19 +75,9 @@
|
|||
}
|
||||
|
||||
/* This override in mutable string classes */
|
||||
- empty
|
||||
- (void) empty
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Override the designated initializer of superclass */
|
||||
- initWithType: (const char *)contentEncoding
|
||||
{
|
||||
if (strcmp(contentEncoding, @encode(char)))
|
||||
[self error:"invalid args to String initializer"];
|
||||
[super initWithType:contentEncoding];
|
||||
return self;
|
||||
}
|
||||
|
||||
- initWithCString: (const char*)aCharPtr length: (unsigned)aLength
|
||||
|
@ -286,21 +276,6 @@
|
|||
|
||||
// TESTING;
|
||||
|
||||
- (const char *) contentsDescription
|
||||
{
|
||||
return @encode(char);
|
||||
}
|
||||
|
||||
- (const char *) contentType
|
||||
{
|
||||
return @encode(char);
|
||||
}
|
||||
|
||||
- (int(*)(elt,elt)) comparisonFunction
|
||||
{
|
||||
return elt_compare_chars;
|
||||
}
|
||||
|
||||
- (unsigned) hash
|
||||
{
|
||||
return elt_hash_string([self cString]);
|
||||
|
|
Loading…
Reference in a new issue