Relation between DOM implementation and NTree implementation

The DOM implementation is based on a Tree class backend called NTree.
Currently, the storage of DOM nodes is done in NTree Node.
Each DOM node has a pointer on its NTree's node.

Every tree-specific method in DOM's Node interface use its counterpart NTree node's method.

So, the memory representation is like:

NTree side DOM Tree side
Root node
 
 
First child item
 
First grand child item
Second child item
<—>
<—>
<—>
<—>
DOM::Document
DOM::Element (HEAD)
DOM::Element (TITLE)
DOM::Element (BODY)

Node allocation

Because of runtime switchable allocators, the tree must allow node deletion by undefined function.

NTree does support using a compile-time/template based Deleter it will call when it doesn't need a node anymore.

This Deleter is currently implemented by calling virtual DOM::Node::returnToAllocator method.

Every DOM's type (Node, Element, Document, Attribute, etc...) implement correct node returning to the allocator.

It's DOM's node responsibility to return any data it has acquired.
However, it's NTree's node responsibility to delete all children's node.

Because of the multiple creation method, it's very easy to get confused which deletion method to call.

Let's take some usage example:
  1. You create a node using DOM methods like createDocument, createElement, etc...
    You then have to link your DOM nodes with DOM::Node methods like appendChild or insertBefore.
       In that case, you'd use DOM::Node::Suicide method on the root node to delete the whole tree
  2. You want to remove a Node, so you call DOM::Node::removeChild method
       In that case, you'd use DOM::Node::Suicide method on the returned DOM::Node to delete this node only
  3. You want to replace a Node, so you call DOM::Node::replaceChild method
       In that case, you'd use DOM::Node::Suicide method on the returned DOM::Node (if any) to delete this node only
  4. You want to set an attribute of an DOM::Element node, so you call DOM::Element::setAttributeNode method.
       In that case, you'd use DOM::Node::Suicide method on the returned DOM::Attr (if any) to delete this attribute

Usually, as long as you use the same allocator for every DOM::Node, you shouldn't get any difficulties creating and/or deleting Node, provided you remember calling DOM::Node::Suicide method on unreachable node before you loose track of the Node.

You shouldn't deal with NTree's nodes and methods directly, as everything has been abstracted by the DOM interface.




(C) An X-Ryl669 project 2007

This document describes Unlimited Zooming Interface source code. UZI stands for Unlimited Zooming Interface, and source code license is