4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief intrusive_refcount public header */
26 #ifndef HH_intrusive_refcount_
27 #define HH_intrusive_refcount_ 1
30 #include <boost/utility.hpp>
32 //#include "intrusive_refcount.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
37 template <class Self> class intrusive_refcount_t;
39 /** \brief Reference count mixin interface baseclass
41 This class is the baseclass of all intrusive refcount mixins. See \ref intrusive_refcount_t
42 and \ref intrusive_refcount for more information.
44 class intrusive_refcount_base
45 : public boost::noncopyable
48 typedef unsigned refcount_t; ///< reference count type
50 virtual ~intrusive_refcount_base();
52 refcount_t refcount(); ///< current refcount
53 bool is_shared(); ///< return \c true if refcount() > 1
56 intrusive_refcount_base();
66 /** \brief Customizable reference count mixin for intrusive_ptr
68 This class provides a simple internally managed refcount and supplies the <a
69 href="http://www.boost.org/libs/smart_ptr/intrusive_ptr.html">boost::intrusive_ptr</a>
70 required interface. To make a class compatible with \c boost::intrusive_ptr, just derive
71 publicly from intrusive_refcount_t.
75 : public intrusive_refcount_t<SomeClass>
80 typedef intrusive_refcount_t<SomeClass> intrusive_base;
84 // somehow call intrusive_base::add_ref()
89 // Call intrusive_base::release() to decrement the
90 // refcount. This call will return 'true' when the refcount reaches 0.
92 // Return 'true', if the instance shall be deleted
95 // Needed to give intrusive_base access to 'add_ref' and 'release'
96 friend class intrusive_base;
100 Two additional benefits of using intrusive_refcount are
101 \li The object can access it's own refcount
102 \li It is valid and safe to convert a plain object pointer to an intrusive_ptr at any time
105 This class allows to customize the reference counting strategy (e.g. additional refcounting
106 within another object or checking some additional condition before deleting the object when
107 the refcount reaches 0).
109 The interface of this class is defined in \ref intrusive_refcount_base (which you should not
112 template <class Self>
113 class intrusive_refcount_t
114 : public intrusive_refcount_base
117 intrusive_refcount_t();
120 void intrusive_ptr_add_ref();
121 void intrusive_ptr_release();
124 friend void senf::intrusive_ptr_add_ref(intrusive_refcount_t<S> * p);
126 friend void senf::intrusive_ptr_release(intrusive_refcount_t<S> * p);
129 /** \brief Reference count mixin for intrusive_ptr
131 This class provides a simple internally managed refcount and supplies the <a
132 href="http://www.boost.org/libs/smart_ptr/intrusive_ptr.html">boost::intrusive_ptr</a>
133 required interface. To make a class compatible with \c boost::intrusive_ptr, just derive
134 publicly from intrusive_refcount.
138 : public intrusive_refcount
144 Two additional benefits of using intrusive_refcount are
145 \li The object can access it's own refcount
146 \li It is valid and safe to convert a plain object pointer to an intrusive_ptr at any time
149 This mixin class directly uses the default allocation strategy. If you want to customize the
150 reference couting, use \ref intrusive_refcount_t.
152 The interface of this class is defined in \ref intrusive_refcount_t and \ref
153 intrusive_refcount_base (the latter of which you should not use directly).
155 class intrusive_refcount
156 : public intrusive_refcount_t<intrusive_refcount>
159 intrusive_refcount();
162 template <class Self>
163 void intrusive_ptr_add_ref(intrusive_refcount_t<Self> * p);
164 template <class Self>
165 void intrusive_ptr_release(intrusive_refcount_t<Self> * p);
169 ///////////////////////////////hh.e////////////////////////////////////////
170 #include "intrusive_refcount.cci"
171 //#include "intrusive_refcount.ct"
172 #include "intrusive_refcount.cti"
179 // c-file-style: "senf"
180 // indent-tabs-mode: nil
181 // ispell-local-dictionary: "american"
182 // compile-command: "scons -u test"
183 // comment-column: 40