Gnash  0.8.11dev
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
gnash::XMLNode_as Class Reference

A node in an XML tree. More...

#include <XMLNode_as.h>

Inheritance diagram for gnash::XMLNode_as:
gnash::Relay gnash::XML_as

Public Types

enum  NodeType {
  Element = 1, Attribute = 2, Text = 3, Cdata = 4,
  EntityRef = 5, Entity = 6, ProcInstr = 7, Comment = 8,
  Document = 9, DocType = 10, DocFragment = 11, Notation = 12
}
 
typedef std::list< XMLNode_as * > Children
 

Public Member Functions

 XMLNode_as (Global_as &gl)
 
virtual ~XMLNode_as ()
 
size_t length () const
 
const std::string & nodeName () const
 
const std::string & nodeValue () const
 
NodeType nodeType () const
 Get the type of an XML Node. More...
 
void nodeTypeSet (NodeType type)
 Set the type of an XML Node. More...
 
void nodeNameSet (const std::string &name)
 Set name of this node. More...
 
bool extractPrefix (std::string &prefix) const
 
void nodeValueSet (const std::string &value)
 Set value of this node. More...
 
void getNamespaceForPrefix (const std::string &prefix, std::string &ns) const
 Performs a recursive search of node attributes to find a match. More...
 
bool getPrefixForNamespace (const std::string &ns, std::string &prefix) const
 Performs a recursive search of node attributes to find a match. More...
 
void setNamespaceURI (const std::string &value)
 
const std::string & getNamespaceURI () const
 
bool descendsFrom (XMLNode_as *node) const
 Returns true if 'this' descends from the specified node. More...
 
bool hasChildNodes () const
 
XMLNode_asfirstChild () const
 
XMLNode_aslastChild () const
 
as_objectchildNodes ()
 
XMLNode_aspreviousSibling () const
 
XMLNode_asnextSibling () const
 
XMLNode_ascloneNode (bool deep) const
 Copy a node. More...
 
void appendChild (XMLNode_as *node)
 Append a child node to this XML object. More...
 
void removeChild (XMLNode_as *node)
 Remove a child node from this XML object. More...
 
XMLNode_asgetParent () const
 Get the parent XMLNode_as of this node. Can be 0. More...
 
void insertBefore (XMLNode_as *newnode, XMLNode_as *pos)
 Insert a node before a node. More...
 
virtual void toString (std::ostream &str, bool encode=false) const
 Convert the XMLNode to a string. More...
 
as_objectgetAttributes () const
 Return the attributes object associated with this node. More...
 
void setAttribute (const std::string &name, const std::string &value)
 Set a named attribute to a value. More...
 
void setObject (as_object *o)
 Associate an as_object with this XMLNode_as. More...
 
as_objectobject ()
 Return the object associated with this XMLNode_as. More...
 
- Public Member Functions inherited from gnash::Relay
virtual ~Relay ()=0
 
virtual void clean ()
 Handle any cleanup necessary before the Relay is destroyed. More...
 

Protected Member Functions

virtual void setReachable ()
 Mark reachable elements. More...
 
void clearChildren ()
 Clear all children, making sure unreferenced children are deleted. More...
 

Protected Attributes

Global_as_global
 

Detailed Description

A node in an XML tree.

This class has various complications to reduce memory usage when parsing very large XML documents. 1. It is a Relay class that can be attached to an as_object.

  1. It does not have to have an associated object. This is only created once the XMLNode is accessed in ActionScript.
  2. The top node of an XML tree is always accessible in ActionScript, either as an XML_as or a user-created XMLNode_as.
  3. XMLNodes consequently mark their children as reachable, but not their parent.
  4. When an XMLNode is destroyed, any children without an associated object are also deleted. Children with an associated object will be destroyed when the GC destroys the object.

Member Typedef Documentation

§ Children

Member Enumeration Documentation

§ NodeType

Enumerator
Element 
Attribute 
Text 
Cdata 
EntityRef 
Entity 
ProcInstr 
Comment 
Document 
DocType 
DocFragment 
Notation 

