/usr/include/boost/xpressive/detail/utility
Edit: /usr/include/boost/xpressive/detail/utility/counted_base.hpp (2384B)
//////////////////////////////////////////////////////////////////////////////
// (c) Copyright Andreas Huber Doenni 2002-2005
// (c) Copyright Eric Niebler 2006
// Distributed under the Boost Software License, Version 1.0. (See accompany-
// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_COUNTED_BASE_HPP_EAN_04_16_2006
#define BOOST_XPRESSIVE_DETAIL_UTILITY_COUNTED_BASE_HPP_EAN_04_16_2006
#include
#include
#include
namespace boost { namespace xpressive { namespace detail
{
template
struct counted_base_access;
//////////////////////////////////////////////////////////////////////////////
// counted_base
template
struct counted_base
{
long use_count() const
{
return this->count_;
}
protected:
counted_base()
: count_(0)
{
}
counted_base(counted_base const &)
: count_(0)
{
}
counted_base &operator =(counted_base const &)
{
return *this;
}
private:
friend struct counted_base_access;
mutable boost::detail::atomic_count count_;
};
//////////////////////////////////////////////////////////////////////////////
// counted_base_access
template
struct counted_base_access
{
static void add_ref(counted_base const *that)
{
++that->count_;
}
static void release(counted_base const *that)
{
BOOST_ASSERT(0 < that->count_);
if(0 == --that->count_)
{
boost::checked_delete(static_cast(that));
}
}
};
template
inline void intrusive_ptr_add_ref(counted_base const *that)
{
counted_base_access::add_ref(that);
}
template
inline void intrusive_ptr_release(counted_base const *that)
{
counted_base_access::release(that);
}
}}} // namespace boost::xpressive::detail
#endif