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
|
|
|
|
struct mapTable {
|
|
|
|
NSMapTable *m;
|
|
|
|
};
|
2015-08-17 00:03:53 -05:00
|
|
|
|
2016-01-07 13:41:20 -06:00
|
|
|
struct mapTable *newMap(void)
|
2015-08-17 00:03:53 -05:00
|
|
|
{
|
2016-01-07 13:41:20 -06:00
|
|
|
struct mapTable *m;
|
|
|
|
|
|
|
|
m = uiNew(struct mapTable);
|
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
|
|
|
}
|
|
|
|
|
2016-01-07 13:41:20 -06:00
|
|
|
void mapDestroy(struct mapTable *m)
|
2015-08-17 00:03:53 -05:00
|
|
|
{
|
2016-01-07 13:41:20 -06:00
|
|
|
if ([m->m count] != 0)
|
2016-05-13 19:14:46 -05:00
|
|
|
implbug("attempt to destroy map with items inside");
|
2016-01-07 13:41:20 -06:00
|
|
|
[m->m release];
|
|
|
|
uiFree(m);
|
|
|
|
}
|
2015-08-17 00:03:53 -05:00
|
|
|
|
2016-01-07 13:41:20 -06:00
|
|
|
void *mapGet(struct mapTable *m, void *key)
|
|
|
|
{
|
|
|
|
return NSMapGet(m->m, key);
|
2015-08-17 00:03:53 -05:00
|
|
|
}
|
|
|
|
|
2016-01-07 13:41:20 -06:00
|
|
|
void mapSet(struct mapTable *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
|
|
|
|
2016-01-07 13:41:20 -06:00
|
|
|
void mapDelete(struct mapTable *m, void *key)
|
|
|
|
{
|
|
|
|
NSMapRemove(m->m, key);
|
2015-08-17 00:03:53 -05:00
|
|
|
}
|