Re: NXAtom
Re: NXAtom
- Subject: Re: NXAtom
- From: Greg Titus <email@hidden>
- Date: Sun, 2 Sep 2001 11:21:49 -0700
On Friday, August 31, 2001, at 10:02 PM, Simson L. Garfinkel wrote:
>
Greetings. /usr/include/objc/hashtable.h references the NXAtom type,
>
one of
>
my favorites, but line 30 of the file says "the API in this header is
>
obsolete."
>
>
1. If it is obsolete, why is it there?
Good question. I think maybe the runtime still uses it internally?
>
2. If it is obsolete, what is the replacement?
Well, the replacements for the hash table stuff are the NSHashTable
functions - see the Foundation Functions documentation. Basically it
works exactly the same as the NXHashTable stuff did.
There is no replacement for NXAtom.
>
I do not want to use NSStrings. I want to use NXAtoms, which have very
>
particular properties and such.
>
>
Sorry to bother the whole list for something that is this trivial. The
>
NSString object just does not give me the functionality that I need.
It wouldn't be hard to write an NSAtom class. I just whipped one up
below (completely untested)... It's also a nice small example of how you
write a subclass for a class cluster.
@interface NSAtom : NSString
{
NSString *internalString;
}
+ (NSAtom *)atomForString:(NSString *)aString;
@end
@implementation NSAtom
static NSMutableSet *allAtoms;
- initWithString:(NSString *)aString
{
[super init];
internalString = [aString copy];
[allAtoms addObject:self];
return self;
}
+ (NSAtom *)atomForString:(NSString *)aString
{
NSAtom *result;
if (!allAtoms)
allAtoms = [[NSMutableSet alloc] init];
result = [allAtoms member:aString];
if (!result)
result = [[[NSAtom alloc] initWithString:aString] autorelease];
return result;
}
// Implement the basic NSString class cluster methods...
- (unsigned int)length
{
return [internalString length];
}
- (unichar)characterAtIndex:(unsigned)index
{
return [internalString characterAtIndex:index];
}
// Implement the retain counting methods to do nothing
- retain { return self; }
- (void)release { }
- autorelease { return self; }
@end
Hope this helps,
--Greg
- Follow-Ups:
- Re: NXAtom
- From: "Simson L. Garfinkel" <email@hidden>
References: | |
| >NXAtom (From: "Simson L. Garfinkel" <email@hidden>) |