Qt 4.8
|
The QStack class is a template class that provides a stack. More...
#include <qcontainerfwd.h>
Public Functions | |
T | pop () |
Removes the top item from the stack and returns it. More... | |
void | push (const T &t) |
Adds element t to the top of the stack. More... | |
QStack () | |
Constructs an empty stack. More... | |
void | swap (QStack< T > &other) |
Swaps stack other with this stack. More... | |
T & | top () |
Returns a reference to the stack's top item. More... | |
const T & | top () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
~QStack () | |
Destroys the stack. More... | |
Public Functions inherited from QVector< T > | |
void | append (const T &t) |
Inserts value at the end of the vector. More... | |
const T & | at (int i) const |
Returns the item at index position i in the vector. More... | |
reference | back () |
This function is provided for STL compatibility. More... | |
const_reference | back () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
iterator | begin () |
Returns an STL-style iterator pointing to the first item in the vector. More... | |
const_iterator | begin () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
int | capacity () const |
Returns the maximum number of items that can be stored in the vector without forcing a reallocation. More... | |
void | clear () |
Removes all the elements from the vector and releases the memory used by the vector. More... | |
const_iterator | constBegin () const |
Returns a const STL-style iterator pointing to the first item in the vector. More... | |
const T * | constData () const |
Returns a const pointer to the data stored in the vector. More... | |
const_iterator | constEnd () const |
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector. More... | |
bool | contains (const T &t) const |
Returns true if the vector contains an occurrence of value; otherwise returns false. More... | |
int | count (const T &t) const |
Returns the number of occurrences of value in the vector. More... | |
int | count () const |
Same as size(). More... | |
T * | data () |
Returns a pointer to the data stored in the vector. More... | |
const T * | data () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | detach () |
bool | empty () const |
This function is provided for STL compatibility. More... | |
iterator | end () |
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector. More... | |
const_iterator | end () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
bool | endsWith (const T &t) const |
Returns true if this vector is not empty and its last item is equal to value; otherwise returns false. More... | |
iterator | erase (iterator begin, iterator end) |
Removes all the items from begin up to (but not including) end. More... | |
iterator | erase (iterator pos) |
Removes the item pointed to by the iterator pos from the vector, and returns an iterator to the next item in the vector (which may be end()). More... | |
QVector< T > & | fill (const T &t, int size=-1) |
Assigns value to all items in the vector. More... | |
T & | first () |
Returns a reference to the first item in the vector. More... | |
const T & | first () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
T & | front () |
This function is provided for STL compatibility. More... | |
const_reference | front () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
int | indexOf (const T &t, int from=0) const |
Returns the index position of the first occurrence of value in the vector, searching forward from index position from. More... | |
void | insert (int i, const T &t) |
Inserts value at index position i in the vector. More... | |
void | insert (int i, int n, const T &t) |
Inserts count copies of value at index position i in the vector. More... | |
iterator | insert (iterator before, int n, const T &x) |
Inserts count copies of value in front of the item pointed to by the iterator before. More... | |
iterator | insert (iterator before, const T &x) |
Inserts value in front of the item pointed to by the iterator before. More... | |
bool | isDetached () const |
bool | isEmpty () const |
Returns true if the vector has size 0; otherwise returns false. More... | |
bool | isSharedWith (const QVector< T > &other) const |
T & | last () |
Returns a reference to the last item in the vector. More... | |
const T & | last () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
int | lastIndexOf (const T &t, int from=-1) const |
Returns the index position of the last occurrence of the value value in the vector, searching backward from index position from. More... | |
QVector< T > | mid (int pos, int length=-1) const |
Returns a vector whose elements are copied from this vector, starting at position pos. More... | |
bool | operator!= (const QVector< T > &v) const |
Returns true if other is not equal to this vector; otherwise returns false. More... | |
QVector< T > | operator+ (const QVector< T > &l) const |
Returns a vector that contains all the items in this vector followed by all the items in the other vector. More... | |
QVector< T > & | operator+= (const QVector< T > &l) |
Appends the items of the other vector to this vector and returns a reference to this vector. More... | |
QVector< T > & | operator+= (const T &t) |
Appends value to the vector. More... | |
QVector< T > & | operator<< (const QVector< T > &l) |
Appends other to the vector and returns a reference to the vector. More... | |
QVector< T > & | operator<< (const T &t) |
Appends value to the vector and returns a reference to this vector. More... | |
QVector< T > & | operator= (const QVector< T > &v) |
Assigns other to this vector and returns a reference to this vector. More... | |
bool | operator== (const QVector< T > &v) const |
Returns true if other is equal to this vector; otherwise returns false. More... | |
T & | operator[] (int i) |
Returns the item at index position i as a modifiable reference. More... | |
const T & | operator[] (int i) const |
Same as at(i). More... | |
void | pop_back () |
This function is provided for STL compatibility. More... | |
void | pop_front () |
This function is provided for STL compatibility. More... | |
void | prepend (const T &t) |
Inserts value at the beginning of the vector. More... | |
void | push_back (const T &t) |
This function is provided for STL compatibility. More... | |
void | push_front (const T &t) |
This function is provided for STL compatibility. More... | |
QVector () | |
Constructs an empty vector. More... | |
QVector (int size) | |
Constructs a vector with an initial size of size elements. More... | |
QVector (int size, const T &t) | |
Constructs a vector with an initial size of size elements. More... | |
QVector (const QVector< T > &v) | |
Constructs a copy of other. More... | |
void | remove (int i) |
Removes the element at index position i. More... | |
void | remove (int i, int n) |
Removes count elements from the middle of the vector, starting at index position i. More... | |
void | replace (int i, const T &t) |
Replaces the item at index position i with value. More... | |
void | reserve (int size) |
Attempts to allocate memory for at least size elements. More... | |
void | resize (int size) |
Sets the size of the vector to size. More... | |
void | setSharable (bool sharable) |
int | size () const |
Returns the number of items in the vector. More... | |
void | squeeze () |
Releases any memory not required to store the items. More... | |
bool | startsWith (const T &t) const |
Returns true if this vector is not empty and its first item is equal to value; otherwise returns false. More... | |
void | swap (QVector< T > &other) |
Swaps vector other with this vector. More... | |
QList< T > | toList () const |
Returns a QList object with the data contained in this QVector. More... | |
std::vector< T > | toStdVector () const |
Returns a std::vector object with the data contained in this QVector. More... | |
T | value (int i) const |
Returns the value at index position i in the vector. More... | |
T | value (int i, const T &defaultValue) const |
If the index i is out of bounds, the function returns defaultValue. More... | |
~QVector () | |
Destroys the vector. More... | |
Additional Inherited Members | |
Public Types inherited from QVector< T > | |
typedef const T * | const_iterator |
The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack. More... | |
typedef const value_type * | const_pointer |
Typedef for const T *. More... | |
typedef const value_type & | const_reference |
Typedef for T &. More... | |
typedef const_iterator | ConstIterator |
Qt-style synonym for QVector::const_iterator. More... | |
typedef qptrdiff | difference_type |
Typedef for ptrdiff_t. More... | |
typedef T * | iterator |
The QVector::iterator typedef provides an STL-style non-const iterator for QVector and QStack. More... | |
typedef iterator | Iterator |
Qt-style synonym for QVector::iterator. More... | |
typedef value_type * | pointer |
Typedef for T *. More... | |
typedef value_type & | reference |
Typedef for T &. More... | |
typedef int | size_type |
Typedef for int. More... | |
typedef T | value_type |
Typedef for T. More... | |
Static Public Functions inherited from QVector< T > | |
static QVector< T > | fromList (const QList< T > &list) |
Returns a QVector object with the data contained in list. More... | |
static QVector< T > | fromStdVector (const std::vector< T > &vector) |
Returns a QVector object with the data contained in vector. More... | |
Related Functions inherited from QVector< T > | |
QDataStream & | operator<< (QDataStream &out, const QVector< T > &vector) |
Writes the vector vector to stream out. More... | |
QDataStream & | operator>> (QDataStream &in, QVector< T > &vector) |
Reads a vector from stream in into vector. More... | |
The QStack class is a template class that provides a stack.
QStack<T> is one of Qt's generic container classes. It implements a stack data structure for items of a same type.
A stack is a last in, first out (LIFO) structure. Items are added to the top of the stack using push() and retrieved from the top using pop(). The top() function provides access to the topmost item without removing it.
Example:
The example will output 3, 2, 1 in that order.
QStack inherits from QVector. All of QVector's functionality also applies to QStack. For example, you can use isEmpty() to test whether the stack is empty, and you can traverse a QStack using QVector's iterator classes (for example, QVectorIterator). But in addition, QStack provides three convenience functions that make it easy to implement LIFO semantics: push(), pop(), and top().
QStack's value type must be an assignable data type. This covers most data types that are commonly used, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *.
Definition at line 63 of file qcontainerfwd.h.
|
inline |
Removes the top item from the stack and returns it.
This function assumes that the stack isn't empty.
Definition at line 67 of file qstack.h.
Referenced by QDirIteratorPrivate::advance(), QTreeWidgetItem::clone(), QPatternist::AccelTree::copyNodeTo(), QSvgHandler::endElement(), QPatternist::ParserContext::endParsingWithParam(), QPatternist::ParserContext::finalizePushedVariable(), QTreeWidgetItem::insertChild(), QTreeWidgetItem::insertChildren(), QTreeModel::insertColumns(), QDirModelPrivate::invalidate(), QTreeView::keyPressEvent(), QPatternist::XSLTTokenizer::leaveState(), Document::load(), QStandardItemModel::mimeData(), QPatternist::PullBridge::next(), StringSplitter::next(), QPatternist::XQueryTokenizer::nextToken(), QDeclarativeStyledTextPrivate::parse(), QXmlSimpleReaderPrivate::parseAttlistDecl(), QXmlSimpleReaderPrivate::parseAttribute(), QXmlSimpleReaderPrivate::parseAttType(), QXmlSimpleReaderPrivate::parseAttValue(), QXmlSimpleReaderPrivate::parseChoiceSeq(), QXmlSimpleReaderPrivate::parseComment(), QXmlSimpleReaderPrivate::parseContent(), QXmlSimpleReaderPrivate::parseDoctype(), QXmlSimpleReaderPrivate::parseElement(), QXmlSimpleReaderPrivate::parseElementDecl(), QXmlSimpleReaderPrivate::parseEntityDecl(), QXmlSimpleReaderPrivate::parseEntityValue(), QXmlSimpleReaderPrivate::parseExternalID(), QXmlSimpleReaderPrivate::parseMarkupdecl(), QXmlSimpleReaderPrivate::parseMisc(), QXmlSimpleReaderPrivate::parseName(), QXmlSimpleReaderPrivate::parseNmtoken(), QXmlSimpleReaderPrivate::parseNotationDecl(), QXmlSimpleReaderPrivate::parsePEReference(), QXmlSimpleReaderPrivate::parsePI(), QXmlSimpleReaderPrivate::parseProlog(), QXmlSimpleReaderPrivate::parseReference(), QXmlSimpleReaderPrivate::parseString(), QSvgHandler::popColor(), QPatternist::XQueryTokenizer::popState(), QXmlSimpleReaderPrivate::processElementEmptyTag(), QXmlSimpleReaderPrivate::processElementETagBegin2(), QTreeWidgetItemPrivate::propagateDisabled(), QStack< State >::push(), QPatternist::XSLTTokenizer::queueOnExit(), QTreeViewPrivate::select(), QDeclarativeListModelParser::setCustomData(), QTreeWidgetItem::setFlags(), QStandardItemPrivate::setModel(), QComboBox::showPopup(), QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(), QGraphicsAnchorLayoutPrivate::simplifyVertices(), QTreeWidgetItem::takeChild(), and QTreeWidgetItem::takeChildren().
|
inline |
Adds element t to the top of the stack.
This is the same as QVector::append().
Definition at line 60 of file qstack.h.
Referenced by QSettingsPrivate::beginGroupOrArray(), QTreeWidgetItem::clone(), QPatternist::AccelTree::copyNodeTo(), QSvgTinyDocument::draw(), QPatternist::XSLTTokenizer::handleStandardAttributes(), QPatternist::XSLTTokenizer::handleXMLBase(), QPatternist::XSLTTokenizer::handleXSLTVersion(), QTreeWidgetItem::insertChild(), QTreeWidgetItem::insertChildren(), QTreeModel::insertColumns(), QXmlSimpleReaderPrivate::insertXmlRef(), QPatternist::XSLTTokenizer::insideSequenceConstructor(), QDirModelPrivate::invalidate(), QTreeView::keyPressEvent(), StringSplitter::loadNext(), QStandardItemModel::mimeData(), QPatternist::PullBridge::next(), QPatternist::XQueryTokenizer::nextToken(), QDeclarativeStyledTextPrivate::parse(), QXmlSimpleReaderPrivate::parseElement(), QPatternist::ParserContext::ParserContext(), QTreeWidgetItemPrivate::propagateDisabled(), QPatternist::PullBridge::PullBridge(), QSvgHandler::pushColor(), QXmlSimpleReaderPrivate::pushParseState(), QPatternist::XQueryTokenizer::pushState(), QPatternist::XSLTTokenizer::pushState(), QPatternist::pushVariable(), QPatternist::XSLTTokenizer::queueNamespaceDeclarations(), QXmlFormatterPrivate::QXmlFormatterPrivate(), QXmlSerializerPrivate::QXmlSerializerPrivate(), QTreeViewPrivate::select(), QDeclarativeListModelParser::setCustomData(), QTreeWidgetItem::setFlags(), QStandardItemPrivate::setModel(), QComboBox::showPopup(), QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(), QGraphicsAnchorLayoutPrivate::simplifyVertices(), QSvgHandler::startElement(), QPatternist::ParserContext::startParsingWithParam(), StringSplitter::StringSplitter(), QTreeWidgetItem::takeChild(), QTreeWidgetItem::takeChildren(), and QSvgNode::transformedBounds().
Swaps stack other with this stack.
This operation is very fast and never fails.
Definition at line 59 of file qstack.h.
|
inline |
Returns a reference to the stack's top item.
This function assumes that the stack isn't empty.
This is the same as QVector::last().
Definition at line 72 of file qstack.h.
Referenced by QDirIteratorPrivate::advance(), QSvgHandler::characters(), QPatternist::AccelTree::copyNodeTo(), QSvgHandler::currentColor(), QPatternist::AccelTreeBuilder< true >::currentParent(), QSvgHandler::endElement(), QPatternist::ParserContext::finalizePushedVariable(), QCoreApplication::hasPendingEvents(), QPatternist::XSLTTokenizer::insideSequenceConstructor(), QPatternist::XSLTTokenizer::insideStylesheetModule(), QPatternist::XSLTTokenizer::isAnyAttributeAllowed(), QPatternist::ParserContext::isParsingWithParam(), Document::load(), QPatternist::PullBridge::next(), QXmlSimpleReaderPrivate::next(), QPatternist::XSLTTokenizer::nextToken(), QDeclarativeStyledTextPrivate::parse(), QXmlSimpleReaderPrivate::parseAttlistDecl(), QXmlSimpleReaderPrivate::parseAttribute(), QXmlSimpleReaderPrivate::parseAttType(), QXmlSimpleReaderPrivate::parseAttValue(), QXmlSimpleReaderPrivate::parseChoiceSeq(), QXmlSimpleReaderPrivate::parseComment(), QXmlSimpleReaderPrivate::parseContent(), QXmlSimpleReaderPrivate::parseDoctype(), QXmlSimpleReaderPrivate::parseElement(), QXmlSimpleReaderPrivate::parseElementDecl(), QXmlSimpleReaderPrivate::parseEntityDecl(), QXmlSimpleReaderPrivate::parseEntityValue(), QXmlSimpleReaderPrivate::parseExternalID(), QXmlSimpleReaderPrivate::parseMarkupdecl(), QXmlSimpleReaderPrivate::parseMisc(), QXmlSimpleReaderPrivate::parseName(), QXmlSimpleReaderPrivate::parseNmtoken(), QXmlSimpleReaderPrivate::parseNotationDecl(), QXmlSimpleReaderPrivate::parsePEReference(), QXmlSimpleReaderPrivate::parsePI(), QXmlSimpleReaderPrivate::parseProlog(), QXmlSimpleReaderPrivate::parseReference(), QXmlSimpleReaderPrivate::parseString(), QSvgHandler::popColor(), QXmlSimpleReaderPrivate::processElementEmptyTag(), QStack< State >::push(), QSvgHandler::pushColorCopy(), QXmlSimpleReaderPrivate::reportEndEntities(), QDeclarativeListModelParser::setCustomData(), QSvgHandler::startElement(), and QPatternist::XSLTTokenizer::whitespaceToSkip().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 76 of file qstack.h.