Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

  • Qt 4.8
  • Qt3SupportLight
  • Q3PtrStack

Q3PtrStack Class

TheQ3PtrStack class is a template class that provides a stack.More...

Header:#include <Q3PtrStack>
Inherits:Q3PtrCollection

Public Functions

Q3PtrStack()
Q3PtrStack(const Q3PtrStack<type> & s)
~Q3PtrStack()
boolautoDelete() const
type *current() const
boolisEmpty() const
type *pop()
voidpush(const type * d)
boolremove()
voidsetAutoDelete(bool enable)
type *top() const
operator type *() const
Q3PtrStack<type> &operator=(const Q3PtrStack<type> & s)

Reimplemented Public Functions

virtual voidclear()
virtual uintcount() const

Reimplemented Protected Functions

virtual QDataStream &read(QDataStream & s, Q3PtrCollection::Item & item)
virtual QDataStream &write(QDataStream & s, Q3PtrCollection::Item item) const

Detailed Description

TheQ3PtrStack class is a template class that provides a stack.

Q3ValueStack is an STL-compatible alternative to this class.

Define a template instanceQ3PtrStack<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 withpush() and retrieved from the top withpop(). Usetop() to get a reference to the top element without changing the stack.

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

For compatibility with theQ3PtrCollection classescurrent() andremove() are provided; they both operate on thetop().

See alsoQ3PtrList andQ3PtrQueue.

Member Function Documentation

Q3PtrStack::Q3PtrStack()

Creates an empty stack.

Q3PtrStack::Q3PtrStack(constQ3PtrStack<type> & s)

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

Q3PtrStack::~Q3PtrStack()

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

bool Q3PtrStack::autoDelete() const

The same asQ3PtrCollection::autoDelete(). Returns true if the auto-delete option is set. If the option is set, the stack auto-deletes its contents.

See alsosetAutoDelete().

[virtual]void Q3PtrStack::clear()

Reimplemented fromQ3PtrCollection::clear().

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

See alsoremove().

[virtual]uint Q3PtrStack::count() const

Reimplemented fromQ3PtrCollection::count().

Returns the number of items in the stack.

See alsoisEmpty().

type * Q3PtrStack::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 Q3PtrStack::isEmpty() const

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

type * Q3PtrStack::pop()

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

void Q3PtrStack::push(consttype * d)

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

[virtual protected]QDataStream & Q3PtrStack::read(QDataStream & s,Q3PtrCollection::Item & item)

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

The default implementation setsitem to 0.

See alsowrite().

bool Q3PtrStack::remove()

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

See alsoclear().

void Q3PtrStack::setAutoDelete(bool enable)

Defines whether this stack auto-deletes its contents. The same asQ3PtrCollection::setAutoDelete(). Ifenable is true, auto-delete is turned on.

If auto-deleting is turned on, all the items in the stack are deleted when the stack itself is deleted. This is convenient if the stack has the only pointers to the items.

The default setting is false, for safety. If you turn it on, be careful about copying the stack, or you might find yourself with two stacks deleting the same items.

Note that the auto-delete setting may also affect other functions in subclasses. For example, a subclass that has aremove() function will remove the item from its data structure, and if auto-delete is enabled, will also delete the item.

See alsoautoDelete().

type * Q3PtrStack::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.

[virtual protected]QDataStream & Q3PtrStack::write(QDataStream & s,Q3PtrCollection::Item item) const

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

The default implementation does nothing.

See alsoread().

Q3PtrStack::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.

Q3PtrStack<type> & Q3PtrStack::operator=(constQ3PtrStack<type> & s)

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

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp