CopperSpice API  1.7.2
QStack< T > Class Template Reference

Template class which provides a stack. More...

Inheritance diagram for QStack< T >:
QVector< T >

Public Typedefs

using allocator_type = typename QVector< T >::allocator_type
 
using const_iterator = typename QVector< T >::const_iterator
 
using const_pointer = typename QVector< T >::const_pointer
 
using const_reference = typename QVector< T >::const_reference
 
using const_reverse_iterator = typename QVector< T >::const_reverse_iterator
 
using difference_type = typename QVector< T >::difference_type
 
using iterator = typename QVector< T >::iterator
 
using pointer = typename QVector< T >::pointer
 
using reference = typename QVector< T >::reference
 
using reverse_iterator = typename QVector< T >::reverse_iterator
 
using size_type = typename QVector< T >::difference_type
 
using value_type = typename QVector< T >::value_type
 
- Public Typedefs inherited from QVector< T >
using allocator_type = typename std::vector< T >::allocator_type
 
using const_iterator = typename std::vector< T >::const_iterator
 
using const_pointer = typename std::vector< T >::const_pointer
 
using const_reference = typename std::vector< T >::const_reference
 
using const_reverse_iterator = typename std::vector< T >::const_reverse_iterator
 
using difference_type = typename std::vector< T >::difference_type
 
using iterator = typename std::vector< T >::iterator
 
using Java_Iterator = QVectorIterator< T >
 
using Java_MutableIterator = QMutableVectorIterator< T >
 
using pointer = typename std::vector< T >::pointer
 
using reference = typename std::vector< T >::reference
 
using reverse_iterator = typename std::vector< T >::reverse_iterator
 
using size_type = typename std::vector< T >::difference_type
 
using value_type = typename std::vector< T >::value_type
 

Public Methods

 QStack () = default
 
 ~QStack () = default
 
pop ()
 
void push (const T &value)
 
void swap (QStack< T > &other)
 
reference top ()
 
const_reference top () const
 
- Public Methods inherited from QVector< T >
 QVector () = default
 
 QVector (const QVector< T > &other) = default
 
template<class Input_Iterator >
 QVector (Input_Iterator first, Input_Iterator last)
 
 QVector (QVector< T > &&other) = default
 
 QVector (size_type size)
 
 QVector (size_type size, const T &value)
 
 QVector (std::initializer_list< T > args)
 
 ~QVector () = default
 
void append (const QVector< T > &other)
 
void append (const T &value)
 
template<typename Iter >
void append (Iter begin, Iter end)
 
void append (T &&value)
 
const_reference at (size_type i) const
 
reference back ()
 
const_reference back () const
 
iterator begin ()
 
const_iterator begin () const
 
size_type capacity () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void clear ()
 
const_iterator constBegin () const
 
const T * constData () const
 
const_iterator constEnd () const
 
const_reference constFirst () const
 
const_reference constLast () const
 
bool contains (const T &value) const
 
size_type count () const
 
size_type count (const T &value) const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
T * data ()
 
const T * data () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
bool endsWith (const T &value) const
 
iterator erase (const_iterator begin, const_iterator end)
 
iterator erase (const_iterator pos)
 
QVector< T > & fill (const T &value, size_type newSize=-1)
 
reference first ()
 
const_reference first () const
 
reference front ()
 
const_reference front () const
 
size_type indexOf (const T &value, size_type from=0) const
 
iterator insert (iterator before, const T &value)
 
iterator insert (iterator before, size_type count, const T &value)
 
template<typename Iter >
iterator insert (iterator pos, Iter begin, Iter end)
 
void insert (size_type pos, const T &value)
 
void insert (size_type pos, size_type count, const T &value)
 
bool isEmpty () const
 
reference last ()
 
const_reference last () const
 
size_type lastIndexOf (const T &value, size_type from=-1) const
 
size_type length () const
 
QVector< T > mid (size_type pos, size_type length=-1) const
 
void move (size_type from, size_type to)
 
bool operator!= (const QVector< T > &other) const
 
QVector< T > operator+ (const QVector< T > &other) const
 
QVector< T > & operator+= (const QVector< T > &other)
 
QVector< T > & operator+= (const T &value)
 
QVector< T > & operator<< (const QVector< T > &other)
 
QVector< T > & operator<< (const T &value)
 
QVector< T > & operator= (const QVector< T > &other) = default
 
QVector< T > & operator= (QVector< T > &&other) = default
 
bool operator== (const QVector< T > &other) const
 
