From 028f23ca6f977c2cd0dda6a5fb87e479a92b3511 Mon Sep 17 00:00:00 2001 From: Xavier Roche Date: Sat, 14 Jun 2014 13:07:33 +0000 Subject: Added coucal_get_pvoid() and coucal_get_intptr() --- src/coucal.c | 16 ++++++++++++++++ src/coucal.h | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/coucal.c b/src/coucal.c index 3a81b87..9654431 100644 --- a/src/coucal.c +++ b/src/coucal.c @@ -709,6 +709,14 @@ int coucal_read_pvoid(coucal hashtable, coucal_key_const name, void **pvalue) { return ret; } +void* coucal_get_pvoid(coucal hashtable, coucal_key_const name) { + void *value; + if (!coucal_read_pvoid(hashtable, name, &value)) { + return NULL; + } + return value; +} + int coucal_write_pvoid(coucal hashtable, coucal_key_const name, void *pvalue) { coucal_value value = INTHASH_VALUE_NULL; @@ -1281,6 +1289,14 @@ int coucal_readptr(coucal hashtable, coucal_key_const name, intptr_t * value) { return ret; } +intptr_t coucal_get_intptr(coucal hashtable, coucal_key_const name) { + intptr_t value; + if (!coucal_read(hashtable, name, &value)) { + return 0; + } + return value; +} + coucal coucal_new(size_t initial_size) { coucal hashtable = (coucal) calloc(1, sizeof(struct_coucal)); diff --git a/src/coucal.h b/src/coucal.h index 6a9da6e..57eaaa1 100644 --- a/src/coucal.h +++ b/src/coucal.h @@ -326,7 +326,14 @@ COUCAL_EXTERN int coucal_read(coucal hashtable, coucal_key_const name, * Same as coucal_read(), but return 0 is the value was zero. **/ COUCAL_EXTERN int coucal_readptr(coucal hashtable, coucal_key_const name, - intptr_t * intvalue); + intptr_t * intvalue); + +/** + * Read an integer entry from the hashtable. + * Return 0 if the entry could not be found. + **/ +COUCAL_EXTERN intptr_t coucal_get_intptr(coucal hashtable, + coucal_key_const name); /** * Return non-zero value if the given entry exists. @@ -354,6 +361,12 @@ COUCAL_EXTERN int coucal_write_value(coucal hashtable, coucal_key_const name, COUCAL_EXTERN int coucal_read_pvoid(coucal hashtable, coucal_key_const name, void **value); +/** + * Read a pointer entry from the hashtable and returns its value. + * Return NULL if the entry could not be found. + **/ +COUCAL_EXTERN void* coucal_get_pvoid(coucal hashtable, coucal_key_const name); + /** * Write a pointer entry to the hashtable. * Return non-zero value if the entry was added, zero if it was replaced. -- cgit v1.2.3