Constructor & Destructor Documentation

§ XMLNode_as()

gnash::XMLNode_as::XMLNode_as ( Global_as gl)

§ ~XMLNode_as()

gnash::XMLNode_as::~XMLNode_as ( )
virtual

References clearChildren().

Member Function Documentation

§ appendChild()

void gnash::XMLNode_as::appendChild ( XMLNode_as node)

Append a child node to this XML object.

The child node's parent is set to this object, the node is added to this object's children. The childNodes array will be updated if it exists.

Parameters
nodeThe node to add as a child

Referenced by gnash::XML_as::toString(), and gnash::xmlnode_class_init().

§ childNodes()

as_object * gnash::XMLNode_as::childNodes ( )

§ clearChildren()

void gnash::XMLNode_as::clearChildren ( )
protected

Clear all children, making sure unreferenced children are deleted.

AS-referenced child nodes will no longer be marked as reachable, so the GC will remove them on the next run.

References _global, gnash::callMethod(), Element, gnash::escapeXML(), gnash::log_debug(), nodeName(), nodeType(), nodeValue(), gnash::NSV::PROP_ESCAPE, Text, gnash::as_value::to_string(), and toString().

Referenced by gnash::XML_as::parseXML(), and ~XMLNode_as().

§ cloneNode()

XMLNode_as * gnash::XMLNode_as::cloneNode ( bool  deep) const

Copy a node.

Method; constructs and returns a new XML node of the same type, name, value, and attributes as the specified XML object. If deep is set to true, all child nodes are recursively cloned, resulting in an exact copy of the original object's document tree.

References XMLNode_as().

Referenced by gnash::xmlnode_class_init().

§ descendsFrom()

bool gnash::XMLNode_as::descendsFrom ( XMLNode_as node) const

Returns true if 'this' descends from the specified node.

References descendsFrom(), and getParent().

Referenced by descendsFrom(), getNamespaceURI(), and gnash::xmlnode_class_init().

§ extractPrefix()

bool gnash::XMLNode_as::extractPrefix ( std::string &  prefix) const

§ firstChild()

XMLNode_as * gnash::XMLNode_as::firstChild ( ) const

§ getAttributes()

as_object* gnash::XMLNode_as::getAttributes ( ) const
inline

Return the attributes object associated with this node.

References name, and setAttribute().

Referenced by gnash::xmlnode_class_init().

§ getNamespaceForPrefix()

void gnash::XMLNode_as::getNamespaceForPrefix ( const std::string &  prefix,
std::string &  ns 
) const

Performs a recursive search of node attributes to find a match.

References gnash::key::_1, and getParent().

Referenced by nodeValueSet(), and gnash::xmlnode_class_init().

§ getNamespaceURI()

const std::string& gnash::XMLNode_as::getNamespaceURI ( ) const
inline

§ getParent()

XMLNode_as* gnash::XMLNode_as::getParent ( ) const
inline

§ getPrefixForNamespace()

bool gnash::XMLNode_as::getPrefixForNamespace ( const std::string &  ns,
std::string &  prefix 
) const

Performs a recursive search of node attributes to find a match.

Returns
false if no match found.

References gnash::key::_1, getParent(), and name.

Referenced by nodeValueSet(), and gnash::xmlnode_class_init().

§ hasChildNodes()

bool gnash::XMLNode_as::hasChildNodes ( ) const

Returns true if the specified node has child nodes; otherwise, returns false.

Referenced by getNamespaceURI(), and gnash::xmlnode_class_init().

§ insertBefore()

void gnash::XMLNode_as::insertBefore ( XMLNode_as newnode,
XMLNode_as pos 
)

Insert a node before a node.

Method; inserts a new child node into the XML object's child list, before the beforeNode node. If the beforeNode parameter is undefined or null, the node is added using the appendChild() method. If beforeNode is not a child of my_xml, the insertion fails.