reference operator[] (size_type i)
 
const_reference operator[] (size_type i) const
 
void pop_back ()
 
void pop_front ()
 
void prepend (const T &value)
 
void push_back (const T &value)
 
void push_back (T &&value)
 
void push_front (const T &value)
 
void push_front (T &&value)
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
void remove (size_type pos)
 
void remove (size_type pos, size_type count)
 
size_type removeAll (const T &value)
 
void removeAt (size_type pos)
 
void removeFirst ()
 
void removeLast ()
 
bool removeOne (const T &value)
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
void replace (size_type i, const T &value)
 
void reserve (size_type size)
 
void resize (size_type size)
 
size_type size () const
 
void squeeze ()
 
bool startsWith (const T &value) const
 
void swap (QVector< T > &other)
 
takeAt (size_type i)
 
takeFirst ()
 
takeLast ()
 
QList< T > toList () const
 
std::vector< T > toStdVector () const
 
value (size_type i) const
 
value (size_type i, const T &defaultValue) const
 

Additional Inherited Members

- Static Public Methods inherited from QVector< T >
static QVector< T > fromList (const QList< T > &list)
 
static QVector< T > fromStdVector (const std::vector< T > &vector)
 

Detailed Description

template<class T>
class QStack< T >

The QStack class is a template class which provides a stack. This container implements a stack using a QVector. A stack is a last in, first out (LIFO) data structure. Items are added to the top of the stack using push() and retrieved from the top using pop().

For an overview and comparison of all containers, refer to the documentation for Container Classes. Refer to the section on Time Complexity for a discussion about which operations will be relatively faster or slower for a given container with a size of n.

Basic Operations

QStack inherits from QVector so all of the methods in QVector are available.

The top() method provides access to the topmost element, it does not remove it from the stack. To retrieve the topmost element and also remove it, use pop(). Use the isEmpty() method to determine if the stack has any elements.

To traverse a QStack the QVector iterators can be used.

stack.push(1);
stack.push(2);
stack.push(3);
while (! stack.isEmpty()) {
cout << stack.pop() << endl; // output: 3, 2, 1
}

Constraints on type T

The QStack value type T should be Default Constructible and Copy Constructible to work with all methods of this class. Data types like QObject are not copy constructible and therefore should never be stored in a container. You can however use a pointer to a QObject or any subclass as the type T.

See also
QVector, QQueue

Member Typedef Documentation

template<class T >
QStack< T >::allocator_type

Typedef for allocator used by the container.

template<class T >
QStack< T >::const_iterator

Typedef for an STL style const iterator.

template<class T >
QStack< T >::const_pointer

Typedef for const T *.

template<class T >
QStack< T >::const_reference

Typedef for T &.

template<class T >
QStack< T >::const_reverse_iterator

Typedef for an STL style const reverse iterator.

template<class T >
QStack< T >::difference_type

Typedef for integral type used to represent the distance between two elements.

template<class T >
QStack< T >::iterator

Typedef for an STL style iterator.

template<class T >
QStack< T >::pointer

Typedef for T *.

template<class T >
QStack< T >::reference

Typedef for T &.

template<class T >
QStack< T >::reverse_iterator

Typedef for an STL style reverse iterator.

template<class T >
QStack< T >::size_type

Typedef for a signed integer of the appropriate size for your platform.

template<class T >
QStack< T >::value_type

Typedef for T.

Constructor & Destructor Documentation

template<class T >
QStack< T >::QStack ( )
default

Constructs an empty stack.

template<class T >
QStack< T >::~QStack ( )
default

Destroys the stack.

Method Documentation

template<class T >
T QStack< T >::pop ( )
inline

Removes the top item from the stack and returns it. This method assumes the stack is not empty.

See also
top(), push(), isEmpty()
template<class T >
void QStack< T >::push ( const T &  value)
inline

Adds element value to the top of the stack. Equivalent to calling QVector::append().

See also
pop(), top()
template<class T >
void QStack< T >::swap ( QStack< T > &  other)
inline

Swaps other with this object. This operation is very fast and never fails.

template<class T >
QStack< T >::reference QStack< T >::top ( )
inline

Returns a reference to the stack's top item. This method assumes that the stack is not empty. Equivalent to calling QVector::last().

See also
pop(), push(), isEmpty()
template<class T >
QStack< T >::const_reference QStack< T >::top ( ) const
inline

Returns a reference to the stack's top item. This method assumes that the stack is not empty.

See also
pop(), push()