diff options
author | Josh Blum | 2013-04-03 23:09:49 -0700 |
---|---|---|
committer | Josh Blum | 2013-04-03 23:09:49 -0700 |
commit | 0651aff49ae7e066bc301faeecfbd519c4743849 (patch) | |
tree | 540884afb2ce0186ce951258359c8effb6ed9aa6 /include | |
parent | 3e0943d0e61b11cdd6b0b2dd7d0815a64e63725d (diff) | |
download | sandhi-0651aff49ae7e066bc301faeecfbd519c4743849.tar.gz sandhi-0651aff49ae7e066bc301faeecfbd519c4743849.tar.bz2 sandhi-0651aff49ae7e066bc301faeecfbd519c4743849.zip |
gras: figured out how to do the python reference
Diffstat (limited to 'include')
-rw-r--r-- | include/gras/detail/element.hpp | 16 | ||||
-rw-r--r-- | include/gras/element.hpp | 11 |
2 files changed, 23 insertions, 4 deletions
diff --git a/include/gras/detail/element.hpp b/include/gras/detail/element.hpp index 35033e1..22a63a0 100644 --- a/include/gras/detail/element.hpp +++ b/include/gras/detail/element.hpp @@ -5,6 +5,19 @@ namespace gras { + struct WeakElementSharedPtr : WeakElement + { + WeakElementSharedPtr(boost::weak_ptr<Element> weak_self) + { + _weak_self = weak_self; + } + boost::shared_ptr<void> lock(void) + { + return _weak_self.lock(); + } + boost::weak_ptr<Element> _weak_self; + }; + template <typename T> inline Element::Element(const boost::shared_ptr<T> &elem) { @@ -16,7 +29,8 @@ namespace gras { try { - this->weak_self = this->shared_from_this(); + if (not this->weak_self) + this->weak_self.reset(new WeakElementSharedPtr(this->shared_from_this())); } catch(...){} return *this; diff --git a/include/gras/element.hpp b/include/gras/element.hpp index 40a24cf..f9a223d 100644 --- a/include/gras/element.hpp +++ b/include/gras/element.hpp @@ -19,6 +19,11 @@ struct ElementImpl; typedef boost::shared_ptr<ElementImpl> ElementBase; +struct WeakElement +{ + virtual boost::shared_ptr<void> lock(void) = 0; +}; + struct Block; struct GRAS_API Element : ElementBase, boost::enable_shared_from_this<Element> @@ -87,13 +92,13 @@ struct GRAS_API Element : ElementBase, boost::enable_shared_from_this<Element> * Good for that factory function/shared ptr paradigm. */ template <typename T> - inline Element(const boost::shared_ptr<T> &elem); + Element(const boost::shared_ptr<T> &elem); //! Convert a shared ptr of a derived class to an Element - inline Element &shared_to_element(void); + Element &shared_to_element(void); //! for internal use only - boost::weak_ptr<Element> weak_self; + boost::shared_ptr<WeakElement> weak_self; }; |