Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Protected Member Functions
nsTArray< E > Class Template Reference

#include <nsTArray.h>

Inheritance diagram for nsTArray< E >:
Inheritance graph
[legend]
Collaboration diagram for nsTArray< E >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef E elem_type
typedef nsTArray< Eself_type
typedef nsTArrayElementTraits< Eelem_traits

Public Member Functions

 ~nsTArray ()
 nsTArray ()
 nsTArray (size_type capacity)
 nsTArray (const self_type &other)
nsTArrayoperator= (const self_type &other)
elem_typeElements ()
const elem_typeElements () const
elem_typeElementAt (index_type i)
const elem_typeElementAt (index_type i) const
elem_typeoperator[] (index_type i)
const elem_typeoperator[] (index_type i) const
template<class Item , class Comparator >
index_type IndexOf (const Item &item, index_type start, const Comparator &comp) const
template<class Item >
index_type IndexOf (const Item &item, index_type start=0) const
template<class Item , class Comparator >
index_type LastIndexOf (const Item &item, index_type start, const Comparator &comp) const
template<class Item >
index_type LastIndexOf (const Item &item, index_type start=NoIndex) const
template<class Item >
elem_typeReplaceElementsAt (index_type start, size_type count, const Item *array, size_type arrayLen)
template<class Item >
elem_typeReplaceElementsAt (index_type start, size_type count, const nsTArray< Item > &array)
template<class Item >
elem_typeReplaceElementsAt (index_type start, size_type count, const Item &item)
template<class Item >
elem_typeInsertElementsAt (index_type index, const Item *array, size_type arrayLen)
template<class Item >
elem_typeInsertElementsAt (index_type index, const nsTArray< Item > &array)
template<class Item >
elem_typeInsertElementAt (index_type index, const Item &item)
elem_typeInsertElementAt (index_type index)
template<class Item >
elem_typeAppendElements (const Item *array, size_type arrayLen)
template<class Item >
elem_typeAppendElements (const nsTArray< Item > &array)
template<class Item >
elem_typeAppendElement (const Item &item)
elem_typeAppendElement ()
void RemoveElementsAt (index_type start, size_type count)
void RemoveElementAt (index_type index)
void Clear ()
template<class Item , class Comparator >
void RemoveElement (const Item &item, const Comparator &comp)
template<class Item >
void RemoveElement (const Item &item)
void SetCapacity (size_type capacity)
PRBool SetLength (size_type newLen)
void Compact ()
template<class Comparator >
void Sort (const Comparator &comp)
void Sort ()

Protected Member Functions

void DestructRange (index_type start, size_type count)
template<class Item >
void AssignRange (index_type start, size_type count, const Item *values)

Detailed Description

template<class E>
class nsTArray< E >

Returns:
True if the elements are equals; false otherwise.
True if (a < b); false otherwise.

Definition at line 205 of file nsTArray.h.


Member Typedef Documentation

template<class E>
typedef nsTArrayElementTraits<E> nsTArray< E >::elem_traits

Definition at line 209 of file nsTArray.h.

template<class E>
typedef E nsTArray< E >::elem_type

Definition at line 207 of file nsTArray.h.

template<class E>
typedef nsTArray<E> nsTArray< E >::self_type

Definition at line 208 of file nsTArray.h.


Constructor & Destructor Documentation

template<class E>
nsTArray< E >::~nsTArray ( ) [inline]

Definition at line 215 of file nsTArray.h.

{ Clear(); }
template<class E>
nsTArray< E >::nsTArray ( ) [inline]

Definition at line 221 of file nsTArray.h.

{}
template<class E>
nsTArray< E >::nsTArray ( size_type  capacity) [inline, explicit]

Definition at line 224 of file nsTArray.h.

template<class E>
nsTArray< E >::nsTArray ( const self_type other) [inline]

Definition at line 230 of file nsTArray.h.

                                     {
      AppendElements(other);
    }

Member Function Documentation

template<class E>
template<class Item >
elem_type* nsTArray< E >::AppendElement ( const Item &  item) [inline]

Definition at line 447 of file nsTArray.h.

                                               {
      return AppendElements(&item, 1);
    }

Here is the caller graph for this function:

template<class E>
elem_type* nsTArray< E >::AppendElement ( ) [inline]

Definition at line 454 of file nsTArray.h.

                               {
      if (!EnsureCapacity(Length() + 1, sizeof(elem_type)))
         return nsnull;
      elem_type *elem = Elements() + Length();
      elem_traits::Construct(elem);
      IncrementLength(1);
      return elem;
    }
template<class E>
template<class Item >
elem_type* nsTArray< E >::AppendElements ( const Item *  array,
size_type  arrayLen 
) [inline]

Definition at line 430 of file nsTArray.h.

                                                                     {
      if (!EnsureCapacity(Length() + arrayLen, sizeof(elem_type)))
        return nsnull;
      index_type len = Length();
      AssignRange(len, arrayLen, array);
      IncrementLength(arrayLen);
      return Elements() + len;
    }

Here is the caller graph for this function:

template<class E>
template<class Item >
elem_type* nsTArray< E >::AppendElements ( const nsTArray< Item > &  array) [inline]

Definition at line 441 of file nsTArray.h.

                                                           {
      return AppendElements(array.Elements(), array.Length());
    }
template<class E>
template<class Item >
void nsTArray< E >::AssignRange ( index_type  start,
size_type  count,
const Item *  values 
) [inline, protected]

Definition at line 579 of file nsTArray.h.

                                         {
      elem_type *iter = Elements() + start, *end = iter + count;
      for (; iter != end; ++iter, ++values) {
        elem_traits::Construct(iter, *values);
      }
    }

Here is the caller graph for this function:

template<class E>
void nsTArray< E >::Clear ( void  ) [inline]

Definition at line 477 of file nsTArray.h.

                 {
      RemoveElementsAt(0, Length());
    }

Here is the caller graph for this function:

template<class E>
void nsTArray< E >::Compact ( void  ) [inline]

Definition at line 538 of file nsTArray.h.

                   {
      ShrinkCapacity(sizeof(elem_type));
    }

Here is the caller graph for this function:

template<class E>
void nsTArray< E >::DestructRange ( index_type  start,
size_type  count 
) [inline, protected]

Definition at line 567 of file nsTArray.h.

                                                          {
      elem_type *iter = Elements() + start, *end = iter + count;
      for (; iter != end; ++iter) {
        elem_traits::Destruct(iter);
      }
    }

Here is the caller graph for this function:

template<class E>
elem_type& nsTArray< E >::ElementAt ( index_type  i) [inline]

Definition at line 264 of file nsTArray.h.

                                       {
      NS_ASSERTION(i < Length(), "invalid array index");
      return Elements()[i];
    }

Here is the caller graph for this function:

template<class E>
const elem_type& nsTArray< E >::ElementAt ( index_type  i) const [inline]

Definition at line 273 of file nsTArray.h.

                                                   {
      NS_ASSERTION(i < Length(), "invalid array index");
      return Elements()[i];
    }
template<class E>
elem_type* nsTArray< E >::Elements ( ) [inline]

Definition at line 249 of file nsTArray.h.

                          {
      return NS_REINTERPRET_CAST(elem_type *, mHdr + 1);
    }

Here is the caller graph for this function:

template<class E>
const elem_type* nsTArray< E >::Elements ( ) const [inline]

Definition at line 256 of file nsTArray.h.

                                      {
      return NS_REINTERPRET_CAST(const elem_type *, mHdr + 1);
    }
template<class E>
template<class Item , class Comparator >
index_type nsTArray< E >::IndexOf ( const Item &  item,
index_type  start,
const Comparator &  comp 
) const [inline]

Definition at line 299 of file nsTArray.h.

                                                     {
      const elem_type* iter = Elements() + start, *end = iter + Length();
      for (; iter != end; ++iter) {
        if (comp.Equals(*iter, item))
          return iter - Elements();
      }
      return NoIndex;
    }

Here is the caller graph for this function:

template<class E>
template<class Item >
index_type nsTArray< E >::IndexOf ( const Item &  item,
index_type  start = 0 
) const [inline]

Definition at line 316 of file nsTArray.h.

template<class E>
template<class Item >
elem_type* nsTArray< E >::InsertElementAt ( index_type  index,
const Item &  item 
) [inline]

Definition at line 408 of file nsTArray.h.

                                                                   {
      return ReplaceElementsAt(index, 0, &item, 1);
    }

Here is the caller graph for this function:

template<class E>
elem_type* nsTArray< E >::InsertElementAt ( index_type  index) [inline]

Definition at line 415 of file nsTArray.h.

                                                 {
      if (!EnsureCapacity(Length() + 1, sizeof(elem_type)))
         return nsnull;
      ShiftData(index, 0, 1, sizeof(elem_type));
      elem_type *elem = Elements() + index;
      elem_traits::Construct(elem);
      return elem;
    }
template<class E>
template<class Item >
elem_type* nsTArray< E >::InsertElementsAt ( index_type  index,
const Item *  array,
size_type  arrayLen 
) [inline]

Definition at line 395 of file nsTArray.h.

                                                    {
      return ReplaceElementsAt(index, 0, array, arrayLen);
    }

Here is the caller graph for this function:

template<class E>
template<class Item >
elem_type* nsTArray< E >::InsertElementsAt ( index_type  index,
const nsTArray< Item > &  array 
) [inline]

Definition at line 402 of file nsTArray.h.

                                                                               {
      return ReplaceElementsAt(index, 0, array.Elements(), array.Length());
    }
template<class E>
template<class Item , class Comparator >
index_type nsTArray< E >::LastIndexOf ( const Item &  item,
index_type  start,
const Comparator &  comp 
) const [inline]

