QOF  0.8.7
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 
43 #define QOF_MOD_UTIL "qof-utilities"
44 
48 #define ENUM_BODY(name, value) \
49  name value,
50 
51 #define AS_STRING_CASE(name, value) \
52  case name: { return #name; }
53 
54 #define FROM_STRING_CASE(name, value) \
55  if (strcmp(str, #name) == 0) { \
56  return name; }
57 
58 #define DEFINE_ENUM(name, list) \
59  typedef enum { \
60  list(ENUM_BODY) \
61  }name;
62 
63 #define AS_STRING_DEC(name, list) \
64  const gchar* name##asString(name n);
65 
66 #define AS_STRING_FUNC(name, list) \
67  const gchar* name##asString(name n) { \
68  switch (n) { \
69  list(AS_STRING_CASE) \
70  default: return ""; } }
71 
72 #define FROM_STRING_DEC(name, list) \
73  name name##fromString \
74  (const gchar* str);
75 
76 #define FROM_STRING_FUNC(name, list) \
77  name name##fromString \
78  (const gchar* str) { \
79  if(str == NULL) { return 0; } \
80  list(FROM_STRING_CASE) \
81  return 0; }
82 
98 #define DEFINE_ENUM_NON_TYPEDEF(name, list) \
99  enum name { \
100  list(ENUM_BODY) \
101  };
102 
103 #define FROM_STRING_DEC_NON_TYPEDEF(name, list) \
104  void name##fromString \
105  (const gchar* str, enum name *type);
106 
107 #define FROM_STRING_CASE_NON_TYPEDEF(name, value) \
108  if (strcmp(str, #name) == 0) { *type = name; }
109 
110 #define FROM_STRING_FUNC_NON_TYPEDEF(name, list) \
111  void name##fromString \
112  (const gchar* str, enum name *type) { \
113  if(str == NULL) { return; } \
114  list(FROM_STRING_CASE_NON_TYPEDEF) }
115 
116 #define AS_STRING_DEC_NON_TYPEDEF(name, list) \
117  const gchar* name##asString(enum name n);
118 
119 #define AS_STRING_FUNC_NON_TYPEDEF(name, list) \
120  const gchar* name##asString(enum name n) { \
121  switch (n) { \
122  list(AS_STRING_CASE_NON_TYPEDEF) \
123  default: return ""; } }
124 
125 #define AS_STRING_CASE_NON_TYPEDEF(name, value) \
126  case name: { return #name; }
127 
139 void qof_init (void);
140 
147 void qof_close (void);
148 
151 /* **** Prototypes *********************************************/
152 
166 gint safe_strcmp (const gchar * da, const gchar * db);
167 
180 gint safe_strcasecmp (const gchar * da, const gchar * db);
181 
186 gint null_strcmp (const gchar * da, const gchar * db);
187 
191 extern gchar *strncasestr (const guchar * str1, const guchar * str2,
192  size_t len);
193 
194 #ifndef _STRING_H
195 extern gchar *strcasestr (const gchar * str1, const gchar * str2);
196 #endif
197 
201 gchar *ultostr (gulong val, gint base);
202 
205 gboolean qof_util_string_isnum (const guchar * s);
206 
208 gint
209 qof_util_double_compare (gdouble v1, gdouble v2);
210 
211 #ifndef HAVE_STPCPY
212 
213 #define stpcpy g_stpcpy
214 #endif
215 
219 const gchar *qof_util_whitespace_filter (const gchar * val);
220 
224 gint qof_util_bool_to_int (const gchar * val);
225 
234 gchar *
235 qof_util_param_to_string (QofEntity * ent, const QofParam * param);
236 
257 gboolean
258 qof_util_param_set_string (QofEntity * ent, const QofParam * param,
259  const gchar * value_string);
260 
270 gchar *
271 qof_util_make_utf8 (gchar * string);
272 
304 
308 void qof_util_string_cache_remove (gconstpointer key);
309 
313 gpointer qof_util_string_cache_insert (gconstpointer key);
314 
315 #define CACHE_INSERT(str) qof_util_string_cache_insert((gconstpointer)(str))
316 #define CACHE_REMOVE(str) qof_util_string_cache_remove((str))
317 
318 /* Replace cached string currently in 'dst' with string in 'src'.
319  * Typical usage:
320  * void foo_set_name(Foo *f, const char *str) {
321  * CACHE_REPLACE(f->name, str);
322  * }
323  * It avoids unnecessary ejection by doing INSERT before REMOVE.
324 */
325 #define CACHE_REPLACE(dst, src) do { \
326  gpointer tmp = CACHE_INSERT((src)); \
327  CACHE_REMOVE((dst)); \
328  (dst) = tmp; \
329  } while (0)
330 
331 #define QOF_CACHE_NEW(void) qof_util_string_cache_insert("")
332 
364 gboolean
365 qof_util_param_edit (QofInstance * inst, const QofParam * param);
366 
381 gboolean
382 qof_util_param_commit (QofInstance * inst, const QofParam * param);
383 
384 #endif /* QOF_UTIL_H */
385 
gchar * qof_util_make_utf8(gchar *string)
Convert strings received from the wrapped objects into UTF-8.
Definition: qofutil.c:333
const gchar * qof_util_whitespace_filter(const gchar *val)
Definition: qofutil.c:234
gint safe_strcasecmp(const gchar *da, const gchar *db)
Definition: qofutil.c:95
Object instance holds common fields that most QofObjects use.
gint qof_util_bool_to_int(const gchar *val)
Definition: qofutil.c:252
gboolean qof_util_param_edit(QofInstance *inst, const QofParam *param)
Prepare to edit a parameter.
Definition: qofutil.c:281
QOF error logging and tracing facility.
gpointer qof_util_string_cache_insert(gconstpointer key)
Definition: qofutil.c:456
void qof_util_string_cache_remove(gconstpointer key)
Definition: qofutil.c:450
void qof_util_string_cache_destroy(void)
Definition: qofutil.c:443
gchar * qof_util_param_to_string(QofEntity *ent, const QofParam *param)
Converts a parameter to a string for storage or display.
Definition: qofutil.c:464
gint null_strcmp(const gchar *da, const gchar *db)
Definition: qofutil.c:115
gboolean qof_util_param_commit(QofInstance *inst, const QofParam *param)
Commit this parameter change, with undo support.
Definition: qofutil.c:309
64bit Date handling routines
gchar * ultostr(gulong val, gint base)
Definition: qofutil.c:134
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:647
Encapsulate all the information about a dataset.
void qof_close(void)
Safely close down the Query Object Framework.
Definition: qofutil.c:840
private api for data storage backend
gboolean qof_util_string_isnum(const guchar *s)
Definition: qofutil.c:198
gint qof_util_double_compare(gdouble v1, gdouble v2)
Compare two gdouble values.
Definition: qofutil.c:182
gint safe_strcmp(const gchar *da, const gchar *db)
Definition: qofutil.c:75
gchar * strncasestr(const guchar *str1, const guchar *str2, size_t len)
Definition: qofutil.c:45
void qof_init(void)
Initialise the Query Object Framework.
Definition: qofutil.c:829
QOF utility functions.