Bug 803688 - Remove LinkedListElements from their list when they're destructed, and assert that a LinkedList is empty when it's destructed. r=waldo, a=tef+

This commit is contained in:
Justin Lebar 2012-10-24 12:40:35 -04:00
Родитель 51dcb1ce60
Коммит f74e96d4ed
1 изменённых файлов: 10 добавлений и 2 удалений

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

@ -13,6 +13,10 @@
* LinkedListElement<T>. A given object may be in only one linked list at a
* time.
*
* A LinkedListElement automatically removes itself from the list upon
* destruction, and a LinkedList will fatally assert in debug builds if it's
* non-empty when it's destructed.
*
* For example, you might use LinkedList in a simple observer list class as
* follows.
*
@ -104,6 +108,11 @@ class LinkedListElement
public:
LinkedListElement() : next(this), prev(this), isSentinel(false) { }
~LinkedListElement() {
if (!isSentinel && isInList())
remove();
}
/*
* Get the next element in the list, or NULL if this is the last element in
* the list.
@ -178,8 +187,7 @@ class LinkedListElement
: next(this),
prev(this),
isSentinel(nodeKind == NODE_KIND_SENTINEL)
{
}
{ }
/*
* Return |this| cast to T* if we're a normal node, or return NULL if we're