GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Macros | Functions

Files

file  qof-string-cache.h
 QOF String cache functions.
 
file  qofutil.h
 QOF utility functions.
 

Macros

#define QOF_MOD_UTIL   "qof.utilities"
 
#define CACHE_INSERT(str)   qof_string_cache_insert((gconstpointer)(str))
 
#define CACHE_REMOVE(str)   qof_string_cache_remove((str))
 
#define CACHE_REPLACE(dst, src)
 
#define QOF_CACHE_NEW(void)   qof_string_cache_insert("")
 
#define QOF_MOD_UTIL   "qof.utilities"
 
#define stpcpy   g_stpcpy
 

Functions

void qof_string_cache_init (void)
 
void qof_string_cache_destroy (void)
 
void qof_string_cache_remove (gconstpointer key)
 
gpointer qof_string_cache_insert (gconstpointer key)
 
void g_hash_table_foreach_sorted (GHashTable *hash_table, GHFunc func, gpointer user_data, GCompareFunc compare_func)
 
gboolean qof_utf8_substr_nocase (const gchar *haystack, const gchar *needle)
 
gint safe_strcasecmp (const gchar *da, const gchar *db)
 
gint null_strcmp (const gchar *da, const gchar *db)
 
gchar * ultostr (gulong val, gint base)
 
gboolean gnc_strisnum (const gchar *s)
 
gboolean qof_begin_edit (QofInstance *inst)
 
gboolean qof_commit_edit (QofInstance *inst)
 
gboolean qof_commit_edit_part2 (QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
 

typedef enum as string macros

#define ENUM_BODY(name, value)   name value,
 
#define AS_STRING_CASE(name, value)   case name: { return #name; }
 
#define FROM_STRING_CASE(name, value)
 
#define DEFINE_ENUM(name, list)
 
#define AS_STRING_DEC(name, list)   const gchar* name##asString(name n);
 
#define AS_STRING_FUNC(name, list)
 
#define FROM_STRING_DEC(name, list)
 
#define FROM_STRING_FUNC(name, list)
 

enum as string with no typedef

Similar but used when the enum is NOT a typedef Make sure you use the DEFINE_ENUM_NON_TYPEDEF macro.

You can precede the FROM_STRING_FUNC_NON_TYPEDEF and AS_STRING_FUNC_NON_TYPEDEF macros with the keyword static if appropriate.

ENUM_BODY is used in both types.

#define DEFINE_ENUM_NON_TYPEDEF(name, list)
 
#define FROM_STRING_DEC_NON_TYPEDEF(name, list)
 
#define FROM_STRING_CASE_NON_TYPEDEF(name, value)   if (strcmp(str, #name) == 0) { *type = name; }
 
#define FROM_STRING_FUNC_NON_TYPEDEF(name, list)
 
#define AS_STRING_DEC_NON_TYPEDEF(name, list)   const gchar* name##asString(enum name n);
 
#define AS_STRING_FUNC_NON_TYPEDEF(name, list)
 
#define AS_STRING_CASE_NON_TYPEDEF(name, value)   case name: { return #name; }
 

Convenience wrappers

void qof_init (void)
 Initialise the Query Object Framework. More...
 
void qof_close (void)
 Safely close down the Query Object Framework. More...
 

Detailed Description

Macro Definition Documentation

#define AS_STRING_FUNC (   name,
  list 
)
Value:
const gchar* name##asString(name n) { \
switch (n) { \
list(AS_STRING_CASE) \
default: return ""; } }

Definition at line 87 of file qofutil.h.

#define AS_STRING_FUNC_NON_TYPEDEF (   name,
  list 
)
Value:
const gchar* name##asString(enum name n) { \
switch (n) { \
list(AS_STRING_CASE_NON_TYPEDEF) \
default: return ""; } }

Definition at line 140 of file qofutil.h.

#define CACHE_REPLACE (   dst,
  src 
)
Value:
do { \
gpointer tmp = CACHE_INSERT((src)); \
CACHE_REMOVE((dst)); \
(dst) = tmp; \
} while (0)

Definition at line 99 of file qof-string-cache.h.

#define DEFINE_ENUM (   name,
  list 
)
Value:
typedef enum { \
list(ENUM_BODY) \
}name;

Definition at line 79 of file qofutil.h.

#define DEFINE_ENUM_NON_TYPEDEF (   name,
  list 
)
Value:
enum name { \
list(ENUM_BODY) \
};

Definition at line 119 of file qofutil.h.

#define FROM_STRING_CASE (   name,
  value 
)
Value:
if (strcmp(str, #name) == 0) { \
return name; }

Definition at line 75 of file qofutil.h.

#define FROM_STRING_DEC (   name,
  list 
)
Value:
name name##fromString \
(const gchar* str);

Definition at line 93 of file qofutil.h.

