TQPtrStack Class

Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# TQPtrStack Class Reference

The TQPtrStack class is a template class that provides a stack. More...

`#include <ntqptrstack.h>`

List of all member functions.

## Public Members

- TQPtrStack ()
- TQPtrStack ( const TQPtrStack<type> & s )
- ~TQPtrStack ()
- TQPtrStack<type> & operator= ( const TQPtrStack<type> & s )
- bool autoDelete () const
- void setAutoDelete ( bool enable )
- uint count () const
- bool isEmpty () const
- void push ( const type * d )
- type * pop ()
- bool remove ()
- void clear ()
- type * top () const
- operator type * () const
- type * current () const

## Protected Members

- virtual TQDataStream & read ( TQDataStream & s, TQPtrCollection::Item & item )
- virtual TQDataStream & write ( TQDataStream & s, TQPtrCollection::Item item ) const

## Detailed Description

The TQPtrStack class is a template class that provides a stack.

TQValueStack is an STL-compatible alternative to this class.

Define a template instance TQPtrStack<X> to create a stack that operates on pointers to X, (X*).

A stack is a last in, first out (LIFO) structure. Items are added to the top of the stack with push() and retrieved from the top with pop(). Use top() to get a reference to the top element without changing the stack.

You can control the stack's deletion policy with setAutoDelete().

For compatibility with the TQPtrCollection classes current() and remove() are provided; they both operate on the top().

See also TQPtrList, TQPtrQueue, and Non-GUI Classes.

## Member Function Documentation

### TQPtrStack::TQPtrStack ()

Creates an empty stack.

### TQPtrStack::TQPtrStack ( const TQPtrStack<type> & s )

Creates a stack by making a shallow copy of another stack s.

### TQPtrStack::~TQPtrStack ()

Destroys the stack. All items will be deleted if autoDelete() is true.

### bool TQPtrStack::autoDelete () const

The same as TQPtrCollection::autoDelete().

See also setAutoDelete().

### void TQPtrStack::clear ()

Removes all items from the stack, deleting them if autoDelete() is true.

See also remove().

### uint TQPtrStack::count () const

Returns the number of items in the stack.

See also isEmpty().

### type * TQPtrStack::current () const

Returns a pointer to the top item on the stack (most recently pushed). The stack is not changed. Returns 0 if the stack is empty.

### bool TQPtrStack::isEmpty () const

Returns true if the stack contains no elements; otherwise returns false.

### TQPtrStack::operator type * () const

Returns a pointer to the top item on the stack (most recently pushed). The stack is not changed. Returns 0 if the stack is empty.

### TQPtrStack<type> & TQPtrStack::operator= ( const TQPtrStack<type> & s )

Sets the contents of this stack by making a shallow copy of another stack s. Elements currently in this stack will be deleted if autoDelete() is true.

### type * TQPtrStack::pop ()

Removes the top item from the stack and returns it. The stack must not be empty.

### void TQPtrStack::push ( const type * d )

Adds an element d to the top of the stack. Last in, first out.

### TQDataStream & TQPtrStack::read ( TQDataStream & s, TQPtrCollection::Item & item )`[virtual protected]`

Reads a stack item, item, from the stream s and returns a reference to the stream.

The default implementation sets item to 0.

See also write().

### bool TQPtrStack::remove ()

Removes the top item from the stack and deletes it if autoDelete() is true. Returns true if there was an item to pop; otherwise returns false.

See also clear().

### void TQPtrStack::setAutoDelete ( bool enable )

Defines whether this stack auto-deletes its contents. The same as TQPtrCollection::setAutoDelete().

If enable is true the stack auto-deletes its contents; if enable is false the stack does not delete its contents.

See also autoDelete().

### type * TQPtrStack::top () const

Returns a pointer to the top item on the stack (most recently pushed). The stack is not changed. Returns 0 if the stack is empty.

### TQDataStream & TQPtrStack::write ( TQDataStream & s, TQPtrCollection::Item item ) const`[virtual protected]`

Writes a stack item, item, to the stream s and returns a reference to the stream.

The default implementation does nothing.

See also read().

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.