2015-08-17 00:03:53 -05:00
|
|
|
// 17 august 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
|
|
|
// unfortunately NSMutableDictionary copies its keys, meaning we can't use it for pointers
|
|
|
|
// hence, this file
|
2016-01-07 13:41:20 -06:00
|
|
|
// we could expose a NSMapTable directly, but let's treat all pointers as opaque and hide the implementation, just to be safe and prevent even more rewrites later
|
2018-05-03 22:00:50 -05:00
|
|
|
struct uiprivMap {
|
2016-01-07 13:41:20 -06:00
|
|
|
NSMapTable *m;
|
|
|
|
};
|
2015-08-17 00:03:53 -05:00
|
|
|
|
2018-05-03 22:00:50 -05:00
|
|
|
uiprivMap *uiprivNewMap(void)
|
2015-08-17 00:03:53 -05:00
|
|
|
{
|
2018-05-03 22:00:50 -05:00
|
|
|
uiprivMap *m;
|
2016-01-07 13:41:20 -06:00
|
|
|
|
2018-05-03 22:00:50 -05:00
|
|
|
m = uiprivNew(uiprivMap);
|
2016-01-07 15:01:11 -06:00
|
|
|
m->m = [[NSMapTable alloc] initWithKeyOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality)
|
|
|
|
valueOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality)
|
|
|
|
capacity:0];
|
2016-01-07 13:41:20 -06:00
|
|
|
return m;
|
2015-08-17 00:03:53 -05:00
|
|
|
}
|
|
|
|
|
2018-05-03 22:00:50 -05:00
|
|
|
void uiprivMapDestroy(uiprivMap *m)
|
2015-08-17 00:03:53 -05:00
|
|
|
{
|
2016-01-07 13:41:20 -06:00
|
|
|
if ([m->m count] != 0)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivImplBug("attempt to destroy map with items inside");
|
2016-01-07 13:41:20 -06:00
|
|
|
[m->m release];
|
2018-04-15 15:05:24 -05:00
|
|
|
uiprivFree(m);
|
2016-01-07 13:41:20 -06:00
|
|
|
}
|
2015-08-17 00:03:53 -05:00
|
|
|
|
2018-05-03 22:00:50 -05:00
|
|
|
void *uiprivMapGet(uiprivMap *m, void *key)
|
2016-01-07 13:41:20 -06:00
|
|
|
{
|
|
|
|
return NSMapGet(m->m, key);
|
2015-08-17 00:03:53 -05:00
|
|
|
}
|
|
|
|
|
2018-05-03 22:00:50 -05:00
|
|
|
void uiprivMapSet(uiprivMap *m, void *key, void *value)
|
2015-08-17 00:03:53 -05:00
|
|
|
{
|
2016-01-07 13:41:20 -06:00
|
|
|
NSMapInsert(m->m, key, value);
|
|
|
|
}
|
2015-08-17 00:03:53 -05:00
|
|
|
|
2018-05-03 22:00:50 -05:00
|
|
|
void uiprivMapDelete(uiprivMap *m, void *key)
|
2016-01-07 13:41:20 -06:00
|
|
|
{
|
|
|
|
NSMapRemove(m->m, key);
|
2015-08-17 00:03:53 -05:00
|
|
|
}
|
2016-05-23 23:41:52 -05:00
|
|
|
|
2018-05-03 22:00:50 -05:00
|
|
|
void uiprivMapWalk(uiprivMap *m, void (*f)(void *key, void *value))
|
2016-05-23 23:41:52 -05:00
|
|
|
{
|
2018-05-03 22:00:50 -05:00
|
|
|
NSMapEnumerator e;
|
|
|
|
void *k, *v;
|
|
|
|
|
|
|
|
e = NSEnumerateMapTable(m->m);
|
|
|
|
k = NULL;
|
|
|
|
v = NULL;
|
|
|
|
while (NSNextMapEnumeratorPair(&e, &k, &v))
|
2016-05-23 23:41:52 -05:00
|
|
|
f(k, v);
|
|
|
|
NSEndMapTableEnumeration(&e);
|
|
|
|
}
|
|
|
|
|
2018-05-03 22:00:50 -05:00
|
|
|
void uiprivMapReset(uiprivMap *m)
|
2016-05-23 23:41:52 -05:00
|
|
|
{
|
|
|
|
NSResetMapTable(m->m);
|
|
|
|
}
|