Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should think about how often you need to do the following:</p> <ul> <li>traverse the tree</li> <li>add/remove elements from the tree</li> <li>how many objects do you need to keep track of</li> </ul> <p>Which is more frequent will help determine the optimum solution</p> <p>Perhaps instead of make a complex tree, just have a list of all types and add a pointer to the object for each type it is derived from. Something like this:</p> <pre><code>map&lt;string,set&lt;componenet *&gt;&gt; myTypeList </code></pre> <p>Then for an object that is of type component::renderable::sprite</p> <pre><code>myTypeList["component"].insert(&amp;object); myTypeList["renderable"].insert(&amp;object); myTypeList["sprite"].insert(&amp;object); </code></pre> <p>By registering each obejct in multiple lists, it then becomes easy to do something to all object of a given type and subtypes</p> <pre><code>for_each(myTypeList["renderable"].begin(),myTypeList["renderable"].end(),renderFunc); </code></pre> <p>Note that std::set and my std::map construct may not be the optimum choice, depending on how you will use it.</p> <p>Or perhaps a hybrid approach storing only the class heirarchy in the tree</p> <pre><code>map&lt;string, set&lt;string&gt; &gt; myTypeList; map&lt;string, set&lt;component *&gt; myObjectList; myTypeList["component"].insert("component"); myTypeList["component"].insert("renderable"); myTypeList["component"].insert("sprite"); myTypeList["renderable"].insert("renderable"); myTypeList["renderable"].insert("sprite"); myTypeList["sprite"].insert("sprite"); // this isn't quite right, but you get the idea struct doForList { UnaryFunction f; doForList(UnaryFunction f): func(f) {}; operator ()(string typename) { for_each(myTypeList[typename].begin();myTypeList[typename].end(), func); } } for_each(myTypeList["renderable"].begin(),myTypeList["renderable"].end(), doForList(myFunc)) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload