]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/smart_ptr/detail/sp_counted_base_nt.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / 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/detail/sp_typeinfo.hpp>
22
23 namespace boost
24 {
25
26 namespace detail
27 {
28
29 class sp_counted_base
30 {
31 private:
32
33 sp_counted_base( sp_counted_base const & );
34 sp_counted_base & operator= ( sp_counted_base const & );
35
36 long use_count_; // #shared
37 long weak_count_; // #weak + (#shared != 0)
38
39 public:
40
41 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
42 {
43 }
44
45 virtual ~sp_counted_base() // nothrow
46 {
47 }
48
49 // dispose() is called when use_count_ drops to zero, to release
50 // the resources managed by *this.
51
52 virtual void dispose() = 0; // nothrow
53
54 // destroy() is called when weak_count_ drops to zero.
55
56 virtual void destroy() // nothrow
57 {
58 delete this;
59 }
60
61 virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
62 virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
63 virtual void * get_untyped_deleter() = 0;
64
65 void add_ref_copy()
66 {
67 ++use_count_;
68 }
69
70 bool add_ref_lock() // true on success
71 {
72 if( use_count_ == 0 ) return false;
73 ++use_count_;
74 return true;
75 }
76
77 void release() // nothrow
78 {
79 if( --use_count_ == 0 )
80 {
81 dispose();
82 weak_release();
83 }
84 }
85
86 void weak_add_ref() // nothrow
87 {
88 ++weak_count_;
89 }
90
91 void weak_release() // nothrow
92 {
93 if( --weak_count_ == 0 )
94 {
95 destroy();
96 }
97 }
98
99 long use_count() const // nothrow
100 {
101 return use_count_;
102 }
103 };
104
105 } // namespace detail
106
107 } // namespace boost
108
109 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED