From f32e18c717520e3482b1a4155ff4e804da7aecbb Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Mon, 11 Oct 2010 13:56:57 +0200 Subject: [PATCH] Add function "hashtable_has_key" in WeeChat and plugin API --- doc/en/weechat_plugin_api.en.txt | 37 +++++++++++++++++++++++++++++ doc/fr/weechat_plugin_api.fr.txt | 37 +++++++++++++++++++++++++++++ doc/it/weechat_plugin_api.it.txt | 40 ++++++++++++++++++++++++++++++++ src/core/wee-hashtable.c | 10 ++++++++ src/core/wee-hashtable.h | 1 + src/plugins/plugin.c | 1 + src/plugins/weechat-plugin.h | 5 +++- 7 files changed, 130 insertions(+), 1 deletion(-) diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt index 0f0add425..5f35210c8 100644 --- a/doc/en/weechat_plugin_api.en.txt +++ b/doc/en/weechat_plugin_api.en.txt @@ -2980,6 +2980,43 @@ void *value = weechat_hashtable_get (hashtable, "my_key"); [NOTE] This function is not available in scripting API. +weechat_hashtable_has_key +^^^^^^^^^^^^^^^^^^^^^^^^^ + +_New in version 0.3.4._ + +Return 1 if hashtable has key, otherwise 0. + +Prototype: + +[source,C] +---------------------------------------- +int weechat_hashtable_has_key (struct t_hashtable *hashtable, void *key); +---------------------------------------- + +Arguments: + +* 'hashtable': hashtable pointer +* 'key': key pointer + +Return value: + +* 1 if key is in hashtable, 0 if key is not in hashtable + +C example: + +[source,C] +---------------------------------------- +if (weechat_hashtable_has_key (hashtable, "my_key")) +{ + /* key is in hashtable */ + /* ... */ +} +---------------------------------------- + +[NOTE] +This function is not available in scripting API. + weechat_hashtable_map ^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt index 3adad9aa9..05a99ffb2 100644 --- a/doc/fr/weechat_plugin_api.fr.txt +++ b/doc/fr/weechat_plugin_api.fr.txt @@ -3011,6 +3011,43 @@ void *value = weechat_hashtable_get (hashtable, "ma_cle"); [NOTE] Cette fonction n'est pas disponible dans l'API script. +weechat_hashtable_has_key +^^^^^^^^^^^^^^^^^^^^^^^^^ + +_Nouveau dans la version 0.3.4._ + +Retourne 1 si la clé est dans la hashtable, sinon 0. + +Prototype : + +[source,C] +---------------------------------------- +int weechat_hashtable_has_key (struct t_hashtable *hashtable, void *key); +---------------------------------------- + +Paramètres : + +* 'hashtable' : pointeur vers la hashtable +* 'key' : pointeur vers la clé + +Valeur en retour : + +* 1 si la clé est dans la hashtable, 0 si la clé n'est pas dans la hashtable + +Exemple en C : + +[source,C] +---------------------------------------- +if (weechat_hashtable_has_key (hashtable, "ma_cle")) +{ + /* la clé est dans la hashtable */ + /* ... */ +} +---------------------------------------- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + weechat_hashtable_map ^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt index 1893255c9..3d47211f6 100644 --- a/doc/it/weechat_plugin_api.it.txt +++ b/doc/it/weechat_plugin_api.it.txt @@ -3013,6 +3013,46 @@ void *value = weechat_hashtable_get (hashtable, "my_key"); [NOTE] Questa funzione non è disponibile nelle API per lo scripting. +weechat_hashtable_has_key +^^^^^^^^^^^^^^^^^^^^^^^^^ + +_Novità nella versione 0.3.4._ + +// TRANSLATION MISSING +Return 1 if hashtable has key, otherwise 0. + +Prototipo: + +[source,C] +---------------------------------------- +int weechat_hashtable_has_key (struct t_hashtable *hashtable, void *key); +---------------------------------------- + +Argomenti: + +* 'hashtable': puntatore alla tabella hash +* 'key': puntatore alla chiave + +Valore restituito: + +// TRANSLATION MISSING +* 1 if key is in hashtable, 0 if key is not in hashtable + +Esempio in C: + +// TRANSLATION MISSING +[source,C] +---------------------------------------- +if (weechat_hashtable_has_key (hashtable, "my_key")) +{ + /* key is in hashtable */ + /* ... */ +} +---------------------------------------- + +[NOTE] +This function is not available in scripting API. + weechat_hashtable_map ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/core/wee-hashtable.c b/src/core/wee-hashtable.c index a8f5b2018..e8e8f1e83 100644 --- a/src/core/wee-hashtable.c +++ b/src/core/wee-hashtable.c @@ -374,6 +374,16 @@ hashtable_get (struct t_hashtable *hashtable, const void *key) return (ptr_item) ? ptr_item->value : NULL; } +/* + * hashtable_has_key: return 1 if key is in hashtable, otherwise 0 + */ + +int +hashtable_has_key (struct t_hashtable *hashtable, const void *key) +{ + return (hashtable_get_item (hashtable, key, NULL) != NULL) ? 1 : 0; +} + /* * hashtable_map: call a function on all hashtable entries */ diff --git a/src/core/wee-hashtable.h b/src/core/wee-hashtable.h index a8fe253cf..ef045889b 100644 --- a/src/core/wee-hashtable.h +++ b/src/core/wee-hashtable.h @@ -113,6 +113,7 @@ extern int hashtable_set_with_size (struct t_hashtable *hashtable, extern int hashtable_set (struct t_hashtable *hashtable, void *key, void *value); extern void *hashtable_get (struct t_hashtable *hashtable, const void *key); +extern int hashtable_has_key (struct t_hashtable *hashtable, const void *key); extern void hashtable_map (struct t_hashtable *hashtable, t_hashtable_map *callback_map, void *callback_map_data); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index a66769b7a..564f16065 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -525,6 +525,7 @@ plugin_load (const char *filename) new_plugin->hashtable_set_with_size = &hashtable_set_with_size; new_plugin->hashtable_set = &hashtable_set; new_plugin->hashtable_get = &hashtable_get; + new_plugin->hashtable_has_key = &hashtable_has_key; new_plugin->hashtable_map = &hashtable_map; new_plugin->hashtable_get_integer = &hashtable_get_integer; new_plugin->hashtable_get_string = &hashtable_get_string; diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index abdea3f52..6b340f677 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -45,7 +45,7 @@ struct timeval; */ /* API version (used to check that plugin has same API and can be loaded) */ -#define WEECHAT_PLUGIN_API_VERSION "20100827-01" +#define WEECHAT_PLUGIN_API_VERSION "20101011-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -265,6 +265,7 @@ struct t_weechat_plugin int (*hashtable_set) (struct t_hashtable *hashtable, void *key, void *value); void *(*hashtable_get) (struct t_hashtable *hashtable, const void *key); + int (*hashtable_has_key) (struct t_hashtable *hashtable, const void *key); void (*hashtable_map) (struct t_hashtable *hashtable, void (*callback_map) (void *data, struct t_hashtable *hashtable, @@ -896,6 +897,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->hashtable_set(__hashtable, __key, __value) #define weechat_hashtable_get(__hashtable, __key) \ weechat_plugin->hashtable_get(__hashtable, __key) +#define weechat_hashtable_has_key(__hashtable, __key) \ + weechat_plugin->hashtable_has_key(__hashtable, __key) #define weechat_hashtable_map(__hashtable, __cb_map, __cb_map_data) \ weechat_plugin->hashtable_map(__hashtable, __cb_map, __cb_map_data) #define weechat_hashtable_get_integer(__hashtable, __property) \