Cyclic relationship with templated container

I have these objects which each have a unique location within a
hypothetical space, and index them via a spatial tree (like an R-tree,
I think). The tree is implemented as a template that takes the
contained object as a template parameter, so I have
space::Tree<MyObjectType>. You can look up an object within this space
via it's coordinates, or (for instance) enumerate all objects within a
given distance of a point and so on.

Now, I've ended up with MyObjectType containing a (weak) pointer to
space::Tree<MyObjectType>::Node, which seems like a violation of the
principle of avoiding cyclic object relationships. On the other hand,
the alternative leads to redundant information storage, since the
object's coordinates are currently available from the Tree's node that
contains it. Also, if I access a node via another pathway and want
some information about the local neighbourhood (this does happen), I
would have to look up the node from the tree's root anyway.

Note that the Tree *template* doesn't depend on MyObjectType, since it
is completely generic, but the particular instance does. The physical
relationship between the header files only goes in one direction
(MyObjectType.hh requires Tree.hh). Does anyone have any comments or
prior experience (good or bad) with this kind of cyclical structure?

Raoul Gough
"Let there be one measure for wine throughout our kingdom, and one
measure for ale, and one measure for corn" - Magna Carta

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
6/29/2003 10:18:56 PM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

0 Replies

Similar Articles

[PageSpeed] 59