2.7 Deque

The Deque class is a templated container acting as a double-ended queue array. It can be either static or dynamic. Static means it’s allocated once in memory and will not autoresize. When full it will throw an overflow exception. Dynamic means the container will autoresize as new items are pushed on the deque. An overflow exception will then only occure if available memory is exhausted.


Synopsis


  #include <lyric/Deque.hpp>
  
  template <class DIT>
  class Deque : private List<DIT>
  {
  public:
    ~Deque ()
      throw();
    Deque ()
      throw ();
    Deque (Size initsize, Size resize = 0)
      throw (Exception::Memory::Alloc);
    Deque (const Deque& deque)
      throw (Exception::Memory::Alloc);
    Deque& operator = (const Deque& deque)
      throw (Exception::Memory::Alloc);
    void create (Size initsize, Size resize = 0)
      throw (Exception::Memory::Alloc);
    void clean ()
      throw ();
    bool empty () const
      throw ();
    void insertl (const DIT& item)
      throw (::Exception::Deque::Overflow);
    void insertr (const DIT& item)
      throw (::Exception::Deque::Overflow);
    DIT deletel ()
      throw (::Exception::Deque::Underflow);
    DIT deleter ()
      throw (::Exception::Deque::Underflow);
    void pushl (const DIT& item)
      throw (Exception::Deque::Overflow);
    void pushr (const DIT& item)
      throw (Exception::Deque::Overflow);
    DIT popl ()
      throw (Exception::Deque::Underflow);
    DIT popr ()
      throw (Exception::Deque::Underflow);
    const DIT& left () const
      throw (::Exception::Deque::Underflow);
    const DIT& right () const
      throw (::Exception::Deque::Underflow);
  };


Description


˜Deque ()
Destroys this deque, releasing eventually reserved memory. All stored items are destroyed.

Deque ()
Constucts this deque as dynamic deque with a resize size of 1.

Deque (Size initsize, Size resize = 0)
Constructs this deque with a starting memory size initsize and a given resize factor. If resize is zero (or not set), the deque is defined static and will not grow over the given initsize. If resize is greater than zero, the deque will automatically grow as items are pushed on.
|\ Exception::Memory::Alloc
is thrown if not enough memory is found for the initial size.

Deque (const Deque& deque)
Constructs this from deque. All properties, content, and status of deque are given to this.
|\ Exception::Memory::Alloc
is thrown if not enough memory is found for this to clone deque.

Deque& operator = (const Deque& deque)
Clones deque into this. All properties, content, and status of deque are given to this.
|\ Exception::Memory::Alloc
is thrown if not enough memory is found for this to clone deque.

void create (Size initsize, Size resize = 0)
Creates this deque with a starting memory size initsize and a given resize factor. If resize is zero (or not set), the deque is defined static and will not grow over the given initsize. If resize is greater than zero, the deque will automatically grow as items are pushed on.
Warning  Create is destructive. It will destroy all items previously stored in this deque.
|\ Exception::Memory::Alloc
is thrown if not enough memory is found for the initial size.

void clean ()
Cleans the content of this deque. Destroys all stored items and sets deque pointer to zero.

bool empty () const
Returns true if this deque is empty, false if not.

void insertl (const DIT& item)
void pushl (const DIT& item)
Inserts item at the left end of this deque, and increments the deque pointer.
|\ Exception::Deque::Overflow
is thrown if this deque was defined static and was full, or if the deque was defined dynamic and no more memory is left on teh system to store the extra item.

void insertr (const DIT& item)
void pushr (const DIT& item)
Inserts item at the right end of this deque, and increments the deque pointer.
|\ Exception::Deque::Overflow
is thrown if this deque was defined static and was full, or if the deque was defined dynamic and no more memory is left on the system to store the extra item.

DIT deletel ()
DIT popl ()
Deletes the left most item from this deque, decrements the deque pointer, and returns the item.
|\ Exception::Deque::Underflow
is thrown if this deque was empty before the pop.

DIT deleter ()
DIT popr ()
Deletes the right most item from this deque, decrements the deque pointer, and returns the item.
|\ Exception::Deque::Underflow
is thrown if this deque was empty before the pop.

const DIT& left () const
Returns the left most item from this deque, without deleting it.
|\ Exception::Deque::Underflow
is thrown if this deque is empty.

const DIT& right () const
Returns the right most item from this deque, without deleting it.
|\ Exception::Deque::Underflow
is thrown if this deque is empty.