diff options
author | Josh Blum | 2013-04-04 22:07:59 -0700 |
---|---|---|
committer | Josh Blum | 2013-04-04 22:07:59 -0700 |
commit | 0f493354d46706ed81b81699c4e5197ee2b82d08 (patch) | |
tree | d177af0a64fa643a5630091dd797d38492e73912 /include/gras/detail | |
parent | 06b800166e995cf53ec0f87200427512e1518d8f (diff) | |
download | sandhi-0f493354d46706ed81b81699c4e5197ee2b82d08.tar.gz sandhi-0f493354d46706ed81b81699c4e5197ee2b82d08.tar.bz2 sandhi-0f493354d46706ed81b81699c4e5197ee2b82d08.zip |
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
Diffstat (limited to 'include/gras/detail')
-rw-r--r-- | include/gras/detail/element.hpp | 27 |
1 files changed, 26 insertions, 1 deletions
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 <boost/weak_ptr.hpp> + namespace gras { + + //! Weak element overload for the case of shared_ptr container + struct WeakElementSharedPtr : WeakElement + { + WeakElementSharedPtr(boost::weak_ptr<const void> weak_self) + { + _weak_self = weak_self; + } + boost::shared_ptr<const void> lock(void) + { + return _weak_self.lock(); + } + boost::weak_ptr<const void> _weak_self; + }; + template <typename T> inline Element::Element(const boost::shared_ptr<T> &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 |