1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/* GdaXql: the xml query object
* Copyright (C) 2000-2002 The GNOME Foundation.
*
* AUTHORS:
* Gerhard Dieringer <gdieringer@compuserve.com>
* Cleber Rodrigues <cleber@gnome-db.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "gda-xql-stack.h"
#include "gda-xql-utils.h"
static void
destroy_object_list(GSList *list);
struct _GdaXqlStackPrivate {
GSList *list;
};
static void gda_xql_stack_init (GdaXqlStack *xqlstack);
static void gda_xql_stack_class_init (GdaXqlStackClass *klass);
static GObjectClass *parent_class = NULL;
GType
gda_xql_stack_get_type (void)
{
static GType type = 0;
if (type == 0) {
static const GTypeInfo info = {
sizeof (GdaXqlStackClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gda_xql_stack_class_init,
(GClassFinalizeFunc) NULL,
NULL /* class_data */,
sizeof (GdaXqlStack),
0 /* n_preallocs */,
(GInstanceInitFunc) gda_xql_stack_init,
};
type = g_type_register_static (G_TYPE_OBJECT, "GdaXqlStack", &info, 0);
}
return type;
}
static void
gda_xql_stack_finalize(GObject *object)
{
GdaXqlStack *xqlstack;
xqlstack = GDA_XQL_STACK (object);
if(G_OBJECT_CLASS(parent_class)->finalize) \
(* G_OBJECT_CLASS(parent_class)->finalize)(object);
if(xqlstack->priv->list) {
destroy_object_list (xqlstack->priv->list);
xqlstack->priv->list = NULL;
}
g_free (xqlstack->priv);
}
static void
gda_xql_stack_init (GdaXqlStack *xqlstack)
{
xqlstack->priv = g_new0 (GdaXqlStackPrivate, 1);
xqlstack->priv->list = NULL;
}
static void
gda_xql_stack_class_init (GdaXqlStackClass *klass)
{
GObjectClass *g_object_class;
g_object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
g_object_class->finalize = gda_xql_stack_finalize;
}
GdaXqlStack *
gda_xql_stack_new (void)
{
return g_object_new (GDA_TYPE_XQL_STACK, NULL);
}
void
gda_xql_stack_push (GdaXqlStack *xqlstack, GdaXqlItem *item)
{
g_return_if_fail (xqlstack != NULL);
g_return_if_fail (GDA_IS_XQL_STACK (xqlstack));
g_return_if_fail (item != NULL);
g_return_if_fail (GDA_IS_XQL_ITEM (item));
g_object_ref (G_OBJECT (item));
xqlstack->priv->list = g_slist_prepend (xqlstack->priv->list, item);
}
GdaXqlItem *
gda_xql_stack_pop (GdaXqlStack * xqlstack)
{
GSList *list;
GdaXqlItem *item;
g_return_val_if_fail (xqlstack != NULL, NULL);
g_return_val_if_fail (GDA_IS_XQL_STACK (xqlstack), NULL);
list = xqlstack->priv->list;
g_return_val_if_fail (list != NULL, NULL);
item = list->data;
g_object_unref (G_OBJECT(item));
xqlstack->priv->list = list->next;
g_slist_free_1(list);
return item;
}
gboolean
gda_xql_stack_empty (GdaXqlStack * xqlstack)
{
g_return_val_if_fail (xqlstack != NULL, FALSE);
g_return_val_if_fail (GDA_IS_XQL_STACK (xqlstack), FALSE);
return (xqlstack->priv->list == NULL) ? TRUE : FALSE;
}
static void
destroy_object_list(GSList *list)
{
g_slist_foreach(list, (GFunc) g_object_unref, NULL);
g_slist_free (list);
}
|