-
Notifications
You must be signed in to change notification settings - Fork 9
/
L0Map.m
121 lines (94 loc) · 2.21 KB
/
L0Map.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// L0Map.m
// MuiKit
//
// Created by ∞ on 12/09/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "L0Map.h"
@implementation L0Map
- (id) initWithKeyCallbacks:(const CFDictionaryKeyCallBacks*) kcbs valueCallbacks:(const CFDictionaryValueCallBacks*) vcbs;
{
if (self = [super init])
dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, kcbs, vcbs);
return self;
}
- (id) init;
{
return [self initWithKeyCallbacks:&kCFTypeDictionaryKeyCallBacks valueCallbacks:&kCFTypeDictionaryValueCallBacks];
}
- (void) dealloc;
{
CFRelease(dict);
[super dealloc];
}
+ map;
{
return [[self new] autorelease];
}
#pragma mark -
#pragma mark Accessors
- (NSUInteger) count;
{
return CFDictionaryGetCount(dict);
}
- (void) setObject:(id) o forKey:(id) k;
{
[self setPointer:o forPointerKey:k];
}
- (id) objectForKey:(id) k;
{
return (id) [self pointerForPointerKey:k];
}
- (void) removeObjectForKey:(id) k;
{
[self removeObjectForPointerKey:k];
}
- (void) setPointer:(void*) o forPointerKey:(void*) k;
{
CFDictionarySetValue(dict, k, o);
}
- (void*) pointerForPointerKey:(void*) k;
{
return (void*) CFDictionaryGetValue(dict, k);
}
- (void) removeObjectForPointerKey:(void*) k;
{
CFDictionaryRemoveValue(dict, (const void*) k);
}
- (void) removeAllObjects;
{
CFDictionaryRemoveAllValues(dict);
}
- (void) getKeys:(void **)keys values:(void **)objects;
{
CFDictionaryGetKeysAndValues(dict, (const void**) keys, (const void**) objects);
}
- (void) getEnumeratorForKeys:(NSEnumerator**) keysEnu values:(NSEnumerator**) valuesEnu;
{
NSUInteger c = [self count];
void** values = malloc(c * sizeof(void*));
void** keys = malloc(c * sizeof(void*));
[self getKeys:keys values:values];
if (keysEnu) {
NSArray* a = [NSArray arrayWithObjects:(const id*) keys count:c];
*keysEnu = [a objectEnumerator];
}
if (valuesEnu) {
NSArray* a = [NSArray arrayWithObjects:(const id*) values count:c];
*valuesEnu = [a objectEnumerator];
}
free(keys);
free(values);
}
- (NSEnumerator*) allValues;
{
NSEnumerator* vals; [self getEnumeratorForKeys:NULL values:&vals];
return vals;
}
- (NSEnumerator*) allKeys;
{
NSEnumerator* vals; [self getEnumeratorForKeys:&vals values:NULL];
return vals;
}
@end