summaryrefslogtreecommitdiff
path: root/src/core/impllist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/impllist.c')
-rw-r--r--src/core/impllist.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/core/impllist.c b/src/core/impllist.c
new file mode 100644
index 0000000..522c3f7
--- /dev/null
+++ b/src/core/impllist.c
@@ -0,0 +1,108 @@
+/*
+ * 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>
+
+/**
+ * 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)
+{
+ struct dom_implementation_list_item *i, *j;
+
+ if (--list->refcnt == 0) {
+ /* Destroy all list entries */
+ for (i = list->head; i; i = j) {
+ j = i->next;
+
+ /* Unreference the implementation */
+ dom_implementation_unref(i->impl);
+
+ /* And free the entry */
+ list->alloc(i, 0, list->pw);
+ }
+
+ /* Free the list object */
+ list->alloc(list, 0, list->pw);
+ }
+}
+
+/**
+ * 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;
+}