GnuCash 2.4.99
qofutil.h
Go to the documentation of this file.
00001 /********************************************************************\
00002  * qof-util.h -- QOF utility functions                              *
00003  *                                                                  *
00004  * This program is free software; you can redistribute it and/or    *
00005  * modify it under the terms of the GNU General Public License as   *
00006  * published by the Free Software Foundation; either version 2 of   *
00007  * the License, or (at your option) any later version.              *
00008  *                                                                  *
00009  * This program is distributed in the hope that it will be useful,  *
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00012  * GNU General Public License for more details.                     *
00013  *                                                                  *
00014  * You should have received a copy of the GNU General Public License*
00015  * along with this program; if not, contact:                        *
00016  *                                                                  *
00017  * Free Software Foundation           Voice:  +1-617-542-5942       *
00018  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00019  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00020 \********************************************************************/
00021 
00032 #ifndef QOF_UTIL_H
00033 #define QOF_UTIL_H
00034 
00035 #include <stddef.h>
00036 #include "qof.h"
00037 #include "qoflog.h"
00038 #include "qofutil.h"
00039 #include "qofbackend.h"
00040 #include "qofclass.h"
00041 #include "qofbook.h"
00042 #include "qofinstance.h"
00043 
00045 #if HAVE_SCANF_LLD
00046 # define QOF_SCANF_LLD "%lld"
00047 #else
00048 # if HAVE_SCANF_QD
00049 #  define QOF_SCANF_LLD "%qd"
00050 # else
00051 #  if HAVE_SCANF_I64D
00052 #   define QOF_SCANF_LLD "%I64d"
00053 #  else
00054 #   error "No scanf format string is known for LLD. Fix your ./configure so that the correct one is detected!"
00055 #  endif
00056 # endif
00057 #endif
00058 
00059 #define QOF_MOD_UTIL "qof.utilities"
00060 
00064 #define ENUM_BODY(name, value)           \
00065     name value,
00066 
00067 #define AS_STRING_CASE(name, value)      \
00068     case name: { return #name; }
00069 
00070 #define FROM_STRING_CASE(name, value)    \
00071     if (strcmp(str, #name) == 0) {       \
00072         return name;  }
00073 
00074 #define DEFINE_ENUM(name, list)          \
00075     typedef enum {                       \
00076         list(ENUM_BODY)                  \
00077     }name;
00078 
00079 #define AS_STRING_DEC(name, list)        \
00080     const gchar* name##asString(name n);
00081 
00082 #define AS_STRING_FUNC(name, list)        \
00083     const gchar* name##asString(name n) { \
00084         switch (n) {                      \
00085             list(AS_STRING_CASE)          \
00086             default: return "";  } }
00087 
00088 #define FROM_STRING_DEC(name, list)      \
00089     name name##fromString                \
00090     (const gchar* str);
00091 
00092 #define FROM_STRING_FUNC(name, list)     \
00093     name name##fromString                \
00094     (const gchar* str) {                 \
00095     if(str == NULL) { return 0; }        \
00096         list(FROM_STRING_CASE)           \
00097         return 0;  }
00098 
00114 #define DEFINE_ENUM_NON_TYPEDEF(name, list)   \
00115     enum name {                               \
00116         list(ENUM_BODY)                       \
00117     };
00118 
00119 #define FROM_STRING_DEC_NON_TYPEDEF(name, list)   \
00120    void name##fromString                          \
00121    (const gchar* str, enum name *type);
00122 
00123 #define FROM_STRING_CASE_NON_TYPEDEF(name, value) \
00124    if (strcmp(str, #name) == 0) { *type = name; }
00125 
00126 #define FROM_STRING_FUNC_NON_TYPEDEF(name, list)  \
00127    void name##fromString                          \
00128    (const gchar* str, enum name *type) {          \
00129    if(str == NULL) { return; }                    \
00130     list(FROM_STRING_CASE_NON_TYPEDEF) }
00131 
00132 #define AS_STRING_DEC_NON_TYPEDEF(name, list)     \
00133    const gchar* name##asString(enum name n);
00134 
00135 #define AS_STRING_FUNC_NON_TYPEDEF(name, list)    \
00136    const gchar* name##asString(enum name n) {     \
00137        switch (n) {                               \
00138            list(AS_STRING_CASE_NON_TYPEDEF)       \
00139            default: return ""; } }
00140 
00141 #define AS_STRING_CASE_NON_TYPEDEF(name, value)   \
00142    case name: { return #name; }
00143 
00155 void qof_init (void);
00156 
00163 void qof_close (void);
00164 
00167 /* **** Prototypes *********************************************/
00168 
00173 void g_hash_table_foreach_sorted(GHashTable *hash_table, GHFunc func, gpointer user_data, GCompareFunc compare_func);
00174 
00178 gboolean qof_utf8_substr_nocase (const gchar *haystack, const gchar *needle);
00179 
00193 gint safe_strcmp (const gchar * da, const gchar * db);
00194 
00207 gint safe_strcasecmp (const gchar * da, const gchar * db);
00208 
00213 gint null_strcmp (const gchar * da, const gchar * db);
00214 
00218 gchar * ultostr (gulong val, gint base);
00219 
00222 gboolean gnc_strisnum(const gchar *s);
00223 
00224 #ifndef HAVE_STPCPY
00225 #define stpcpy g_stpcpy
00226 #endif
00227 
00234 gboolean qof_begin_edit(QofInstance *inst);
00235 
00249 gboolean qof_commit_edit(QofInstance *inst);
00250 
00270 gboolean
00271 qof_commit_edit_part2(QofInstance *inst,
00272                       void (*on_error)(QofInstance *, QofBackendError),
00273                       void (*on_done)(QofInstance *),
00274                       void (*on_free)(QofInstance *));
00275 
00276 #endif /* QOF_UTIL_H */
00277 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines