blob: 2f25926baab9bf77cc44bf7863605f35f5690e32 (
plain)
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
|
/*
* This file is part of libdom.
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
*/
#include <dom/bootstrap/implpriv.h>
#include <dom/core/implementation.h>
#include <dom/core/impllist.h>
extern void dom_implementation_list_destroy(
struct dom_implementation_list *list);
/**
* Claim a reference on a DOM implementation list
*
* \param list The list to claim a reference on
*/
void dom_implementation_list_ref(struct dom_implementation_list *list)
{
list->refcnt++;
}
/**
* Release a reference from a DOM implementation list
*
* \param list The list to release the reference from
*
* If the reference count reaches zero, any memory claimed by the
* list will be released
*/
void dom_implementation_list_unref(struct dom_implementation_list *list)
{
if (--list->refcnt == 0) {
dom_implementation_list_destroy(list);
}
}
/**
* Retrieve the length of a DOM implementation list
*
* \param list The list to retrieve the length of
* \param length Pointer to location to receive result
* \return DOM_NO_ERR.
*/
dom_exception dom_implementation_list_get_length(
struct dom_implementation_list *list, unsigned long *length)
{
unsigned long count = 0;
struct dom_implementation_list_item *i;
for (i = list->head; i; i = i->next)
count++;
*length = count;
return DOM_NO_ERR;
}
/**
* Retrieve an item by index from a DOM implementation list
*
* \param list The list to retrieve the item from
* \param index The list index to retrieve
* \param impl Pointer to location to receive result
* \return DOM_NO_ERR.
*
* ::index is a zero-based index into ::list.
* ::index lies in the range [0, length-1]
*
* The returned implementation will have had its reference count increased.
* The client should unref the implementation once it has finished with it.
*/
dom_exception dom_implementation_list_item(
struct dom_implementation_list *list, unsigned long index,
struct dom_implementation **impl)
{
unsigned long idx = 0;
struct dom_implementation_list_item *i;
for (i = list->head; i; i = i->next) {
if (idx == index)
break;
idx++;
}
if (i == NULL) {
*impl = NULL;
} else {
dom_implementation_ref(i->impl);
*impl = i->impl;
}
return DOM_NO_ERR;
}
|