mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 17:59:34 +00:00
Bug 1161627 - part 3 - remove TemporaryRef<T> from RefPtr.h; r=ehsan
This commit is contained in:
parent
974d8120f2
commit
a2f2f68970
@ -30,7 +30,6 @@ namespace mozilla {
|
|||||||
|
|
||||||
template<typename T> class RefCounted;
|
template<typename T> class RefCounted;
|
||||||
template<typename T> class RefPtr;
|
template<typename T> class RefPtr;
|
||||||
template<typename T> class TemporaryRef;
|
|
||||||
template<typename T> class OutParamRef;
|
template<typename T> class OutParamRef;
|
||||||
template<typename T> OutParamRef<T> byRef(RefPtr<T>&);
|
template<typename T> OutParamRef<T> byRef(RefPtr<T>&);
|
||||||
|
|
||||||
@ -227,7 +226,6 @@ template<typename T>
|
|||||||
class RefPtr
|
class RefPtr
|
||||||
{
|
{
|
||||||
// To allow them to use unref()
|
// To allow them to use unref()
|
||||||
friend class TemporaryRef<T>;
|
|
||||||
friend class OutParamRef<T>;
|
friend class OutParamRef<T>;
|
||||||
|
|
||||||
struct DontRef {};
|
struct DontRef {};
|
||||||
@ -235,7 +233,6 @@ class RefPtr
|
|||||||
public:
|
public:
|
||||||
RefPtr() : mPtr(0) {}
|
RefPtr() : mPtr(0) {}
|
||||||
RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {}
|
RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {}
|
||||||
MOZ_IMPLICIT RefPtr(const TemporaryRef<T>& aOther) : mPtr(aOther.take()) {}
|
|
||||||
MOZ_IMPLICIT RefPtr(already_AddRefed<T>& aOther) : mPtr(aOther.take()) {}
|
MOZ_IMPLICIT RefPtr(already_AddRefed<T>& aOther) : mPtr(aOther.take()) {}
|
||||||
MOZ_IMPLICIT RefPtr(already_AddRefed<T>&& aOther) : mPtr(aOther.take()) {}
|
MOZ_IMPLICIT RefPtr(already_AddRefed<T>&& aOther) : mPtr(aOther.take()) {}
|
||||||
MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {}
|
MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {}
|
||||||
@ -250,11 +247,6 @@ public:
|
|||||||
assign(ref(aOther.mPtr));
|
assign(ref(aOther.mPtr));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
RefPtr& operator=(const TemporaryRef<T>& aOther)
|
|
||||||
{
|
|
||||||
assign(aOther.take());
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
RefPtr& operator=(already_AddRefed<T>& aOther)
|
RefPtr& operator=(already_AddRefed<T>& aOther)
|
||||||
{
|
{
|
||||||
assign(aOther.take());
|
assign(aOther.take());
|
||||||
@ -315,50 +307,6 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* TemporaryRef<T> represents an object that holds a temporary
|
|
||||||
* reference to a T. TemporaryRef objects can't be manually ref'd or
|
|
||||||
* unref'd (being temporaries, not lvalues), so can only relinquish
|
|
||||||
* references to other objects, or unref on destruction.
|
|
||||||
*/
|
|
||||||
template<typename T>
|
|
||||||
class TemporaryRef
|
|
||||||
{
|
|
||||||
// To allow it to construct TemporaryRef from a bare T*
|
|
||||||
friend class RefPtr<T>;
|
|
||||||
|
|
||||||
typedef typename RefPtr<T>::DontRef DontRef;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Please see already_AddRefed for a description of what these constructors
|
|
||||||
// do.
|
|
||||||
TemporaryRef() : mPtr(nullptr) {}
|
|
||||||
typedef void (TemporaryRef::* MatchNullptr)(double, float);
|
|
||||||
MOZ_IMPLICIT TemporaryRef(MatchNullptr aRawPtr) : mPtr(nullptr) {}
|
|
||||||
explicit TemporaryRef(T* aVal) : mPtr(RefPtr<T>::ref(aVal)) {}
|
|
||||||
|
|
||||||
TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.take()) {}
|
|
||||||
|
|
||||||
template<typename U>
|
|
||||||
TemporaryRef(const TemporaryRef<U>& aOther) : mPtr(aOther.take()) {}
|
|
||||||
|
|
||||||
~TemporaryRef() { RefPtr<T>::unref(mPtr); }
|
|
||||||
|
|
||||||
MOZ_WARN_UNUSED_RESULT T* take() const
|
|
||||||
{
|
|
||||||
T* tmp = mPtr;
|
|
||||||
mPtr = nullptr;
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {}
|
|
||||||
|
|
||||||
mutable T* MOZ_OWNING_REF mPtr;
|
|
||||||
|
|
||||||
void operator=(const TemporaryRef&) = delete;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OutParamRef is a wrapper that tracks a refcounted pointer passed as
|
* OutParamRef is a wrapper that tracks a refcounted pointer passed as
|
||||||
* an outparam argument to a function. OutParamRef implements COM T**
|
* an outparam argument to a function. OutParamRef implements COM T**
|
||||||
@ -369,7 +317,7 @@ private:
|
|||||||
* returns the same T* passed to it through the T** outparam, as long
|
* returns the same T* passed to it through the T** outparam, as long
|
||||||
* as the callee obeys the COM discipline.
|
* as the callee obeys the COM discipline.
|
||||||
*
|
*
|
||||||
* Prefer returning TemporaryRef<T> from functions over creating T**
|
* Prefer returning already_AddRefed<T> from functions over creating T**
|
||||||
* outparams and passing OutParamRef<T> to T**. Prefer RefPtr<T>*
|
* outparams and passing OutParamRef<T> to T**. Prefer RefPtr<T>*
|
||||||
* outparams over T** outparams.
|
* outparams over T** outparams.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user