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 "qof.h"
00037 #include "qoflog.h"
00038 #include "qofdate.h"
00039 #include "qofutil.h"
00040 #include "qofbackend-p.h"
00041 #include "qofbook.h"
00042 #include "qofinstance.h"
00043
00045 #if HAVE_SCANF_LLD
00046 # define QOF_SCANF_LLD "%lld"
00047 #else
00048 # define QOF_SCANF_LLD "%qd"
00049 #endif
00050
00051 #define QOF_MOD_UTIL "qof-utilities"
00052
00056 #define ENUM_BODY(name, value) \
00057 name value,
00058
00059 #define AS_STRING_CASE(name, value) \
00060 case name: { return #name; }
00061
00062 #define FROM_STRING_CASE(name, value) \
00063 if (strcmp(str, #name) == 0) { \
00064 return name; }
00065
00066 #define DEFINE_ENUM(name, list) \
00067 typedef enum { \
00068 list(ENUM_BODY) \
00069 }name;
00070
00071 #define AS_STRING_DEC(name, list) \
00072 const gchar* name##asString(name n);
00073
00074 #define AS_STRING_FUNC(name, list) \
00075 const gchar* name##asString(name n) { \
00076 switch (n) { \
00077 list(AS_STRING_CASE) \
00078 default: return ""; } }
00079
00080 #define FROM_STRING_DEC(name, list) \
00081 name name##fromString \
00082 (const gchar* str);
00083
00084 #define FROM_STRING_FUNC(name, list) \
00085 name name##fromString \
00086 (const gchar* str) { \
00087 if(str == NULL) { return 0; } \
00088 list(FROM_STRING_CASE) \
00089 return 0; }
00090
00106 #define DEFINE_ENUM_NON_TYPEDEF(name, list) \
00107 enum name { \
00108 list(ENUM_BODY) \
00109 };
00110
00111 #define FROM_STRING_DEC_NON_TYPEDEF(name, list) \
00112 void name##fromString \
00113 (const gchar* str, enum name *type);
00114
00115 #define FROM_STRING_CASE_NON_TYPEDEF(name, value) \
00116 if (strcmp(str, #name) == 0) { *type = name; }
00117
00118 #define FROM_STRING_FUNC_NON_TYPEDEF(name, list) \
00119 void name##fromString \
00120 (const gchar* str, enum name *type) { \
00121 if(str == NULL) { return; } \
00122 list(FROM_STRING_CASE_NON_TYPEDEF) }
00123
00124 #define AS_STRING_DEC_NON_TYPEDEF(name, list) \
00125 const gchar* name##asString(enum name n);
00126
00127 #define AS_STRING_FUNC_NON_TYPEDEF(name, list) \
00128 const gchar* name##asString(enum name n) { \
00129 switch (n) { \
00130 list(AS_STRING_CASE_NON_TYPEDEF) \
00131 default: return ""; } }
00132
00133 #define AS_STRING_CASE_NON_TYPEDEF(name, value) \
00134 case name: { return #name; }
00135
00147 void qof_init (void);
00148
00155 void qof_close (void);
00156
00159
00160
00174 gint safe_strcmp (const gchar * da, const gchar * db);
00175
00188 gint safe_strcasecmp (const gchar * da, const gchar * db);
00189
00194 gint null_strcmp (const gchar * da, const gchar * db);
00195
00199 extern gchar *strncasestr (const guchar * str1, const guchar * str2,
00200 size_t len);
00201
00202 extern gchar *strcasestr (const gchar * str1, const gchar * str2);
00203
00207 gchar *ultostr (gulong val, gint base);
00208
00211 gboolean qof_util_string_isnum (const guchar * s);
00212
00213 #ifndef HAVE_STPCPY
00214
00215 #define stpcpy g_stpcpy
00216 #endif
00217
00221 const gchar *qof_util_whitespace_filter (const gchar * val);
00222
00226 gint qof_util_bool_to_int (const gchar * val);
00227
00236 gchar *
00237 qof_util_param_to_string (QofEntity * ent, const QofParam * param);
00238
00259 gboolean
00260 qof_util_param_set_string (QofEntity * ent, const QofParam * param,
00261 const gchar * value_string);
00262
00293 void qof_util_string_cache_destroy (void);
00294
00298 void qof_util_string_cache_remove (gconstpointer key);
00299
00303 gpointer qof_util_string_cache_insert (gconstpointer key);
00304
00305 #define CACHE_INSERT(str) qof_util_string_cache_insert((gconstpointer)(str))
00306 #define CACHE_REMOVE(str) qof_util_string_cache_remove((str))
00307
00308
00309
00310
00311
00312
00313
00314
00315 #define CACHE_REPLACE(dst, src) do { \
00316 gpointer tmp = CACHE_INSERT((src)); \
00317 CACHE_REMOVE((dst)); \
00318 (dst) = tmp; \
00319 } while (0)
00320
00321 #define QOF_CACHE_NEW(void) qof_util_string_cache_insert("")
00322
00354 gboolean
00355 qof_util_param_edit (QofInstance * inst, const QofParam * param);
00356
00371 gboolean
00372 qof_util_param_commit (QofInstance * inst, const QofParam * param);
00373
00374 #endif
00375