Index: src/map.c ================================================================== --- src/map.c +++ src/map.c @@ -27,10 +27,11 @@ #include #include "object.h" #include "map.h" #include "hash.h" +#include "string.h" static struct bucket { CFWObject *key, *obj; uint32_t hash; } deleted = { NULL, NULL, 0 }; @@ -249,10 +250,26 @@ return map->data[i]->obj; } return NULL; } + +void* +cfw_map_get_c(CFWMap *map, const char *key) +{ + CFWString *str; + void *ret; + + if ((str = cfw_new(cfw_string, key)) == NULL) + return NULL; + + ret = cfw_map_get(map, str); + + cfw_unref(str); + + return ret; +} bool cfw_map_set(CFWMap *map, void *key, void *obj) { uint32_t i, hash, last; @@ -353,10 +370,26 @@ return false; } return true; } + +bool +cfw_map_set_c(CFWMap *map, const char *key, void *obj) +{ + CFWString *str; + bool ret; + + if ((str = cfw_new(cfw_string, key)) == NULL) + return false; + + ret = cfw_map_set(map, str, obj); + + cfw_unref(str); + + return ret; +} void cfw_map_iter(CFWMap *map, cfw_map_iter_t *iter) { iter->_map = map; Index: src/map.h ================================================================== --- src/map.h +++ src/map.h @@ -39,10 +39,12 @@ } cfw_map_iter_t; extern CFWClass *cfw_map; extern size_t cfw_map_size(CFWMap*); extern void* cfw_map_get(CFWMap*, void*); +extern void* cfw_map_get_c(CFWMap*, const char*); extern bool cfw_map_set(CFWMap*, void*, void*); +extern bool cfw_map_set_c(CFWMap*, const char*, void*); extern void cfw_map_iter(CFWMap*, cfw_map_iter_t*); extern void cfw_map_iter_next(cfw_map_iter_t*); #endif