Add function "hashtable_set_pointer" in plugin API

v2.8-utf8proc
Sebastien Helleu 2011-01-02 16:32:54 +01:00
parent fcfe854441
commit 44e16c0511
8 changed files with 193 additions and 14 deletions

View File

@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
v0.3.4-rc2, 2011-01-01
v0.3.4-rc2, 2011-01-02
Version 0.3.4 (under dev!)
@ -42,8 +42,9 @@ Version 0.3.4 (under dev!)
(bug #30759)
* api: add priority for hooks (task #10550)
* api: add new functions: list_search_pos, list_casesearch_pos,
hashtable_get_string, hook_info_hashtable, info_get_hashtable, hook_hsignal,
hook_hsignal_send, hook_completion_get_string, nicklist_group_get_integer,
hashtable_get_string, hashtable_set_pointer, hook_info_hashtable,
info_get_hashtable, hook_hsignal, hook_hsignal_send,
hook_completion_get_string, nicklist_group_get_integer,
nicklist_group_get_string, nicklist_group_get_pointer, nicklist_group_set,
nicklist_nick_get_integer, nicklist_nick_get_string, nicklist_nick_get_pointer,
nicklist_nick_set

View File

@ -3278,6 +3278,43 @@ weechat_printf (NULL, "list of keys: %s",
[NOTE]
This function is not available in scripting API.
weechat_hashtable_set_pointer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_New in version 0.3.4._
Set pointer value of a hashtable property.
Prototype:
[source,C]
----------------------------------------
void weechat_hashtable_set_pointer (struct t_hashtable *hashtable,
const char *property, void *pointer);
----------------------------------------
Arguments:
* 'hashtable': hashtable pointer
* 'property' and 'value': property name, with its value:
** 'callback_free_value': set callback function used to free values in hashtable
C example:
[source,C]
----------------------------------------
void
my_free_value_cb (struct t_hashtable *hashtable, const void *key, void *value)
{
/* ... */
}
weechat_hashtable_set_pointer (hashtable, "callback_free_value", &my_free_value_cb);
----------------------------------------
[NOTE]
This function is not available in scripting API.
weechat_hashtable_add_to_infolist
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -3310,6 +3310,44 @@ weechat_printf (NULL, "liste des clés: %s",
[NOTE]
Cette fonction n'est pas disponible dans l'API script.
weechat_hashtable_set_pointer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_Nouveau dans la version 0.3.4._
Affecte un pointeur à une propriété d'une hashtable.
Prototype :
[source,C]
----------------------------------------
void weechat_hashtable_set_pointer (struct t_hashtable *hashtable,
const char *property, void *pointer);
----------------------------------------
Paramètres :
* 'hashtable' : pointeur vers la hashtable
* 'property' et 'value' : nom de la propriété, avec sa valeur :
** 'callback_free_value' : définit la fonction "callback" pour libérer les
valeurs de la hashtable
Exemple en C :
[source,C]
----------------------------------------
void
my_free_value_cb (struct t_hashtable *hashtable, const void *key, void *value)
{
/* ... */
}
weechat_hashtable_set_pointer (hashtable, "callback_free_value", &my_free_value_cb);
----------------------------------------
[NOTE]
Cette fonction n'est pas disponible dans l'API script.
weechat_hashtable_add_to_infolist
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -3268,6 +3268,45 @@ weechat_printf (NULL, "list of keys: %s",
[NOTE]
Questa funzione non è disponibile nelle API per lo scripting.
weechat_hashtable_set_pointer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_Novità nella versione 0.3.4._
// TRANSLATION MISSING
Set pointer value of a hashtable property.
Prototipo:
[source,C]
----------------------------------------
void weechat_hashtable_set_pointer (struct t_hashtable *hashtable,
const char *property, void *pointer);
----------------------------------------
Argomenti:
* 'hashtable': puntatore alla tabella hash
* 'property' e 'value': nome della proprietà, con il proprio valore:
// TRANSLATION MISSING
** 'callback_free_value': set callback function used to free values in hashtable
Esempio in C:
[source,C]
----------------------------------------
void
my_free_value_cb (struct t_hashtable *hashtable, const void *key, void *value)
{
/* ... */
}
weechat_hashtable_set_pointer (hashtable, "callback_free_value", &my_free_value_cb);
----------------------------------------
[NOTE]
Questa funzione non è disponibile nelle API per lo scripting.
weechat_hashtable_add_to_infolist
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -149,6 +149,8 @@ hashtable_new (int size,
new_hashtable->callback_keycmp = &hashtable_keycmp_string_cb;
else
new_hashtable->callback_keycmp = callback_keycmp;
new_hashtable->callback_free_value = NULL;
}
return new_hashtable;
}
@ -211,19 +213,20 @@ hashtable_alloc_type (enum t_hashtable_type type,
}
/*
* hashtable_free_type: free space used by a key or value
* hashtable_free_key: free space used by a key
*/
void
hashtable_free_type (enum t_hashtable_type type, void *value)
hashtable_free_key (struct t_hashtable *hashtable,
struct t_hashtable_item *item)
{
switch (type)
switch (hashtable->type_keys)
{
case HASHTABLE_INTEGER:
case HASHTABLE_STRING:
case HASHTABLE_BUFFER:
case HASHTABLE_TIME:
free (value);
free (item->key);
break;
case HASHTABLE_POINTER:
break;
@ -232,6 +235,38 @@ hashtable_free_type (enum t_hashtable_type type, void *value)
}
}
/*
* hashtable_free_value: free space used by a value
*/
void
hashtable_free_value (struct t_hashtable *hashtable,
struct t_hashtable_item *item)
{
if (hashtable->callback_free_value)
{
(void) (hashtable->callback_free_value) (hashtable,
item->key,
item->value);
}
else
{
switch (hashtable->type_values)
{
case HASHTABLE_INTEGER:
case HASHTABLE_STRING:
case HASHTABLE_BUFFER:
case HASHTABLE_TIME:
free (item->value);
break;
case HASHTABLE_POINTER:
break;
case HASHTABLE_NUM_TYPES:
break;
}
}
}
/*
* hashtable_set_with_size: set value for item in hash table
* argument size is used only for type "buffer"
@ -267,7 +302,7 @@ hashtable_set_with_size (struct t_hashtable *hashtable,
/* replace value if item is already in hash table */
if (ptr_item && (hashtable->callback_keycmp (hashtable, key, ptr_item->key) == 0))
{
hashtable_free_type (hashtable->type_values, ptr_item->value);
hashtable_free_value (hashtable, ptr_item);
hashtable_alloc_type (hashtable->type_values,
value, value_size,
&ptr_item->value, &ptr_item->value_size);
@ -732,6 +767,21 @@ hashtable_get_string (struct t_hashtable *hashtable, const char *property)
return NULL;
}
/*
* hashtable_set_pointer: set a hashtable property (pointer)
*/
void
hashtable_set_pointer (struct t_hashtable *hashtable, const char *property,
void *pointer)
{
if (hashtable && property)
{
if (string_strcasecmp (property, "callback_free_value") == 0)
hashtable->callback_free_value = pointer;
}
}
/*
* hashtable_add_to_infolist: add hashtable keys and values to infolist
* return 1 if ok, 0 if error
@ -813,8 +863,8 @@ hashtable_remove_item (struct t_hashtable *hashtable,
return;
/* free key and value */
hashtable_free_type (hashtable->type_keys, item->key);
hashtable_free_type (hashtable->type_values, item->value);
hashtable_free_value (hashtable, item);
hashtable_free_key (hashtable, item);
/* remove item from list */
if (item->prev_item)

View File

@ -27,6 +27,8 @@ typedef unsigned int (t_hashtable_hash_key)(struct t_hashtable *hashtable,
const void *key);
typedef int (t_hashtable_keycmp)(struct t_hashtable *hashtable,
const void *key1, const void *key2);
typedef void (t_hashtable_free_value)(struct t_hashtable *hashtable,
const void *key, void *value);
typedef void (t_hashtable_map)(void *data,
struct t_hashtable *hashtable,
const void *key, const void *value);
@ -95,9 +97,10 @@ struct t_hashtable
enum t_hashtable_type type_values; /* type for values: int/str/pointer */
/* callbacks */
t_hashtable_hash_key *callback_hash_key; /* hash key to integer value */
t_hashtable_keycmp *callback_keycmp; /* compare two keys */
t_hashtable_hash_key *callback_hash_key; /* hash key to int value */
t_hashtable_keycmp *callback_keycmp; /* compare two keys */
t_hashtable_free_value *callback_free_value; /* callback to free value */
/* keys/values as string */
char *keys_values; /* keys/values as string (NULL if */
/* never asked) */
@ -122,6 +125,9 @@ extern int hashtable_get_integer (struct t_hashtable *hashtable,
const char *property);
extern const char *hashtable_get_string (struct t_hashtable *hashtable,
const char *property);
extern void hashtable_set_pointer (struct t_hashtable *hashtable,
const char *property,
void *pointer);
extern int hashtable_add_to_infolist (struct t_hashtable *hashtable,
struct t_infolist_item *infolist_item,
const char *prefix);

View File

@ -532,6 +532,7 @@ plugin_load (const char *filename)
new_plugin->hashtable_map = &hashtable_map;
new_plugin->hashtable_get_integer = &hashtable_get_integer;
new_plugin->hashtable_get_string = &hashtable_get_string;
new_plugin->hashtable_set_pointer = &hashtable_set_pointer;
new_plugin->hashtable_add_to_infolist = &hashtable_add_to_infolist;
new_plugin->hashtable_remove = &hashtable_remove;
new_plugin->hashtable_remove_all = &hashtable_remove_all;

View File

@ -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 "20101220-01"
#define WEECHAT_PLUGIN_API_VERSION "20110102-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@ -281,6 +281,9 @@ struct t_weechat_plugin
const char *property);
const char *(*hashtable_get_string) (struct t_hashtable *hashtable,
const char *property);
void (*hashtable_set_pointer) (struct t_hashtable *hashtable,
const char *property,
void *pointer);
int (*hashtable_add_to_infolist) (struct t_hashtable *hashtable,
struct t_infolist_item *infolist_item,
const char *prefix);
@ -950,6 +953,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->hashtable_get_integer(__hashtable, __property)
#define weechat_hashtable_get_string(__hashtable, __property) \
weechat_plugin->hashtable_get_string(__hashtable, __property)
#define weechat_hashtable_set_pointer(__hashtable, __property, \
__pointer) \
weechat_plugin->hashtable_set_pointer(__hashtable, __property, \
__pointer)
#define weechat_hashtable_add_to_infolist(__hashtable, __infolist_item, \
__prefix) \
weechat_plugin->hashtable_add_to_infolist(__hashtable, \