{ 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>
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.
Files | |
| file | qofchoice.h |
| Linking one entity to other entities of many possible types. | |
| gboolean | qof_object_is_choice (QofIdTypeConst type) |
| Does this object contain a choice parameter? | |
| gboolean | qof_choice_create (char *type) |
| Set an object as using QOF_TYPE_CHOICE. | |
| gboolean | qof_choice_add_class (const char *choice, char *add, char *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 (const char *choice_obj, const char *param_name, const char *choice) |
| Is the choice valid for this param_name? | |
| #define | QOF_TYPE_CHOICE "choice" |
| Identify an object as containing a choice. | |
Defines | |
| #define | QOF_MOD_CHOICE "qof.choice" |
| gboolean qof_choice_add_class | ( | const char * | choice, | |
| char * | add, | |||
| char * | 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 70 of file qofchoice.c.
00073 { 00074 GHashTable *param_table; 00075 GList *option_list; 00076 00077 option_list = NULL; 00078 param_table = NULL; 00079 g_return_val_if_fail(select != NULL, FALSE); 00080 g_return_val_if_fail(qof_object_is_choice(select), FALSE); 00081 param_table = (GHashTable*)g_hash_table_lookup(qof_choice_table, select); 00082 g_return_val_if_fail(param_table, FALSE); 00083 option_list = (GList*)g_hash_table_lookup(param_table, param_name); 00084 option_list = g_list_append(option_list, option); 00085 g_hash_table_insert(param_table, param_name, option_list); 00086 return TRUE; 00087 }
| gboolean qof_choice_check | ( | const char * | choice_obj, | |
| const char * | param_name, | |||
| const char * | 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 102 of file qofchoice.c.
00105 { 00106 GList *choices, *result; 00107 GHashTable *param_table; 00108 00109 choices = result = NULL; 00110 g_return_val_if_fail(qof_object_is_choice(choice_obj), FALSE); 00111 param_table = g_hash_table_lookup(qof_choice_table, choice_obj); 00112 choices = g_hash_table_lookup(param_table, param_name); 00113 result = g_list_find(choices, choice); 00114 if(!result) { return FALSE; } 00115 return TRUE; 00116 }
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 89 of file qofchoice.c.
00090 { 00091 GList *choices; 00092 GHashTable *param_table; 00093 00094 g_return_val_if_fail(type != NULL, NULL); 00095 g_return_val_if_fail(qof_choice_is_initialized() == TRUE, FALSE); 00096 choices = NULL; 00097 param_table = g_hash_table_lookup(qof_choice_table, type); 00098 choices = g_hash_table_lookup(param_table, param->param_name); 00099 return choices; 00100 }
| gboolean qof_object_is_choice | ( | QofIdTypeConst | 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 44 of file qofchoice.c.
00045 { 00046 gpointer value, check; 00047 00048 value = NULL; 00049 check = NULL; 00050 if(!qof_choice_is_initialized()) { return FALSE; } 00051 g_return_val_if_fail(type != NULL, FALSE); 00052 value = g_hash_table_lookup(qof_choice_table, type); 00053 if((GHashTable*)value) { return TRUE; } 00054 DEBUG (" QOF_TYPE_CHOICE setup failed for %s\n", type); 00055 return FALSE; 00056 }
1.5.2