diff --git a/src/map.c b/src/map.c index 502e09e..0009a6c 100644 --- a/src/map.c +++ b/src/map.c @@ -29,6 +29,7 @@ #include "object.h" #include "map.h" #include "hash.h" +#include "string.h" static struct bucket { CFWObject *key, *obj; @@ -252,6 +253,22 @@ cfw_map_get(CFWMap *map, void *key) 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) { @@ -356,6 +373,22 @@ cfw_map_set(CFWMap *map, void *key, void *obj) 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) { diff --git a/src/map.h b/src/map.h index 25e3108..95117fb 100644 --- a/src/map.h +++ b/src/map.h @@ -41,7 +41,9 @@ typedef struct 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*);