MADNESS  0.10.1
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
madness::Stack< T, N > Class Template Reference

Dynamically sized Stack with small stack size optimization. More...

#include <stack.h>

Inheritance diagram for madness::Stack< T, N >:
Inheritance graph
[legend]
Collaboration diagram for madness::Stack< T, N >:
Collaboration graph
[legend]

Public Types

typedef const Tconst_reference
 Element constant reference type. More...
 
typedef Treference
 Element reference type. More...
 
typedef unsigned int size_type
 An unsigned integral type. More...
 
typedef T value_type
 Type of the stack elements. More...
 

Public Member Functions

 Stack ()
 Construct an empty stack. More...
 
 Stack (const Stack< T, N > &other)
 Copy constructor. More...
 
 Stack (Stack< T, N > &&other)
 Move constructor. More...
 
 ~Stack ()
 Destructor. More...
 
size_type capacity () const
 Capacity accessor. More...
 
void clear ()
 Empty the stack. More...
 
Tdata ()
 Data accessor. More...
 
const Tdata () const
 Data accessor. More...
 
bool empty () const
 Check if the stack is empty. More...
 
bool empty () const volatile
 Check if the stack is empty. More...
 
Stack< T, N > & operator= (const Stack< T, N > &other)
 Assignment operator. More...
 
Stack< T, N > & operator= (Stack< T, N > &&other)
 Move assignment operator. More...
 
void pop ()
 Pop an item off of the stack. More...
 
void push (const_reference value)
 Push a new item onto the stack. More...
 
void reset ()
 Empty the stack and free memory. More...
 
size_type size () const
 Size accessor. More...
 
size_type size () const volatile
 Size accessor. More...
 
reference top ()
 Get the last item pushed onto the stack. More...
 
const_reference top () const
 Get the last item pushed onto the stack. More...
 

Private Types

typedef detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value > StackBase_
 

Private Member Functions

Tallocate (const size_type n)
 Allocate a raw buffer. More...
 
void deallocate ()
 Deallocate memory. More...
 
bool is_small () const
 Check if the stack is using the small buffer to store data. More...
 
void move (Stack< T, N > &other)
 

Private Attributes

char buffer_ [sizeof(T) *N]
 Static buffer for storing a small number of elements. More...
 
size_type capacity_
 The maximum size, in elements, of the data_ buffer. More...
 
Tdata_
 Pointer to the stack data. More...
 
size_type size_
 Number of elements on the stack. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >
static void destroy (T *first, T *last)
 Destroy a range of non-POD objects. More...
 
static void destroy (T *ptr)
 Destroy a non-POD object. More...
 
static void uninitialized_copy (T *first, T *last, T *dest)
 Copy a range of POD objects. More...
 
static void uninitialized_move (T *first, T *last, T *dest)
 Move a range of POD objects. More...
 

Detailed Description

template<typename T, unsigned int N>
class madness::Stack< T, N >

Dynamically sized Stack with small stack size optimization.

This object is a dynamically sized stack that functions similarly to a std::vector. It also includes an optimization for small stack sizes that avoids memory allocations when the stack size is less than or equal to N.

Template Parameters
TThe type of data stored in the stack.
NThe fixed size of the stack.

Member Typedef Documentation

◆ const_reference

template<typename T , unsigned int N>
typedef const T& madness::Stack< T, N >::const_reference

Element constant reference type.

◆ reference

template<typename T , unsigned int N>
typedef T& madness::Stack< T, N >::reference

Element reference type.

◆ size_type

template<typename T , unsigned int N>
typedef unsigned int madness::Stack< T, N >::size_type

An unsigned integral type.

◆ StackBase_

template<typename T , unsigned int N>
typedef detail::StackBase<T, std::is_standard_layout<T>::value && std::is_trivial<T>::value> madness::Stack< T, N >::StackBase_
private

◆ value_type

template<typename T , unsigned int N>
typedef T madness::Stack< T, N >::value_type

Type of the stack elements.

Constructor & Destructor Documentation

◆ Stack() [1/3]

template<typename T , unsigned int N>
madness::Stack< T, N >::Stack ( )
inline

Construct an empty stack.

The capacity of the stack is N.

◆ Stack() [2/3]

template<typename T , unsigned int N>
madness::Stack< T, N >::Stack ( const Stack< T, N > &  other)
inline

Copy constructor.

If the size of other is less than or equal to N, then this object will use the small buffer. Otherwise, it will allocate memory and copy the data of other. The capacity of the object will be equal to max(N, other.size()).

Parameters
[in]otherThe stack to be copied.

References madness::Stack< T, N >::allocate(), madness::Stack< T, N >::buffer_, madness::Stack< T, N >::capacity_, madness::Stack< T, N >::data_, N, madness::Stack< T, N >::size_, T(), and madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::uninitialized_copy().

◆ Stack() [3/3]

template<typename T , unsigned int N>
madness::Stack< T, N >::Stack ( Stack< T, N > &&  other)
inline

Move constructor.

Move the data from other to this object.

Parameters
[in]otherThe original stack.

References madness::Stack< T, N >::move().

◆ ~Stack()

template<typename T , unsigned int N>
madness::Stack< T, N >::~Stack ( )
inline

Member Function Documentation

◆ allocate()

template<typename T , unsigned int N>
T* madness::Stack< T, N >::allocate ( const size_type  n)
inlineprivate

Allocate a raw buffer.

Allocate an uninitialized buffer.

Parameters
[in]nThe size of the new buffer.
Returns
Pointer to the new buffer.

References malloc(), and T().

Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::operator=(), and madness::Stack< T, N >::push().

◆ capacity()

template<typename T , unsigned int N>
size_type madness::Stack< T, N >::capacity ( ) const
inline

Capacity accessor.

Returns
The size of allocated storage capacity.

References madness::Stack< T, N >::capacity_.

◆ clear()

template<typename T , unsigned int N>
void madness::Stack< T, N >::clear ( )
inline

◆ data() [1/2]

template<typename T , unsigned int N>
T* madness::Stack< T, N >::data ( )
inline

Data accessor.

Returns
A pointer to the stack data.

References madness::Stack< T, N >::data_.

◆ data() [2/2]

template<typename T , unsigned int N>
const T* madness::Stack< T, N >::data ( ) const
inline

Data accessor.

Returns
A const pointer to the stack data.

References madness::Stack< T, N >::data_.

◆ deallocate()

template<typename T , unsigned int N>
void madness::Stack< T, N >::deallocate ( )
inlineprivate

Deallocate memory.

Destroy the pointer if it is a dynamically allocated buffer; otherwise do nothing.

References madness::Stack< T, N >::data_, and madness::Stack< T, N >::is_small().

Referenced by madness::Stack< T, N >::~Stack(), madness::Stack< T, N >::operator=(), madness::Stack< T, N >::push(), and madness::Stack< T, N >::reset().

◆ empty() [1/2]

template<typename T , unsigned int N>
bool madness::Stack< T, N >::empty ( ) const
inline

Check if the stack is empty.

Returns
True if the size of the stack is 0; otherwise false.

References madness::Stack< T, N >::size_.

Referenced by madness::DependencyInterface::do_callbacks(), and madness::FutureImpl< T >::set_assigned().

◆ empty() [2/2]

template<typename T , unsigned int N>
bool madness::Stack< T, N >::empty ( ) const volatile
inline

Check if the stack is empty.

Returns
True if the size of the stack is 0; otherwise false.

References madness::Stack< T, N >::size_.

◆ is_small()

template<typename T , unsigned int N>
bool madness::Stack< T, N >::is_small ( ) const
inlineprivate

Check if the stack is using the small buffer to store data.

