5 // Created by Joseph Spiros on Thu Dec 25 2003.
6 // Copyright (c) 2003 __MyCompanyName__. All rights reserved.
9 #import "ITMacResource.h"
12 @implementation ITMacResource
14 static NSMutableDictionary *_resourceTypeClasses = nil;
16 + (void)_registerClass:(Class)class forType:(ITMacResourceType)type {
17 if (!_resourceTypeClasses) {
18 _resourceTypeClasses = [[NSMutableDictionary dictionary] retain];
20 [_resourceTypeClasses setObject:class forKey:[NSString stringWithCString:(char *)type]];
23 + (Class)_classForType:(ITMacResourceType)type {
24 Class _class = [_resourceTypeClasses objectForKey:[NSString stringWithCString:(char *)type]];
25 return ((_class == nil) ? [ITMacResource class] : _class);
28 + (id)_resourceWithHandle:(Handle)handle { // THIS *WILL* RETURN A MORE SPECIFIC INSTANCE USING THE REGISTRATION DATABASE IF SUCH A CLASS EXISTS
29 return [[[self alloc] _initWithHandle:handle] autorelease];
32 - (id)_initWithHandle:(Handle)handle {
33 if (self = [super init]) {
46 _data = [NSData dataWithBytes:(*_handle) length:GetHandleSize(_handle)];
51 - (ITMacResourceType)type {
55 GetResInfo(_handle, &_id, &_type, _name);
56 return (ITMacResourceType)_type;
63 GetResInfo(_handle, &_id, &_type, _name);
64 return [NSNumber numberWithShort:_id];
71 GetResInfo(_handle, &_id, &_type, _name);
72 return [(NSString*)CFStringCreateWithPascalString(NULL,
73 _name, kCFStringEncodingMacRomanLatin1) autorelease];
76 - (Class)nativeRepresentationClass {
80 - (id)nativeRepresentation {
85 ReleaseResource(_handle);