/usr/include/cal3d/refptr.h is in libcal3d12-dev 0.11.0-4.1ubuntu1.
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 | #ifndef CAL_REF_PTR_H
#define CAL_REF_PTR_H
namespace cal3d
{
/// A container-safe smart pointer used for refcounted classes.
template<typename T>
class RefPtr
{
public:
// For compatibility with Boost.Python.
typedef T element_type;
RefPtr(T* ptr = 0)
{
m_ptr = 0;
*this = ptr;
}
RefPtr(const RefPtr<T>& ptr)
{
m_ptr = 0;
*this = ptr;
}
~RefPtr()
{
if (m_ptr)
{
explicitDecRef(m_ptr);
m_ptr = 0;
}
}
template<typename U>
RefPtr<T>& operator=(U* ptr)
{
if (ptr != m_ptr)
{
if (m_ptr)
{
explicitDecRef(m_ptr);
}
m_ptr = ptr;
if (m_ptr)
{
explicitIncRef(m_ptr);
}
}
return *this;
}
template<typename U>
RefPtr<T>& operator=(const RefPtr<U>& ptr)
{
*this = ptr.get();
return *this;
}
/// Need this to override the built-in operator=
RefPtr<T>& operator=(const RefPtr<T>& ptr)
{
*this = ptr.get();
return *this;
}
/// Need this to override the built-in operator!
bool operator!() const
{
return !get();
}
T* operator->() const
{
assert(get() && "Accessing member of null pointer!");
return get();
}
T& operator*() const
{
assert(get() && "Dereferencing null pointer!");
return *get();
}
typedef RefPtr<T> this_type;
/// Inspired by boost's smart_ptr facilities.
typedef T* this_type::*unspecified_bool_type;
/// This lets us write code like: if (ptr && ptr->valid())
operator unspecified_bool_type() const
{
return (get() ? &this_type::m_ptr : 0);
}
T* get() const
{
assert(!m_ptr || m_ptr->getRefCount() > 0 &&
"Dereferencing pointer with refCount <= 0");
return m_ptr;
}
private:
T* m_ptr;
};
// For compatibility with Boost.Python.
template<class T>
T* get_pointer(const RefPtr<T>& p)
{
return p.get();
}
template<typename T, typename U>
bool operator==(const RefPtr<T>& a, const RefPtr<U>& b)
{
return (a.get() == b.get());
}
template<typename T, typename U>
bool operator==(const RefPtr<T>& a, const U* b)
{
return (a.get() == b);
}
template<typename T, typename U>
bool operator==(const T* a, const RefPtr<U>& b)
{
return (a == b.get());
}
template<typename T, typename U>
bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b)
{
return (a.get() != b.get());
}
template<typename T, typename U>
bool operator!=(const RefPtr<T>& a, const U* b)
{
return (a.get() != b);
}
template<typename T, typename U>
bool operator!=(const T* a, const RefPtr<U>& b)
{
return (a != b.get());
}
template<typename T, typename U>
bool operator<(const RefPtr<T>& a, const RefPtr<U>& b)
{
return (a.get() < b.get());
}
template<typename T, typename U>
bool operator<(const RefPtr<T>& a, const U* b)
{
return (a.get() < b);
}
template<typename T, typename U>
bool operator<(const T* a, const RefPtr<U>& b)
{
return (a < b.get());
}
}
#endif
|