This commit is contained in:
Adam Ierymenko 2019-08-23 12:40:08 -07:00
parent b727e2a67a
commit f12370c348
No known key found for this signature in database
GPG key ID: 1657198823E52A61
4 changed files with 82 additions and 82 deletions

View file

@ -30,11 +30,11 @@ template<typename T>
class SharedPtr
{
public:
inline SharedPtr() : _ptr((T *)0) {}
inline SharedPtr(T *obj) : _ptr(obj) { ++obj->__refCount; }
inline SharedPtr(const SharedPtr &sp) : _ptr(sp._getAndInc()) {}
ZT_ALWAYS_INLINE SharedPtr() : _ptr((T *)0) {}
ZT_ALWAYS_INLINE SharedPtr(T *obj) : _ptr(obj) { ++obj->__refCount; }
ZT_ALWAYS_INLINE SharedPtr(const SharedPtr &sp) : _ptr(sp._getAndInc()) {}
inline ~SharedPtr()
ZT_ALWAYS_INLINE ~SharedPtr()
{
if (_ptr) {
if (--_ptr->__refCount <= 0)
@ -42,7 +42,7 @@ public:
}
}
inline SharedPtr &operator=(const SharedPtr &sp)
ZT_ALWAYS_INLINE SharedPtr &operator=(const SharedPtr &sp)
{
if (_ptr != sp._ptr) {
T *p = sp._getAndInc();
@ -63,7 +63,7 @@ public:
*
* @param ptr Naked pointer to assign
*/
inline void set(T *ptr)
ZT_ALWAYS_INLINE void set(T *ptr)
{
zero();
++ptr->__refCount;
@ -75,26 +75,26 @@ public:
*
* @param with Pointer to swap with
*/
inline void swap(SharedPtr &with)
ZT_ALWAYS_INLINE void swap(SharedPtr &with)
{
T *tmp = _ptr;
_ptr = with._ptr;
with._ptr = tmp;
}
inline operator bool() const { return (_ptr != (T *)0); }
inline T &operator*() const { return *_ptr; }
inline T *operator->() const { return _ptr; }
ZT_ALWAYS_INLINE operator bool() const { return (_ptr != (T *)0); }
ZT_ALWAYS_INLINE T &operator*() const { return *_ptr; }
ZT_ALWAYS_INLINE T *operator->() const { return _ptr; }
/**
* @return Raw pointer to held object
*/
inline T *ptr() const { return _ptr; }
ZT_ALWAYS_INLINE T *ptr() const { return _ptr; }
/**
* Set this pointer to NULL
*/
inline void zero()
ZT_ALWAYS_INLINE void zero()
{
if (_ptr) {
if (--_ptr->__refCount <= 0)
@ -106,22 +106,22 @@ public:
/**
* @return Number of references according to this object's ref count or 0 if NULL
*/
inline int references()
ZT_ALWAYS_INLINE int references()
{
if (_ptr)
return _ptr->__refCount.load();
return 0;
}
inline bool operator==(const SharedPtr &sp) const { return (_ptr == sp._ptr); }
inline bool operator!=(const SharedPtr &sp) const { return (_ptr != sp._ptr); }
inline bool operator>(const SharedPtr &sp) const { return (_ptr > sp._ptr); }
inline bool operator<(const SharedPtr &sp) const { return (_ptr < sp._ptr); }
inline bool operator>=(const SharedPtr &sp) const { return (_ptr >= sp._ptr); }
inline bool operator<=(const SharedPtr &sp) const { return (_ptr <= sp._ptr); }
ZT_ALWAYS_INLINE bool operator==(const SharedPtr &sp) const { return (_ptr == sp._ptr); }
ZT_ALWAYS_INLINE bool operator!=(const SharedPtr &sp) const { return (_ptr != sp._ptr); }
ZT_ALWAYS_INLINE bool operator>(const SharedPtr &sp) const { return (_ptr > sp._ptr); }
ZT_ALWAYS_INLINE bool operator<(const SharedPtr &sp) const { return (_ptr < sp._ptr); }
ZT_ALWAYS_INLINE bool operator>=(const SharedPtr &sp) const { return (_ptr >= sp._ptr); }
ZT_ALWAYS_INLINE bool operator<=(const SharedPtr &sp) const { return (_ptr <= sp._ptr); }
private:
inline T *_getAndInc() const
ZT_ALWAYS_INLINE T *_getAndInc() const
{
if (_ptr)
++_ptr->__refCount;