QOF
0.7.5
|
00001 /********************************************************************\ 00002 * qofutil.h -- QOF utility functions * 00003 * * 00004 * This program is free software; you can redistribute it and/or * 00005 * modify it under the terms of the GNU General Public License as * 00006 * published by the Free Software Foundation; either version 2 of * 00007 * the License, or (at your option) any later version. * 00008 * * 00009 * This program is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00012 * GNU General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU General Public License* 00015 * along with this program; if not, contact: * 00016 * * 00017 * Free Software Foundation Voice: +1-617-542-5942 * 00018 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 00019 * Boston, MA 02110-1301, USA gnu@gnu.org * 00020 \********************************************************************/ 00021 00032 #ifndef QOF_UTIL_H 00033 #define QOF_UTIL_H 00034 00035 #include <stddef.h> 00036 #include "qoflog.h" 00037 #include "qofdate.h" 00038 #include "qofutil.h" 00039 #include "qofbackend-p.h" 00040 #include "qofbook.h" 00041 #include "qofinstance.h" 00042 00044 #if HAVE_SCANF_LLD 00045 # define QOF_SCANF_LLD "%lld" 00046 #else 00047 # define QOF_SCANF_LLD "%qd" 00048 #endif 00049 00050 #define QOF_MOD_UTIL "qof-utilities" 00051 00055 #define ENUM_BODY(name, value) \ 00056 name value, 00057 00058 #define AS_STRING_CASE(name, value) \ 00059 case name: { return #name; } 00060 00061 #define FROM_STRING_CASE(name, value) \ 00062 if (strcmp(str, #name) == 0) { \ 00063 return name; } 00064 00065 #define DEFINE_ENUM(name, list) \ 00066 typedef enum { \ 00067 list(ENUM_BODY) \ 00068 }name; 00069 00070 #define AS_STRING_DEC(name, list) \ 00071 const gchar* name##asString(name n); 00072 00073 #define AS_STRING_FUNC(name, list) \ 00074 const gchar* name##asString(name n) { \ 00075 switch (n) { \ 00076 list(AS_STRING_CASE) \ 00077 default: return ""; } } 00078 00079 #define FROM_STRING_DEC(name, list) \ 00080 name name##fromString \ 00081 (const gchar* str); 00082 00083 #define FROM_STRING_FUNC(name, list) \ 00084 name name##fromString \ 00085 (const gchar* str) { \ 00086 if(str == NULL) { return 0; } \ 00087 list(FROM_STRING_CASE) \ 00088 return 0; } 00089 00105 #define DEFINE_ENUM_NON_TYPEDEF(name, list) \ 00106 enum name { \ 00107 list(ENUM_BODY) \ 00108 }; 00109 00110 #define FROM_STRING_DEC_NON_TYPEDEF(name, list) \ 00111 void name##fromString \ 00112 (const gchar* str, enum name *type); 00113 00114 #define FROM_STRING_CASE_NON_TYPEDEF(name, value) \ 00115 if (strcmp(str, #name) == 0) { *type = name; } 00116 00117 #define FROM_STRING_FUNC_NON_TYPEDEF(name, list) \ 00118 void name##fromString \ 00119 (const gchar* str, enum name *type) { \ 00120 if(str == NULL) { return; } \ 00121 list(FROM_STRING_CASE_NON_TYPEDEF) } 00122 00123 #define AS_STRING_DEC_NON_TYPEDEF(name, list) \ 00124 const gchar* name##asString(enum name n); 00125 00126 #define AS_STRING_FUNC_NON_TYPEDEF(name, list) \ 00127 const gchar* name##asString(enum name n) { \ 00128 switch (n) { \ 00129 list(AS_STRING_CASE_NON_TYPEDEF) \ 00130 default: return ""; } } 00131 00132 #define AS_STRING_CASE_NON_TYPEDEF(name, value) \ 00133 case name: { return #name; } 00134 00146 void qof_init (void); 00147 00154 void qof_close (void); 00155 00158 /* **** Prototypes *********************************************/ 00159 00173 gint safe_strcmp (const gchar * da, const gchar * db); 00174 00187 gint safe_strcasecmp (const gchar * da, const gchar * db); 00188 00193 gint null_strcmp (const gchar * da, const gchar * db); 00194 00198 extern gchar *strncasestr (const guchar * str1, const guchar * str2, 00199 size_t len); 00200 00201 extern gchar *strcasestr (const gchar * str1, const gchar * str2); 00202 00206 gchar *ultostr (gulong val, gint base); 00207 00210 gboolean qof_util_string_isnum (const guchar * s); 00211 00213 gint 00214 qof_util_double_compare (gdouble v1, gdouble v2); 00215 00216 #ifndef HAVE_STPCPY 00217 00218 #define stpcpy g_stpcpy 00219 #endif 00220 00224 const gchar *qof_util_whitespace_filter (const gchar * val); 00225 00229 gint qof_util_bool_to_int (const gchar * val); 00230 00239 gchar * 00240 qof_util_param_to_string (QofEntity * ent, const QofParam * param); 00241 00262 gboolean 00263 qof_util_param_set_string (QofEntity * ent, const QofParam * param, 00264 const gchar * value_string); 00265 00275 gchar * 00276 qof_util_make_utf8 (gchar * string); 00277 00308 void qof_util_string_cache_destroy (void); 00309 00313 void qof_util_string_cache_remove (gconstpointer key); 00314 00318 gpointer qof_util_string_cache_insert (gconstpointer key); 00319 00320 #define CACHE_INSERT(str) qof_util_string_cache_insert((gconstpointer)(str)) 00321 #define CACHE_REMOVE(str) qof_util_string_cache_remove((str)) 00322 00323 /* Replace cached string currently in 'dst' with string in 'src'. 00324 * Typical usage: 00325 * void foo_set_name(Foo *f, const char *str) { 00326 * CACHE_REPLACE(f->name, str); 00327 * } 00328 * It avoids unnecessary ejection by doing INSERT before REMOVE. 00329 */ 00330 #define CACHE_REPLACE(dst, src) do { \ 00331 gpointer tmp = CACHE_INSERT((src)); \ 00332 CACHE_REMOVE((dst)); \ 00333 (dst) = tmp; \ 00334 } while (0) 00335 00336 #define QOF_CACHE_NEW(void) qof_util_string_cache_insert("") 00337 00369 gboolean 00370 qof_util_param_edit (QofInstance * inst, const QofParam * param); 00371 00386 gboolean 00387 qof_util_param_commit (QofInstance * inst, const QofParam * param); 00388 00389 #endif /* QOF_UTIL_H */ 00390