Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

glib-missing.h

Go to the documentation of this file.
00001 /*
00002  * $Id: glib-missing.h 13955 2007-06-24 03:25:03Z cbiere $
00003  *
00004  * Copyright (c) 2003, Raphael Manfredi
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *----------------------------------------------------------------------
00024  */
00025 
00042 #ifndef _glib_missing_h_
00043 #define _glib_missing_h_
00044 
00045 #include "common.h"
00046 
00047 #ifdef USE_GLIB1
00048 typedef gboolean (*GEqualFunc)(gconstpointer a, gconstpointer b);
00049 
00050 typedef struct GMemVTable {
00051     gpointer    (*gmvt_malloc)      (gsize n_bytes);
00052     gpointer    (*gmvt_realloc)     (gpointer mem, gsize n_bytes);
00053     void        (*gmvt_free)        (gpointer mem);
00054     /* optional */
00055     gpointer    (*gmvt_calloc)      (gsize n_blocks, gsize n_block_bytes);
00056     gpointer    (*gmvt_try_malloc)  (gsize n_bytes);
00057     gpointer    (*gmvt_try_realloc) (gpointer mem, gsize n_bytes);
00058 } GMemVTable;
00059 #endif
00060 
00061 /*
00062  * Public interface.
00063  */
00064 
00065 gboolean gm_slist_is_looping(const GSList *slist);
00066 GSList *gm_slist_insert_after(GSList *list, GSList *lnk, gpointer data);
00067 
00068 GList *gm_list_insert_after(GList *list, GList *lnk, gpointer data);
00069 
00070 #ifdef USE_GLIB1
00071 GList *g_list_delete_link(GList *l, GList *lnk);
00072 GSList *g_slist_delete_link(GSList *sl, GSList *lnk);
00073 GString *g_string_append_len(GString *gs, const gchar *val, gssize len);
00074 
00075 void g_hash_table_replace(GHashTable *ht, gpointer key, gpointer value);
00076 
00077 void g_mem_set_vtable(GMemVTable *vtable);
00078 gboolean g_mem_is_system_malloc(void);
00079 #endif
00080 
00081 gchar *gm_string_finalize(GString *gs);
00082 
00083 size_t gm_vsnprintf(gchar *str, size_t n, gchar const *fmt, va_list args);
00084 size_t gm_snprintf(gchar *str, size_t n,
00085     gchar const *fmt, ...) G_GNUC_PRINTF (3, 4);
00086 
00087 void gm_savemain(gint argc, gchar **argv, gchar **env);
00088 const gchar *gm_getproctitle(void);
00089 void gm_setproctitle(const gchar *title);
00090 gchar *gm_sanitize_filename(const gchar *filename,
00091     gboolean no_spaces, gboolean no_evil);
00092 
00093 static inline void
00094 gm_hash_table_insert_const(GHashTable *ht,
00095     gconstpointer key, gconstpointer value)
00096 {
00097     g_hash_table_insert(ht, (gpointer) key, (gpointer) value);
00098 }
00099 
00100 static inline void
00101 gm_hash_table_replace_const(GHashTable *ht,
00102     gconstpointer key, gconstpointer value)
00103 {
00104     g_hash_table_replace(ht, (gpointer) key, (gpointer) value);
00105 }
00106 
00107 GSList *gm_hash_table_all_keys(GHashTable *ht);
00108 void gm_hash_table_foreach_key(GHashTable *ht, GFunc func, gpointer user_data);
00109 
00110 /*
00111  * The G_*LIST_FOREACH_* macros are supposed to be used with ``func'' being
00112  * a function declared ``static inline'' whereas the protoype MUST match
00113  * ``GFunc''. ``func'' is not assigned to a variable so that the compiler
00114  * can prevent any function call overhead along with ``inline''.
00115  * These macros were rejected by the GLib maintainers so we can safely use
00116  * the G_ prefix.
00117  */
00118 
00119 /* NB: Sub-statement func is evaluated more than once! */
00120 #define G_LIST_FOREACH(list, func) \
00121     G_STMT_START { \
00122         GList *l_ = (list); \
00123         while (NULL != l_) { \
00124             func(l_->data); \
00125             l_ = g_list_next(l_); \
00126         } \
00127     } G_STMT_END
00128 
00129 #define G_LIST_FOREACH_WITH_DATA(list, func, user_data) \
00130     G_STMT_START { \
00131         GList *l_ = (list); \
00132         gpointer user_data_ = (user_data); \
00133         while (NULL != l_) { \
00134             func(l_->data, user_data_); \
00135             l_ = g_list_next(l_); \
00136         } \
00137     } G_STMT_END
00138 
00139 #define G_LIST_FOREACH_SWAPPED(list, func, user_data) \
00140     G_STMT_START { \
00141         GList *l_ = (list); \
00142         gpointer user_data_ = (user_data); \
00143         while (NULL != l_) { \
00144             func(user_data_, l_->data); \
00145             l_ = g_list_next(l_); \
00146         } \
00147     } G_STMT_END
00148 
00149 /* NB: Sub-statement func is evaluated more than once! */
00150 #define G_SLIST_FOREACH(slist, func) \
00151     G_STMT_START { \
00152         GSList *sl_ = (slist); \
00153         while (NULL != sl_) { \
00154             func(sl_->data); \
00155             sl_ = g_slist_next(sl_); \
00156         } \
00157     } G_STMT_END
00158 
00159 /* NB: Sub-statement func is evaluated more than once! */
00160 #define G_SLIST_FOREACH_WITH_DATA(slist, func, user_data) \
00161     G_STMT_START { \
00162         GSList *sl_ = (slist); \
00163         gpointer user_data_ = (user_data); \
00164         while (NULL != sl_) { \
00165             func(sl_->data, user_data_); \
00166             sl_ = g_slist_next(sl_); \
00167         } \
00168     } G_STMT_END
00169 
00170 
00171 /* NB: Sub-statement func is evaluated more than once! */
00172 #define G_SLIST_FOREACH_SWAPPED(slist, func, user_data) \
00173     G_STMT_START { \
00174         GSList *sl_ = (slist); \
00175         gpointer user_data_ = (user_data); \
00176         while (NULL != sl_) { \
00177             func(user_data_, sl_->data); \
00178             sl_ = g_slist_next(sl_); \
00179         } \
00180     } while(0)
00181 
00182 #define GM_SLIST_FOREACH(slist, iter) \
00183     for ((iter) = (slist); NULL != (iter); (iter) = g_slist_next(iter))
00184 
00185 /* vi: set ts=4 sw=4: */
00186 #endif  /* _glib_missing_h_ */

Generated on Sat Jun 30 17:53:23 2007 for gtk-gnutella by  doxygen 1.3.9.1