C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cyclic relationship with templated container

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Raoul Gough
Guest





PostPosted: Sun Jun 29, 2003 10:18 pm    Post subject: Cyclic relationship with templated container Reply with quote



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! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.