From ac3830ae0c369fe9ab9f403f94215d073b9330aa Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 9 Dec 2012 12:24:10 +0100 Subject: Implement copy construction and assignment for observers. --- cells-impl.hpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'cells-impl.hpp') diff --git a/cells-impl.hpp b/cells-impl.hpp index 86d7c98..deae2fd 100644 --- a/cells-impl.hpp +++ b/cells-impl.hpp @@ -58,6 +58,29 @@ namespace cells { static thread_local dynvar> current_dependencies; static thread_local dynvar current_transaction; + inline observer::observer() : self(std::make_shared(this)) { }; + + inline observer::observer(observer const& other) : self(std::make_shared(this)) { + reset_dependents(other.dependents); + reset_dependencies(other.dependencies); + } + + inline observer& observer::operator =(observer const& other) { + reset_dependents(other.dependents); + reset_dependencies(other.dependencies); + return *this; + } + + inline void observer::reset_dependents(std::list> const& new_dependents) { + for (auto const& dependent : dependents) { + std::shared_ptr sdependent = dependent.lock(); + if (sdependent) { + remove_dependent(*sdependent); + } + } + dependents = new_dependents; + } + inline void observer::clear_dependencies() { for (auto const& dep : dependencies) { std::shared_ptr sdep = dep.lock(); @@ -79,6 +102,17 @@ namespace cells { }); } + inline void observer::reset_dependencies(std::forward_list> const& newdeps) { + clear_dependencies(); + dependencies = newdeps; + for (auto const& dep : newdeps) { + shared_ptr p = dep.lock(); + if (p) { + (*p)->add_dependent(this); + } + } + } + inline void observer::reset_dependencies(std::forward_list const& newdeps) { clear_dependencies(); for (auto const& dep : newdeps) { -- cgit v1.2.3