gnc-engine-util.h

Go to the documentation of this file.
00001 /********************************************************************\
00002  * gnc-engine-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  * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
00019  * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
00020 \********************************************************************/
00021 
00033 #ifndef QOF_UTIL_H
00034 #define QOF_UTIL_H
00035 
00036 #include <glib.h>
00037 #include <stddef.h>
00038 #include "config.h"
00039 #include "qof.h"
00040 
00041 /* Macros *****************************************************/
00042 
00052 #define SAFE_STRCMP_REAL(fcn,da,db) {    \
00053   if ((da) && (db)) {                    \
00054     if ((da) != (db)) {                  \
00055       int retval = fcn ((da), (db));     \
00056       /* if strings differ, return */    \
00057       if (retval) return retval;         \
00058     }                                    \
00059   } else                                 \
00060   if ((!(da)) && (db)) {                 \
00061     return -1;                           \
00062   } else                                 \
00063   if ((da) && (!(db))) {                 \
00064     return +1;                           \
00065   }                                      \
00066 }
00067 
00069 #define SAFE_STRCMP(da,db) SAFE_STRCMP_REAL(strcmp,(da),(db))
00070 
00071 #define SAFE_STRCASECMP(da,db) SAFE_STRCMP_REAL(strcasecmp,(da),(db))
00072 
00076 #define ENUM_BODY(name, value)           \
00077     name value,
00078 
00079 #define AS_STRING_CASE(name, value)      \
00080     case name: { return #name; }
00081 
00082 #define FROM_STRING_CASE(name, value)    \
00083     if (strcmp(str, #name) == 0) {       \
00084         return name;  }
00085 
00086 #define DEFINE_ENUM(name, list)          \
00087     typedef enum {                       \
00088         list(ENUM_BODY)                  \
00089     }name;
00090 
00091 #define AS_STRING_DEC(name, list)        \
00092     const char* name##asString(name n);
00093 
00094 #define AS_STRING_FUNC(name, list)       \
00095     const char* name##asString(name n) {       \
00096         switch (n) {                     \
00097             list(AS_STRING_CASE)         \
00098             default: return "";  } }
00099 
00100 #define FROM_STRING_DEC(name, list)      \
00101     name name##fromString                \
00102     (const char* str);
00103 
00104 #define FROM_STRING_FUNC(name, list)     \
00105     name name##fromString                \
00106     (const char* str) {                  \
00107     if(str == NULL) { return 0; }        \
00108         list(FROM_STRING_CASE)           \
00109         return 0;  }
00110 
00122 #define FROM_STRING_DEC_NON_TYPEDEF(name, list)      \
00123    void name##fromString                          \
00124         (const char* str, enum name *type);
00125 
00126 #define FROM_STRING_CASE_NON_TYPEDEF(name, value)    \
00127     if (strcmp(str, #name) == 0) { *type = name; }
00128 
00129 #define FROM_STRING_FUNC_NON_TYPEDEF(name, list)     \
00130    void name##fromString                          \
00131         (const char* str, enum name *type) {         \
00132    if(str == NULL) { return; }                    \
00133     list(FROM_STRING_CASE_NON_TYPEDEF) }
00134 
00135 #define AS_STRING_DEC_NON_TYPEDEF(name, list)        \
00136     const char* name##asString(enum name n);
00137 
00138 #define AS_STRING_FUNC_NON_TYPEDEF(name, list)       \
00139     const char* name##asString(enum name n) {        \
00140         switch (n) {                     \
00141             list(AS_STRING_CASE_NON_TYPEDEF)         \
00142            default: return ""; } }
00143 
00144 #define AS_STRING_CASE_NON_TYPEDEF(name, value)      \
00145     case name: { return #name; }
00146 
00149 /* Define the long long int conversion for scanf */
00150 #if HAVE_SCANF_LLD
00151 # define GNC_SCANF_LLD "%lld"
00152 #else
00153 # define GNC_SCANF_LLD "%qd"
00154 #endif
00155 
00165 void qof_init (void);
00166 
00173 void qof_close (void);
00174 
00177 /* **** Prototypes *********************************************/
00178 
00192 int safe_strcmp (const char * da, const char * db);
00193 
00206 int safe_strcasecmp (const char * da, const char * db);
00207 
00212 int null_strcmp (const char * da, const char * db);
00213 
00217 extern char *strncasestr(const char *str1, const char *str2, size_t len);
00218 extern char *strcasestr(const char *str1, const char *str2);
00219 
00223 char * ultostr (unsigned long val, int base);
00224 
00227 gboolean gnc_strisnum(const char *s);
00228 
00230 char * gnc_stpcpy (char *dest, const char *src);
00231 
00232 #ifndef HAVE_STPCPY
00233 #define stpcpy gnc_stpcpy
00234 #endif
00235 
00239 const char * qof_util_whitespace_filter (const char * val);
00240 
00244 int qof_util_bool_to_int (const char * val);
00245 
00246 
00281 GCache* gnc_engine_get_string_cache(void);
00282 
00284 void gnc_engine_string_cache_destroy (void);
00285 
00289 void gnc_string_cache_remove(gconstpointer key);
00290 
00294 gpointer gnc_string_cache_insert(gpointer key);
00295 
00296 #define CACHE_INSERT(str) gnc_string_cache_insert((gpointer)(str));
00297 #define CACHE_REMOVE(str) gnc_string_cache_remove((str));
00298 
00299 #endif /* QOF_UTIL_H */
00300 

Generated on Fri Oct 21 15:49:54 2005 for QOF by  doxygen 1.4.5