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
00043 #define QOF_MOD_UTIL "qof-utilities"
00044
00048 #define ENUM_BODY(name, value) \
00049 name value,
00050
00051 #define AS_STRING_CASE(name, value) \
00052 case name: { return #name; }
00053
00054 #define FROM_STRING_CASE(name, value) \
00055 if (strcmp(str, #name) == 0) { \
00056 return name; }
00057
00058 #define DEFINE_ENUM(name, list) \
00059 typedef enum { \
00060 list(ENUM_BODY) \
00061 }name;
00062
00063 #define AS_STRING_DEC(name, list) \
00064 const gchar* name##asString(name n);
00065
00066 #define AS_STRING_FUNC(name, list) \
00067 const gchar* name##asString(name n) { \
00068 switch (n) { \
00069 list(AS_STRING_CASE) \
00070 default: return ""; } }
00071
00072 #define FROM_STRING_DEC(name, list) \
00073 name name##fromString \
00074 (const gchar* str);
00075
00076 #define FROM_STRING_FUNC(name, list) \
00077 name name##fromString \
00078 (const gchar* str) { \
00079 if(str == NULL) { return 0; } \
00080 list(FROM_STRING_CASE) \
00081 return 0; }
00082
00098 #define DEFINE_ENUM_NON_TYPEDEF(name, list) \
00099 enum name { \
00100 list(ENUM_BODY) \
00101 };
00102
00103 #define FROM_STRING_DEC_NON_TYPEDEF(name, list) \
00104 void name##fromString \
00105 (const gchar* str, enum name *type);
00106
00107 #define FROM_STRING_CASE_NON_TYPEDEF(name, value) \
00108 if (strcmp(str, #name) == 0) { *type = name; }
00109
00110 #define FROM_STRING_FUNC_NON_TYPEDEF(name, list) \
00111 void name##fromString \
00112 (const gchar* str, enum name *type) { \
00113 if(str == NULL) { return; } \
00114 list(FROM_STRING_CASE_NON_TYPEDEF) }
00115
00116 #define AS_STRING_DEC_NON_TYPEDEF(name, list) \
00117 const gchar* name##asString(enum name n);
00118
00119 #define AS_STRING_FUNC_NON_TYPEDEF(name, list) \
00120 const gchar* name##asString(enum name n) { \
00121 switch (n) { \
00122 list(AS_STRING_CASE_NON_TYPEDEF) \
00123 default: return ""; } }
00124
00125 #define AS_STRING_CASE_NON_TYPEDEF(name, value) \
00126 case name: { return #name; }
00127
00139 void qof_init (void);
00140
00147 void qof_close (void);
00148
00151
00152
00166 gint safe_strcmp (const gchar * da, const gchar * db);
00167
00180 gint safe_strcasecmp (const gchar * da, const gchar * db);
00181
00186 gint null_strcmp (const gchar * da, const gchar * db);
00187
00191 extern gchar *strncasestr (const guchar * str1, const guchar * str2,
00192 size_t len);
00193
00194 #ifndef _STRING_H
00195 extern gchar *strcasestr (const gchar * str1, const gchar * str2);
00196 #endif
00197
00201 gchar *ultostr (gulong val, gint base);
00202
00205 gboolean qof_util_string_isnum (const guchar * s);
00206
00208 gint
00209 qof_util_double_compare (gdouble v1, gdouble v2);
00210
00211 #ifndef HAVE_STPCPY
00212
00213 #define stpcpy g_stpcpy
00214 #endif
00215
00219 const gchar *qof_util_whitespace_filter (const gchar * val);
00220
00224 gint qof_util_bool_to_int (const gchar * val);
00225
00234 gchar *
00235 qof_util_param_to_string (QofEntity * ent, const QofParam * param);
00236
00257 gboolean
00258 qof_util_param_set_string (QofEntity * ent, const QofParam * param,
00259 const gchar * value_string);
00260
00270 gchar *
00271 qof_util_make_utf8 (gchar * string);
00272
00303 void qof_util_string_cache_destroy (void);
00304
00308 void qof_util_string_cache_remove (gconstpointer key);
00309
00313 gpointer qof_util_string_cache_insert (gconstpointer key);
00314
00315 #define CACHE_INSERT(str) qof_util_string_cache_insert((gconstpointer)(str))
00316 #define CACHE_REMOVE(str) qof_util_string_cache_remove((str))
00317
00318
00319
00320
00321
00322
00323
00324
00325 #define CACHE_REPLACE(dst, src) do { \
00326 gpointer tmp = CACHE_INSERT((src)); \
00327 CACHE_REMOVE((dst)); \
00328 (dst) = tmp; \
00329 } while (0)
00330
00331 #define QOF_CACHE_NEW(void) qof_util_string_cache_insert("")
00332
00364 gboolean
00365 qof_util_param_edit (QofInstance * inst, const QofParam * param);
00366
00381 gboolean
00382 qof_util_param_commit (QofInstance * inst, const QofParam * param);
00383
00384 #endif
00385