From 0f493354d46706ed81b81699c4e5197ee2b82d08 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 4 Apr 2013 22:07:59 -0700 Subject: gras: revisit container storage after yesterdays learning The mechanisms of connect are now resonsible for grabbing the container ref. When the object is a shared ptr, the element contructor overload sets weakself. When the object is in python, the python reference is held, even if its shared ptr underneath that. * removed the need for shared_from_this * removed the ref stuff in python Block --- include/gras/detail/element.hpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'include/gras/detail') diff --git a/include/gras/detail/element.hpp b/include/gras/detail/element.hpp index 2b97c8f..f8a8904 100644 --- a/include/gras/detail/element.hpp +++ b/include/gras/detail/element.hpp @@ -3,12 +3,37 @@ #ifndef INCLUDED_GRAS_DETAIL_ELEMENT_HPP #define INCLUDED_GRAS_DETAIL_ELEMENT_HPP +#include + namespace gras { + + //! Weak element overload for the case of shared_ptr container + struct WeakElementSharedPtr : WeakElement + { + WeakElementSharedPtr(boost::weak_ptr weak_self) + { + _weak_self = weak_self; + } + boost::shared_ptr lock(void) + { + return _weak_self.lock(); + } + boost::weak_ptr _weak_self; + }; + template inline Element::Element(const boost::shared_ptr &elem) { - *this = elem->shared_to_element(); + //the container is a shared pointer, so save the reference, + //unless the reference was already set to something + if (not elem->weak_self) + { + elem->weak_self.reset(new WeakElementSharedPtr(elem)); + } + + //initialize this new Element from the argument passed + *this = *elem; } } //namespace gras -- cgit