Bug 1229985 - remove nsAutoArrayPtr; r=erahm

This commit is contained in:
Nathan Froyd 2015-12-06 10:51:43 -05:00
parent 713785ea79
commit 49a6985c41
2 changed files with 0 additions and 426 deletions

View File

@ -449,354 +449,6 @@ operator!=(decltype(nullptr), const nsAutoPtr<T>& aRhs)
}
/*****************************************************************************/
// template <class T> class nsAutoArrayPtrGetterTransfers;
template <class T>
class nsAutoArrayPtr
{
private:
void**
begin_assignment()
{
assign(0);
return reinterpret_cast<void**>(&mRawPtr);
}
void
assign(T* aNewPtr)
{
T* oldPtr = mRawPtr;
mRawPtr = aNewPtr;
delete [] oldPtr;
}
private:
T* MOZ_OWNING_REF mRawPtr;
public:
typedef T element_type;
~nsAutoArrayPtr()
{
delete [] mRawPtr;
}
// Constructors
nsAutoArrayPtr()
: mRawPtr(0)
// default constructor
{
}
MOZ_IMPLICIT nsAutoArrayPtr(T* aRawPtr)
: mRawPtr(aRawPtr)
// construct from a raw pointer (of the right type)
{
}
nsAutoArrayPtr(nsAutoArrayPtr<T>& aSmartPtr)
: mRawPtr(aSmartPtr.forget())
// Construct by transferring ownership from another smart pointer.
{
}
// Assignment operators
nsAutoArrayPtr<T>&
operator=(T* aRhs)
// assign from a raw pointer (of the right type)
{
assign(aRhs);
return *this;
}
nsAutoArrayPtr<T>& operator=(nsAutoArrayPtr<T>& aRhs)
// assign by transferring ownership from another smart pointer.
{
assign(aRhs.forget());
return *this;
}
// Other pointer operators
T*
get() const
/*
Prefer the implicit conversion provided automatically by
|operator T*() const|. Use |get()| _only_ to resolve
ambiguity.
*/
{
return mRawPtr;
}
operator T*() const
/*
...makes an |nsAutoArrayPtr| act like its underlying raw pointer
type whenever it is used in a context where a raw pointer
is expected. It is this operator that makes an |nsAutoArrayPtr|
substitutable for a raw pointer.
Prefer the implicit use of this operator to calling |get()|,
except where necessary to resolve ambiguity.
*/
{
return get();
}
T*
forget()
{
T* temp = mRawPtr;
mRawPtr = 0;
return temp;
}
T*
operator->() const
{
NS_PRECONDITION(mRawPtr != 0,
"You can't dereference a NULL nsAutoArrayPtr with operator->().");
return get();
}
nsAutoArrayPtr<T>*
get_address()
// This is not intended to be used by clients. See |address_of|
// below.
{
return this;
}
const nsAutoArrayPtr<T>*
get_address() const
// This is not intended to be used by clients. See |address_of|
// below.
{
return this;
}
public:
T&
operator*() const
{
NS_PRECONDITION(mRawPtr != 0,
"You can't dereference a NULL nsAutoArrayPtr with operator*().");
return *get();
}
T**
StartAssignment()
{
#ifndef NSCAP_FEATURE_INLINE_STARTASSIGNMENT
return reinterpret_cast<T**>(begin_assignment());
#else
assign(0);
return reinterpret_cast<T**>(&mRawPtr);
#endif
}
size_t
SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return aMallocSizeOf(mRawPtr);
}
size_t
SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}
};
template <class T>
inline nsAutoArrayPtr<T>*
address_of(nsAutoArrayPtr<T>& aPtr)
{
return aPtr.get_address();
}
template <class T>
inline const nsAutoArrayPtr<T>*
address_of(const nsAutoArrayPtr<T>& aPtr)
{
return aPtr.get_address();
}
template <class T>
class nsAutoArrayPtrGetterTransfers
/*
...
This class is designed to be used for anonymous temporary objects in the
argument list of calls that return COM interface pointers, e.g.,
nsAutoArrayPtr<IFoo> fooP;
...->GetTransferedPointer(getter_Transfers(fooP))
DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. Use |getter_Transfers()| instead.
When initialized with a |nsAutoArrayPtr|, as in the example above, it returns
a |void**|, a |T**|, or an |nsISupports**| as needed, that the
outer call (|GetTransferedPointer| in this case) can fill in.
This type should be a nested class inside |nsAutoArrayPtr<T>|.
*/
{
public:
explicit
nsAutoArrayPtrGetterTransfers(nsAutoArrayPtr<T>& aSmartPtr)
: mTargetSmartPtr(aSmartPtr)
{
// nothing else to do
}
operator void**()
{
return reinterpret_cast<void**>(mTargetSmartPtr.StartAssignment());
}
operator T**()
{
return mTargetSmartPtr.StartAssignment();
}
T*&
operator*()
{
return *(mTargetSmartPtr.StartAssignment());
}
private:
nsAutoArrayPtr<T>& mTargetSmartPtr;
};
template <class T>
inline nsAutoArrayPtrGetterTransfers<T>
getter_Transfers(nsAutoArrayPtr<T>& aSmartPtr)
/*
Used around a |nsAutoArrayPtr| when
...makes the class |nsAutoArrayPtrGetterTransfers<T>| invisible.
*/
{
return nsAutoArrayPtrGetterTransfers<T>(aSmartPtr);
}
// Comparing two |nsAutoArrayPtr|s
template <class T, class U>
inline bool
operator==(const nsAutoArrayPtr<T>& aLhs, const nsAutoArrayPtr<U>& aRhs)
{
return static_cast<const T*>(aLhs.get()) == static_cast<const U*>(aRhs.get());
}
template <class T, class U>
inline bool
operator!=(const nsAutoArrayPtr<T>& aLhs, const nsAutoArrayPtr<U>& aRhs)
{
return static_cast<const T*>(aLhs.get()) != static_cast<const U*>(aRhs.get());
}
// Comparing an |nsAutoArrayPtr| to a raw pointer
template <class T, class U>
inline bool
operator==(const nsAutoArrayPtr<T>& aLhs, const U* aRhs)
{
return static_cast<const T*>(aLhs.get()) == static_cast<const U*>(aRhs);
}
template <class T, class U>
inline bool
operator==(const U* aLhs, const nsAutoArrayPtr<T>& aRhs)
{
return static_cast<const U*>(aLhs) == static_cast<const T*>(aRhs.get());
}
template <class T, class U>
inline bool
operator!=(const nsAutoArrayPtr<T>& aLhs, const U* aRhs)
{
return static_cast<const T*>(aLhs.get()) != static_cast<const U*>(aRhs);
}
template <class T, class U>
inline bool
operator!=(const U* aLhs, const nsAutoArrayPtr<T>& aRhs)
{
return static_cast<const U*>(aLhs) != static_cast<const T*>(aRhs.get());
}
template <class T, class U>
inline bool
operator==(const nsAutoArrayPtr<T>& aLhs, U* aRhs)
{
return static_cast<const T*>(aLhs.get()) == const_cast<const U*>(aRhs);
}
template <class T, class U>
inline bool
operator==(U* aLhs, const nsAutoArrayPtr<T>& aRhs)
{
return const_cast<const U*>(aLhs) == static_cast<const T*>(aRhs.get());
}
template <class T, class U>
inline bool
operator!=(const nsAutoArrayPtr<T>& aLhs, U* aRhs)
{
return static_cast<const T*>(aLhs.get()) != const_cast<const U*>(aRhs);
}
template <class T, class U>
inline bool
operator!=(U* aLhs, const nsAutoArrayPtr<T>& aRhs)
{
return const_cast<const U*>(aLhs) != static_cast<const T*>(aRhs.get());
}
// Comparing an |nsAutoArrayPtr| to |nullptr|
template <class T>
inline bool
operator==(const nsAutoArrayPtr<T>& aLhs, decltype(nullptr))
{
return aLhs.get() == nullptr;
}
template <class T>
inline bool
operator==(decltype(nullptr), const nsAutoArrayPtr<T>& aRhs)
{
return nullptr == aRhs.get();
}
template <class T>
inline bool
operator!=(const nsAutoArrayPtr<T>& aLhs, decltype(nullptr))
{
return aLhs.get() != nullptr;
}
template <class T>
inline bool
operator!=(decltype(nullptr), const nsAutoArrayPtr<T>& aRhs)
{
return nullptr != aRhs.get();
}
/*****************************************************************************/
#endif // !defined(nsAutoPtr_h)

