File indexing completed on 2025-01-18 09:51:42
0001 #ifndef BOOST_SMART_PTR_DETAIL_LOCAL_COUNTED_BASE_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_LOCAL_COUNTED_BASE_HPP_INCLUDED
0003
0004
0005
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <boost/smart_ptr/detail/shared_count.hpp>
0021 #include <boost/config.hpp>
0022 #include <utility>
0023
0024 namespace boost
0025 {
0026
0027 namespace detail
0028 {
0029
0030 class BOOST_SYMBOL_VISIBLE local_counted_base
0031 {
0032 private:
0033
0034 local_counted_base & operator= ( local_counted_base const & );
0035
0036 private:
0037
0038
0039 enum count_type { min_ = 0, initial_ = 1, max_ = 2147483647 };
0040
0041 count_type local_use_count_;
0042
0043 public:
0044
0045 BOOST_CONSTEXPR local_counted_base() BOOST_SP_NOEXCEPT: local_use_count_( initial_ )
0046 {
0047 }
0048
0049 BOOST_CONSTEXPR local_counted_base( local_counted_base const & ) BOOST_SP_NOEXCEPT: local_use_count_( initial_ )
0050 {
0051 }
0052
0053 virtual ~local_counted_base()
0054 {
0055 }
0056
0057 virtual void local_cb_destroy() BOOST_SP_NOEXCEPT = 0;
0058
0059 virtual boost::detail::shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT = 0;
0060
0061 void add_ref() BOOST_SP_NOEXCEPT
0062 {
0063 #if !defined(__NVCC__)
0064 #if defined( __has_builtin )
0065 # if __has_builtin( __builtin_assume )
0066
0067 __builtin_assume( local_use_count_ >= 1 );
0068
0069 # endif
0070 #endif
0071 #endif
0072
0073 local_use_count_ = static_cast<count_type>( local_use_count_ + 1 );
0074 }
0075
0076 void release() BOOST_SP_NOEXCEPT
0077 {
0078 local_use_count_ = static_cast<count_type>( local_use_count_ - 1 );
0079
0080 if( local_use_count_ == 0 )
0081 {
0082 local_cb_destroy();
0083 }
0084 }
0085
0086 long local_use_count() const BOOST_SP_NOEXCEPT
0087 {
0088 return local_use_count_;
0089 }
0090 };
0091
0092 class BOOST_SYMBOL_VISIBLE local_counted_impl: public local_counted_base
0093 {
0094 private:
0095
0096 local_counted_impl( local_counted_impl const & );
0097
0098 private:
0099
0100 shared_count pn_;
0101
0102 public:
0103
0104 explicit local_counted_impl( shared_count const& pn ) BOOST_SP_NOEXCEPT: pn_( pn )
0105 {
0106 }
0107
0108 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
0109
0110 explicit local_counted_impl( shared_count && pn ) BOOST_SP_NOEXCEPT: pn_( std::move(pn) )
0111 {
0112 }
0113
0114 #endif
0115
0116 void local_cb_destroy() BOOST_SP_NOEXCEPT BOOST_OVERRIDE
0117 {
0118 delete this;
0119 }
0120
0121 boost::detail::shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT BOOST_OVERRIDE
0122 {
0123 return pn_;
0124 }
0125 };
0126
0127 class BOOST_SYMBOL_VISIBLE local_counted_impl_em: public local_counted_base
0128 {
0129 public:
0130
0131 shared_count pn_;
0132
0133 void local_cb_destroy() BOOST_SP_NOEXCEPT BOOST_OVERRIDE
0134 {
0135 shared_count().swap( pn_ );
0136 }
0137
0138 boost::detail::shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT BOOST_OVERRIDE
0139 {
0140 return pn_;
0141 }
0142 };
0143
0144 }
0145
0146 }
0147
0148 #endif