Definition at line 328 of file nsTArray.h.

                                                         {
      if (start >= Length())
        start = Length() - 1;
      const elem_type* end = Elements() - 1, *iter = end + start + 1;
      for (; iter != end; --iter) {
        if (comp.Equals(*iter, item))
          return iter - Elements();
      }
      return NoIndex;
    }

Here is the caller graph for this function:

template<class E>
template<class Item >
index_type nsTArray< E >::LastIndexOf ( const Item &  item,
index_type  start = NoIndex 
) const [inline]

Definition at line 348 of file nsTArray.h.

template<class E>
nsTArray& nsTArray< E >::operator= ( const self_type other) [inline]

Definition at line 237 of file nsTArray.h.

                                                {
      ReplaceElementsAt(0, Length(), other.Elements(), other.Length());
      return *this;
    }
template<class E>
elem_type& nsTArray< E >::operator[] ( index_type  i) [inline]

Definition at line 279 of file nsTArray.h.

                                        {
      return ElementAt(i);
    }
template<class E>
const elem_type& nsTArray< E >::operator[] ( index_type  i) const [inline]

Definition at line 284 of file nsTArray.h.

                                                    {
      return ElementAt(i);
    }
template<class E>
template<class Item , class Comparator >
void nsTArray< E >::RemoveElement ( const Item &  item,
const Comparator &  comp 
) [inline]

Definition at line 486 of file nsTArray.h.

                                                                 {
      index_type i = IndexOf(item, 0, comp);
      if (i != NoIndex)
        RemoveElementAt(i);
    }

Here is the caller graph for this function:

template<class E>
template<class Item >
void nsTArray< E >::RemoveElement ( const Item &  item) [inline]

Definition at line 495 of file nsTArray.h.

template<class E>
void nsTArray< E >::RemoveElementAt ( index_type  index) [inline]

Definition at line 472 of file nsTArray.h.

Here is the caller graph for this function:

template<class E>
void nsTArray< E >::RemoveElementsAt ( index_type  start,
size_type  count 
) [inline]

Definition at line 466 of file nsTArray.h.

                                                             {
      DestructRange(start, count);
      ShiftData(start, count, 0, sizeof(elem_type));
    }

Here is the caller graph for this function:

template<class E>
template<class Item >
elem_type* nsTArray< E >::ReplaceElementsAt ( index_type  start,
size_type  count,
const Item *  array,
size_type  arrayLen 
) [inline]

Definition at line 368 of file nsTArray.h.

                                                                        {
      // Adjust memory allocation up-front to catch errors.
      if (!EnsureCapacity(Length() + arrayLen - count, sizeof(elem_type)))
        return nsnull;
      DestructRange(start, count);
      ShiftData(start, count, arrayLen, sizeof(elem_type));
      AssignRange(start, arrayLen, array);
      return Elements() + start;
    }

Here is the caller graph for this function:

template<class E>
template<class Item >
elem_type* nsTArray< E >::ReplaceElementsAt ( index_type  start,
size_type  count,
const nsTArray< Item > &  array 
) [inline]

Definition at line 381 of file nsTArray.h.

                                                              {
      return ReplaceElementsAt(start, count, array.Elements(), array.Length());
    }
template<class E>
template<class Item >
elem_type* nsTArray< E >::ReplaceElementsAt ( index_type  start,
size_type  count,
const Item &  item 
) [inline]

Definition at line 388 of file nsTArray.h.

                                                   {
      return ReplaceElementsAt(start, count, &item, 1);
    }
template<class E>
void nsTArray< E >::SetCapacity ( size_type  capacity) [inline]

Definition at line 508 of file nsTArray.h.

                                         {
      EnsureCapacity(capacity, sizeof(elem_type));
    }

Here is the caller graph for this function:

template<class E>
PRBool nsTArray< E >::SetLength ( size_type  newLen) [inline]

Definition at line 518 of file nsTArray.h.

                                       {
      size_type oldLen = Length();
      if (newLen > oldLen) {
        SetCapacity(newLen);
        // Check for out of memory conditions
        if (Capacity() < newLen)
          return PR_FALSE;
        // Initialize the extra array elements
        elem_type *iter = Elements() + oldLen, *end = Elements() + newLen;
        for (; iter != end; ++iter) {
          elem_traits::Construct(iter);
        }
        IncrementLength(newLen - oldLen);
      } else {
        RemoveElementsAt(newLen, oldLen - newLen);
      }
      return PR_TRUE;
    }

Here is the caller graph for this function:

template<class E>
template<class Comparator >
void nsTArray< E >::Sort ( const Comparator &  comp) [inline]

Definition at line 550 of file nsTArray.h.

Here is the caller graph for this function:

template<class E>
void nsTArray< E >::Sort ( void  ) [inline]

Definition at line 558 of file nsTArray.h.

Here is the caller graph for this function:


The documentation for this class was generated from the following file: