dynamic_cast
operator. Nevertheless the "double dispatching" technique requires that the RTTI is more precise than just a downcast that succeeds or fails.SFType::printInheritanceTree();
This tree is dynamic meaning that its form depends on the execution and contains only the types that are in used.
Inherited type and name can be accessed:
X3DTK::SFAbstractNode N; // Gets the name of the type X3DTK::SFString name = N->getType()->getName(); // Gets the parent of the type X3DTK::SFType *type = N->getType()->getParent(); // Gets the children of the type X3DTK::MFType mtype = N->getType()->getChildren();
You access to the component and the scene graph of a X3DTK::SFType by:
X3DTK::SFAbstractNode N; // Gets the component of the type X3DTK::SFComponent *com = N->getType()->getComponent(); // Gets the component of the type X3DTK::SFSceneGraph *sg = com->getSceneGraph();
These informations are not really useful but are necessary to the working of the "double dispatching" technique.
// creating a new node SFAbstractNode N = new X3DTK::X3D::Box(); // cloning the node SFAbstractNode C = N->clone();
Usually, node creation is not explicit, but is made by an abstract factory X3DTK::X3D::Creator that creates a node from its name, and is called by an X3DTK::X3DLoader, or by a processor that converts a scene graph to another one.
You can delete the node by calling explictly the delete operator, but it suppresses only the node and not its children. For that use the generic processor called X3DTK::MemReleaser that ensures you to delete all the sub-tree, except for shared nodes that are not deleted.
X3DTK::SFAbstractNode N = new X3D::Group(); // Gets the name of the type X3DTK::SFString name = N->getTypeName(); // Gets the component name of the type X3DTK::SFString com = N->getComponentName(); // Gets the scene graph name of the type X3DTK::SFString sg = N->getSceneGraphName();
// new nodes SFAbstractNode S = new X3D::Shape(); SFAbstractNode B1 = new X3D::Box(); SFAbstractNode B2 = new X3D::Box(); // sets the child B1 S->setChild(B1); // cannot add the child B2, because there is already one of type X3DGeometryNode! S->addChild(B2); // Removes B1 and adds B2 S->removeChild(B1); S->addChild(B2);
When a node is cloned and has children, they are not cloned but shared, nevertheless the clone has no father.
// new nodes SFAbstractNode G = new X3D::Group(); SFAbstractNode S = new X3D::Shape(); SFAbstractNode B = new X3D::Box(); // adding children G->addChild(S); S->addChild(B); // cloning S SFAbstractNode C = S->clone(); // B is now a shared child by S and C, but C has no father.
Let's see how to delete a sub-tree where nodes are shared, and let's take the former nodes.
#include <X3DTK/memreleaser.h> // Getting the instance of MemReleaser X3DTK::MemReleaser *releaser = X3DTK::X3DProcessor::getInstanceOf<X3DTK::MemReleaser>(); // releases C, but not B because B is shared by S releaser->release(C); // releases S and B because B is not shared releaser->release(S);