GnuCash  4.12-74-g36b33262ad+
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 "qofbackend.h"
44 #include "qofclass.h"
45 #include "qofbook.h"
46 #include "qofinstance.h"
47 
49 #if HAVE_SCANF_LLD
50 # define QOF_SCANF_LLD "%lld"
51 #else
52 # if HAVE_SCANF_QD
53 # define QOF_SCANF_LLD "%qd"
54 # else
55 # if HAVE_SCANF_I64D
56 # define QOF_SCANF_LLD "%I64d"
57 # else
58 # error "No scanf format string is known for LLD. Fix your ./configure so that the correct one is detected!"
59 # endif
60 # endif
61 #endif
62 
63 #define QOF_MOD_UTIL "qof.utilities"
64 
68 #define ENUM_BODY(name, value) \
69  name value,
70 
71 #define AS_STRING_CASE(name, value) \
72  case name: { return #name; }
73 
74 #define FROM_STRING_CASE(name, value) \
75  if (strcmp(str, #name) == 0) { \
76  return name; }
77 
78 #define DEFINE_ENUM(name, list) \
79  typedef enum { \
80  list(ENUM_BODY) \
81  }name;
82 
83 #define AS_STRING_DEC(name, list) \
84  const gchar* name##asString(name n);
85 
86 #define AS_STRING_FUNC(name, list) \
87  const gchar* name##asString(name n) { \
88  switch (n) { \
89  list(AS_STRING_CASE) \
90  default: return ""; } }
91 
92 #define FROM_STRING_DEC(name, list) \
93  name name##fromString \
94  (const gchar* str);
95 
96 #define FROM_STRING_FUNC(name, list) \
97  name name##fromString \
98  (const gchar* str) { \
99  if(str == NULL) { return 0; } \
100  list(FROM_STRING_CASE) \
101  return 0; }
102 
118 #define DEFINE_ENUM_NON_TYPEDEF(name, list) \
119  enum name { \
120  list(ENUM_BODY) \
121  };
122 
123 #define FROM_STRING_DEC_NON_TYPEDEF(name, list) \
124  void name##fromString \
125  (const gchar* str, enum name *type);
126 
127 #define FROM_STRING_CASE_NON_TYPEDEF(name, value) \
128  if (strcmp(str, #name) == 0) { *type = name; }
129 
130 #define FROM_STRING_FUNC_NON_TYPEDEF(name, list) \
131  void name##fromString \
132  (const gchar* str, enum name *type) { \
133  if(str == NULL) { return; } \
134  list(FROM_STRING_CASE_NON_TYPEDEF) }
135 
136 #define AS_STRING_DEC_NON_TYPEDEF(name, list) \
137  const gchar* name##asString(enum name n);
138 
139 #define AS_STRING_FUNC_NON_TYPEDEF(name, list) \
140  const gchar* name##asString(enum name n) { \
141  switch (n) { \
142  list(AS_STRING_CASE_NON_TYPEDEF) \
143  default: return ""; } }
144 
145 #define AS_STRING_CASE_NON_TYPEDEF(name, value) \
146  case name: { return #name; }
147 
159 void qof_init (void);
160 
167 void qof_close (void);
168 
171 /* **** Prototypes *********************************************/
172 
177 void g_hash_table_foreach_sorted(GHashTable *hash_table, GHFunc func, gpointer user_data, GCompareFunc compare_func);
178 
182 gboolean qof_utf8_substr_nocase (const gchar *haystack, const gchar *needle);
183 
196 gint safe_strcasecmp (const gchar * da, const gchar * db);
197 
202 gint null_strcmp (const gchar * da, const gchar * db);
203 
207 gchar * ultostr (gulong val, gint base);
208 
211 gboolean gnc_strisnum(const gchar *s);
212 
213 #ifndef HAVE_STPCPY
214 #define stpcpy g_stpcpy
215 #endif
216 
223 gboolean qof_begin_edit(QofInstance *inst);
224 
238 gboolean qof_commit_edit(QofInstance *inst);
239 
259 gboolean
260 qof_commit_edit_part2(QofInstance *inst,
261  void (*on_error)(QofInstance *, QofBackendError),
262  void (*on_done)(QofInstance *),
263  void (*on_free)(QofInstance *));
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 #endif /* QOF_UTIL_H */
270 
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