~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/corelib/tools/qstack.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the core module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
/*!
 
30
    \class QStack
 
31
    \brief The QStack class is a template class that provides a stack.
 
32
 
 
33
    \ingroup tools
 
34
    \ingroup shared
 
35
    \mainclass
 
36
    \reentrant
 
37
 
 
38
    QStack\<T\> is one of Qt's generic \l{container classes}. It implements
 
39
    a stack data structure for items of a same type.
 
40
 
 
41
    A stack is a last in, first out (LIFO) structure. Items are added
 
42
    to the top of the stack using push() and retrieved from the top
 
43
    using pop(). The top() function provides access to the topmost
 
44
    item without removing it.
 
45
 
 
46
    Example:
 
47
    \code
 
48
        QStack<int> stack;
 
49
        stack.push(1);
 
50
        stack.push(2);
 
51
        stack.push(3);
 
52
        while (!stack.isEmpty())
 
53
            cout << stack.pop() << endl;
 
54
    \endcode
 
55
 
 
56
    The example will output 3, 2, 1 in that order.
 
57
 
 
58
    QStack inherits from QVector. All of QVector's functionality also
 
59
    applies to QStack. For example, you can use isEmpty() to test
 
60
    whether the stack is empty, and you can traverse a QStack using
 
61
    QVector's iterator classes (for example, QVectorIterator). But in
 
62
    addition, QStack provides three convenience functions that make
 
63
    it easy to implement LIFO semantics: push(), pop(), and top().
 
64
 
 
65
    QStack's value type must be an \l{assignable data type}. This
 
66
    covers most data types that are commonly used, but the compiler
 
67
    won't let you, for example, store a QWidget as a value; instead,
 
68
    store a QWidget *.
 
69
 
 
70
    \sa QVector, QQueue
 
71
*/
 
72
 
 
73
/*!
 
74
    \fn QStack::QStack()
 
75
 
 
76
    Constructs an empty stack.
 
77
*/
 
78
 
 
79
/*!
 
80
    \fn QStack::~QStack()
 
81
 
 
82
    Destroys the stack. References to the values in the stack, and all
 
83
    iterators over this stack, become invalid.
 
84
*/
 
85
 
 
86
/*!
 
87
    \fn void QStack::push(const T& t)
 
88
 
 
89
    Adds element \a t to the top of the stack.
 
90
 
 
91
    This is the same as QVector::append().
 
92
 
 
93
    \sa pop(), top()
 
94
*/
 
95
 
 
96
/*!
 
97
    \fn T& QStack::top()
 
98
 
 
99
    Returns a reference to the stack's top item. This function
 
100
    assumes that the stack isn't empty.
 
101
 
 
102
    This is the same as QVector::last().
 
103
 
 
104
    \sa pop(), push(), isEmpty()
 
105
*/
 
106
 
 
107
/*!
 
108
    \fn const T& QStack::top() const
 
109
 
 
110
    \overload
 
111
 
 
112
    \sa pop(), push()
 
113
*/
 
114
 
 
115
/*!
 
116
    \fn T QStack::pop()
 
117
 
 
118
    Removes the top item from the stack and returns it. This function
 
119
    assumes that the stack isn't empty.
 
120
 
 
121
    \sa top(), push(), isEmpty()
 
122
*/