diff options
author | Josh Blum | 2013-04-10 00:21:31 -0700 |
---|---|---|
committer | Josh Blum | 2013-04-10 00:21:31 -0700 |
commit | fb55fd6737902ed6270c2518bdc81a6971f9b3a1 (patch) | |
tree | c31dcb488f97f4c016ad326c726d5f42bcb6bca0 /lib | |
parent | ca4819c56e7f085c1358cd75a9f4635ce3ae2f1f (diff) | |
download | sandhi-fb55fd6737902ed6270c2518bdc81a6971f9b3a1.tar.gz sandhi-fb55fd6737902ed6270c2518bdc81a6971f9b3a1.tar.bz2 sandhi-fb55fd6737902ed6270c2518bdc81a6971f9b3a1.zip |
gras: formalize the weak container api w/ docs
address issue #69, we now have a set_container call,
which is now formally part of the api.
Anyone can call set_container for custom container types.
GRAS supports shared ptr and pyobject out of the box.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/element.cpp | 5 | ||||
-rw-r--r-- | lib/element_impl.hpp | 1 | ||||
-rw-r--r-- | lib/hier_block.cpp | 5 | ||||
-rw-r--r-- | lib/weak_container.cpp | 15 |
5 files changed, 25 insertions, 2 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index ff36a5a..5d059e7 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -58,6 +58,7 @@ list(APPEND GRAS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/top_block_query.cpp ${CMAKE_CURRENT_SOURCE_DIR}/register_messages.cpp ${CMAKE_CURRENT_SOURCE_DIR}/theron_allocator.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/weak_container.cpp ) ######################################################################## diff --git a/lib/element.cpp b/lib/element.cpp index 989c184..dfc3f57 100644 --- a/lib/element.cpp +++ b/lib/element.cpp @@ -48,6 +48,11 @@ ElementImpl::~ElementImpl(void) if (this->block) this->block_cleanup(); } +void Element::set_container(WeakContainer *container) +{ + (*this)->weak_self.reset(container); +} + bool Element::equals(const Element &rhs) { return this->get() == rhs.get(); diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp index 869006e..3148d93 100644 --- a/lib/element_impl.hpp +++ b/lib/element_impl.hpp @@ -29,6 +29,7 @@ struct ElementImpl std::string name; long unique_id; std::string id; + boost::shared_ptr<WeakContainer> weak_self; //top block stuff SharedThreadGroup thread_group; diff --git a/lib/hier_block.cpp b/lib/hier_block.cpp index d8756a4..758af0c 100644 --- a/lib/hier_block.cpp +++ b/lib/hier_block.cpp @@ -40,9 +40,10 @@ void HierBlock::disconnect(const Element &elem) static Apology::Wax get_ref(const Element &elem) { - if (elem.weak_self) + boost::shared_ptr<WeakContainer> weak_self = elem->weak_self; + if (weak_self) { - boost::shared_ptr<const void> shared_self = elem.weak_self->lock(); + boost::shared_ptr<const void> shared_self = weak_self->lock(); if (shared_self) return shared_self; } return elem; diff --git a/lib/weak_container.cpp b/lib/weak_container.cpp new file mode 100644 index 0000000..192a2fd --- /dev/null +++ b/lib/weak_container.cpp @@ -0,0 +1,15 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#include <gras/weak_container.hpp> + +using namespace gras; + +WeakContainer::WeakContainer(void) +{ + //NOP +} + +WeakContainer::~WeakContainer(void) +{ + //NOP +} |