00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00324
00325
00326
00327
00328
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
00390