File indexing completed on 2025-01-18 09:53:52
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_COUNTED_BASE_HPP_EAN_04_16_2006
0008 #define BOOST_XPRESSIVE_DETAIL_UTILITY_COUNTED_BASE_HPP_EAN_04_16_2006
0009
0010 #include <boost/assert.hpp>
0011 #include <boost/checked_delete.hpp>
0012 #include <boost/detail/atomic_count.hpp>
0013
0014 namespace boost { namespace xpressive { namespace detail
0015 {
0016 template<typename Derived>
0017 struct counted_base_access;
0018
0019
0020
0021 template<typename Derived>
0022 struct counted_base
0023 {
0024 long use_count() const
0025 {
0026 return this->count_;
0027 }
0028
0029 protected:
0030 counted_base()
0031 : count_(0)
0032 {
0033 }
0034
0035 counted_base(counted_base<Derived> const &)
0036 : count_(0)
0037 {
0038 }
0039
0040 counted_base &operator =(counted_base<Derived> const &)
0041 {
0042 return *this;
0043 }
0044
0045 private:
0046 friend struct counted_base_access<Derived>;
0047 mutable boost::detail::atomic_count count_;
0048 };
0049
0050
0051
0052 template<typename Derived>
0053 struct counted_base_access
0054 {
0055 static void add_ref(counted_base<Derived> const *that)
0056 {
0057 ++that->count_;
0058 }
0059
0060 static void release(counted_base<Derived> const *that)
0061 {
0062 BOOST_ASSERT(0 < that->count_);
0063 if(0 == --that->count_)
0064 {
0065 boost::checked_delete(static_cast<Derived const *>(that));
0066 }
0067 }
0068 };
0069
0070 template<typename Derived>
0071 inline void intrusive_ptr_add_ref(counted_base<Derived> const *that)
0072 {
0073 counted_base_access<Derived>::add_ref(that);
0074 }
0075
0076 template<typename Derived>
0077 inline void intrusive_ptr_release(counted_base<Derived> const *that)
0078 {
0079 counted_base_access<Derived>::release(that);
0080 }
0081
0082 }}}
0083
0084 #endif