forked from mirrors/gecko-dev
Bug 1121269 - Add an AutoCleanLinkedList template that removes and deletes elements upon destruction. r=Waldo
This commit is contained in:
parent
693a41b39b
commit
c18398b98d
1 changed files with 16 additions and 0 deletions
|
|
@ -55,6 +55,10 @@
|
||||||
* }
|
* }
|
||||||
* };
|
* };
|
||||||
*
|
*
|
||||||
|
* Additionally, the class AutoCleanLinkedList<T> is a LinkedList<T> that will
|
||||||
|
* remove and delete each element still within itself upon destruction. Note
|
||||||
|
* that because each element is deleted, elements must have been allocated
|
||||||
|
* using |new|.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef mozilla_LinkedList_h
|
#ifndef mozilla_LinkedList_h
|
||||||
|
|
@ -478,6 +482,18 @@ private:
|
||||||
LinkedList(const LinkedList<T>& aOther) = delete;
|
LinkedList(const LinkedList<T>& aOther) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class AutoCleanLinkedList : public LinkedList<T>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~AutoCleanLinkedList()
|
||||||
|
{
|
||||||
|
while (T* element = this->popFirst()) {
|
||||||
|
delete element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} /* namespace mozilla */
|
} /* namespace mozilla */
|
||||||
|
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue