Add cfw_map_{get,set}_c() for convenience.
This commit is contained in:
parent
f97a687778
commit
4a683a33fc
2 changed files with 35 additions and 0 deletions
33
src/map.c
33
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)
|
||||
{
|
||||
|
|
|
@ -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*);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue