Re: NXAtom
Re: NXAtom
- Subject: Re: NXAtom
- From: "Simson L. Garfinkel" <email@hidden>
- Date: Sun, 2 Sep 2001 23:48:42 -0400
If the runtime uses Hashtable and NXAtom, then they should be accessible to
the user and including the file shouldn't produce an error. If they are not
present, then the include files should probably be removed.
One can use the atomForString methods you outline below, although the nice
thing about the NXAtom is that it is a (unsigned char *) and you can compare
equivalence of strings with ==, and then use them in %s formats.
----- Original Message -----
From: Greg Titus
To: Simson L. Garfinkel
Cc: email@hidden
Sent: Sunday, September 02, 2001 2:21 PM
Subject: Re: NXAtom
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
References: | |
| >Re: NXAtom (From: Greg Titus <email@hidden>) |