00001 #ifndef GO_GLIB_EXTRAS_H
00002 #define GO_GLIB_EXTRAS_H
00003
00004 #include <goffice/utils/goffice-utils.h>
00005 #include <glib.h>
00006 #include <sys/types.h>
00007 #include <glib-object.h>
00008
00009 G_BEGIN_DECLS
00010
00011
00012
00013 typedef gpointer (*GOMapFunc) (gpointer value);
00014
00015 void go_ptr_array_insert (GPtrArray *array, gpointer value, int index);
00016
00017 GSList *go_hash_keys (GHashTable *hash);
00018 GSList *go_hash_values (GHashTable *hash);
00019
00020 GSList *go_slist_map (GSList const *list, GOMapFunc map_func);
00021 GSList *go_slist_create (gpointer item1, ...);
00022 void go_slist_free_custom (GSList *list, GFreeFunc free_func);
00023 #define go_string_slist_copy(list) go_slist_map (list, (GOMapFunc) g_strdup)
00024 GSList *go_strsplit_to_slist (char const *str, gchar delimiter);
00025 #define GO_SLIST_FOREACH(list,valtype,val,stmnt) \
00026 G_STMT_START { \
00027 GSList const *go_l; \
00028 for (go_l = (list); go_l != NULL; go_l = go_l->next) { \
00029 valtype *val = go_l->data; \
00030 stmnt \
00031 ; \
00032 } \
00033 } G_STMT_END
00034 #define GO_SLIST_PREPEND(list,item) \
00035 (list = g_slist_prepend (list, item))
00036 #define GO_SLIST_APPEND(list,item) \
00037 (list = g_slist_append (list, item))
00038 #define GO_SLIST_REMOVE(list,item) \
00039 (list = g_slist_remove (list, item))
00040 #define GO_SLIST_CONCAT(list_a,list_b) \
00041 (list_a = g_slist_concat (list_a, list_b))
00042 #define GO_SLIST_REVERSE(list) \
00043 (list = g_slist_reverse (list))
00044 #define GO_SLIST_SORT(list,cmp_func) \
00045 (list = g_slist_sort (list, cmp_func))
00046
00047 gint go_list_index_custom (GList *list, gpointer data, GCompareFunc cmp_func);
00048 void go_list_free_custom (GList *list, GFreeFunc free_func);
00049 #define GO_LIST_FOREACH(list,valtype,val,stmnt) \
00050 G_STMT_START { \
00051 GList *go_l; \
00052 for (go_l = (list); go_l != NULL; go_l = go_l->next) { \
00053 valtype *val = go_l->data; \
00054 stmnt \
00055 ; \
00056 } \
00057 } G_STMT_END
00058 #define GO_LIST_PREPEND(list,item) \
00059 (list = g_list_prepend (list, item))
00060 #define GO_LIST_APPEND(list,item) \
00061 (list = g_list_append (list, item))
00062 #define GO_LIST_REMOVE(list,item) \
00063 (list = g_list_remove (list, item))
00064 #define GO_LIST_CONCAT(list_a,list_b) \
00065 (list_a = g_list_concat (list_a, list_b))
00066 #define GO_LIST_REVERSE(list) \
00067 (list = g_list_reverse (list))
00068 #define GO_LIST_SORT(list,cmp_func) \
00069 (list = g_list_sort (list, cmp_func))
00070
00071 int go_str_compare (void const *x, void const *y);
00072 guint go_ascii_strcase_hash (gconstpointer v);
00073 gint go_ascii_strcase_equal (gconstpointer v, gconstpointer v2);
00074 gint go_utf8_collate_casefold (char const *a, char const *b);
00075 char *go_utf8_strcapital (char const *p, gssize len);
00076 void go_strescape (GString *target, char const *str);
00077 char const *go_strunescape (GString *target, char const *str);
00078 void go_string_append_gstring (GString *target, const GString *src);
00079 char const *go_guess_encoding (char const *raw, size_t len,
00080 char const *user_guess,
00081 char **utf8_str);
00082
00083 char const *go_get_real_name (void);
00084 void go_destroy_password (char *passwd);
00085
00086 GOMemChunk *go_mem_chunk_new (char const *name, size_t user_atom_size, size_t chunk_size);
00087 void go_mem_chunk_destroy (GOMemChunk *chunk, gboolean expect_leaks);
00088 gpointer go_mem_chunk_alloc (GOMemChunk *chunk);
00089 gpointer go_mem_chunk_alloc0 (GOMemChunk *chunk);
00090 void go_mem_chunk_free (GOMemChunk *chunk, gpointer mem);
00091 void go_mem_chunk_foreach_leak (GOMemChunk *chunk, GFunc cb, gpointer user);
00092
00093 void go_object_toggle (gpointer object,
00094 const gchar *property_name);
00095 GSList *go_object_properties_collect (GObject *obj);
00096 void go_object_properties_apply (GObject *obj,
00097 GSList *props,
00098 gboolean changed_only);
00099 void go_object_properties_free (GSList *props);
00100
00101 G_END_DECLS
00102
00103 #endif