QOF
0.7.5
|
Files | |
file | qofchoice.h |
Linking one entity to other entities of many possible types. | |
Defines | |
#define | QOF_MOD_CHOICE "qof-choice" |
gboolean | qof_object_is_choice (QofIdType type) |
Does this object contain a choice parameter? | |
gboolean | qof_choice_create (gchar *type) |
Set an object as using QOF_TYPE_CHOICE. | |
gboolean | qof_choice_add_class (gchar *choice, gchar *add, gchar *param_name) |
Add the choices for this parameter to the object. | |
GList * | qof_object_get_choices (QofIdType type, QofParam *param) |
Return the list of all object types usable with this parameter. | |
gboolean | qof_choice_check (gchar *choice_obj, gchar *param_name, gchar *choice) |
Is the choice valid for this param_name? | |
#define | QOF_TYPE_CHOICE "choice" |
Identify an object as containing a choice. |
Objects can be linked together one-to-one by simply using the name of the related object as the parameter type in the QofClass parameter list.
{ FOO_PARAM, BAR_ID, (QofAccessFunc)qofFooGetBar, (QofSetterFunc)qofFooSetBar },
This is limited as each FOO entity can contain only one reference to a single BAR entity per parameter. Also, this parameter cannot be used to link to a similar object, OBJ. This requires "one to many" links.
There are two types of one-to-many links in QOF.
Currently, there is no explicit way to support many-to-many links but existing methods can be combined to give approximately the same results.
A QOF_TYPE_CHOICE object is like a C++ template. QOF_TYPE_CHOICE doesn't really exist by itself:
QOF_TYPE_CHOICE<QOF_X, QOF_Y, QOF_Z>
It holds a single entity of type X, Y, or Z for the purposes of QOF or ::QSF. For querying the object it queries as if it's an X, Y, or Z.
Each choice type has it's own definition of the allowable objects - each of which need to be registered as normal. Objects can declare themselves to be one option of a particular choice. There is no requirement for any object to be either a choice or an option for a choice object.
#define QOF_TYPE_CHOICE "choice" |
gboolean qof_choice_add_class | ( | gchar * | choice, |
gchar * | add, | ||
gchar * | param_name | ||
) |
Add the choices for this parameter to the object.
choice | The choice object. |
add | The object to be added as an option. |
param_name | The parameter that will be used to get or set options. |
Definition at line 75 of file qofchoice.c.
{ GHashTable *param_table; GList *option_list; option_list = NULL; param_table = NULL; g_return_val_if_fail (select != NULL, FALSE); g_return_val_if_fail (qof_object_is_choice (select), FALSE); param_table = (GHashTable *) g_hash_table_lookup (qof_choice_table, select); g_return_val_if_fail (param_table, FALSE); option_list = (GList *) g_hash_table_lookup (param_table, param_name); option_list = g_list_append (option_list, option); g_hash_table_insert (param_table, param_name, option_list); return TRUE; }
gboolean qof_choice_check | ( | gchar * | choice_obj, |
gchar * | param_name, | ||
gchar * | choice | ||
) |
Is the choice valid for this param_name?
choice_obj | The object containing the QOF_TYPE_CHOICE parameter. |
param_name | The name of a QOF_TYPE_CHOICE parameter in this object. |
choice | The QofIdType to look for in the list of choices. |
Definition at line 108 of file qofchoice.c.
{ GList *choices, *result; GHashTable *param_table; choices = result = NULL; g_return_val_if_fail (qof_object_is_choice (choice_obj), FALSE); param_table = g_hash_table_lookup (qof_choice_table, choice_obj); choices = g_hash_table_lookup (param_table, param_name); result = g_list_find (choices, choice); if (!result) return FALSE; return TRUE; }
GList* qof_object_get_choices | ( | QofIdType | type, |
QofParam * | param | ||
) |
Return the list of all object types usable with this parameter.
type | The choice object type. |
param | The name of the parameter that will be used to get or set options. |
Definition at line 94 of file qofchoice.c.
{
GList *choices;
GHashTable *param_table;
g_return_val_if_fail (type != NULL, NULL);
g_return_val_if_fail (qof_choice_is_initialized () == TRUE, FALSE);
choices = NULL;
param_table = g_hash_table_lookup (qof_choice_table, type);
choices = g_hash_table_lookup (param_table, param->param_name);
return choices;
}
gboolean qof_object_is_choice | ( | QofIdType | type | ) |
Does this object contain a choice parameter?
Returns TRUE if any parameter in the object definition uses a choice of elements, whether or not those parameters contain any data.
type | Type of object/entity. |
Definition at line 45 of file qofchoice.c.
{ gpointer value, check; value = NULL; check = NULL; if (!qof_choice_is_initialized ()) return FALSE; g_return_val_if_fail (type != NULL, FALSE); value = g_hash_table_lookup (qof_choice_table, type); if ((GHashTable *) value) return TRUE; return FALSE; }