From 3b81a8e6c008bba96fa61aad58b2b3b955e73e66 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Fri, 16 Nov 2018 16:02:22 +0100 Subject: [PATCH] Add context_destroyed to verifiables Avoids destruction order fiasco as context can be destroyed before the functions/verifiables --- include/turtle/detail/function_impl_template.hpp | 5 +++++ include/turtle/detail/group.hpp | 7 +++++++ include/turtle/detail/object_impl.hpp | 2 ++ include/turtle/detail/verifiable.hpp | 2 ++ 4 files changed, 16 insertions(+) diff --git a/include/turtle/detail/function_impl_template.hpp b/include/turtle/detail/function_impl_template.hpp index 4d47a82..8cc79af 100644 --- a/include/turtle/detail/function_impl_template.hpp +++ b/include/turtle/detail/function_impl_template.hpp @@ -255,6 +255,11 @@ namespace detail context_ = &c; } + virtual void context_destroyed() + { + context_ = NULL; + } + friend std::ostream& operator<<( std::ostream& s, const function_impl& impl ) { diff --git a/include/turtle/detail/group.hpp b/include/turtle/detail/group.hpp index d0668cc..7e0fc15 100644 --- a/include/turtle/detail/group.hpp +++ b/include/turtle/detail/group.hpp @@ -22,6 +22,13 @@ namespace detail class group { public: + ~group() + { + for( verifiables_cit it = verifiables_.begin(); + it != verifiables_.end(); ++it ) + (*it)->context_destroyed(); + } + void add( verifiable& v ) { verifiables_.push_back( &v ); diff --git a/include/turtle/detail/object_impl.hpp b/include/turtle/detail/object_impl.hpp index 5679b1c..5670825 100644 --- a/include/turtle/detail/object_impl.hpp +++ b/include/turtle/detail/object_impl.hpp @@ -56,6 +56,8 @@ namespace detail if( children_.empty() ) detail::root::inst().remove( *this ); } + virtual void context_destroyed() + {} virtual void serialize( std::ostream& s, const verifiable& v ) const { diff --git a/include/turtle/detail/verifiable.hpp b/include/turtle/detail/verifiable.hpp index 5d85c93..23203b5 100644 --- a/include/turtle/detail/verifiable.hpp +++ b/include/turtle/detail/verifiable.hpp @@ -25,6 +25,8 @@ namespace detail virtual bool verify() const = 0; virtual void reset() = 0; + + virtual void context_destroyed() = 0; }; } } // mock