File indexing completed on 2025-01-18 09:51:42
0001 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_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
0021 #include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
0022 #include <boost/smart_ptr/detail/sp_noexcept.hpp>
0023 #include <boost/config.hpp>
0024 #include <boost/cstdint.hpp>
0025
0026 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0027
0028 #include <boost/config/pragma_message.hpp>
0029 BOOST_PRAGMA_MESSAGE("Using single-threaded, non-atomic sp_counted_base")
0030
0031 #endif
0032
0033 namespace boost
0034 {
0035
0036 namespace detail
0037 {
0038
0039 class BOOST_SYMBOL_VISIBLE sp_counted_base
0040 {
0041 private:
0042
0043 sp_counted_base( sp_counted_base const & );
0044 sp_counted_base & operator= ( sp_counted_base const & );
0045
0046 boost::int_least32_t use_count_;
0047 boost::int_least32_t weak_count_;
0048
0049 public:
0050
0051 sp_counted_base() BOOST_SP_NOEXCEPT: use_count_( 1 ), weak_count_( 1 )
0052 {
0053 }
0054
0055 virtual ~sp_counted_base()
0056 {
0057 }
0058
0059
0060
0061
0062 virtual void dispose() BOOST_SP_NOEXCEPT = 0;
0063
0064
0065
0066 virtual void destroy() BOOST_SP_NOEXCEPT
0067 {
0068 delete this;
0069 }
0070
0071 virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
0072 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
0073 virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT = 0;
0074
0075 void add_ref_copy() BOOST_SP_NOEXCEPT
0076 {
0077 ++use_count_;
0078 }
0079
0080 bool add_ref_lock() BOOST_SP_NOEXCEPT
0081 {
0082 if( use_count_ == 0 ) return false;
0083 ++use_count_;
0084 return true;
0085 }
0086
0087 void release() BOOST_SP_NOEXCEPT
0088 {
0089 if( --use_count_ == 0 )
0090 {
0091 dispose();
0092 weak_release();
0093 }
0094 }
0095
0096 void weak_add_ref() BOOST_SP_NOEXCEPT
0097 {
0098 ++weak_count_;
0099 }
0100
0101 void weak_release() BOOST_SP_NOEXCEPT
0102 {
0103 if( --weak_count_ == 0 )
0104 {
0105 destroy();
0106 }
0107 }
0108
0109 long use_count() const BOOST_SP_NOEXCEPT
0110 {
0111 return use_count_;
0112 }
0113 };
0114
0115 }
0116
0117 }
0118
0119 #endif