Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I solved a similar problem using the wxWidgets tree control. I used a singleton reference counter to track the objects I was putting in the control, and an iterator to traverse them. Here's an example.</p> <pre><code>class ReferenceCounter { public: // Singleton pattern. Implementation left up to you. static ReferenceCounter&amp; get(); void add(const TreeData&amp; data) { mCounter[data.getId()].push_back(&amp;data); } void remove(const TreeData&amp; data) { const CounterType::const_iterator itr = mCounter.find(data.getId()); if (itr != mCounter.end()) { ItemType&amp; items = itr-&gt;second; items.erase(std::remove(items.begin(), items.end(), &amp;data), items.end()); if (items.empty()) { mCounter.erase(itr); } } } typedef std::vector&lt;TreeData*&gt; ItemType; ItemType::iterator begin(const TreeData&amp; data) { const CounterType::const_iterator itr = mCounter.find(data.getId()); if (itr != mCounter.end()) { return itr-&gt;second.begin(); } // Else condition handling left up to you. } ItemType::iterator end(const TreeData&amp; data) { const CounterType::const_iterator itr = mCounter.find(data.getId()); if (itr != mCounter.end()) { return itr-&gt;second.end(); } // Else condition handling left up to you. } private: typedef std::map&lt;int, ItemType&gt; CounterType; CounterType mCounter; }; class TreeData { public: TreeData() { ReferenceCounter::get().add(*this); } ~TreeData() { ReferenceCounter::get().remove(*this); } // Get database rows or whatever your tree is tracking. int getId() const; }; </code></pre> <p>So given any TreeData, you can look up all the other TreeData's with matching ids in the reference counter. This makes it easy and fast keeping names and stuff up to date. Our tree handles over 1,000,000 nodes without a problem. In my implementation, I wrapped the iteration stuff up in a <code>boost::iterator_facade</code> class for easier use.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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