]> git.lyx.org Git - lyx.git/blob - 3rdparty/boost/boost/smart_ptr/detail/sp_counted_base_nt.hpp
Update to boost 1.72
[lyx.git] / 3rdparty / boost / boost / smart_ptr / detail / sp_counted_base_nt.hpp
1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
3
4 // MS compatible compilers support #pragma once
5
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
9
10 //
11 //  detail/sp_counted_base_nt.hpp
12 //
13 //  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
14 //  Copyright 2004-2005 Peter Dimov
15 //
16 // Distributed under the Boost Software License, Version 1.0. (See
17 // accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
19 //
20
21 #include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
22 #include <boost/smart_ptr/detail/sp_noexcept.hpp>
23 #include <boost/config.hpp>
24 #include <boost/cstdint.hpp>
25
26 namespace boost
27 {
28
29 namespace detail
30 {
31
32 class BOOST_SYMBOL_VISIBLE sp_counted_base
33 {
34 private:
35
36     sp_counted_base( sp_counted_base const & );
37     sp_counted_base & operator= ( sp_counted_base const & );
38
39     boost::int_least32_t use_count_;        // #shared
40     boost::int_least32_t weak_count_;       // #weak + (#shared != 0)
41
42 public:
43
44     sp_counted_base() BOOST_SP_NOEXCEPT: use_count_( 1 ), weak_count_( 1 )
45     {
46     }
47
48     virtual ~sp_counted_base() /*BOOST_SP_NOEXCEPT*/
49     {
50     }
51
52     // dispose() is called when use_count_ drops to zero, to release
53     // the resources managed by *this.
54
55     virtual void dispose() BOOST_SP_NOEXCEPT = 0; // nothrow
56
57     // destroy() is called when weak_count_ drops to zero.
58
59     virtual void destroy() BOOST_SP_NOEXCEPT // nothrow
60     {
61         delete this;
62     }
63
64     virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
65     virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
66     virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT = 0;
67
68     void add_ref_copy() BOOST_SP_NOEXCEPT
69     {
70         ++use_count_;
71     }
72
73     bool add_ref_lock() BOOST_SP_NOEXCEPT // true on success
74     {
75         if( use_count_ == 0 ) return false;
76         ++use_count_;
77         return true;
78     }
79
80     void release() BOOST_SP_NOEXCEPT
81     {
82         if( --use_count_ == 0 )
83         {
84             dispose();
85             weak_release();
86         }
87     }
88
89     void weak_add_ref() BOOST_SP_NOEXCEPT
90     {
91         ++weak_count_;
92     }
93
94     void weak_release() BOOST_SP_NOEXCEPT
95     {
96         if( --weak_count_ == 0 )
97         {
98             destroy();
99         }
100     }
101
102     long use_count() const BOOST_SP_NOEXCEPT
103     {
104         return use_count_;
105     }
106 };
107
108 } // namespace detail
109
110 } // namespace boost
111
112 #endif  // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED