2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsTObserverArray_h___
|
|
|
|
#define nsTObserverArray_h___
|
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
#include "nsTArray.h"
|
2012-11-14 23:32:39 -08:00
|
|
|
#include "nsCycleCollectionNoteChild.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-14 09:15:27 -08:00
|
|
|
/**
|
|
|
|
* An array of observers. Like a normal array, but supports iterators that are
|
|
|
|
* stable even if the array is modified during iteration.
|
|
|
|
* The template parameter T is the observer type the array will hold;
|
|
|
|
* N is the number of built-in storage slots that come with the array.
|
|
|
|
* NOTE: You probably want to use nsTObserverArray, unless you specifically
|
|
|
|
* want built-in storage. See below.
|
|
|
|
* @see nsTObserverArray, nsTArray
|
|
|
|
*/
|
|
|
|
|
2007-05-22 12:39:14 -07:00
|
|
|
class NS_COM_GLUE nsTObserverArray_base {
|
2007-12-21 17:06:43 -08:00
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
typedef uint32_t index_type;
|
|
|
|
typedef uint32_t size_type;
|
|
|
|
typedef int32_t diff_type;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-21 17:06:43 -08:00
|
|
|
protected:
|
2007-03-22 10:30:00 -07:00
|
|
|
class Iterator_base {
|
|
|
|
protected:
|
|
|
|
friend class nsTObserverArray_base;
|
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
Iterator_base(index_type aPosition, Iterator_base* aNext)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mPosition(aPosition),
|
2007-12-19 23:30:04 -08:00
|
|
|
mNext(aNext) {
|
2007-12-13 17:41:48 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// The current position of the iterator. Its exact meaning differs
|
|
|
|
// depending on iterator. See nsTObserverArray<T>::ForwardIterator.
|
|
|
|
index_type mPosition;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The next iterator currently iterating the same array
|
|
|
|
Iterator_base* mNext;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTObserverArray_base()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mIterators(nullptr) {
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-12-21 03:22:31 -08:00
|
|
|
~nsTObserverArray_base() {
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(mIterators == nullptr, "iterators outlasting array");
|
2007-12-21 03:22:31 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Adjusts iterators after an element has been inserted or removed
|
|
|
|
* from the array.
|
|
|
|
* @param modPos Position where elements were added or removed.
|
|
|
|
* @param adjustment -1 if an element was removed, 1 if an element was
|
|
|
|
* added.
|
|
|
|
*/
|
2007-12-19 23:30:04 -08:00
|
|
|
void AdjustIterators(index_type aModPos, diff_type aAdjustment);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears iterators when the array is destroyed.
|
|
|
|
*/
|
|
|
|
void ClearIterators();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-22 12:40:57 -07:00
|
|
|
mutable Iterator_base* mIterators;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
template<class T, uint32_t N>
|
2007-12-19 23:30:04 -08:00
|
|
|
class nsAutoTObserverArray : protected nsTObserverArray_base {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2007-12-19 23:30:04 -08:00
|
|
|
typedef T elem_type;
|
|
|
|
typedef nsTArray<T> array_type;
|
2007-12-13 17:41:48 -08:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
nsAutoTObserverArray() {
|
2007-12-18 22:03:05 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
//
|
|
|
|
// Accessor methods
|
|
|
|
//
|
|
|
|
|
|
|
|
// @return The number of elements in the array.
|
|
|
|
size_type Length() const {
|
|
|
|
return mArray.Length();
|
2007-12-18 22:03:05 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// @return True if the array is empty or false otherwise.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsEmpty() const {
|
2007-12-19 23:30:04 -08:00
|
|
|
return mArray.IsEmpty();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// This method provides direct access to the i'th element of the array.
|
2012-11-23 10:50:05 -08:00
|
|
|
// The given index must be within the array bounds. If the underlying array
|
|
|
|
// may change during iteration, use an iterator instead of this function.
|
2007-12-19 23:30:04 -08:00
|
|
|
// @param i The index of an element in the array.
|
|
|
|
// @return A reference to the i'th element of the array.
|
|
|
|
elem_type& ElementAt(index_type i) {
|
|
|
|
return mArray.ElementAt(i);
|
2007-12-13 17:41:48 -08:00
|
|
|
}
|
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// Same as above, but readonly.
|
|
|
|
const elem_type& ElementAt(index_type i) const {
|
|
|
|
return mArray.ElementAt(i);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// This method provides direct access to the i'th element of the array in
|
|
|
|
// a bounds safe manner. If the requested index is out of bounds the
|
|
|
|
// provided default value is returned.
|
|
|
|
// @param i The index of an element in the array.
|
|
|
|
// @param def The value to return if the index is out of bounds.
|
|
|
|
elem_type& SafeElementAt(index_type i, elem_type& def) {
|
|
|
|
return mArray.SafeElementAt(i, def);
|
|
|
|
}
|
2007-12-18 17:06:34 -08:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// Same as above, but readonly.
|
|
|
|
const elem_type& SafeElementAt(index_type i, const elem_type& def) const {
|
|
|
|
return mArray.SafeElementAt(i, def);
|
2007-12-18 17:06:34 -08:00
|
|
|
}
|
|
|
|
|
2012-11-23 10:50:05 -08:00
|
|
|
// No operator[] is provided because the point of this class is to support
|
|
|
|
// allow modifying the array during iteration, and ElementAt() is not safe
|
|
|
|
// in those conditions.
|
2012-11-02 17:57:05 -07:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
//
|
|
|
|
// Search methods
|
|
|
|
//
|
|
|
|
|
|
|
|
// This method searches, starting from the beginning of the array,
|
|
|
|
// for the first element in this array that is equal to the given element.
|
|
|
|
// 'operator==' must be defined for elem_type.
|
|
|
|
// @param item The item to search for.
|
2011-10-17 07:59:28 -07:00
|
|
|
// @return true if the element was found.
|
2007-12-19 23:30:04 -08:00
|
|
|
template<class Item>
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Contains(const Item& item) const {
|
2007-12-19 23:30:04 -08:00
|
|
|
return IndexOf(item) != array_type::NoIndex;
|
2007-12-18 17:06:34 -08:00
|
|
|
}
|
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// This method searches for the offset of the first element in this
|
|
|
|
// array that is equal to the given element.
|
|
|
|
// 'operator==' must be defined for elem_type.
|
|
|
|
// @param item The item to search for.
|
|
|
|
// @param start The index to start from.
|
|
|
|
// @return The index of the found element or NoIndex if not found.
|
|
|
|
template<class Item>
|
|
|
|
index_type IndexOf(const Item& item, index_type start = 0) const {
|
|
|
|
return mArray.IndexOf(item, start);
|
2007-12-18 22:03:05 -08:00
|
|
|
}
|
2007-12-18 17:06:34 -08:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
//
|
|
|
|
// Mutation methods
|
|
|
|
//
|
2012-06-29 01:32:21 -07:00
|
|
|
|
|
|
|
// Insert a given element at the given index.
|
|
|
|
// @param index The index at which to insert item.
|
|
|
|
// @param item The item to insert,
|
|
|
|
// @return A pointer to the newly inserted element, or a null on DOM
|
|
|
|
template<class Item>
|
|
|
|
elem_type *InsertElementAt(index_type aIndex, const Item& aItem) {
|
|
|
|
elem_type* item = mArray.InsertElementAt(aIndex, aItem);
|
|
|
|
AdjustIterators(aIndex, 1);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above but without copy constructing.
|
|
|
|
// This is useful to avoid temporaries.
|
|
|
|
elem_type* InsertElementAt(index_type aIndex) {
|
|
|
|
elem_type* item = mArray.InsertElementAt(aIndex);
|
|
|
|
AdjustIterators(aIndex, 1);
|
|
|
|
return item;
|
|
|
|
}
|
2007-12-19 23:30:04 -08:00
|
|
|
|
|
|
|
// Prepend an element to the array unless it already exists in the array.
|
|
|
|
// 'operator==' must be defined for elem_type.
|
|
|
|
// @param item The item to prepend.
|
2011-10-17 07:59:28 -07:00
|
|
|
// @return true if the element was found, or inserted successfully.
|
2007-12-19 23:30:04 -08:00
|
|
|
template<class Item>
|
2011-09-28 23:19:26 -07:00
|
|
|
bool PrependElementUnlessExists(const Item& item) {
|
2012-06-29 01:32:21 -07:00
|
|
|
if (Contains(item)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
bool inserted = mArray.InsertElementAt(0, item) != nullptr;
|
2012-06-29 01:32:21 -07:00
|
|
|
AdjustIterators(0, 1);
|
|
|
|
return inserted;
|
2007-12-18 22:03:05 -08:00
|
|
|
}
|
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// Append an element to the array.
|
|
|
|
// @param item The item to append.
|
|
|
|
// @return A pointer to the newly appended element, or null on OOM.
|
|
|
|
template<class Item>
|
|
|
|
elem_type* AppendElement(const Item& item) {
|
|
|
|
return mArray.AppendElement(item);
|
2007-12-18 22:03:05 -08:00
|
|
|
}
|
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// Same as above, but without copy-constructing. This is useful to avoid
|
|
|
|
// temporaries.
|
|
|
|
elem_type* AppendElement() {
|
|
|
|
return mArray.AppendElement();
|
2007-12-18 22:03:05 -08:00
|
|
|
}
|
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// Append an element to the array unless it already exists in the array.
|
|
|
|
// 'operator==' must be defined for elem_type.
|
|
|
|
// @param item The item to append.
|
2011-10-17 07:59:28 -07:00
|
|
|
// @return true if the element was found, or inserted successfully.
|
2007-12-19 23:30:04 -08:00
|
|
|
template<class Item>
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AppendElementUnlessExists(const Item& item) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return Contains(item) || AppendElement(item) != nullptr;
|
2007-12-19 23:30:04 -08:00
|
|
|
}
|
2007-12-18 22:03:05 -08:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// Remove an element from the array.
|
|
|
|
// @param index The index of the item to remove.
|
|
|
|
void RemoveElementAt(index_type index) {
|
|
|
|
NS_ASSERTION(index < mArray.Length(), "invalid index");
|
|
|
|
mArray.RemoveElementAt(index);
|
|
|
|
AdjustIterators(index, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This helper function combines IndexOf with RemoveElementAt to "search
|
|
|
|
// and destroy" the first element that is equal to the given element.
|
|
|
|
// 'operator==' must be defined for elem_type.
|
|
|
|
// @param item The item to search for.
|
2011-10-17 07:59:28 -07:00
|
|
|
// @return true if the element was found and removed.
|
2007-12-19 23:30:04 -08:00
|
|
|
template<class Item>
|
2011-09-28 23:19:26 -07:00
|
|
|
bool RemoveElement(const Item& item) {
|
2007-12-19 23:30:04 -08:00
|
|
|
index_type index = mArray.IndexOf(item, 0);
|
|
|
|
if (index == array_type::NoIndex)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-12-19 23:30:04 -08:00
|
|
|
|
|
|
|
mArray.RemoveElementAt(index);
|
|
|
|
AdjustIterators(index, -1);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-12-19 23:30:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Removes all observers and collapses all iterators to the beginning of
|
|
|
|
// the array. The result is that forward iterators will see all elements
|
|
|
|
// in the array.
|
|
|
|
void Clear() {
|
|
|
|
mArray.Clear();
|
|
|
|
ClearIterators();
|
|
|
|
}
|
|
|
|
|
2011-09-14 17:37:45 -07:00
|
|
|
// Returns the number of bytes on the heap taken up by this object, not
|
|
|
|
// including sizeof(*this).
|
2012-02-01 13:58:01 -08:00
|
|
|
size_t SizeOfExcludingThis(nsMallocSizeOfFun mallocSizeOf) const {
|
2011-12-15 14:59:53 -08:00
|
|
|
return mArray.SizeOfExcludingThis(mallocSizeOf);
|
2011-09-14 17:37:45 -07:00
|
|
|
}
|
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
//
|
|
|
|
// Iterators
|
|
|
|
//
|
|
|
|
|
|
|
|
// Base class for iterators. Do not use this directly.
|
|
|
|
class Iterator : public Iterator_base {
|
|
|
|
protected:
|
|
|
|
friend class nsAutoTObserverArray;
|
|
|
|
typedef nsAutoTObserverArray<T, N> array_type;
|
|
|
|
|
|
|
|
Iterator(index_type aPosition, const array_type& aArray)
|
|
|
|
: Iterator_base(aPosition, aArray.mIterators),
|
|
|
|
mArray(const_cast<array_type&>(aArray)) {
|
|
|
|
aArray.mIterators = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
~Iterator() {
|
|
|
|
NS_ASSERTION(mArray.mIterators == this,
|
|
|
|
"Iterators must currently be destroyed in opposite order "
|
|
|
|
"from the construction order. It is suggested that you "
|
|
|
|
"simply put them on the stack");
|
|
|
|
mArray.mIterators = mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The array we're iterating
|
|
|
|
array_type& mArray;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Iterates the array forward from beginning to end. mPosition points
|
|
|
|
// to the element that will be returned on next call to GetNext.
|
|
|
|
// Elements:
|
|
|
|
// - prepended to the array during iteration *will not* be traversed
|
|
|
|
// - appended during iteration *will* be traversed
|
|
|
|
// - removed during iteration *will not* be traversed.
|
|
|
|
// @see EndLimitedIterator
|
|
|
|
class ForwardIterator : protected Iterator {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2007-12-19 23:30:04 -08:00
|
|
|
typedef nsAutoTObserverArray<T, N> array_type;
|
|
|
|
typedef Iterator base_type;
|
|
|
|
|
|
|
|
ForwardIterator(const array_type& aArray)
|
|
|
|
: Iterator(0, aArray) {
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-12-19 23:30:04 -08:00
|
|
|
|
|
|
|
ForwardIterator(const array_type& aArray, index_type aPos)
|
|
|
|
: Iterator(aPos, aArray) {
|
2007-12-13 17:41:48 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool operator <(const ForwardIterator& aOther) const {
|
2007-12-19 23:30:04 -08:00
|
|
|
NS_ASSERTION(&this->mArray == &aOther.mArray,
|
2007-12-13 17:41:48 -08:00
|
|
|
"not iterating the same array");
|
2007-12-19 23:30:04 -08:00
|
|
|
return base_type::mPosition < aOther.mPosition;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// Returns true if there are more elements to iterate.
|
|
|
|
// This must precede a call to GetNext(). If false is
|
2007-12-19 23:30:04 -08:00
|
|
|
// returned, GetNext() must not be called.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasMore() const {
|
2007-12-19 23:30:04 -08:00
|
|
|
return base_type::mPosition < base_type::mArray.Length();
|
2007-12-13 17:41:48 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// Returns the next element and steps one step. This must
|
|
|
|
// be preceded by a call to HasMore().
|
|
|
|
// @return The next observer.
|
|
|
|
elem_type& GetNext() {
|
|
|
|
NS_ASSERTION(HasMore(), "iterating beyond end of array");
|
|
|
|
return base_type::mArray.ElementAt(base_type::mPosition++);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
2007-12-13 17:41:48 -08:00
|
|
|
|
|
|
|
// EndLimitedIterator works like ForwardIterator, but will not iterate new
|
2007-12-19 23:30:04 -08:00
|
|
|
// observers appended to the array after the iterator was created.
|
|
|
|
class EndLimitedIterator : protected ForwardIterator {
|
2007-12-13 17:41:48 -08:00
|
|
|
public:
|
2007-12-19 23:30:04 -08:00
|
|
|
typedef nsAutoTObserverArray<T, N> array_type;
|
|
|
|
typedef Iterator base_type;
|
2007-12-13 17:41:48 -08:00
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
EndLimitedIterator(const array_type& aArray)
|
2007-12-13 17:41:48 -08:00
|
|
|
: ForwardIterator(aArray),
|
2007-12-19 23:30:04 -08:00
|
|
|
mEnd(aArray, aArray.Length()) {
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// Returns true if there are more elements to iterate.
|
|
|
|
// This must precede a call to GetNext(). If false is
|
2007-12-19 23:30:04 -08:00
|
|
|
// returned, GetNext() must not be called.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasMore() const {
|
2007-12-19 23:30:04 -08:00
|
|
|
return *this < mEnd;
|
2007-12-13 17:41:48 -08:00
|
|
|
}
|
|
|
|
|
2007-12-19 23:30:04 -08:00
|
|
|
// Returns the next element and steps one step. This must
|
|
|
|
// be preceded by a call to HasMore().
|
|
|
|
// @return The next observer.
|
|
|
|
elem_type& GetNext() {
|
|
|
|
NS_ASSERTION(HasMore(), "iterating beyond end of array");
|
|
|
|
return base_type::mArray.ElementAt(base_type::mPosition++);
|
2007-12-13 17:41:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ForwardIterator mEnd;
|
|
|
|
};
|
2007-12-19 23:30:04 -08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsAutoTArray<T, N> mArray;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
class nsTObserverArray : public nsAutoTObserverArray<T, 0> {
|
|
|
|
public:
|
|
|
|
typedef nsAutoTObserverArray<T, 0> base_type;
|
|
|
|
typedef nsTObserverArray_base::size_type size_type;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialization methods
|
|
|
|
//
|
|
|
|
|
|
|
|
nsTObserverArray() {}
|
|
|
|
|
|
|
|
// Initialize this array and pre-allocate some number of elements.
|
|
|
|
explicit nsTObserverArray(size_type capacity) {
|
|
|
|
base_type::mArray.SetCapacity(capacity);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-11-23 11:13:39 -08:00
|
|
|
template <typename T, uint32_t N>
|
2012-11-14 23:32:39 -08:00
|
|
|
inline void
|
2012-11-23 11:13:39 -08:00
|
|
|
ImplCycleCollectionUnlink(nsAutoTObserverArray<T, N>& aField)
|
2012-11-14 23:32:39 -08:00
|
|
|
{
|
|
|
|
aField.Clear();
|
|
|
|
}
|
|
|
|
|
2012-11-23 11:13:39 -08:00
|
|
|
template <typename T, uint32_t N>
|
2012-11-14 23:32:39 -08:00
|
|
|
inline void
|
|
|
|
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
2012-11-23 11:13:39 -08:00
|
|
|
nsAutoTObserverArray<T, N>& aField,
|
2012-11-14 23:32:39 -08:00
|
|
|
const char* aName,
|
|
|
|
uint32_t aFlags = 0)
|
|
|
|
{
|
|
|
|
aFlags |= CycleCollectionEdgeNameArrayFlag;
|
|
|
|
size_t length = aField.Length();
|
|
|
|
for (size_t i = 0; i < length; ++i) {
|
2012-11-23 10:50:05 -08:00
|
|
|
ImplCycleCollectionTraverse(aCallback, aField.ElementAt(i), aName, aFlags);
|
2012-11-14 23:32:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXXbz I wish I didn't have to pass in the observer type, but I
|
|
|
|
// don't see a way to get it out of array_.
|
2007-12-19 23:30:04 -08:00
|
|
|
// Note that this macro only works if the array holds pointers to XPCOM objects.
|
2010-07-21 08:33:31 -07:00
|
|
|
#define NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(array_, obstype_, func_, params_) \
|
2007-03-22 10:30:00 -07:00
|
|
|
PR_BEGIN_MACRO \
|
2007-12-19 23:30:04 -08:00
|
|
|
nsTObserverArray<obstype_ *>::ForwardIterator iter_(array_); \
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<obstype_> obs_; \
|
2007-12-19 23:30:04 -08:00
|
|
|
while (iter_.HasMore()) { \
|
|
|
|
obs_ = iter_.GetNext(); \
|
2007-03-22 10:30:00 -07:00
|
|
|
obs_ -> func_ params_ ; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2010-07-21 08:33:31 -07:00
|
|
|
// Note that this macro only works if the array holds pointers to XPCOM objects.
|
|
|
|
#define NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(array_, obstype_, func_, params_) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
nsTObserverArray<obstype_ *>::ForwardIterator iter_(array_); \
|
|
|
|
obstype_* obs_; \
|
|
|
|
while (iter_.HasMore()) { \
|
|
|
|
obs_ = iter_.GetNext(); \
|
|
|
|
obs_ -> func_ params_ ; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // nsTObserverArray_h___
|