QOF: qofchoice.c Source File

QOF 0.7.5

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

qofchoice.c
1 /***************************************************************************
2 * qofchoice.c
3 *
4 * Thu Jul 7 12:24:30 2005
5 * Copyright 2005 Neil Williams
6 * linux@codehelp.co.uk
7 ****************************************************************************/
8 /*
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23
24 #include "config.h"
25 #include <glib.h>
26 #include "qof.h"
27 #include "qofchoice.h"
28
29 static QofLogModule log_module = QOF_MOD_CHOICE;
30 static GHashTable *qof_choice_table = NULL;
31
32 /* To initialise, call qof_choice_add_class in
33 qof_object_register for the choice object. */
34 static gboolean
35 qof_choice_is_initialized (void)
36 {
37 if (!qof_choice_table)
38 qof_choice_table = g_hash_table_new (g_str_hash, g_str_equal);
39 if (!qof_choice_table)
40 return FALSE;
41 return TRUE;
42 }
43
44 gboolean
45 qof_object_is_choice (QofIdType type)
46 {
47 gpointer value, check;
48
49 value = NULL;
50 check = NULL;
51 if (!qof_choice_is_initialized ())
52 return FALSE;
53 g_return_val_if_fail (type != NULL, FALSE);
54 value = g_hash_table_lookup (qof_choice_table, type);
55 if ((GHashTable *) value)
56 return TRUE;
57 return FALSE;
58 }
59
60 gboolean
61 qof_choice_create (gchar *type)
62 {
63 GHashTable *param_table;
64
65 g_return_val_if_fail (type != NULL, FALSE);
66 g_return_val_if_fail (qof_choice_is_initialized () == TRUE, FALSE);
67 ENTER (" ");
68 param_table = g_hash_table_new (g_str_hash, g_str_equal);
69 g_hash_table_insert (qof_choice_table, type, param_table);
70 LEAVE (" ");
71 return TRUE;
72 }
73
74 gboolean
75 qof_choice_add_class (gchar *select, gchar *option, gchar *param_name)
76 {
77 GHashTable *param_table;
78 GList *option_list;
79
80 option_list = NULL;
81 param_table = NULL;
82 g_return_val_if_fail (select != NULL, FALSE);
83 g_return_val_if_fail (qof_object_is_choice (select), FALSE);
84 param_table =
85 (GHashTable *) g_hash_table_lookup (qof_choice_table, select);
86 g_return_val_if_fail (param_table, FALSE);
87 option_list = (GList *) g_hash_table_lookup (param_table, param_name);
88 option_list = g_list_append (option_list, option);
89 g_hash_table_insert (param_table, param_name, option_list);
90 return TRUE;
91 }
92
93 GList *
94 qof_object_get_choices (QofIdType type, QofParam * param)
95 {
96 GList *choices;
97 GHashTable *param_table;
98
99 g_return_val_if_fail (type != NULL, NULL);
100 g_return_val_if_fail (qof_choice_is_initialized () == TRUE, FALSE);
101 choices = NULL;
102 param_table = g_hash_table_lookup (qof_choice_table, type);
103 choices = g_hash_table_lookup (param_table, param->param_name);
104 return choices;
105 }
106
107 gboolean
108 qof_choice_check (gchar *choice_obj, gchar *param_name, gchar *choice)
109 {
110 GList *choices, *result;
111 GHashTable *param_table;
112
113 choices = result = NULL;
114 g_return_val_if_fail (qof_object_is_choice (choice_obj), FALSE);
115 param_table = g_hash_table_lookup (qof_choice_table, choice_obj);
116 choices = g_hash_table_lookup (param_table, param_name);
117 result = g_list_find (choices, choice);
118 if (!result)
119 return FALSE;
120 return TRUE;
121 }
QofIdType
const gchar * QofIdType
Definition: qofid.h:81
_QofParam
Definition: qofclass.h:195
qof_choice_create
gboolean qof_choice_create(gchar *type)
Set an object as using QOF_TYPE_CHOICE.
Definition: qofchoice.c:61
LEAVE
#define LEAVE(format, args...)
Definition: qoflog.h:227
qof_object_get_choices
GList * qof_object_get_choices(QofIdType type, QofParam *param)
Return the list of all object types usable with this parameter.
Definition: qofchoice.c:94
qofchoice.h
Linking one entity to other entities of many possible types.
qof_object_is_choice
gboolean qof_object_is_choice(QofIdType type)
Does this object contain a choice parameter?
Definition: qofchoice.c:45
qof_choice_add_class
gboolean qof_choice_add_class(gchar *select, gchar *option, gchar *param_name)
Add the choices for this parameter to the object.
Definition: qofchoice.c:75
qof_choice_check
gboolean qof_choice_check(gchar *choice_obj, gchar *param_name, gchar *choice)
Is the choice valid for this param_name?
Definition: qofchoice.c:108
ENTER
#define ENTER(format, args...)
Definition: qoflog.h:217
QofLogModule
const gchar * QofLogModule
Definition: qofid.h:85