From 54447d4b63e18cc6a43182d3b52c79f548772261 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 12 Jul 2007 23:45:43 +0000 Subject: Make NamedNodeMap more generic svn path=/trunk/dom/; revision=3404 --- src/core/document.c | 11 ++++++----- src/core/document.h | 4 ++-- src/core/namednodemap.c | 34 +++++++++++++++++----------------- src/core/namednodemap.h | 14 +++----------- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/core/document.c b/src/core/document.c index 102153c..7f2aee8 100644 --- a/src/core/document.c +++ b/src/core/document.c @@ -9,6 +9,7 @@ #include #include "core/document.h" +#include "core/namednodemap.h" #include "core/node.h" #include "core/nodelist.h" #include "utils/utils.h" @@ -866,8 +867,8 @@ void dom_document_remove_nodelist(struct dom_document *doc, * Get a namednodemap, creating one if necessary * * \param doc The document to get a namednodemap for - * \param root Node containing items in map - * \param type The type of map + * \param head Start of list containing items in map + * \param type The type of items in map * \param map Pointer to location to receive map * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion. * @@ -876,14 +877,14 @@ void dom_document_remove_nodelist(struct dom_document *doc, * finished with it. */ dom_exception dom_document_get_namednodemap(struct dom_document *doc, - struct dom_node *root, dom_namednodemap_type type, + struct dom_node *head, dom_node_type type, struct dom_namednodemap **map) { struct dom_doc_nnm *m; dom_exception err; for (m = doc->maps; m; m = m->next) { - if (dom_namednodemap_match(m->map, root, type)) + if (dom_namednodemap_match(m->map, head, type)) break; } @@ -899,7 +900,7 @@ dom_exception dom_document_get_namednodemap(struct dom_document *doc, return DOM_NO_MEM_ERR; /* Create namednodemap */ - err = dom_namednodemap_create(doc, root, type, &m->map); + err = dom_namednodemap_create(doc, head, type, &m->map); if (err != DOM_NO_ERR) { doc->alloc(m, 0, doc->pw); return err; diff --git a/src/core/document.h b/src/core/document.h index 236ab4a..7238456 100644 --- a/src/core/document.h +++ b/src/core/document.h @@ -11,7 +11,7 @@ #include #include -#include "core/namednodemap.h" +#include struct dom_document; struct dom_namednodemap; @@ -36,7 +36,7 @@ void dom_document_remove_nodelist(struct dom_document *doc, /* Get a namednodemap, creating one if necessary */ dom_exception dom_document_get_namednodemap(struct dom_document *doc, - struct dom_node *root, dom_namednodemap_type type, + struct dom_node *head, dom_node_type type, struct dom_namednodemap **map); /* Remove a namednodemap */ void dom_document_remove_namednodemap(struct dom_document *doc, diff --git a/src/core/namednodemap.c b/src/core/namednodemap.c index b13dee6..239dd6f 100644 --- a/src/core/namednodemap.c +++ b/src/core/namednodemap.c @@ -18,9 +18,9 @@ struct dom_namednodemap { struct dom_document *owner; /**< Owning document */ - struct dom_node *root; /**< Node containing items in map */ + struct dom_node *head; /**< Start of item list */ - dom_namednodemap_type type; /**< Type of map */ + dom_node_type type; /**< Type of items in map */ uint32_t refcnt; /**< Reference count */ }; @@ -29,24 +29,24 @@ struct dom_namednodemap { * Create a namednodemap * * \param doc The owning document - * \param root Node containing items in map - * \param type The type of map + * \param head Start of list containing items in map + * \param type The type of items in the map * \param map Pointer to location to receive created map * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion * - * ::root must be a node owned by ::doc and must be either an Element or + * ::head must be a node owned by ::doc and must be either an Element or * DocumentType node. * - * If ::root is of type Element, ::type must be DOM_NAMEDNODEMAP_ATTRIBUTES - * If ::root is of type DocumentType, ::type may be either - * DOM_NAMEDNODEMAP_ENTITIES or DOM_NAMEDNODEMAP_NOTATIONS. + * If ::head is of type Element, ::type must be DOM_ATTRIBUTE_NODE + * If ::head is of type DocumentType, ::type may be either + * DOM_ENTITY_NODE or DOM_NOTATION_NODE. * * The returned map will already be referenced, so the client need not * explicitly reference it. The client must unref the map once it is * finished with it. */ dom_exception dom_namednodemap_create(struct dom_document *doc, - struct dom_node *root, dom_namednodemap_type type, + struct dom_node *head, dom_node_type type, struct dom_namednodemap **map) { struct dom_namednodemap *m; @@ -58,8 +58,8 @@ dom_exception dom_namednodemap_create(struct dom_document *doc, dom_node_ref((struct dom_node *) doc); m->owner = doc; - dom_node_ref(root); - m->root = root; + dom_node_ref(head); + m->head = head; m->type = type; @@ -93,7 +93,7 @@ void dom_namednodemap_unref(struct dom_namednodemap *map) if (--map->refcnt == 0) { struct dom_node *owner = (struct dom_node *) map->owner; - dom_node_unref(map->root); + dom_node_unref(map->head); /* Remove map from document */ dom_document_remove_namednodemap(map->owner, map); @@ -330,15 +330,15 @@ dom_exception dom_namednodemap_remove_named_item_ns( /** * Match a namednodemap instance against a set of creation parameters * - * \param map The map to match - * \param root Node containing items in map - * \param type The type of map + * \param map The map to match + * \param head Start of list containing items in map + * \param type The type of items in the map * \return true if list matches, false otherwise */ bool dom_namednodemap_match(struct dom_namednodemap *map, - struct dom_node *root, dom_namednodemap_type type) + struct dom_node *head, dom_node_type type) { - if (map->root == root && map->type == type) + if (map->head == head && map->type == type) return true; return false; diff --git a/src/core/namednodemap.h b/src/core/namednodemap.h index 1cd2b0c..a2705e4 100644 --- a/src/core/namednodemap.h +++ b/src/core/namednodemap.h @@ -11,29 +11,21 @@ #include #include +#include struct dom_document; struct dom_node; struct dom_namednodemap; struct dom_string; -/** - * Type of a named node map - */ -typedef enum { - DOM_NAMEDNODEMAP_ATTRIBUTES, - DOM_NAMEDNODEMAP_ENTITIES, - DOM_NAMEDNODEMAP_NOTATIONS -} dom_namednodemap_type; - /* Create a namednodemap */ dom_exception dom_namednodemap_create(struct dom_document *doc, - struct dom_node *root, dom_namednodemap_type type, + struct dom_node *head, dom_node_type type, struct dom_namednodemap **map); /* Match a namednodemap instance against a set of creation parameters */ bool dom_namednodemap_match(struct dom_namednodemap *map, - struct dom_node *root, dom_namednodemap_type type); + struct dom_node *head, dom_node_type type); #endif -- cgit v1.2.3