GnuCash  4.8a-80-g9825132ea+
qofutil.h
Go to the documentation of this file.
1 /********************************************************************\
2  * qof-util.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 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39 
40 #include <stddef.h>
41 #include "qof.h"
42 #include "qoflog.h"
43 #include "qofutil.h"
44 #include "qofbackend.h"
45 #include "qofclass.h"
46 #include "qofbook.h"
47 #include "qofinstance.h"
48 
50 #if HAVE_SCANF_LLD
51 # define QOF_SCANF_LLD "%lld"
52 #else
53 # if HAVE_SCANF_QD
54 # define QOF_SCANF_LLD "%qd"
55 # else
56 # if HAVE_SCANF_I64D
57 # define QOF_SCANF_LLD "%I64d"
58 # else
59 # error "No scanf format string is known for LLD. Fix your ./configure so that the correct one is detected!"
60 # endif
61 # endif
62 #endif
63 
64 #define QOF_MOD_UTIL "qof.utilities"
65 
69 #define ENUM_BODY(name, value) \
70  name value,
71 
72 #define AS_STRING_CASE(name, value) \
73  case name: { return #name; }
74 
75 #define FROM_STRING_CASE(name, value) \
76  if (strcmp(str, #name) == 0) { \
77  return name; }
78 
79 #define DEFINE_ENUM(name, list) \
80  typedef enum { \
81  list(ENUM_BODY) \
82  }name;
83 
84 #define AS_STRING_DEC(name, list) \
85  const gchar* name##asString(name n);
86 
87 #define AS_STRING_FUNC(name, list) \
88  const gchar* name##asString(name n) { \
89  switch (n) { \
90  list(AS_STRING_CASE) \
91  default: return ""; } }
92 
93 #define FROM_STRING_DEC(name, list) \
94  name name##fromString \
95  (const gchar* str);
96 
97 #define FROM_STRING_FUNC(name, list) \
98  name name##fromString \
99  (const gchar* str) { \
100  if(str == NULL) { return 0; } \
101  list(FROM_STRING_CASE) \
102  return 0; }
103 
119 #define DEFINE_ENUM_NON_TYPEDEF(name, list) \
120  enum name { \
121  list(ENUM_BODY) \
122  };
123 
124 #define FROM_STRING_DEC_NON_TYPEDEF(name, list) \
125  void name##fromString \
126  (const gchar* str, enum name *type);
127 
128 #define FROM_STRING_CASE_NON_TYPEDEF(name, value) \
129  if (strcmp(str, #name) == 0) { *type = name; }
130 
131 #define FROM_STRING_FUNC_NON_TYPEDEF(name, list) \
132  void name##fromString \
133  (const gchar* str, enum name *type) { \
134  if(str == NULL) { return; } \
135  list(FROM_STRING_CASE_NON_TYPEDEF) }
136 
137 #define AS_STRING_DEC_NON_TYPEDEF(name, list) \
138  const gchar* name##asString(enum name n);
139 
140 #define AS_STRING_FUNC_NON_TYPEDEF(name, list) \
141  const gchar* name##asString(enum name n) { \
142  switch (n) { \
143  list(AS_STRING_CASE_NON_TYPEDEF) \
144  default: return ""; } }
145 
146 #define AS_STRING_CASE_NON_TYPEDEF(name, value) \
147  case name: { return #name; }
148 
160 void qof_init (void);
161 
168 void qof_close (void);
169 
172 /* **** Prototypes *********************************************/
173 
178 void g_hash_table_foreach_sorted(GHashTable *hash_table, GHFunc func, gpointer user_data, GCompareFunc compare_func);
179 
183 gboolean qof_utf8_substr_nocase (const gchar *haystack, const gchar *needle);
184 
197 gint safe_strcasecmp (const gchar * da, const gchar * db);
198 
203 gint null_strcmp (const gchar * da, const gchar * db);
204 
208 gchar * ultostr (gulong val, gint base);
209 
212 gboolean gnc_strisnum(const gchar *s);
213 
214 #ifndef HAVE_STPCPY
215 #define stpcpy g_stpcpy
216 #endif
217 
224 gboolean qof_begin_edit(QofInstance *inst);
225 
239 gboolean qof_commit_edit(QofInstance *inst);
240 
260 gboolean
261 qof_commit_edit_part2(QofInstance *inst,
262  void (*on_error)(QofInstance *, QofBackendError),
263  void (*on_done)(QofInstance *),
264  void (*on_free)(QofInstance *));
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 #endif /* QOF_UTIL_H */
271 
API for data storage Backend.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition: qofbackend.h:57
gint safe_strcasecmp(const gchar *da, const gchar *db)
case sensitive comparison of strings da and db - either may be NULL.
Definition: qofutil.cpp:100
Object instance holds common fields that most gnucash objects use.
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
gboolean gnc_strisnum(const gchar *s)
Returns true if string s is a number, possibly surrounded by whitespace.
Definition: qofutil.cpp:187
gboolean qof_begin_edit(QofInstance *inst)
begin_edit
gint null_strcmp(const gchar *da, const gchar *db)
The null_strcmp compares strings a and b the same way that strcmp() does, except that either may be n...
Definition: qofutil.cpp:123
gchar * ultostr(gulong val, gint base)
The ultostr() subroutine is the inverse of strtoul().
Definition: qofutil.cpp:137
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
void g_hash_table_foreach_sorted(GHashTable *hash_table, GHFunc func, gpointer user_data, GCompareFunc compare_func)
Calls the given function for each of the key/value pairs in the GHashTable in an order determined by ...
Definition: qofutil.cpp:40
Encapsulate all the information about a dataset.
API for registering parameters on objects.
void qof_close(void)
Safely close down the Query Object Framework.
Definition: qofutil.cpp:269
gboolean qof_utf8_substr_nocase(const gchar *haystack, const gchar *needle)
Search for an occurrence of the substring needle in the string haystack, ignoring case...
Definition: qofutil.cpp:54
void qof_init(void)
Initialise the Query Object Framework.
Definition: qofutil.cpp:259
QOF utility functions.