Fri, 20 Jan 2006 00:19:53 +0000
[gaim-migrate @ 15309]
Add .cvsignore actions to meanwhile so cvs shuts up about it.
| 10969 | 1 | |
| 2 | /* | |
| 3 | Meanwhile - Unofficial Lotus Sametime Community Client Library | |
| 4 | Copyright (C) 2004 Christopher (siege) O'Brien | |
| 5 | ||
| 6 | This library is free software; you can redistribute it and/or | |
| 7 | modify it under the terms of the GNU Library General Public | |
| 8 | License as published by the Free Software Foundation; either | |
| 9 | version 2 of the License, or (at your option) any later version. | |
| 10 | ||
| 11 | This library is distributed in the hope that it will be useful, | |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | Library General Public License for more details. | |
| 15 | ||
| 16 | You should have received a copy of the GNU Library General Public | |
| 17 | License along with this library; if not, write to the Free | |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | */ | |
| 20 | ||
| 21 | #include "mw_util.h" | |
| 22 | ||
| 23 | ||
| 24 | static void collect_keys(gpointer key, gpointer val, gpointer data) { | |
| 25 | GList **list = data; | |
| 26 | *list = g_list_append(*list, key); | |
| 27 | } | |
| 28 | ||
| 29 | ||
| 30 | GList *map_collect_keys(GHashTable *ht) { | |
| 31 | GList *ret = NULL; | |
| 32 | g_hash_table_foreach(ht, collect_keys, &ret); | |
| 33 | return ret; | |
| 34 | } | |
| 35 | ||
| 36 | ||
| 37 | static void collect_values(gpointer key, gpointer val, gpointer data) { | |
| 38 | GList **list = data; | |
| 39 | *list = g_list_append(*list, val); | |
| 40 | } | |
| 41 | ||
| 42 | ||
| 43 | GList *map_collect_values(GHashTable *ht) { | |
| 44 | GList *ret = NULL; | |
| 45 | g_hash_table_foreach(ht, collect_values, &ret); | |
| 46 | return ret; | |
| 47 | } | |
| 48 | ||
| 49 | ||
| 50 | struct mw_datum *mw_datum_new(gpointer data, GDestroyNotify clear) { | |
| 51 | struct mw_datum *d = g_new(struct mw_datum, 1); | |
| 52 | mw_datum_set(d, data, clear); | |
| 53 | return d; | |
| 54 | } | |
| 55 | ||
| 56 | ||
| 57 | void mw_datum_set(struct mw_datum *d, gpointer data, GDestroyNotify clear) { | |
| 58 | d->data = data; | |
| 59 | d->clear = clear; | |
| 60 | } | |
| 61 | ||
| 62 | ||
| 63 | gpointer mw_datum_get(struct mw_datum *d) { | |
| 64 | return d->data; | |
| 65 | } | |
| 66 | ||
| 67 | ||
| 68 | void mw_datum_clear(struct mw_datum *d) { | |
| 69 | if(d->clear) { | |
| 70 | d->clear(d->data); | |
| 71 | d->clear = NULL; | |
| 72 | } | |
| 73 | d->data = NULL; | |
| 74 | } | |
| 75 | ||
| 76 | ||
| 77 | void mw_datum_free(struct mw_datum *d) { | |
| 78 | mw_datum_clear(d); | |
| 79 | g_free(d); | |
| 80 | } |