mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
revise to make embedding in other classes easier
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27865 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f5e3a00a50
commit
5b183e80e8
2 changed files with 98 additions and 91 deletions
|
@ -25,32 +25,41 @@
|
||||||
|
|
||||||
#import "Foundation/NSPointerFunctions.h"
|
#import "Foundation/NSPointerFunctions.h"
|
||||||
|
|
||||||
|
/* Declare a structure type to copy poinnnnnnter functions information
|
||||||
|
* around easily.
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
void* (*acquireFunction)(const void *item,
|
||||||
|
NSUInteger (*size)(const void *item), BOOL shouldCopy);
|
||||||
|
|
||||||
|
NSString *(*descriptionFunction)(const void *item);
|
||||||
|
|
||||||
|
NSUInteger (*hashFunction)(const void *item,
|
||||||
|
NSUInteger (*size)(const void *item));
|
||||||
|
|
||||||
|
BOOL (*isEqualFunction)(const void *item1, const void *item2,
|
||||||
|
NSUInteger (*size)(const void *item));
|
||||||
|
|
||||||
|
void (*relinquishFunction)(const void *item,
|
||||||
|
NSUInteger (*size)(const void *item));
|
||||||
|
|
||||||
|
NSUInteger (*sizeFunction)(const void *item);
|
||||||
|
|
||||||
|
BOOL shouldCopyIn;
|
||||||
|
|
||||||
|
BOOL usesStrongWriteBarrier;
|
||||||
|
|
||||||
|
BOOL usesWeakReadAndWriteBarriers;
|
||||||
|
} PFInfo;
|
||||||
|
|
||||||
|
/* Declare the concrete pointer functions class as a wrapper around
|
||||||
|
* an instance of the PFInfo structure.
|
||||||
|
*/
|
||||||
@interface NSConcretePointerFunctions : NSPointerFunctions
|
@interface NSConcretePointerFunctions : NSPointerFunctions
|
||||||
{
|
{
|
||||||
@public
|
@public
|
||||||
NSUInteger _options;
|
PFInfo _x;
|
||||||
|
|
||||||
void* (*_acquireFunction)(const void *item,
|
|
||||||
NSUInteger (*size)(const void *item), BOOL shouldCopy);
|
|
||||||
|
|
||||||
NSString *(*_descriptionFunction)(const void *item);
|
|
||||||
|
|
||||||
NSUInteger (*_hashFunction)(const void *item,
|
|
||||||
NSUInteger (*size)(const void *item));
|
|
||||||
|
|
||||||
BOOL (*_isEqualFunction)(const void *item1, const void *item2,
|
|
||||||
NSUInteger (*size)(const void *item));
|
|
||||||
|
|
||||||
void (*_relinquishFunction)(const void *item,
|
|
||||||
NSUInteger (*size)(const void *item));
|
|
||||||
|
|
||||||
NSUInteger (*_sizeFunction)(const void *item);
|
|
||||||
|
|
||||||
BOOL _shouldCopyIn;
|
|
||||||
|
|
||||||
BOOL _usesStrongWriteBarrier;
|
|
||||||
|
|
||||||
BOOL _usesWeakReadAndWriteBarriers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -61,11 +70,11 @@
|
||||||
/* Acquire the pointer value to store for the specified item.
|
/* Acquire the pointer value to store for the specified item.
|
||||||
*/
|
*/
|
||||||
static inline void
|
static inline void
|
||||||
pointerFunctionsAcquire(NSConcretePointerFunctions *PF, void **dst, void *src)
|
pointerFunctionsAcquire(PFInfo *PF, void **dst, void *src)
|
||||||
{
|
{
|
||||||
if (PF->_acquireFunction != 0)
|
if (PF->acquireFunction != 0)
|
||||||
src = (*PF->_acquireFunction)(src, PF->_sizeFunction, PF->_shouldCopyIn);
|
src = (*PF->acquireFunction)(src, PF->sizeFunction, PF->shouldCopyIn);
|
||||||
#if GS_WITH_GC
|
#if GSWITHGC
|
||||||
if (PF->usesWeakReadAndWriteBarriers)
|
if (PF->usesWeakReadAndWriteBarriers)
|
||||||
GSAssignZeroingWeakPointer(dst, src);
|
GSAssignZeroingWeakPointer(dst, src);
|
||||||
else
|
else
|
||||||
|
@ -77,10 +86,10 @@ pointerFunctionsAcquire(NSConcretePointerFunctions *PF, void **dst, void *src)
|
||||||
/* Generate an NSString description of the item
|
/* Generate an NSString description of the item
|
||||||
*/
|
*/
|
||||||
static inline NSString *
|
static inline NSString *
|
||||||
pointerFunctionsDescribe(NSConcretePointerFunctions *PF, void *item)
|
pointerFunctionsDescribe(PFInfo *PF, void *item)
|
||||||
{
|
{
|
||||||
if (PF->_descriptionFunction != 0)
|
if (PF->descriptionFunction != 0)
|
||||||
return (*PF->_descriptionFunction)(item);
|
return (*PF->descriptionFunction)(item);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,10 +97,10 @@ pointerFunctionsDescribe(NSConcretePointerFunctions *PF, void *item)
|
||||||
/* Generate the hash of the item
|
/* Generate the hash of the item
|
||||||
*/
|
*/
|
||||||
static inline NSUInteger
|
static inline NSUInteger
|
||||||
pointerFunctionsHash(NSConcretePointerFunctions *PF, void *item)
|
pointerFunctionsHash(PFInfo *PF, void *item)
|
||||||
{
|
{
|
||||||
if (PF->_hashFunction != 0)
|
if (PF->hashFunction != 0)
|
||||||
return (*PF->_hashFunction)(item, PF->_sizeFunction);
|
return (*PF->hashFunction)(item, PF->sizeFunction);
|
||||||
return (NSUInteger)item;
|
return (NSUInteger)item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,10 +108,10 @@ pointerFunctionsHash(NSConcretePointerFunctions *PF, void *item)
|
||||||
/* Compare two items for equality
|
/* Compare two items for equality
|
||||||
*/
|
*/
|
||||||
static inline BOOL
|
static inline BOOL
|
||||||
pointerFunctionsEqual(NSConcretePointerFunctions *PF, void *item1, void *item2)
|
pointerFunctionsEqual(PFInfo *PF, void *item1, void *item2)
|
||||||
{
|
{
|
||||||
if (PF->_isEqualFunction != 0)
|
if (PF->isEqualFunction != 0)
|
||||||
return (*PF->_isEqualFunction)(item1, item2, PF->_sizeFunction);
|
return (*PF->isEqualFunction)(item1, item2, PF->sizeFunction);
|
||||||
if (item1 == item2)
|
if (item1 == item2)
|
||||||
return YES;
|
return YES;
|
||||||
return NO;
|
return NO;
|
||||||
|
@ -112,11 +121,11 @@ pointerFunctionsEqual(NSConcretePointerFunctions *PF, void *item1, void *item2)
|
||||||
/* Relinquish the specified item and set it to zero.
|
/* Relinquish the specified item and set it to zero.
|
||||||
*/
|
*/
|
||||||
static inline void
|
static inline void
|
||||||
pointerFunctionsRelinquish(NSConcretePointerFunctions *PF, void **itemptr)
|
pointerFunctionsRelinquish(PFInfo *PF, void **itemptr)
|
||||||
{
|
{
|
||||||
if (PF->_relinquishFunction != 0)
|
if (PF->relinquishFunction != 0)
|
||||||
(*PF->_relinquishFunction)(*itemptr, PF->_sizeFunction);
|
(*PF->relinquishFunction)(*itemptr, PF->sizeFunction);
|
||||||
if (PF->_usesWeakReadAndWriteBarriers)
|
if (PF->usesWeakReadAndWriteBarriers)
|
||||||
GSAssignZeroingWeakPointer(itemptr, (void*)0);
|
GSAssignZeroingWeakPointer(itemptr, (void*)0);
|
||||||
else
|
else
|
||||||
*itemptr = 0;
|
*itemptr = 0;
|
||||||
|
|
|
@ -62,7 +62,7 @@ acquireExistingMemory(const void *item,
|
||||||
static NSString*
|
static NSString*
|
||||||
describeString(const void *item)
|
describeString(const void *item)
|
||||||
{
|
{
|
||||||
return AUTORELEASE([[NSString alloc] initWithUTF8String: item]);
|
return [NSString stringWithFormat: @"%s", item];
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSString*
|
static NSString*
|
||||||
|
@ -187,28 +187,26 @@ relinquishRetainedMemory(const void *item,
|
||||||
|
|
||||||
- (id) initWithOptions: (NSPointerFunctionsOptions)options
|
- (id) initWithOptions: (NSPointerFunctionsOptions)options
|
||||||
{
|
{
|
||||||
_options = options;
|
|
||||||
|
|
||||||
/* First we look at the memory management options to see which function
|
/* First we look at the memory management options to see which function
|
||||||
* should be used to relinquish contents of a container with these
|
* should be used to relinquish contents of a container with these
|
||||||
* options.
|
* options.
|
||||||
*/
|
*/
|
||||||
if (options & NSPointerFunctionsZeroingWeakMemory)
|
if (options & NSPointerFunctionsZeroingWeakMemory)
|
||||||
{
|
{
|
||||||
_relinquishFunction = 0;
|
_x.relinquishFunction = 0;
|
||||||
_usesWeakReadAndWriteBarriers = YES;
|
_x.usesWeakReadAndWriteBarriers = YES;
|
||||||
}
|
}
|
||||||
else if (options & NSPointerFunctionsOpaqueMemory)
|
else if (options & NSPointerFunctionsOpaqueMemory)
|
||||||
{
|
{
|
||||||
_relinquishFunction = 0;
|
_x.relinquishFunction = 0;
|
||||||
}
|
}
|
||||||
else if (options & NSPointerFunctionsMallocMemory)
|
else if (options & NSPointerFunctionsMallocMemory)
|
||||||
{
|
{
|
||||||
_relinquishFunction = relinquishMallocMemory;
|
_x.relinquishFunction = relinquishMallocMemory;
|
||||||
}
|
}
|
||||||
else if (options & NSPointerFunctionsMachVirtualMemory)
|
else if (options & NSPointerFunctionsMachVirtualMemory)
|
||||||
{
|
{
|
||||||
_relinquishFunction = relinquishMallocMemory;
|
_x.relinquishFunction = relinquishMallocMemory;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -216,58 +214,58 @@ relinquishRetainedMemory(const void *item,
|
||||||
* so for these we set the usesStrongWriteBarrier flag to tell
|
* so for these we set the usesStrongWriteBarrier flag to tell
|
||||||
* containers to allocate scanned memory.
|
* containers to allocate scanned memory.
|
||||||
*/
|
*/
|
||||||
_usesStrongWriteBarrier = YES;
|
_x.usesStrongWriteBarrier = YES;
|
||||||
_relinquishFunction = relinquishRetainedMemory;
|
_x.relinquishFunction = relinquishRetainedMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options & NSPointerFunctionsCopyIn)
|
if (options & NSPointerFunctionsCopyIn)
|
||||||
{
|
{
|
||||||
_shouldCopyIn = YES;
|
_x.shouldCopyIn = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now we look at the personality options to determine other functions.
|
/* Now we look at the personality options to determine other functions.
|
||||||
*/
|
*/
|
||||||
if (options & NSPointerFunctionsOpaquePersonality)
|
if (options & NSPointerFunctionsOpaquePersonality)
|
||||||
{
|
{
|
||||||
_acquireFunction = acquireExistingMemory;
|
_x.acquireFunction = acquireExistingMemory;
|
||||||
_descriptionFunction = describePointer;
|
_x.descriptionFunction = describePointer;
|
||||||
_hashFunction = hashShifted;
|
_x.hashFunction = hashShifted;
|
||||||
_isEqualFunction = equalDirect;
|
_x.isEqualFunction = equalDirect;
|
||||||
}
|
}
|
||||||
else if (options & NSPointerFunctionsObjectPointerPersonality)
|
else if (options & NSPointerFunctionsObjectPointerPersonality)
|
||||||
{
|
{
|
||||||
_acquireFunction = acquireRetainedObject;
|
_x.acquireFunction = acquireRetainedObject;
|
||||||
_descriptionFunction = describeObject;
|
_x.descriptionFunction = describeObject;
|
||||||
_hashFunction = hashShifted;
|
_x.hashFunction = hashShifted;
|
||||||
_isEqualFunction = equalDirect;
|
_x.isEqualFunction = equalDirect;
|
||||||
}
|
}
|
||||||
else if (options & NSPointerFunctionsCStringPersonality)
|
else if (options & NSPointerFunctionsCStringPersonality)
|
||||||
{
|
{
|
||||||
_acquireFunction = acquireMallocMemory;
|
_x.acquireFunction = acquireMallocMemory;
|
||||||
_descriptionFunction = describeString;
|
_x.descriptionFunction = describeString;
|
||||||
_hashFunction = hashString;
|
_x.hashFunction = hashString;
|
||||||
_isEqualFunction = equalString;
|
_x.isEqualFunction = equalString;
|
||||||
}
|
}
|
||||||
else if (options & NSPointerFunctionsStructPersonality)
|
else if (options & NSPointerFunctionsStructPersonality)
|
||||||
{
|
{
|
||||||
_acquireFunction = acquireMallocMemory;
|
_x.acquireFunction = acquireMallocMemory;
|
||||||
_descriptionFunction = describePointer;
|
_x.descriptionFunction = describePointer;
|
||||||
_hashFunction = hashMemory;
|
_x.hashFunction = hashMemory;
|
||||||
_isEqualFunction = equalMemory;
|
_x.isEqualFunction = equalMemory;
|
||||||
}
|
}
|
||||||
else if (options & NSPointerFunctionsIntegerPersonality)
|
else if (options & NSPointerFunctionsIntegerPersonality)
|
||||||
{
|
{
|
||||||
_acquireFunction = acquireExistingMemory;
|
_x.acquireFunction = acquireExistingMemory;
|
||||||
_descriptionFunction = describeInteger;
|
_x.descriptionFunction = describeInteger;
|
||||||
_hashFunction = hashDirect;
|
_x.hashFunction = hashDirect;
|
||||||
_isEqualFunction = equalDirect;
|
_x.isEqualFunction = equalDirect;
|
||||||
}
|
}
|
||||||
else /* objects */
|
else /* objects */
|
||||||
{
|
{
|
||||||
_acquireFunction = acquireRetainedObject;
|
_x.acquireFunction = acquireRetainedObject;
|
||||||
_descriptionFunction = describeObject;
|
_x.descriptionFunction = describeObject;
|
||||||
_hashFunction = hashObject;
|
_x.hashFunction = hashObject;
|
||||||
_isEqualFunction = equalObject;
|
_x.isEqualFunction = equalObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -276,89 +274,89 @@ relinquishRetainedMemory(const void *item,
|
||||||
- (void* (*)(const void *item,
|
- (void* (*)(const void *item,
|
||||||
NSUInteger (*size)(const void *item), BOOL shouldCopy)) acquireFunction
|
NSUInteger (*size)(const void *item), BOOL shouldCopy)) acquireFunction
|
||||||
{
|
{
|
||||||
return _acquireFunction;
|
return _x.acquireFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *(*)(const void *item)) descriptionFunction
|
- (NSString *(*)(const void *item)) descriptionFunction
|
||||||
{
|
{
|
||||||
return _descriptionFunction;
|
return _x.descriptionFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSUInteger (*)(const void *item,
|
- (NSUInteger (*)(const void *item,
|
||||||
NSUInteger (*size)(const void *item))) hashFunction
|
NSUInteger (*size)(const void *item))) hashFunction
|
||||||
{
|
{
|
||||||
return _hashFunction;
|
return _x.hashFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL (*)(const void *item1, const void *item2,
|
- (BOOL (*)(const void *item1, const void *item2,
|
||||||
NSUInteger (*size)(const void *item))) isEqualFunction
|
NSUInteger (*size)(const void *item))) isEqualFunction
|
||||||
{
|
{
|
||||||
return _isEqualFunction;
|
return _x.isEqualFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void (*)(const void *item,
|
- (void (*)(const void *item,
|
||||||
NSUInteger (*size)(const void *item))) relinquishFunction
|
NSUInteger (*size)(const void *item))) relinquishFunction
|
||||||
{
|
{
|
||||||
return _relinquishFunction;
|
return _x.relinquishFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setAcquireFunction: (void* (*)(const void *item,
|
- (void) setAcquireFunction: (void* (*)(const void *item,
|
||||||
NSUInteger (*size)(const void *item), BOOL shouldCopy))func
|
NSUInteger (*size)(const void *item), BOOL shouldCopy))func
|
||||||
{
|
{
|
||||||
_acquireFunction = func;
|
_x.acquireFunction = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setDescriptionFunction: (NSString *(*)(const void *item))func
|
- (void) setDescriptionFunction: (NSString *(*)(const void *item))func
|
||||||
{
|
{
|
||||||
_descriptionFunction = func;
|
_x.descriptionFunction = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setHashFunction: (NSUInteger (*)(const void *item,
|
- (void) setHashFunction: (NSUInteger (*)(const void *item,
|
||||||
NSUInteger (*size)(const void *item)))func
|
NSUInteger (*size)(const void *item)))func
|
||||||
{
|
{
|
||||||
_hashFunction = func;
|
_x.hashFunction = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setIsEqualFunction: (BOOL (*)(const void *item1, const void *item2,
|
- (void) setIsEqualFunction: (BOOL (*)(const void *item1, const void *item2,
|
||||||
NSUInteger (*size)(const void *item)))func
|
NSUInteger (*size)(const void *item)))func
|
||||||
{
|
{
|
||||||
_isEqualFunction = func;
|
_x.isEqualFunction = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setRelinquishFunction: (void (*)(const void *item,
|
- (void) setRelinquishFunction: (void (*)(const void *item,
|
||||||
NSUInteger (*size)(const void *item))) func
|
NSUInteger (*size)(const void *item))) func
|
||||||
{
|
{
|
||||||
_relinquishFunction = func;
|
_x.relinquishFunction = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setSizeFunction: (NSUInteger (*)(const void *item))func
|
- (void) setSizeFunction: (NSUInteger (*)(const void *item))func
|
||||||
{
|
{
|
||||||
_sizeFunction = func;
|
_x.sizeFunction = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setUsesStrongWriteBarrier: (BOOL)flag
|
- (void) setUsesStrongWriteBarrier: (BOOL)flag
|
||||||
{
|
{
|
||||||
_usesStrongWriteBarrier = flag;
|
_x.usesStrongWriteBarrier = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setUsesWeakReadAndWriteBarriers: (BOOL)flag
|
- (void) setUsesWeakReadAndWriteBarriers: (BOOL)flag
|
||||||
{
|
{
|
||||||
_usesWeakReadAndWriteBarriers = flag;
|
_x.usesWeakReadAndWriteBarriers = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSUInteger (*)(const void *item)) sizeFunction
|
- (NSUInteger (*)(const void *item)) sizeFunction
|
||||||
{
|
{
|
||||||
return _sizeFunction;
|
return _x.sizeFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) usesStrongWriteBarrier
|
- (BOOL) usesStrongWriteBarrier
|
||||||
{
|
{
|
||||||
return _usesStrongWriteBarrier;
|
return _x.usesStrongWriteBarrier;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) usesWeakReadAndWriteBarriers
|
- (BOOL) usesWeakReadAndWriteBarriers
|
||||||
{
|
{
|
||||||
return _usesStrongWriteBarrier;
|
return _x.usesStrongWriteBarrier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue