|
Boost : |
From: Fred_at_[hidden]
Date: 2007-03-15 14:22:00
Hello,
I am currently integrating boost smart ptr to an existing project and I
have a few questions about it uses. I will try to be as clear as possible.
I have a parent - child structure (where each child has only one parent, but
a parent can have zero or many children) represented as a tree structure
where each parent has a vector of children.
Their is no distinction between parent and child, they are both of the same
class, let's call it Node.
Other parts of the application can hold references to nodes but the main
reference is always held by the parent.
The node children are shared ptr and I need to be able to delete them no
matter how many people hold references to them. But, obviously, I want the
references to be cleared too and become NULL ptr. Now the only way I found
to get this working is pretty tedious, I am not sure I am doing it right.
What I do now is that everyone who holds a reference to a node holds it via
a weak_ptr and each time they need to access the data I convert from weak to
shared. Is this really to way to do this?
Also, the only way to delete a node seems to be calling shared_ptr::reset()
from inside the parent node. This is annoying because even if I know which
child to delete I have to browse the tree to find it and call reset on the
pointer. Is this right or is their a way to delete a shared object
explicitlly, clearing all reference to it?
Is this helps, my app is a graphic editor and if the user selects an object
and hits delete I would like to be able to delete it without having to
explicitely clear every references to it.
Thank you!
-- View this message in context: http://www.nabble.com/smart-ptr-use-tf3410093.html#a9500575 Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk