Bug 1287623, part 3 - Add more methods involving StaticRefPtr. r=froydnj

This patch adds a number of standard conversions to and from RefPtr<>
and already_AddRefed<>.
This commit is contained in:
Andrew McCreight 2016-07-21 09:54:17 -07:00
Родитель 4f63d0eaf2
Коммит a5a3cca3f9
2 изменённых файлов: 45 добавлений и 0 удалений

Просмотреть файл

@ -19,6 +19,7 @@ class nsCOMPtr_helper;
namespace mozilla {
template<class T> class OwningNonNull;
template<class T> class StaticRefPtr;
// Traditionally, RefPtr supports automatic refcounting of any pointer type
// with AddRef() and Release() methods that follow the traditional semantics.
@ -148,6 +149,10 @@ public:
template<class U>
MOZ_IMPLICIT RefPtr(const mozilla::OwningNonNull<U>& aOther);
// Defined in StaticPtr.h
template<class U>
MOZ_IMPLICIT RefPtr(const mozilla::StaticRefPtr<U>& aOther);
// Assignment operators
RefPtr<T>&
@ -208,6 +213,11 @@ public:
RefPtr<T>&
operator=(const mozilla::OwningNonNull<U>& aOther);
// Defined in StaticPtr.h
template<class U>
RefPtr<T>&
operator=(const mozilla::StaticRefPtr<U>& aOther);
// Other pointer operators
void

Просмотреть файл

@ -7,8 +7,10 @@
#ifndef mozilla_StaticPtr_h
#define mozilla_StaticPtr_h
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/RefPtr.h"
namespace mozilla {
@ -110,6 +112,26 @@ public:
return (this = aRhs.mRawPtr);
}
StaticRefPtr<T>& operator=(already_AddRefed<T>& aRhs)
{
AssignAssumingAddRef(aRhs.take());
return *this;
}
StaticRefPtr<T>& operator=(already_AddRefed<T>&& aRhs)
{
AssignAssumingAddRef(aRhs.take());
return *this;
}
already_AddRefed<T>
forget()
{
T* temp = mRawPtr;
mRawPtr = nullptr;
return already_AddRefed<T>(temp);
}
T* get() const { return mRawPtr; }
operator T*() const { return get(); }
@ -232,4 +254,17 @@ REFLEXIVE_EQUALITY_OPERATORS(const StaticRefPtr<T>&, StaticPtr_internal::Zero*,
} // namespace mozilla
// Declared in mozilla/RefPtr.h
template<class T> template<class U>
RefPtr<T>::RefPtr(const mozilla::StaticRefPtr<U>& aOther)
: RefPtr(aOther.get())
{}
template<class T> template<class U>
RefPtr<T>&
RefPtr<T>::operator=(const mozilla::StaticRefPtr<U>& aOther)
{
return operator=(aOther.get());
}
#endif