1 //////////////////////////////////////////////////////////////////////////////
2 // (c) Copyright Andreas Huber Doenni 2002-2005, Eric Niebler 2006
3 // Distributed under the Boost Software License, Version 1.0. (See accompany-
4 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 //////////////////////////////////////////////////////////////////////////////
7 #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_COUNTED_BASE_HPP_EAN_04_16_2006
8 #define BOOST_XPRESSIVE_DETAIL_UTILITY_COUNTED_BASE_HPP_EAN_04_16_2006
10 #include <boost/assert.hpp>
11 #include <boost/checked_delete.hpp>
12 #include <boost/detail/atomic_count.hpp>
14 namespace boost { namespace xpressive { namespace detail
16 template<typename Derived>
17 struct counted_base_access;
19 //////////////////////////////////////////////////////////////////////////////
21 template<typename Derived>
24 long use_count() const
35 counted_base(counted_base<Derived> const &)
40 counted_base &operator =(counted_base<Derived> const &)
46 friend struct counted_base_access<Derived>;
47 mutable boost::detail::atomic_count count_;
50 //////////////////////////////////////////////////////////////////////////////
51 // counted_base_access
52 template<typename Derived>
53 struct counted_base_access
55 static void add_ref(counted_base<Derived> const *that)
60 static void release(counted_base<Derived> const *that)
62 BOOST_ASSERT(0 < that->count_);
63 if(0 == --that->count_)
65 boost::checked_delete(static_cast<Derived const *>(that));
70 template<typename Derived>
71 inline void intrusive_ptr_add_ref(counted_base<Derived> const *that)
73 counted_base_access<Derived>::add_ref(that);
76 template<typename Derived>
77 inline void intrusive_ptr_release(counted_base<Derived> const *that)
79 counted_base_access<Derived>::release(that);
82 }}} // namespace boost::xpressive::detail