View File

@ -183,14 +183,6 @@ int main()
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create 3 |TestObject|s:\n");
nsAutoArrayPtr<TestObject> pobj( new TestObject[3] );
printf("Should create 5 |TestObject|s and then destroy 3:\n");
pobj = new TestObject[5];
printf("Should destroy 5 |TestObject|s:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj( new TestRefObject() );
@ -381,14 +373,6 @@ int main()
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create 3 |TestObject|s:\n");
nsAutoArrayPtr<TestObject> pobj( new TestObject[3] );
printf("Should do nothing:\n");
nsAutoArrayPtr<TestObject> pobj2( pobj.forget() );
printf("Should destroy 3 |TestObject|s:\n");
}
{
printf("Should create one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj( new TestRefObject() );
@ -405,12 +389,6 @@ int main()
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create 3 |TestObject|s:\n");
nsAutoArrayPtr<TestObject> pobj(new TestObject[3]);
printf("Should destroy 3 |TestObject|s:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj = new TestRefObject();
@ -429,20 +407,6 @@ int main()
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create 3 |TestObject|s:\n");
nsAutoArrayPtr<TestObject> pobj(new TestObject[3]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObject(&pobj[2]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObject(&pobj[1]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObject(pobj + 2);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObject(pobj + 1);
printf("Should destroy 3 |TestObject|s:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj = new TestRefObject();
@ -463,20 +427,6 @@ int main()
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create 3 |TestObject|s:\n");
nsAutoArrayPtr<TestObject> pobj(new TestObject[3]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObjectBaseB(&pobj[2]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObjectBaseB(&pobj[1]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObjectBaseB(pobj + 2);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObjectBaseB(pobj + 1);
printf("Should destroy 3 |TestObject|s:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj = new TestRefObject();
@ -497,20 +447,6 @@ int main()
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create 3 |TestObject|s:\n");
const nsAutoArrayPtr<TestObject> pobj(new TestObject[3]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObject(&pobj[2]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObject(&pobj[1]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObject(pobj + 2);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObject(pobj + 1);
printf("Should destroy 3 |TestObject|s:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
const RefPtr<TestRefObject> pobj = new TestRefObject();
@ -531,20 +467,6 @@ int main()
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create 3 |TestObject|s:\n");
const nsAutoArrayPtr<TestObject> pobj(new TestObject[3]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObjectBaseB(&pobj[2]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObjectBaseB(&pobj[1]);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObjectBaseB(pobj + 2);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObjectBaseB(pobj + 1);
printf("Should destroy 3 |TestObject|s:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
const RefPtr<TestRefObject> pobj = new TestRefObject();