forked from AravisProject/aravis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharvdomnodechildlist.c
137 lines (107 loc) · 3.53 KB
/
arvdomnodechildlist.c
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
/* Aravis - Digital camera library
*
* Copyright © 2009-2022 Emmanuel Pacaud
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Author:
* Emmanuel Pacaud <[email protected]>
*/
#include <arvdomnodechildlist.h>
#include <arvdomnode.h>
#include <arvdomnodelist.h>
/**
* SECTION:arvdomnodechildlist
* @short_description: Class for DOM node child lists
*/
/* ArvDomNodeChildList */
struct _ArvDomNodeChildList {
ArvDomNodeList base;
ArvDomNode *parent_node;
};
struct _ArvDomNodeChildListClass {
ArvDomNodeListClass parent_class;
};
G_DEFINE_TYPE (ArvDomNodeChildList, arv_dom_node_child_list, ARV_TYPE_DOM_NODE_LIST)
static void
arv_dom_node_child_list_weak_notify_cb (void *user_data, GObject *object)
{
ArvDomNodeChildList *list = user_data;
list->parent_node = NULL;
}
static ArvDomNode *
arv_dom_node_child_list_get_item (ArvDomNodeList *list, unsigned int index)
{
ArvDomNodeChildList *child_list = ARV_DOM_NODE_CHILD_LIST (list);
ArvDomNode *iter;
unsigned int i = 0;
if (child_list->parent_node == NULL)
return NULL;
for (iter = arv_dom_node_get_first_child (child_list->parent_node);
iter != NULL; iter = arv_dom_node_get_next_sibling (iter)) {
if (i == index)
return iter;
i++;
}
return NULL;
}
static unsigned int
arv_dom_node_child_list_get_length (ArvDomNodeList *list)
{
ArvDomNodeChildList *child_list = ARV_DOM_NODE_CHILD_LIST (list);
ArvDomNode *iter;
unsigned int length = 0;
if (child_list->parent_node == NULL)
return 0;
for (iter = arv_dom_node_get_first_child (child_list->parent_node);
iter != NULL;
iter = arv_dom_node_get_next_sibling (iter))
length++;
return length;
}
ArvDomNodeList *
arv_dom_node_child_list_new (ArvDomNode *parent_node)
{
ArvDomNodeChildList *list;
g_return_val_if_fail (ARV_IS_DOM_NODE (parent_node), NULL);
list = g_object_new (ARV_TYPE_DOM_NODE_CHILD_LIST, NULL);
list->parent_node = parent_node;
g_object_weak_ref (G_OBJECT (parent_node), arv_dom_node_child_list_weak_notify_cb, list);
return ARV_DOM_NODE_LIST (list);
}
static void
arv_dom_node_child_list_init (ArvDomNodeChildList *list)
{
}
static void
arv_dom_node_child_list_finalize (GObject *object)
{
ArvDomNodeChildList *list = ARV_DOM_NODE_CHILD_LIST (object);
if (list->parent_node != NULL) {
g_object_weak_unref (G_OBJECT (list->parent_node), arv_dom_node_child_list_weak_notify_cb, list);
list->parent_node = NULL;
}
G_OBJECT_CLASS (arv_dom_node_child_list_parent_class)->finalize (object);
}
static void
arv_dom_node_child_list_class_init (ArvDomNodeChildListClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
ArvDomNodeListClass *node_list_class = ARV_DOM_NODE_LIST_CLASS (klass);
object_class->finalize = arv_dom_node_child_list_finalize;
node_list_class->get_item = arv_dom_node_child_list_get_item;
node_list_class->get_length = arv_dom_node_child_list_get_length;
}