Parameters
newnodeThe node to insert, moving from its current tree
posThe node before which to insert the new one. Must be a child of this XMLNode or the operation will fail.

References _, getParent(), IF_VERBOSE_ASCODING_ERRORS, gnash::log_aserror(), and removeChild().

Referenced by getParent(), and gnash::xmlnode_class_init().

§ lastChild()

XMLNode_as * gnash::XMLNode_as::lastChild ( ) const

§ length()

size_t gnash::XMLNode_as::length ( ) const
inline

§ nextSibling()

XMLNode_as * gnash::XMLNode_as::nextSibling ( ) const

§ nodeName()

const std::string& gnash::XMLNode_as::nodeName ( ) const
inline

§ nodeNameSet()

void gnash::XMLNode_as::nodeNameSet ( const std::string &  name)
inline

Set name of this node.

References extractPrefix(), and name.

Referenced by gnash::registerXMLNative(), gnash::XML_as::toString(), and gnash::xmlnode_class_init().

§ nodeType()

NodeType gnash::XMLNode_as::nodeType ( ) const
inline

Get the type of an XML Node.

Referenced by clearChildren(), and gnash::xmlnode_class_init().

§ nodeTypeSet()

void gnash::XMLNode_as::nodeTypeSet ( NodeType  type)
inline

Set the type of an XML Node.

Referenced by gnash::registerXMLNative(), and gnash::XML_as::toString().

§ nodeValue()

const std::string& gnash::XMLNode_as::nodeValue ( ) const
inline

§ nodeValueSet()

void gnash::XMLNode_as::nodeValueSet ( const std::string &  value)
inline

§ object()

as_object * gnash::XMLNode_as::object ( )

§ previousSibling()

XMLNode_as * gnash::XMLNode_as::previousSibling ( ) const

§ removeChild()

void gnash::XMLNode_as::removeChild ( XMLNode_as node)

Remove a child node from this XML object.

The child node's parent is set to 0, the node is removed from this object's children. The childNodes array will be updated if it exists.

Parameters
nodeThe node to remove.

Referenced by insertBefore(), and gnash::xmlnode_class_init().

§ setAttribute()

void gnash::XMLNode_as::setAttribute ( const std::string &  name,
const std::string &  value 
)

Set a named attribute to a value.

Parameters
nameThe name of the attribute to set. If already present, the value is changed. If not present, the attribute is added.
valueThe value to set the named attribute to.

References _global, gnash::getURI(), gnash::getVM(), and gnash::as_object::set_member().

Referenced by getAttributes(), and gnash::XML_as::toString().

§ setNamespaceURI()

void gnash::XMLNode_as::setNamespaceURI ( const std::string &  value)
inline

Referenced by gnash::XML_as::toString().

§ setObject()

void gnash::XMLNode_as::setObject ( as_object o)
inline

Associate an as_object with this XMLNode_as.

An XMLNode_as with an associated object is regarded as being owned by that object, so make sure it is! Using as_object::setRelay will achieve that.

References gnash::key::o, object(), and setReachable().

Referenced by object(), and gnash::XML_as::XML_as().

§ setReachable()

void gnash::XMLNode_as::setReachable ( )
protectedvirtual

Mark reachable elements.

These are: children, attributes object, associated as_object.

Reimplemented from gnash::Relay.

References gnash::renderer::opengl::for_each(), and gnash::GcResource::setReachable().

Referenced by setObject().

§ toString()

void gnash::XMLNode_as::toString ( std::ostream &  str,
bool  encode = false 
) const
virtual

Convert the XMLNode to a string.

Parameters
oThe ostream to write the string to.
encodeWhether to URL encode the node values. This is false by default, as it is only necessary for XML.sendAndLoad.

Reimplemented in gnash::XML_as.

Referenced by clearChildren(), getParent(), and gnash::xmlnode_class_init().

Member Data Documentation

§ _global

Global_as& gnash::XMLNode_as::_global
protected

The documentation for this class was generated from the following files: