Boost logo

Geometry :

Subject: [ggl] spacial index construction interface
From: Adam Wulkiewicz (adam.wulkiewicz)
Date: 2011-03-07 16:50:13


> Just brainstorming, maybe virtual methods are unavoidable. Still think
> in a tree with a fixed amount of levels, its behaviour could be fixed so
> not virtual. But don't know if that is the best solution.

Another thought. There is always root node which is internal node so we
may store is_leaf condition outside the node. All methods starts with
root and traverse tree depending on node type anyway.

class node
{
   node_ptr parent;
};

class internal_node : node
{
   std::vector< boost::tuple<Box, bool, node_ptr> > m_nodes;

   void add_leaf(node_ptr n)
   {
     m_nodes.push_back(boost::tuple<...>(Box(...), true, n));
   }

   void add_internal_node(node_ptr n)
   {
     m_nodes.push_back(boost::tuple<...>(Box(...), false, n));
   }

   void some_method() {}
};

class leaf : node
{
   std::vector<Value> m_values;

   void some_leaf_method() {}
};

class rtree
{
   void do_something(internal_node n)
   {
     BOOST_FOREACH(boost::tuple<...> t, n->nodes())
     {
       if ( get<1>(t) )
         static_cast<leaf*>(get<2>(t))->some_leaf_method();
       else
       {
         static_cast<internal_node*>(get<2>(t))->some_method();
         do_something(static_cast<internal_node*>(get<2>(t)));
       }
     }
   }
};

Regards,
Adam


Geometry list run by mateusz at loskot.net