/usr/include/xapian-1.3/xapian/intrusive_ptr.h is in libxapian-1.3-dev 1.3.4-0ubuntu6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | #ifndef XAPIAN_INCLUDED_INTRUSIVE_PTR_H
#define XAPIAN_INCLUDED_INTRUSIVE_PTR_H
//
// Based on Boost's intrusive_ptr.hpp
//
// Copyright (c) 2001, 2002 Peter Dimov
// Copyright (c) 2011,2013,2014,2015 Olly Betts
//
// Distributed under the Boost Software License, Version 1.0.
//
// Boost Software License - Version 1.0 - August 17th, 2003
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// See http://www.boost.org/libs/smart_ptr/intrusive_ptr.html for documentation.
//
#if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
# error "Never use <xapian/intrusive_ptr.h> directly; include <xapian.h> instead."
#endif
namespace Xapian {
namespace Internal {
/// Base class for objects managed by intrusive_ptr.
class intrusive_base {
/// Prevent copying.
intrusive_base(const intrusive_base&);
/// Prevent assignment.
void operator=(const intrusive_base&);
public:
/** Construct with no references.
*
* The references get added if/when this object is put into an
* intrusive_ptr.
*/
intrusive_base() : _refs(0) { }
/* There's no need for a virtual destructor here as we never delete a
* subclass of intrusive_base by calling delete on intrusive_base*.
*/
/** Reference count.
*
* This needs to be mutable so we can add/remove references through const
* pointers.
*/
mutable unsigned _refs;
};
//
// intrusive_ptr
//
/// A smart pointer that uses intrusive reference counting.
template<class T> class intrusive_ptr
{
private:
typedef intrusive_ptr this_type;
public:
intrusive_ptr(): px( 0 )
{
}
intrusive_ptr( T * p): px( p )
{
if( px != 0 ) ++px->_refs;
}
template<class U>
intrusive_ptr( intrusive_ptr<U> const & rhs )
: px( rhs.get() )
{
if( px != 0 ) ++px->_refs;
}
intrusive_ptr(intrusive_ptr const & rhs): px( rhs.px )
{
if( px != 0 ) ++px->_refs;
}
~intrusive_ptr()
{
if( px != 0 && --px->_refs == 0 ) delete px;
}
intrusive_ptr & operator=(intrusive_ptr const & rhs)
{
this_type(rhs).swap(*this);
return *this;
}
intrusive_ptr & operator=(T * rhs)
{
this_type(rhs).swap(*this);
return *this;
}
T * get() const
{
return px;
}
T & operator*() const
{
return *px;
}
T * operator->() const
{
return px;
}
void swap(intrusive_ptr & rhs)
{
T * tmp = px;
px = rhs.px;
rhs.px = tmp;
}
private:
T * px;
};
template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
{
return a.get() == b.get();
}
template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
{
return a.get() != b.get();
}
template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, U * b)
{
return a.get() == b;
}
template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, U * b)
{
return a.get() != b;
}
template<class T, class U> inline bool operator==(T * a, intrusive_ptr<U> const & b)
{
return a == b.get();
}
template<class T, class U> inline bool operator!=(T * a, intrusive_ptr<U> const & b)
{
return a != b.get();
}
/// Base class for objects managed by opt_intrusive_ptr.
class opt_intrusive_base {
public:
opt_intrusive_base(const opt_intrusive_base&) : _refs(0) { }
opt_intrusive_base& operator=(const opt_intrusive_base&) {
// Don't touch _refs.
return *this;
}
/** Construct object which is initially not reference counted.
*
* The reference counting starts if release() is called.
*/
opt_intrusive_base() : _refs(0) { }
/* Subclasses of opt_intrusive_base may be deleted by calling delete on a
* pointer to opt_intrusive_base.
*/
virtual ~opt_intrusive_base() { }
void ref() const {
if (_refs == 0)
_refs = 2;
else
++_refs;
}
void unref() const {
if (--_refs == 1)
delete this;
}
/** Reference count.
*
* This needs to be mutable so we can add/remove references through const
* pointers.
*/
mutable unsigned _refs;
protected:
/** Start reference counting.
*
* The object is constructed with _refs set to 0, meaning it isn't being
* reference counted.
*
* Calling release() sets _refs to 1 if it is 0, and from then
* opt_intrusive_ptr will increment and decrement _refs. If it is
* decremented to 1, the object is deleted.
*/
void release() const {
if (_refs == 0)
_refs = 1;
}
};
//
// opt_intrusive_ptr
//
/// A smart pointer that optionally uses intrusive reference counting.
template<class T> class opt_intrusive_ptr
{
private:
typedef opt_intrusive_ptr this_type;
public:
opt_intrusive_ptr(): px( 0 ), counting( false )
{
}
opt_intrusive_ptr( T * p): px( p ), counting( px != 0 && px->_refs )
{
if( counting ) ++px->_refs;
}
template<class U>
opt_intrusive_ptr( opt_intrusive_ptr<U> const & rhs )
: px( rhs.get() ), counting( rhs.counting )
{
if( counting ) ++px->_refs;
}
opt_intrusive_ptr(opt_intrusive_ptr const & rhs)
: px( rhs.px ), counting( rhs.counting )
{
if( counting ) ++px->_refs;
}
~opt_intrusive_ptr()
{
if( counting && --px->_refs == 1 ) delete px;
}
opt_intrusive_ptr & operator=(opt_intrusive_ptr const & rhs)
{
this_type(rhs).swap(*this);
return *this;
}
opt_intrusive_ptr & operator=(T * rhs)
{
this_type(rhs).swap(*this);
return *this;
}
T * get() const
{
return px;
}
T & operator*() const
{
return *px;
}
T * operator->() const
{
return px;
}
void swap(opt_intrusive_ptr & rhs)
{
T * tmp = px;
px = rhs.px;
rhs.px = tmp;
bool tmp2 = counting;
counting = rhs.counting;
rhs.counting = tmp2;
}
private:
T * px;
bool counting;
};
template<class T, class U> inline bool operator==(opt_intrusive_ptr<T> const & a, opt_intrusive_ptr<U> const & b)
{
return a.get() == b.get();
}
template<class T, class U> inline bool operator!=(opt_intrusive_ptr<T> const & a, opt_intrusive_ptr<U> const & b)
{
return a.get() != b.get();
}
template<class T, class U> inline bool operator==(opt_intrusive_ptr<T> const & a, U * b)
{
return a.get() == b;
}
template<class T, class U> inline bool operator!=(opt_intrusive_ptr<T> const & a, U * b)
{
return a.get() != b;
}
template<class T, class U> inline bool operator==(T * a, opt_intrusive_ptr<U> const & b)
{
return a == b.get();
}
template<class T, class U> inline bool operator!=(T * a, opt_intrusive_ptr<U> const & b)
{
return a != b.get();
}
}
}
#endif // XAPIAN_INCLUDED_INTRUSIVE_PTR_H
|