node<> is a generic, templated class that can be used to represent nodes in and the n-ary trees themselves. Data is associated with nodes, also they can be indexed by keys.
Included are various algorithms for traversal (shallow, deep, top-down, bottom-up …) and finding similar to xpath (e.g. findByPath(“scene/nodes/scenenode/entity”)) and others.
Yes. It's a self-contained set of a few files.
The license is (for the sake of simplicity) currently the same as for YAKE: LGPL, even though the LGPL isn't really ideal for template code.
If you need the code under a different license or have suggestions please send an E-Mail to info AT yake.org or use the contact form on http://www.yake.org.
Files for client use:
Optional files for client use:
Files for internal use:
Yes. Use this feature with care. Also the read the section about callbacks/notifications.
node<> can optionally provide callbacks and notifications for certain events (like “child node added”). You can subscribe to them either via signals (using boost::signals and boost::bind) or via listeners or via inheritance and notification methods.
All the three options can be configured seperately.
Have a look at node.h for more details on all the possible options. For example, you can also select the policy for default implementation of notification methods.
In node_xml.h you can select the XML parsing provider for the XML DOM wrapper.
#include <tree/node.h> #include <tree/node_xml.h> #include <tree/node_xml_algorithm.h> using namespace tree; XmlDom doc; doc.replace("data/test.scene.xml"); // You can replace the currently loaded data: doc.replace("data/anotherWorld.scene.xml"); // Dump the tree to the console (or any other stream, if you want to): doc.print( std::cout ); // Explicitely clear the DOM: doc.clear();
<scene> <nodes> <scenenode id="1"> <position x="1" y="1" z="0" /> </scenenode> <scenenode id="2"> <position x="100" y="0" z="0" /> </scenenode> </nodes> </scene>
XmlNode* foundNode = find_path(doc.getDocumentNode(), "scene/nodes/scenenode/position"); // "foundNode" now points to the XML DOM node for the "scenenode" tag with id "1". std::cout << *foundNode; // dump to console if you want :)
double x = foundNode->value().getAttributeAs<double>("x");
// In case the node and/or attribute cannot be found we let x default to 0.0. double x = getXmlAttributeByPathAs<double>( doc.getDocumentNode(), "scene/nodes/scenenode/position/x", 0.0 ); // x is now 1. as the first "scenenode" found has been used. See below for filtering options.
… to select a different than the first scenenode:
// Let's select the scene node whose "id" attribute is "2": double x = getXmlAttributeByPathAs<double>( doc.getDocumentNode(), "scene/nodes/scenenode|id=2/position/x", 0.0 ); // x is now 100.