QOF
0.7.5
|
Files | |
file | qofutil.h |
QOF utility functions. | |
Macros | |
#define | QOF_SCANF_LLD "%qd" |
#define | QOF_MOD_UTIL "qof-utilities" |
#define | stpcpy g_stpcpy |
omitted if stpcpy exists. | |
#define | CACHE_INSERT(str) qof_util_string_cache_insert((gconstpointer)(str)) |
#define | CACHE_REMOVE(str) qof_util_string_cache_remove((str)) |
#define | CACHE_REPLACE(dst, src) |
#define | QOF_CACHE_NEW(void) qof_util_string_cache_insert("") |
Functions | |
gint | safe_strcmp (const gchar *da, const gchar *db) |
gint | safe_strcasecmp (const gchar *da, const gchar *db) |
gint | null_strcmp (const gchar *da, const gchar *db) |
gchar * | strncasestr (const guchar *str1, const guchar *str2, size_t len) |
gchar * | strcasestr (const gchar *str1, const gchar *str2) |
gchar * | ultostr (gulong val, gint base) |
gboolean | qof_util_string_isnum (const guchar *s) |
gint | qof_util_double_compare (gdouble v1, gdouble v2) |
Compare two gdouble values. | |
const gchar * | qof_util_whitespace_filter (const gchar *val) |
gint | qof_util_bool_to_int (const gchar *val) |
gchar * | qof_util_param_to_string (QofEntity *ent, const QofParam *param) |
Converts a parameter to a string for storage or display. More... | |
gboolean | qof_util_param_set_string (QofEntity *ent, const QofParam *param, const gchar *value_string) |
Set a parameter from a value string. More... | |
gchar * | qof_util_make_utf8 (gchar *string) |
Convert strings received from the wrapped objects into UTF-8. More... | |
void | qof_util_string_cache_destroy (void) |
void | qof_util_string_cache_remove (gconstpointer key) |
gpointer | qof_util_string_cache_insert (gconstpointer key) |
gboolean | qof_util_param_edit (QofInstance *inst, const QofParam *param) |
Prepare to edit a parameter. More... | |
gboolean | qof_util_param_commit (QofInstance *inst, const QofParam *param) |
Commit this parameter change, with undo support. More... | |
Convenience wrappers | |
void | qof_init (void) |
Initialise the Query Object Framework. More... | |
void | qof_close (void) |
Safely close down the Query Object Framework. More... | |
#define AS_STRING_FUNC | ( | name, | |
list | |||
) |
#define AS_STRING_FUNC_NON_TYPEDEF | ( | name, | |
list | |||
) |
#define CACHE_REPLACE | ( | dst, | |
src | |||
) |
#define DEFINE_ENUM | ( | name, | |
list | |||
) |
#define DEFINE_ENUM_NON_TYPEDEF | ( | name, | |
list | |||
) |
#define FROM_STRING_CASE | ( | name, | |
value | |||
) |
#define FROM_STRING_DEC | ( | name, | |
list | |||
) |
#define FROM_STRING_DEC_NON_TYPEDEF | ( | name, | |
list | |||
) |
#define FROM_STRING_FUNC | ( | name, | |
list | |||
) |
#define FROM_STRING_FUNC_NON_TYPEDEF | ( | name, | |
list | |||
) |
#define QOF_SCANF_LLD "%qd" |
|
inline |
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.
void qof_close | ( | void | ) |
Safely close down the Query Object Framework.
Use in place of separate close / shutdown functions (like guid_shutdown(), qof_query_shutdown() etc.) to protect against future changes.
Definition at line 844 of file qofutil.c.
void qof_init | ( | void | ) |
Initialise the Query Object Framework.
Use in place of separate init functions (like guid_init() and qof_query_init() etc.) to protect against future changes.
Definition at line 833 of file qofutil.c.
gint qof_util_bool_to_int | ( | const gchar * | val | ) |
gchar* qof_util_make_utf8 | ( | gchar * | string | ) |
Convert strings received from the wrapped objects into UTF-8.
A wrapper for g_locale_to_utf8 that removes the extra arguments. If the string is already valid UTF-8, it is returned unchanged.
Definition at line 330 of file qofutil.c.
gboolean qof_util_param_commit | ( | QofInstance * | inst, |
const QofParam * | param | ||
) |
Commit this parameter change, with undo support.
Calls the commit() routine of the backend to commit an edit. If an undo operation has been started, also maintains the undo record so the change can be undone.
param_name can only be NULL if the QofSQLite backend is not in use.
inst | The QofInstance. |
param | The parameter being modified. |
Definition at line 306 of file qofutil.c.
gboolean qof_util_param_edit | ( | QofInstance * | inst, |
const QofParam * | param | ||
) |
Prepare to edit a parameter.
Calls the begin() routine of the backend to prepare for an edit. If an undo operation has been started, also prepares an undo record.
param_name can only be NULL if the QofSQLite backend is not in use.
Making parameter changes using qof_util_param_edit and qof_util_param_commit makes for simpler QofUndo code because the undo handlers are called implicitly.
qof_book_start_operation (book, "edit PARAM_X"); param = qof_class_get_parameter(OBJ_TYPE, PARAM_NAME); retbool = qof_util_param_edit (inst, param); if (retbool) param->param_setfcn(ent, value); retbool = qof_util_param_commit (inst, param);
inst | The QofInstance. |
param | The parameter being modified. |
Definition at line 278 of file qofutil.c.
gboolean qof_util_param_set_string | ( | QofEntity * | ent, |
const QofParam * | param, | ||
const gchar * | value_string | ||
) |
Set a parameter from a value string.
Used by string-based backends to set a value from a string previously written out to storage.
The string must be the same format as produced by qof_util_param_to_string for the same parameter type.
ent | The entity in which the value is to be set. |
param | The parameter that stores the value. |
value_string | A string of exactly the same format as produced by qof_util_param_to_string for the parameter type. |
e.g. a numeric type would require a string like 50/100 and a time type would require a UTC date stamp like 1907-10-07T03:34:29Z
< secondary collections are used for one-to-many references between entities and are implemented using QofCollection. These are NOT the same as the main collections in the QofBook. -# Each QofCollection contains one or many entities - all of a single type. -# The entity type within the collection can be determined at run time. -# Easy conversions to GList or whatever in the param_setfcn handler. -# Each parameter can have its own collection. -# Each entity can have a different type of collection to its siblings, provided that it is acceptable to the set function. -# Each object decides which types are acceptable for which parameter in the set functions. This is then part of the API for that object. QOF_TYPE_COLLECT has two functions, both related to one-to-many links: - Represent a reference between 2 entities with a list of acceptable types. (one object linked to many types of single entities) - Represent a reference between one entity and many entities of another type. (one object linked to many entities of a single type.) If the set function can handle it, it could also be used for true one-to-many links: one object linked to many entities of many types. n.b. Always subject to each collection holding only one type at runtime. (otherwise use books).
Definition at line 644 of file qofutil.c.
Converts a parameter to a string for storage or display.
The returned string must be freed by the caller.
Use qof_util_param_set_string to set the parameter using the string. Designed for backends that store all values as strings.
< secondary collections are used for one-to-many references between entities and are implemented using QofCollection. These are NOT the same as the main collections in the QofBook. -# Each QofCollection contains one or many entities - all of a single type. -# The entity type within the collection can be determined at run time. -# Easy conversions to GList or whatever in the param_setfcn handler. -# Each parameter can have its own collection. -# Each entity can have a different type of collection to its siblings, provided that it is acceptable to the set function. -# Each object decides which types are acceptable for which parameter in the set functions. This is then part of the API for that object. QOF_TYPE_COLLECT has two functions, both related to one-to-many links: - Represent a reference between 2 entities with a list of acceptable types. (one object linked to many types of single entities) - Represent a reference between one entity and many entities of another type. (one object linked to many entities of a single type.) If the set function can handle it, it could also be used for true one-to-many links: one object linked to many entities of many types. n.b. Always subject to each collection holding only one type at runtime. (otherwise use books).
Definition at line 447 of file qofutil.c.
void qof_util_string_cache_destroy | ( | 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_util_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_util_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.Destroy the qof_util_string_cache
gpointer qof_util_string_cache_insert | ( | gconstpointer | key | ) |
void qof_util_string_cache_remove | ( | gconstpointer | key | ) |
gboolean qof_util_string_isnum | ( | const guchar * | s | ) |
const gchar* qof_util_whitespace_filter | ( | const gchar * | val | ) |
Return NULL if the field is whitespace (blank, tab, formfeed etc.) Else return pointer to first non-whitespace character.
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.
da | string 1. |
db | string 2. |
gint safe_strcmp | ( | const gchar * | da, |
const gchar * | db | ||
) |
The safe_strcmp compares strings da and db the same way that strcmp() does, except that either may be null. This routine assumes that a non-null string is always greater than a null string.
da | string 1. |
db | string 2. |
gchar* strncasestr | ( | const guchar * | str1, |
const guchar * | str2, | ||
size_t | len | ||
) |
Search for str2 in first nchar chars of str1, ignore case. Return pointer to first match, or null. These are just like that strnstr and the strstr functions, except that they ignore the case.