00001 #ifndef BOOST_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
00002 #define BOOST_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
00003
00004
00005
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <typeinfo>
00022
00023 namespace boost
00024 {
00025
00026 namespace detail
00027 {
00028
00029 class sp_counted_base
00030 {
00031 private:
00032
00033 sp_counted_base( sp_counted_base const & );
00034 sp_counted_base & operator= ( sp_counted_base const & );
00035
00036 long use_count_;
00037 long weak_count_;
00038
00039 public:
00040
00041 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
00042 {
00043 }
00044
00045 virtual ~sp_counted_base()
00046 {
00047 }
00048
00049
00050
00051
00052 virtual void dispose() = 0;
00053
00054
00055
00056 virtual void destroy()
00057 {
00058 delete this;
00059 }
00060
00061 virtual void * get_deleter( std::type_info const & ti ) = 0;
00062
00063 void add_ref_copy()
00064 {
00065 ++use_count_;
00066 }
00067
00068 bool add_ref_lock()
00069 {
00070 if( use_count_ == 0 ) return false;
00071 ++use_count_;
00072 return true;
00073 }
00074
00075 void release()
00076 {
00077 if( --use_count_ == 0 )
00078 {
00079 dispose();
00080 weak_release();
00081 }
00082 }
00083
00084 void weak_add_ref()
00085 {
00086 ++weak_count_;
00087 }
00088
00089 void weak_release()
00090 {
00091 if( --weak_count_ == 0 )
00092 {
00093 destroy();
00094 }
00095 }
00096
00097 long use_count() const
00098 {
00099 return use_count_;
00100 }
00101 };
00102
00103 }
00104
00105 }
00106
00107 #endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED