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);
|
|
|
|
m->m = [NSMapTable mapTableWithKeyOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality)
|
|
|
|
valueOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality)];
|
2016-01-07 14:43:35 -06:00
|
|
|
// TODO why do I need this
|
|
|
|
[m->m retain];
|
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)
|
|
|
|
complain("attempt to destroy map with items inside; did you forget to deallocate something?");
|
|
|
|
[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
|
|
|
}
|