diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 363762d4..9a6bc56b 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -42,49 +42,19 @@ namespace chaiscript */ struct Data { - /** - * used to provide type-erased access to the internal boost::shared_ptr - * reference count information - */ - struct Shared_Ptr_Proxy - { - virtual ~Shared_Ptr_Proxy() - { - } - - virtual bool unique(boost::any *) = 0; - virtual long use_count(boost::any *) = 0; - }; - - /** - * Typed implementation of the Shared_Ptr_Proxy - */ template - struct Shared_Ptr_Proxy_Impl : Shared_Ptr_Proxy - { - virtual ~Shared_Ptr_Proxy_Impl() - { - } - - virtual bool unique(boost::any *a) + static bool unique(boost::any *a) { boost::shared_ptr *ptr = boost::any_cast >(a); return ptr->unique(); } - virtual long use_count(boost::any *a) - { - boost::shared_ptr *ptr = boost::any_cast >(a); - return ptr->use_count(); - } - }; - Data(const Type_Info &ti, const boost::any &to, bool tr, - const boost::shared_ptr &t_proxy = boost::shared_ptr()) + const boost::function &t_unique = boost::function()) : m_type_info(ti), m_obj(to), - m_is_ref(tr), m_ptr_proxy(t_proxy) + m_is_ref(tr), m_unique(t_unique) { } @@ -93,7 +63,7 @@ namespace chaiscript m_type_info = rhs.m_type_info; m_obj = rhs.m_obj; m_is_ref = rhs.m_is_ref; - m_ptr_proxy = rhs.m_ptr_proxy; + m_unique = rhs.m_unique; return *this; } @@ -101,7 +71,7 @@ namespace chaiscript Type_Info m_type_info; boost::any m_obj; bool m_is_ref; - boost::shared_ptr m_ptr_proxy; + boost::function m_unique; }; /** @@ -141,7 +111,7 @@ namespace chaiscript detail::Get_Type_Info::get(), boost::any(obj), false, - boost::shared_ptr(new Data::Shared_Ptr_Proxy_Impl())) + &Data::unique) ); std::map, Data>::iterator itr @@ -200,7 +170,7 @@ namespace chaiscript detail::Get_Type_Info::get(), boost::any(boost::shared_ptr(new T(t))), false, - boost::shared_ptr(new Data::Shared_Ptr_Proxy_Impl())) + &Data::unique) ); boost::shared_ptr *ptr = boost::any_cast >(&data->m_obj); @@ -226,7 +196,7 @@ namespace chaiscript { ++m_cullcount; - if (force || m_cullcount % 10 != 0) + if (force || m_cullcount % 20 != 0) { return; } @@ -236,7 +206,7 @@ namespace chaiscript while (itr != m_ptrs.end()) { - if (itr->second.m_ptr_proxy->unique(&itr->second.m_obj) == 1) + if (itr->second.m_unique(&itr->second.m_obj)) { std::map, Data >::iterator todel = itr; ++itr;