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

Protected Members


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.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8