SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWTStack< T, C > Class Template Reference

Maintains a stack of values. More...

#include <rw/tstack.h>

Public Member Functions

 RWTStack ()
 
 RWTStack (C &&rhs)
 
 RWTStack (const C &rhs)
 
 RWTStack (const RWTStack &rhs)
 
 RWTStack (RWTStack &&rhs)
 
void clear ()
 
size_t entries () const
 
bool isEmpty () const
 
RWTStackoperator= (const RWTStack &rhs)
 
RWTStackoperator= (RWTStack &&rhs)
 
pop ()
 
void push (const T &a)
 
void push (T &&a)
 
void swap (RWTStack< T, C > &rhs)
 
top () const
 

Detailed Description

template<class T, class C>
class RWTStack< T, C >

Class RWTStack maintains a stack of values. Not only can the type of object inserted onto the stack be parameterized, but also the implementation of the stack.

Parameter T represents the type of object in the stack, either a class or built-in type. Class T must have:

  • well-defined copy semantics (T::T(const T&) or equivalent)
  • well-defined assignment semantics (T::operator=(const T&) or equivalent)
  • any other semantics required by class C.

Parameter C represents the class used for implementation. The class C must provide the following interface (or equivalent):

  • void C::append(const T&)
  • void C::clear()
  • size_t C::entries() const
  • T C::last()
  • bool C::isEmpty() const
  • T C::removeLast()
  • a default constructor (C::C())
  • a copy constructor (C::C(const C&))
  • an assignment operator (C& C::operator=(const C&))

These methods must behave in a manner that is consistent with that of RWTValDlist for this class to function as intended.

Useful choices for C are RWTValDlist or RWTValOrderedVector. Singly- linked list classes, such as RWTValSlist, can also be used, but tend to be less efficient at removing the last item.

Synopsis
#include <rw/tstack.h>
Maintains a stack of values.
Definition tstack.h:101
Persistence
None
Example
#include <rw/tstack.h>
#include <rw/tvordvec.h>
#include <iostream>
int main() {
stack.push(1);
stack.push(5);
stack.push(6);
while (!stack.isEmpty()) {
std::cout << stack.pop() << "\n";
}
return 0;
}
T pop()
Definition tstack.h:197
bool isEmpty() const
Definition tstack.h:175
void push(const T &a)
Definition tstack.h:180

Program output:

6
5
1

Constructor & Destructor Documentation

◆ RWTStack() [1/5]

template<class T , class C >
RWTStack< T, C >::RWTStack ( )
inline

Constructs a stack.

◆ RWTStack() [2/5]

template<class T , class C >
RWTStack< T, C >::RWTStack ( const C & rhs)
inlineexplicit

Constructs a stack from the container rhs.

◆ RWTStack() [3/5]

template<class T , class C >
RWTStack< T, C >::RWTStack ( const RWTStack< T, C > & rhs)
inline

Copy constructor. Constructs self as a copy of rhs.

◆ RWTStack() [4/5]

template<class T , class C >
RWTStack< T, C >::RWTStack ( C && rhs)
inlineexplicit

Move constructor. Takes ownership of the data owned by rhs.

Condition:
This method is available only on platforms with rvalue reference support.

◆ RWTStack() [5/5]

template<class T , class C >
RWTStack< T, C >::RWTStack ( RWTStack< T, C > && rhs)
inline

Move constructor. Takes ownership of the data owned by rhs.

Condition:
This method is available only on platforms with rvalue reference support.

Member Function Documentation

◆ clear()

template<class T , class C >
void RWTStack< T, C >::clear ( )
inline

Calls C::clear() on the underlying container.

◆ entries()

template<class T , class C >
size_t RWTStack< T, C >::entries ( ) const
inline

Returns the result of calling C::entries() on the underlying container.

◆ isEmpty()

template<class T , class C >
bool RWTStack< T, C >::isEmpty ( ) const
inline

Returns the result of calling C::isEmpty() on the underlying container.

◆ operator=() [1/2]

template<class T , class C >
RWTStack & RWTStack< T, C >::operator= ( const RWTStack< T, C > & rhs)
inline

Assignment operator. Sets self to a copy of rhs.

◆ operator=() [2/2]

template<class T , class C >
RWTStack & RWTStack< T, C >::operator= ( RWTStack< T, C > && rhs)
inline

Move assignment. Takes ownership of the data owned by rhs.

Condition:
This method is available only on platforms with rvalue reference support.

◆ pop()

template<class T , class C >
T RWTStack< T, C >::pop ( )
inline

Returns the result of calling C::removeLast() on the underlying container.

◆ push() [1/2]

template<class T , class C >
void RWTStack< T, C >::push ( const T & a)
inline

Calls C::append(a) on the underlying container.

◆ push() [2/2]

template<class T , class C >
void RWTStack< T, C >::push ( T && a)
inline

Calls C::append(a) on the underlying container.

Condition:
This method is available only on platforms with rvalue reference support.

◆ swap()

template<class T , class C >
void RWTStack< T, C >::swap ( RWTStack< T, C > & rhs)
inline

Swaps the data owned by self with the data owned by rhs.

◆ top()

template<class T , class C >
T RWTStack< T, C >::top ( ) const
inline

Returns the result of calling C::last() on the underlying container.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.