QOF: qofutil.h Source File

QOF 0.7.5

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

qofutil.h
Go to the documentation of this file.
1 /********************************************************************\
2 * qofutil.h -- QOF utility functions *
3 * *
4 * This program is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU General Public License as *
6 * published by the Free Software Foundation; either version 2 of *
7 * the License, or (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License*
15 * along with this program; if not, contact: *
16 * *
17 * Free Software Foundation Voice: +1-617-542-5942 *
18 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19 * Boston, MA 02110-1301, USA gnu@gnu.org *
20 \********************************************************************/
21
32 #ifndef QOF_UTIL_H
33 #define QOF_UTIL_H
34
35 #include <stddef.h>
36 #include "qoflog.h"
37 #include "qofdate.h"
38 #include "qofutil.h"
39 #include "qofbackend-p.h"
40 #include "qofbook.h"
41 #include "qofinstance.h"
42
44 #if HAVE_SCANF_LLD
45 # define QOF_SCANF_LLD "%lld"
46 #else
47 # define QOF_SCANF_LLD "%qd"
48 #endif
49
50 #define QOF_MOD_UTIL "qof-utilities"
51
55 #define ENUM_BODY(name, value) \
56 name value,
57
58 #define AS_STRING_CASE(name, value) \
59 case name: { return #name; }
60
61 #define FROM_STRING_CASE(name, value) \
62 if (strcmp(str, #name) == 0) { \
63 return name; }
64
65 #define DEFINE_ENUM(name, list) \
66 typedef enum { \
67 list(ENUM_BODY) \
68 }name;
69
70 #define AS_STRING_DEC(name, list) \
71 const gchar* name##asString(name n);
72
73 #define AS_STRING_FUNC(name, list) \
74 const gchar* name##asString(name n) { \
75 switch (n) { \
76 list(AS_STRING_CASE) \
77 default: return ""; } }
78
79 #define FROM_STRING_DEC(name, list) \
80 name name##fromString \
81 (const gchar* str);
82
83 #define FROM_STRING_FUNC(name, list) \
84 name name##fromString \
85 (const gchar* str) { \
86 if(str == NULL) { return 0; } \
87 list(FROM_STRING_CASE) \
88 return 0; }
89
105 #define DEFINE_ENUM_NON_TYPEDEF(name, list) \
106 enum name { \
107 list(ENUM_BODY) \
108 };
109
110 #define FROM_STRING_DEC_NON_TYPEDEF(name, list) \
111 void name##fromString \
112 (const gchar* str, enum name *type);
113
114 #define FROM_STRING_CASE_NON_TYPEDEF(name, value) \
115 if (strcmp(str, #name) == 0) { *type = name; }
116
117 #define FROM_STRING_FUNC_NON_TYPEDEF(name, list) \
118 void name##fromString \
119 (const gchar* str, enum name *type) { \
120 if(str == NULL) { return; } \
121 list(FROM_STRING_CASE_NON_TYPEDEF) }
122
123 #define AS_STRING_DEC_NON_TYPEDEF(name, list) \
124 const gchar* name##asString(enum name n);
125
126 #define AS_STRING_FUNC_NON_TYPEDEF(name, list) \
127 const gchar* name##asString(enum name n) { \
128 switch (n) { \
129 list(AS_STRING_CASE_NON_TYPEDEF) \
130 default: return ""; } }
131
132 #define AS_STRING_CASE_NON_TYPEDEF(name, value) \
133 case name: { return #name; }
134
146 void qof_init (void);
147
154 void qof_close (void);
155
158 /* **** Prototypes *********************************************/
159
173 gint safe_strcmp (const gchar * da, const gchar * db);
174
187 gint safe_strcasecmp (const gchar * da, const gchar * db);
188
193 gint null_strcmp (const gchar * da, const gchar * db);
194
198 extern gchar *strncasestr (const guchar * str1, const guchar * str2,
199 size_t len);
200
201 extern gchar *strcasestr (const gchar * str1, const gchar * str2);
202
206 gchar *ultostr (gulong val, gint base);
207
210 gboolean qof_util_string_isnum (const guchar * s);
211
213 gint
214 qof_util_double_compare (gdouble v1, gdouble v2);
215
216 #ifndef HAVE_STPCPY
217
218 #define stpcpy g_stpcpy
219 #endif
220
224 const gchar *qof_util_whitespace_filter (const gchar * val);
225
229 gint qof_util_bool_to_int (const gchar * val);
230
239 gchar *
240 qof_util_param_to_string (QofEntity * ent, const QofParam * param);
241
262 gboolean
263 qof_util_param_set_string (QofEntity * ent, const QofParam * param,
264 const gchar * value_string);
265
275 gchar *
276 qof_util_make_utf8 (gchar * string);
277
308 void qof_util_string_cache_destroy (void);
309
313 void qof_util_string_cache_remove (gconstpointer key);
314
318 gpointer qof_util_string_cache_insert (gconstpointer key);
319
320 #define CACHE_INSERT(str) qof_util_string_cache_insert((gconstpointer)(str))
321 #define CACHE_REMOVE(str) qof_util_string_cache_remove((str))
322
323 /* Replace cached string currently in 'dst' with string in 'src'.
324 * Typical usage:
325 * void foo_set_name(Foo *f, const char *str) {
326 * CACHE_REPLACE(f->name, str);
327 * }
328 * It avoids unnecessary ejection by doing INSERT before REMOVE.
329 */
330 #define CACHE_REPLACE(dst, src) do { \
331 gpointer tmp = CACHE_INSERT((src)); \
332 CACHE_REMOVE((dst)); \
333 (dst) = tmp; \
334 } while (0)
335
336 #define QOF_CACHE_NEW(void) qof_util_string_cache_insert("")
337
369 gboolean
370 qof_util_param_edit (QofInstance * inst, const QofParam * param);
371
386 gboolean
387 qof_util_param_commit (QofInstance * inst, const QofParam * param);
388
389 #endif /* QOF_UTIL_H */
390
qof_util_make_utf8
gchar * qof_util_make_utf8(gchar *string)
Convert strings received from the wrapped objects into UTF-8.
Definition: qofutil.c:330
qof_util_whitespace_filter
const gchar * qof_util_whitespace_filter(const gchar *val)
Definition: qofutil.c:231
QofInstance_s
Definition: qofinstance-p.h:35
_QofParam
Definition: qofclass.h:195
QofEntity_s
Definition: qofid.h:147
safe_strcasecmp
gint safe_strcasecmp(const gchar *da, const gchar *db)
Definition: qofutil.c:92
qofinstance.h
Object instance holds common fields that most QofObjects use.
qof_util_bool_to_int
gint qof_util_bool_to_int(const gchar *val)
Definition: qofutil.c:249
qof_util_param_edit
gboolean qof_util_param_edit(QofInstance *inst, const QofParam *param)
Prepare to edit a parameter.
Definition: qofutil.c:278
qoflog.h
QOF error logging and tracing facility.
qof_util_string_cache_insert
gpointer qof_util_string_cache_insert(gconstpointer key)
Definition: qofutil.c:439
qof_util_string_cache_remove
void qof_util_string_cache_remove(gconstpointer key)
Definition: qofutil.c:432
qof_util_string_cache_destroy
void qof_util_string_cache_destroy(void)
Definition: qofutil.c:424
qof_util_param_to_string
gchar * qof_util_param_to_string(QofEntity *ent, const QofParam *param)
Converts a parameter to a string for storage or display.
Definition: qofutil.c:447
null_strcmp
gint null_strcmp(const gchar *da, const gchar *db)
Definition: qofutil.c:112
qof_util_param_commit
gboolean qof_util_param_commit(QofInstance *inst, const QofParam *param)
Commit this parameter change, with undo support.
Definition: qofutil.c:306
qofdate.h
64bit Date handling routines
ultostr
gchar * ultostr(gulong val, gint base)
Definition: qofutil.c:131
qof_util_param_set_string
gboolean qof_util_param_set_string(QofEntity *ent, const QofParam *param, const gchar *value_string)
Set a parameter from a value string.
Definition: qofutil.c:644
qofbook.h
Encapsulate all the information about a dataset.
qof_close
void qof_close(void)
Safely close down the Query Object Framework.
Definition: qofutil.c:844
qofbackend-p.h
private api for data storage backend
qof_util_string_isnum
gboolean qof_util_string_isnum(const guchar *s)
Definition: qofutil.c:195
qof_util_double_compare
gint qof_util_double_compare(gdouble v1, gdouble v2)
Compare two gdouble values.
Definition: qofutil.c:179
safe_strcmp
gint safe_strcmp(const gchar *da, const gchar *db)
Definition: qofutil.c:72
strncasestr
gchar * strncasestr(const guchar *str1, const guchar *str2, size_t len)
Definition: qofutil.c:45
qof_init
void qof_init(void)
Initialise the Query Object Framework.
Definition: qofutil.c:833
qofutil.h
QOF utility functions.