GnuCash c935c2f+
Loading...
Searching...
No Matches
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#include <stddef.h>
36#include "qof.h"
37#include "qoflog.h"
38#include "qofbackend.h"
39#include "qofclass.h"
40#include "qofbook.h"
41#include "qofinstance.h"
42
43#ifdef __cplusplus
44extern "C"
45{
46#endif
47
48#define QOF_MOD_UTIL "qof.utilities"
49
53#define ENUM_BODY(name, value) \
54 name value,
55
56#define AS_STRING_CASE(name, value) \
57 case name: { return #name; }
58
59#define FROM_STRING_CASE(name, value) \
60 if (strcmp(str, #name) == 0) { \
61 return name; }
62
63#define DEFINE_ENUM(name, list) \
64 typedef enum { \
65 list(ENUM_BODY) \
66 }name;
67
68#define AS_STRING_DEC(name, list) \
69 const gchar* name##asString(name n);
70
71#define AS_STRING_FUNC(name, list) \
72 const gchar* name##asString(name n) { \
73 switch (n) { \
74 list(AS_STRING_CASE) \
75 default: return ""; } }
76
77#define FROM_STRING_DEC(name, list) \
78 name name##fromString \
79 (const gchar* str);
80
81#define FROM_STRING_FUNC(name, list) \
82 name name##fromString \
83 (const gchar* str) { \
84 if(str == NULL) { return 0; } \
85 list(FROM_STRING_CASE) \
86 return 0; }
87
103#define DEFINE_ENUM_NON_TYPEDEF(name, list) \
104 enum name { \
105 list(ENUM_BODY) \
106 };
107
108#define FROM_STRING_DEC_NON_TYPEDEF(name, list) \
109 void name##fromString \
110 (const gchar* str, enum name *type);
111
112#define FROM_STRING_CASE_NON_TYPEDEF(name, value) \
113 if (strcmp(str, #name) == 0) { *type = name; }
114
115#define FROM_STRING_FUNC_NON_TYPEDEF(name, list) \
116 void name##fromString \
117 (const gchar* str, enum name *type) { \
118 if(str == NULL) { return; } \
119 list(FROM_STRING_CASE_NON_TYPEDEF) }
120
121#define AS_STRING_DEC_NON_TYPEDEF(name, list) \
122 const gchar* name##asString(enum name n);
123
124#define AS_STRING_FUNC_NON_TYPEDEF(name, list) \
125 const gchar* name##asString(enum name n) { \
126 switch (n) { \
127 list(AS_STRING_CASE_NON_TYPEDEF) \
128 default: return ""; } }
129
130#define AS_STRING_CASE_NON_TYPEDEF(name, value) \
131 case name: { return #name; }
132
144void qof_init (void);
145
152void qof_close (void);
153
156/* **** Prototypes *********************************************/
157
162void g_hash_table_foreach_sorted(GHashTable *hash_table, GHFunc func, gpointer user_data, GCompareFunc compare_func);
163
167gboolean qof_utf8_substr_nocase (const gchar *haystack, const gchar *needle);
168
181gint safe_strcasecmp (const gchar * da, const gchar * db);
182
187gint null_strcmp (const gchar * da, const gchar * db);
188
192gchar * ultostr (gulong val, gint base);
193
196gboolean gnc_strisnum(const gchar *s);
197
198#ifndef HAVE_STPCPY
199#define stpcpy g_stpcpy
200#endif
201
208gboolean qof_begin_edit(QofInstance *inst);
209
223gboolean qof_commit_edit(QofInstance *inst);
224
244gboolean
246 void (*on_error)(QofInstance *, QofBackendError),
247 void (*on_done)(QofInstance *),
248 void (*on_free)(QofInstance *));
249
250#ifdef __cplusplus
251}
252#endif
253
254#endif /* QOF_UTIL_H */
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition qofbackend.h:58
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
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
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
gboolean gnc_strisnum(const gchar *s)
Returns true if string s is a number, possibly surrounded by whitespace.
Definition qofutil.cpp:187
void qof_init(void)
Initialise the Query Object Framework.
Definition qofutil.cpp:259
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
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
gchar * ultostr(gulong val, gint base)
The ultostr() subroutine is the inverse of strtoul().
Definition qofutil.cpp:137
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
gboolean qof_begin_edit(QofInstance *inst)
begin_edit
void qof_close(void)
Safely close down the Query Object Framework.
Definition qofutil.cpp:269
API for data storage Backend.
Encapsulate all the information about a dataset.
API for registering parameters on objects.
Object instance holds common fields that most gnucash objects use.