Difference between revisions of "DOM guide: Working with elements"

From COLLADA Public Wiki
Jump to: navigation, search
 
(Element Types: just editing)
Line 1: Line 1:
 
daeElement is the base class for all of the COLLADA Object Model classes. The daeElement class uses the Reflective Object System (ROS) to provide considerable functionality without the need to use the generated subclass.
 
daeElement is the base class for all of the COLLADA Object Model classes. The daeElement class uses the Reflective Object System (ROS) to provide considerable functionality without the need to use the generated subclass.
  
==Element Types==
+
==Determining an Element's Type==
There are three different approaches to finding which type of element a daeElement is.
+
There are three approaches to determining the type of a '''daeElement''':
  
The easiest is with the daeElement::getElementType method which returns an enumerated value respresenting the type of the element. The values returned by this function can be found in the dom/domTypes.h header.
+
* Using the '''daeElement::getElementType''' method, which returns an enumerated value respresenting the element's type. The values returned by this function are in the '''dom/domTypes.h''' header. This is the easiest approach.
  
The daeElement::getTypeName method returns a daeString of the type name. You can compare this string with the constant strings defined in dom/domConstants.h to check for type.
+
*Using the '''daeElement::getTypeName''' method, which returns a '''daeString''' containing the type name. You can compare this string with the constant strings defined in '''dom/domConstants.h''' to determine the type.
  
The last way is by comparing _meta. The _meta is a pointer to a daeMetaElement which is the class that contains all of the ROS information for an element type. By doing a pointer comparison on daeElement::getMeta and the generated class's static dom*::_Meta it is possible to find the element type. This is the approach that the daeSafeCast method uses to ensure type safety.
+
*By comparing '''_meta'''. The '''_meta''' is a pointer to a '''daeMetaElement''', which is the class that contains all of the ROS information for an element type. By doing a pointer comparison on '''daeElement::getMeta''' and the generated class's static '''dom*::_Meta''', it is possible to find the element type. This is the approach that the '''daeSafeCast''' method uses to ensure type safety.
  
The daeSafeCast and daeElement::getElementType are rather new additions to the COLLADA DOM. When looking at older source code using the DOM expect to see the older methods used frequently for type checking.
+
'''''NOTE:''' The '''daeSafeCast''' and '''daeElement::getElementType''' approaches are newer additions to the COLLADA DOM. When looking at older source code using the DOM, expect to see the older methods used frequently for type checking.''
  
 
==Accessing Element Data==
 
==Accessing Element Data==

Revision as of 17:54, 23 March 2007

daeElement is the base class for all of the COLLADA Object Model classes. The daeElement class uses the Reflective Object System (ROS) to provide considerable functionality without the need to use the generated subclass.

Determining an Element's Type

There are three approaches to determining the type of a daeElement:

  • Using the daeElement::getElementType method, which returns an enumerated value respresenting the element's type. The values returned by this function are in the dom/domTypes.h header. This is the easiest approach.
  • Using the daeElement::getTypeName method, which returns a daeString containing the type name. You can compare this string with the constant strings defined in dom/domConstants.h to determine the type.
  • By comparing _meta. The _meta is a pointer to a daeMetaElement, which is the class that contains all of the ROS information for an element type. By doing a pointer comparison on daeElement::getMeta and the generated class's static dom*::_Meta, it is possible to find the element type. This is the approach that the daeSafeCast method uses to ensure type safety.

NOTE: The daeSafeCast and daeElement::getElementType approaches are newer additions to the COLLADA DOM. When looking at older source code using the DOM, expect to see the older methods used frequently for type checking.

Accessing Element Data

The easier way to access element data is to cast the daeElement to it's strongly typed subclass. At times, it may not be possible to do the cast or it is more convenient not to cast. The daeElement class provides methods to access and manipulate the data directly for such a situation.

Navigating the Object Model

daeElement provides access to the document it belongs to with the getDocument method. The getDocumentURI method is a helper method is all you need is the name of the document that the element belongs to.

daeElement::getParentElement returns the parent element which allows you to traverse up the tree to the root. If daeElement::getParentElement returns NULL the element is the root of the tree. If the element belongs to a document then it is safe to assume the element is a domCOLLADA element.

daeElement::getChildren populates an array with the children of an element. This allows you to iterate over all of the children of an element and traverse down the element hierarchy. This array will be ordered the same as it would be if the element were written out to a COLLADA instance Document. This array will be the same as the _contents array, if an element's type has a _contents array.

Accessing Attributes