diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2007-07-12 21:24:08 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2007-07-12 21:24:08 +0000 |
commit | 0448f3de0bc3e9aa71bd095e87fd1cc2584e0a99 (patch) | |
tree | 9ad95bcba5e6f988763835f24b40e773551f53f6 /src/core/impllist.c | |
parent | 92311b20c73b13766fb93c123c67e5045356ff49 (diff) | |
download | libdom-0448f3de0bc3e9aa71bd095e87fd1cc2584e0a99.tar.gz libdom-0448f3de0bc3e9aa71bd095e87fd1cc2584e0a99.tar.bz2 |
Add DOMImplementation, DOMImplementationList
Add DOMImplementationRegistry
Define DOMImplementationSource and provide API to allow their registration
This little lot should permit some kind of sensible DOM bootstrapping.
svn path=/trunk/dom/; revision=3403
Diffstat (limited to 'src/core/impllist.c')
-rw-r--r-- | src/core/impllist.c | 108 |
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; +} |