// (C) Copyright Jonathan Turkanis 2004. // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999. // (C) Copyright 2001, 2002, 2003 Peter Dimov // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) // Based on // Disclaimer: Not a Boost library. // reinterpret_cast is eliminable here; it is used to simplify the // implementation. #ifndef BOOST_IDL_SHARED_OBJ_HPP_INCLUDED #define BOOST_IDL_SHARED_OBJ_HPP_INCLUDED #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif #include // swap. #include #include #include #include #include // BOOST_IDL_PRIVATE. #include #include #include #include namespace boost { namespace interfaces { namespace detail { template class shared_obj_impl { public: static fixed_view* get(const shared_obj& obj) { return access::get_interface_pointer(obj) ? const_cast*>( static_cast*>(&obj) ) : 0; } static void reset(shared_obj& obj) { shared_obj temp; shared_obj_impl::swap(temp, obj); } template static void reset(shared_obj& obj, T* t) { BOOST_ASSERT(t && t != access::get_interface_pointer(obj)); shared_obj temp(t); shared_obj_impl::swap(temp, obj); } template static void reset(shared_obj& obj, T* t, D d) { BOOST_ASSERT(t && t != access::get_interface_pointer(obj)); shared_obj temp(t, d); shared_obj_impl::swap(temp, obj); } static void swap(shared_obj& lhs, shared_obj& rhs) { boost::interfaces::swap( implicit_cast< fixed_view& >(lhs), implicit_cast< fixed_view& >(rhs) ); lhs.pn_idl_.swap(rhs.pn_idl_); } static bool unique(const shared_obj& obj) { return obj.pn_idl_.unique(); } static long use_count(const shared_obj& obj) { return obj.pn_idl_.use_count(); } }; } // End namespace detail. template class shared_obj : public fixed_view { public: BOOST_IDL_BEFRIEND_TEMPLATE_CLASS(shared_obj, 1, T) BOOST_IDL_BEFRIEND_TEMPLATE_CLASS(detail::shared_obj_impl, 1, T) friend class access; // Constructors shared_obj() : pn_idl_() { } shared_obj(const shared_obj& obj) : fixed_view( reinterpret_cast(obj) ), pn_idl_(obj.pn_idl_) { } template shared_obj(const shared_obj& obj) : fixed_view( reinterpret_cast(obj) ), pn_idl_(obj.pn_idl_) { } template explicit shared_obj(T* t) : fixed_view(*t), pn_idl_(t, checked_deleter()) { } template shared_obj(T* t, D d) : fixed_view(*t), pn_idl_(t, d) { } // Assignment shared_obj& operator=(const shared_obj& obj) { fixed_view::assign_interface( reinterpret_cast(obj) ); pn_idl_ = obj.pn_idl_; return *this; } template shared_obj& operator=(const shared_obj& obj) { fixed_view::assign_interface( reinterpret_cast(obj) ); pn_idl_ = obj.pn_idl_; return *this; } BOOST_IDL_PRIVATE: boost::detail::shared_count pn_idl_; // reference counter }; template fixed_view* get(const shared_obj& obj) { return detail::shared_obj_impl::get(obj); } template void reset(shared_obj& obj) { detail::shared_obj_impl::reset(obj); } template void reset(shared_obj& obj, T* t) { detail::shared_obj_impl::reset(obj, t); } template void reset(shared_obj& obj, T* t, D d) { detail::shared_obj_impl::reset(obj, t, d); } template void swap(shared_obj& lhs, shared_obj& rhs) { detail::shared_obj_impl::swap(lhs, rhs); } template bool unique(const shared_obj& obj) { return detail::shared_obj_impl::unique(obj); } template long use_count(const shared_obj& obj) { return detail::shared_obj_impl::use_count(obj); } } } // End namespace interfaces, boost. #endif // #ifndef BOOST_IDL_SHARED_OBJ_HPP_INCLUDED