Returns
True if the small buffer is being used; false otherwise.

References madness::Stack< T, N >::buffer_, and madness::Stack< T, N >::data_.

Referenced by madness::Stack< T, N >::deallocate(), and madness::Stack< T, N >::move().

◆ move()

template<typename T , unsigned int N>
void madness::Stack< T, N >::move ( Stack< T, N > &  other)
inlineprivate

◆ operator=() [1/2]

template<typename T , unsigned int N>
Stack<T,N>& madness::Stack< T, N >::operator= ( const Stack< T, N > &  other)
inline

Assignment operator.

If the size of other is less than or equal to N, then this object will use the small buffer. Otherwise, it will allocate memory and copy the data of other. The capacity of the object will be equal to max(N, other.size()).

Parameters
[in]otherThe stack to be copied.

References madness::Stack< T, N >::allocate(), madness::Stack< T, N >::capacity_, madness::Stack< T, N >::data_, madness::Stack< T, N >::deallocate(), madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::destroy(), madness::Stack< T, N >::size_, T(), and madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::uninitialized_copy().

◆ operator=() [2/2]

template<typename T , unsigned int N>
Stack<T,N>& madness::Stack< T, N >::operator= ( Stack< T, N > &&  other)
inline

Move assignment operator.

Move the data from other to this object. If other object is is using the static buffer, the data is moved to this object's static buffer. Otherwise, the pointer to the allocated buffer is moved.

Parameters
[in]otherThe other stack object to be moved
Note
other is left in a default constructed state so that it can continue to be used.

References madness::Stack< T, N >::data_, madness::Stack< T, N >::deallocate(), madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::destroy(), madness::Stack< T, N >::move(), and madness::Stack< T, N >::size_.

◆ pop()

template<typename T , unsigned int N>
void madness::Stack< T, N >::pop ( )
inline

◆ push()

template<typename T , unsigned int N>
void madness::Stack< T, N >::push ( const_reference  value)
inline

◆ reset()

template<typename T , unsigned int N>
void madness::Stack< T, N >::reset ( )
inline

◆ size() [1/2]

template<typename T , unsigned int N>
size_type madness::Stack< T, N >::size ( ) const
inline

Size accessor.

Returns
The number of items pushed to the stack.

References madness::Stack< T, N >::size_.

◆ size() [2/2]

template<typename T , unsigned int N>
size_type madness::Stack< T, N >::size ( ) const volatile
inline

Size accessor.

Returns
The number of items pushed to the stack.

References madness::Stack< T, N >::size_.

◆ top() [1/2]

template<typename T , unsigned int N>
reference madness::Stack< T, N >::top ( )
inline

Get the last item pushed onto the stack.

Returns
A reference to the top of the stack.
Exceptions
MadnessExceptionWhen the stack is empty

References madness::Stack< T, N >::data_, MADNESS_ASSERT, and madness::Stack< T, N >::size_.

Referenced by madness::DependencyInterface::do_callbacks(), and madness::FutureImpl< T >::set_assigned().

◆ top() [2/2]

template<typename T , unsigned int N>
const_reference madness::Stack< T, N >::top ( ) const
inline

Get the last item pushed onto the stack.

Returns
A const reference to the top of the stack.
Exceptions
MadnessExceptionWhen the stack is empty.

References madness::Stack< T, N >::data_, MADNESS_ASSERT, and madness::Stack< T, N >::size_.

Member Data Documentation

◆ buffer_

template<typename T , unsigned int N>
char madness::Stack< T, N >::buffer_[sizeof(T) *N]
private

◆ capacity_

template<typename T , unsigned int N>
size_type madness::Stack< T, N >::capacity_
private

◆ data_

template<typename T , unsigned int N>
T* madness::Stack< T, N >::data_
private

◆ size_

template<typename T , unsigned int N>
size_type madness::Stack< T, N >::size_
private

The documentation for this class was generated from the following file: