Casting from a class to its child?



Hi.

I'm making a DOM implementation, here; http://gybe.sf.net/dominigue/,
and have trouble to test the implementations.
But this is not about DOM-specific issue. :-)

Interface Element is child of another interface Node.
And dominigue implements such interfaces with GObject.
So Node inherit GObject, and Element inherit the Node.

Another interface NodeList is a list of Node (and children of Node).
And just return Node, not any children type of Node.

This is the problem;

I've tried to test getElementsByTagName() method of Element.
Build a Document from HTML file, and get a NodeList.
With NodeList::item(), a Node returned.

The Node is also Element. Every tag of HTML document is Element.
But GObject system don't know that.
When I cast the Node to Element by DOM_ELEMENT(node),
a warning from GObject system scroll up;

GLib-GObject-WARNING **: invalid cast from `domNode' to `domElement'

BTW, there's no other way to get anonymous Element from DOM.
Getting Element from DOM is done by 1) create newly or 2) get by id.
NodeList is the only way to go.

When I use just a danger cast of elem = (domElement *)node;,
DOM_IS_ELEMENT(elem) return FALSE
and SIGSEGV raised with Element-related code.

How can I break through this problem?


Thanks for reading this long text, :)
Kang Jeong-Hee.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]