sp_counted_base_nt.hpp
Go to the documentation of this file.
00001 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
00002 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
00003 
00004 // MS compatible compilers support #pragma once
00005 
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009 
00010 //
00011 //  detail/sp_counted_base_nt.hpp
00012 //
00013 //  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
00014 //  Copyright 2004-2005 Peter Dimov
00015 //
00016 // Distributed under the Boost Software License, Version 1.0. (See
00017 // accompanying file LICENSE_1_0.txt or copy at
00018 // http://www.boost.org/LICENSE_1_0.txt)
00019 //
00020 
00021 #include <boost/detail/sp_typeinfo.hpp>
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_;        // #shared
00037     long weak_count_;       // #weak + (#shared != 0)
00038 
00039 public:
00040 
00041     sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
00042     {
00043     }
00044 
00045     virtual ~sp_counted_base() // nothrow
00046     {
00047     }
00048 
00049     // dispose() is called when use_count_ drops to zero, to release
00050     // the resources managed by *this.
00051 
00052     virtual void dispose() = 0; // nothrow
00053 
00054     // destroy() is called when weak_count_ drops to zero.
00055 
00056     virtual void destroy() // nothrow
00057     {
00058         delete this;
00059     }
00060 
00061     virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
00062 
00063     void add_ref_copy()
00064     {
00065         ++use_count_;
00066     }
00067 
00068     bool add_ref_lock() // true on success
00069     {
00070         if( use_count_ == 0 ) return false;
00071         ++use_count_;
00072         return true;
00073     }
00074 
00075     void release() // nothrow
00076     {
00077         if( --use_count_ == 0 )
00078         {
00079             dispose();
00080             weak_release();
00081         }
00082     }
00083 
00084     void weak_add_ref() // nothrow
00085     {
00086         ++weak_count_;
00087     }
00088 
00089     void weak_release() // nothrow
00090     {
00091         if( --weak_count_ == 0 )
00092         {
00093             destroy();
00094         }
00095     }
00096 
00097     long use_count() const // nothrow
00098     {
00099         return use_count_;
00100     }
00101 };
00102 
00103 } // namespace detail
00104 
00105 } // namespace boost
00106 
00107 #endif  // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29