Class:nsTDeque

From MozillaWiki
Jump to: navigation, search
template <class T>
class nsTDeque {
public:
  /**
   * @constructor
   * @param objectsPerPage
   *    Optional parameter that specifies the number of objects per page
   *    in the deque.
   */
  explicit nsTDeque(PRUint32 objectsPerPage = 32);
   
  /**
   * @destructor
   */
  ~nsTDeque();
   
  /**
   * Clear all elements from the deque.
   */
  void Clear();
   
  /**
   * @returns
   *   PR_TRUE if the deque contains no elements and PR_FALSE otherwise.
   */
  PRBool IsEmpty();
   
  /**
   * Adds a new element to the front of the deque.
   * @param obj
   *   The object to be added.
   */
  void PushFront(const T& obj);
   
  /**
   * Adds a new element using T's default constructor to the front of the 
   * deque.
   * @returns
   *   The address of the newly added element or null if the object
   *   could not be allocated. 
   */
  T* PushFront();
   
  /**
   * Adds a new element to the back of the deque.
   * @param obj
   *   The object to be added.
   */
  void PushBack(const T& obj);
   
  /**
   * Adds a new element using T's default constructor to the back of the 
   * deque.
   * @returns
   *   The address of the newly added element or null if the object
   *   could not be allocated. 
   */
  T* PushBack();
   
  /**
   * @returns
   *   A const reference to the element at the front of the deque.
   *   It is an error to call this method on an empty deque.
   */
  const T& Front() const;
   
  /**
   * @returns
   *   A reference to the element at the front of the deque.
   *   It is an error to call this method on an empty deque.
   */
  T& Front();
   
  /**
   * @returns
   *   A const reference to the element at the back of the deque.
   *   It is an error to call this method on an empty deque.
   */
  const T& Back() const;
   
  /**
   * @returns
   *   A reference to the element at the back of the deque.
   *   It is an error to call this method on an empty deque.
   */
  T& Back();
   
  /**
   * Removes the element at the front of the deque.  This method
   * has no effect if the deque is empty.
   */
  void PopFront();
   
  /**
   * Removes the element at the back of the deque.  This method
   * has no effect if the deque is empty.
   */
  void PopBack();
};