/usr/include/odb/details/shared-ptr/base.txx is in libodb-dev 2.4.0-1.
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 | // file : odb/details/shared-ptr/base.txx
// copyright : Copyright (c) 2009-2015 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
#include <odb/details/meta/answer.hxx>
#include <odb/details/meta/polymorphic-p.hxx>
namespace odb
{
namespace details
{
namespace bits
{
// Support for locating the counter in the memory block.
//
struct LIBODB_EXPORT locator_common
{
static std::size_t*
counter (void*);
};
template <typename X, bool poly = meta::polymorphic_p<X>::result>
struct locator;
template <typename X>
struct locator<X, false>: locator_common
{
static std::size_t*
counter (X* x)
{
return locator_common::counter (x);
}
};
template <typename X>
struct locator<X, true>: locator_common
{
static std::size_t*
counter (X* x)
{
return locator_common::counter (dynamic_cast<void*> (x));
}
};
template <typename X>
std::size_t*
counter (const X* p)
{
return bits::locator<X>::counter (const_cast<X*> (p));
}
// Counter type and operations.
//
meta::no test (...);
meta::yes test (shared_base*);
template <typename X,
std::size_t A = sizeof (bits::test (reinterpret_cast<X*> (0)))>
struct counter_type;
template <typename X>
struct counter_type<X, sizeof (meta::no)>
{
typedef typename details::counter_type<X>::counter r;
};
template <typename X>
struct counter_type<X, sizeof (meta::yes)>
{
typedef shared_base r;
};
template <typename X, typename Y>
struct counter_ops;
template <typename X>
struct counter_ops<X, X>
{
counter_ops (const X* p) : counter_ (p ? bits::counter (p) : 0) {}
counter_ops (const counter_ops& x) : counter_ (x.counter_) {}
template <typename Z>
counter_ops (const counter_ops<Z, Z>& x) : counter_ (x.counter_) {}
counter_ops&
operator= (const counter_ops& x)
{
counter_ = x.counter_;
return *this;
}
template <typename Z>
counter_ops&
operator= (const counter_ops<Z, Z>& x)
{
counter_ = x.counter_;
return *this;
}
void
reset (const X* p)
{
counter_ = p ? bits::counter (p) : 0;
}
void
inc (X*)
{
(*counter_)++;
}
void
dec (X* p)
{
if (--(*counter_) == 0)
{
p->~X ();
// Counter is the top of the memory block.
//
operator delete (counter_);
}
}
std::size_t
count (const X*) const
{
return *counter_;
}
std::size_t* counter_;
};
template <typename Y>
struct counter_ops<shared_base, Y>
{
counter_ops (const Y*) {}
counter_ops (const counter_ops&) {}
template <typename Z>
counter_ops (const counter_ops<shared_base, Z>&) {}
counter_ops&
operator= (const counter_ops&)
{
return *this;
}
template <typename Z>
counter_ops&
operator= (const counter_ops<shared_base, Z>&)
{
return *this;
}
void
reset (const Y*) {}
void
inc (shared_base* p) {p->_inc_ref ();}
void
dec (Y* p)
{
if (static_cast<shared_base*> (p)->_dec_ref ())
delete p;
}
std::size_t
count (const shared_base* p) const {return p->_ref_count ();}
};
}
template <typename X>
inline X*
inc_ref (X* p)
{
bits::counter_ops<typename bits::counter_type<X>::r, X> c (p);
c.inc (p);
return p;
}
template <typename X>
inline void
dec_ref (X* p)
{
bits::counter_ops<typename bits::counter_type<X>::r, X> c (p);
c.dec (p);
}
template <typename X>
inline std::size_t
ref_count (const X* p)
{
bits::counter_ops<typename bits::counter_type<X>::r, X> c (p);
return c.count (p);
}
}
}
|