#define FROM_STRING_DEC_NON_TYPEDEF (   name,
  list 
)
Value:
void name##fromString \
(const gchar* str, enum name *type);

Definition at line 124 of file qofutil.h.

#define FROM_STRING_FUNC (   name,
  list 
)
Value:
name name##fromString \
(const gchar* str) { \
if(str == NULL) { return 0; } \
list(FROM_STRING_CASE) \
return 0; }

Definition at line 97 of file qofutil.h.

#define FROM_STRING_FUNC_NON_TYPEDEF (   name,
  list 
)
Value:
void name##fromString \
(const gchar* str, enum name *type) { \
if(str == NULL) { return; } \
list(FROM_STRING_CASE_NON_TYPEDEF) }

Definition at line 131 of file qofutil.h.

#define QOF_MOD_UTIL   "qof.utilities"

Do not use these for printf, only scanf

Definition at line 64 of file qofutil.h.

Function Documentation

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 the GCompareFunc applied to the keys. The function is passed the key and value of each pair, and the given user_data parameter.

gboolean gnc_strisnum ( const gchar *  s)

Returns true if string s is a number, possibly surrounded by whitespace.

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 null. This routine assumes that a null string is equal to the empty string.

gboolean qof_begin_edit ( QofInstance inst)

begin_edit

Parameters
instan instance of QofInstance

The caller should use this macro first and then perform any other operations.

void qof_close ( void  )

Safely close down the Query Object Framework.

Use in place of separate close / shutdown functions (like qof_query_shutdown(), etc.) to protect against future changes.

gboolean qof_commit_edit ( QofInstance inst)

commit_edit helpers

The caller should call PART1 as the first thing, then perform any local operations prior to calling the backend. Then call PART2. part1 – deal with the editlevel

Parameters
instan instance of QofInstance
gboolean qof_commit_edit_part2 ( QofInstance inst,
void(*)(QofInstance *, QofBackendError on_error,
void(*)(QofInstance *)  on_done,
void(*)(QofInstance *)  on_free 
)

part2 – deal with the backend

Parameters
instan instance of QofInstance
on_errora function called if there is a backend error. void (*on_error)(inst, QofBackendError)
on_donea function called after the commit is completed successfully for an object which remained valid. void (*on_done)(inst)
on_freea function called if the commit succeeded and the instance is to be freed. void (*on_free)(inst)

Note that only one callback will be called (or zero, if that callback is NULL). In particular, 'on_done' will not be called for an object which is to be freed.

Returns TRUE, if the commit succeeded, FALSE otherwise.

void qof_init ( void  )

Initialise the Query Object Framework.

Use in place of separate init functions (like qof_query_init(), etc.) to protect against future changes.

void qof_string_cache_destroy ( void  )

Destroy the qof_string_cache

void qof_string_cache_init ( void  )

The QOF String Cache:

Many strings used throughout QOF and QOF applications are likely to be duplicated.

QOF provides a reference counted cache system for the strings, which shares strings whenever possible.

Use qof_string_cache_insert to insert a string into the cache (it will return a pointer to the cached string). Basically you should use this instead of g_strdup.

Use qof_string_cache_remove (giving it a pointer to a cached string) if the string is unused. If this is the last reference to the string it will be removed from the cache, otherwise it will just decrement the reference count. Basically you should use this instead of g_free.

Just in case it's not clear: The remove function must NOT be called for the string you passed INTO the insert function. It must be called for the cached string that is returned by the insert function.

Note that all the work is done when inserting or removing. Once cached the strings are just plain C strings.

The string cache is demand-created on first use.Initialize the string cache

gpointer qof_string_cache_insert ( gconstpointer  key)

You can use this function with g_hash_table_insert(), for the key (or value), as long as you use the destroy notifier above.

void qof_string_cache_remove ( gconstpointer  key)

You can use this function as a destroy notifier for a GHashTable that uses common strings as keys (or values, for that matter.)

gboolean qof_utf8_substr_nocase ( const gchar *  haystack,
const gchar *  needle 
)

Search for an occurence of the substring needle in the string haystack, ignoring case. Return TRUE if one is found or FALSE otherwise.

gint safe_strcasecmp ( const gchar *  da,
const gchar *  db 
)

case sensitive comparison of strings da and db - either may be NULL. A non-NULL string is greater than a NULL string.

Parameters
dastring 1.
dbstring 2.
Returns
If da == NULL && db != NULL, returns -1. If da != NULL && db == NULL, returns +1. If da != NULL && db != NULL, returns the result of strcmp(da, db). If da == NULL && db == NULL, returns 0.
gchar* ultostr ( gulong  val,
gint  base 
)

The ultostr() subroutine is the inverse of strtoul(). It accepts a number and prints it in the indicated base. The returned string should be g_freed when done.