MADNESS 0.10.1
|
Dynamically sized Stack with small stack size optimization. More...
#include <stack.h>
Public Types | |
typedef const T & | const_reference |
Element constant reference type. | |
typedef T & | reference |
Element reference type. | |
typedef unsigned int | size_type |
An unsigned integral type. | |
typedef T | value_type |
Type of the stack elements. | |
Public Member Functions | |
Stack () | |
Construct an empty stack. | |
Stack (const Stack< T, N > &other) | |
Copy constructor. | |
Stack (Stack< T, N > &&other) | |
Move constructor. | |
~Stack () | |
Destructor. | |
size_type | capacity () const |
Capacity accessor. | |
void | clear () |
Empty the stack. | |
T * | data () |
Data accessor. | |
const T * | data () const |
Data accessor. | |
bool | empty () const |
Check if the stack is empty. | |
bool | empty () const volatile |
Check if the stack is empty. | |
Stack< T, N > & | operator= (const Stack< T, N > &other) |
Assignment operator. | |
Stack< T, N > & | operator= (Stack< T, N > &&other) |
Move assignment operator. | |
void | pop () |
Pop an item off of the stack. | |
void | push (const_reference value) |
Push a new item onto the stack. | |
void | reset () |
Empty the stack and free memory. | |
size_type | size () const |
Size accessor. | |
size_type | size () const volatile |
Size accessor. | |
reference | top () |
Get the last item pushed onto the stack. | |
const_reference | top () const |
Get the last item pushed onto the stack. | |
Private Types | |
typedef detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value > | StackBase_ |
Private Member Functions | |
T * | allocate (const size_type n) |
Allocate a raw buffer. | |
void | deallocate () |
Deallocate memory. | |
bool | is_small () const |
Check if the stack is using the small buffer to store data. | |
void | move (Stack< T, N > &other) |
Private Attributes | |
char | buffer_ [sizeof(T) *N] |
Static buffer for storing a small number of elements. | |
size_type | capacity_ |
The maximum size, in elements, of the data_ buffer. | |
T * | data_ |
Pointer to the stack data. | |
size_type | size_ |
Number of elements on the stack. | |
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. | |
static void | destroy (T *ptr) |
Destroy a non-POD object. | |
static void | uninitialized_copy (T *first, T *last, T *dest) |
Copy a range of POD objects. | |
static void | uninitialized_move (T *first, T *last, T *dest) |
Move a range of POD objects. | |
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
.
T | The type of data stored in the stack. |
N | The fixed size of the stack. |
typedef const T& madness::Stack< T, N >::const_reference |
Element constant reference type.
typedef T& madness::Stack< T, N >::reference |
Element reference type.
typedef unsigned int madness::Stack< T, N >::size_type |
An unsigned integral type.
|
private |
typedef T madness::Stack< T, N >::value_type |
Type of the stack elements.
|
inline |
Construct an empty stack.
The capacity of the stack is N
.
|
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())
.
[in] | other | The 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().
|
inline |
Move constructor.
Move the data from other
to this object.
[in] | other | The original stack. |
References madness::Stack< T, N >::move().
|
inline |
|
inlineprivate |
Allocate a raw buffer.
Allocate an uninitialized buffer.
[in] | n | The size of the new buffer. |
References T().
Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::operator=(), and madness::Stack< T, N >::push().
|
inline |
Capacity accessor.
References madness::Stack< T, N >::capacity_.
|
inline |
Empty the stack.
Destroy items on the stack (if any) and set the size to 0.
References madness::Stack< T, N >::data_, madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::destroy(), madness::Stack< T, N >::size_, and u().
|
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 >::operator=(), madness::Stack< T, N >::push(), and madness::Stack< T, N >::reset().
|
inline |
Check if the stack is empty.
References madness::Stack< T, N >::size_.
|
inline |
Check if the stack is empty.
References madness::Stack< T, N >::size_.
|
inlineprivate |
Check if the stack is using the small buffer to store data.
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().
|
inlineprivate |
other | Description needed. |
References madness::Stack< T, N >::buffer_, madness::Stack< T, N >::capacity_, madness::Stack< T, N >::data_, madness::Stack< T, N >::is_small(), N, madness::Stack< T, N >::size_, T(), u(), and madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::uninitialized_move().
Referenced by madness::Stack< T, N >::Stack(), and madness::Stack< T, N >::operator=().
|
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())
.
[in] | other | The 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().
|
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.
[in] | other | The other stack object to be moved |
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_.
|
inline |
Pop an item off of the stack.
MadnessException | (via MADNESS_ASSERT) if the stack is empty. |
References madness::Stack< T, N >::data_, madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::destroy(), MADNESS_ASSERT, and madness::Stack< T, N >::size_.
|
inline |
Push a new item onto the stack.
Push an item onto the top of the stack. If the stack size is equal to the capacity, resize the stack (double).
[in] | value | The item to be pushed onto the stack. |
References madness::Stack< T, N >::allocate(), madness::Stack< T, N >::capacity_, madness::Stack< T, N >::data_, madness::Stack< T, N >::deallocate(), madness::Stack< T, N >::size_, T(), and madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::uninitialized_move().
|
inline |
Empty the stack and free memory.
Destroy items on the stack (if any) and return it to the default constructed state.
References madness::Stack< T, N >::buffer_, 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(), N, madness::Stack< T, N >::size_, T(), and u().
|
inline |
Size accessor.
References madness::Stack< T, N >::size_.
|
inline |
Size accessor.
References madness::Stack< T, N >::size_.
|
inline |
Get the last item pushed onto the stack.
MadnessException | When the stack is empty |
References madness::Stack< T, N >::data_, MADNESS_ASSERT, and madness::Stack< T, N >::size_.
|
inline |
Get the last item pushed onto the stack.
MadnessException | When the stack is empty. |
References madness::Stack< T, N >::data_, MADNESS_ASSERT, and madness::Stack< T, N >::size_.
Static buffer for storing a small number of elements.
Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::is_small(), madness::Stack< T, N >::move(), and madness::Stack< T, N >::reset().
|
private |
The maximum size, in elements, of the data_
buffer.
Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::capacity(), madness::Stack< T, N >::move(), madness::Stack< T, N >::operator=(), madness::Stack< T, N >::push(), and madness::Stack< T, N >::reset().
|
private |
Pointer to the stack data.
Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::~Stack(), madness::Stack< T, N >::clear(), madness::Stack< T, N >::data(), madness::Stack< T, N >::data(), madness::Stack< T, N >::deallocate(), madness::Stack< T, N >::is_small(), madness::Stack< T, N >::move(), madness::Stack< T, N >::operator=(), madness::Stack< T, N >::operator=(), madness::Stack< T, N >::pop(), madness::Stack< T, N >::push(), madness::Stack< T, N >::reset(), madness::Stack< T, N >::top(), and madness::Stack< T, N >::top().
|
private |
Number of elements on the stack.
Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::~Stack(), madness::Stack< T, N >::clear(), madness::Stack< T, N >::empty(), madness::Stack< T, N >::empty(), madness::Stack< T, N >::move(), madness::Stack< T, N >::operator=(), madness::Stack< T, N >::operator=(), madness::Stack< T, N >::pop(), madness::Stack< T, N >::push(), madness::Stack< T, N >::reset(), madness::Stack< T, N >::size(), madness::Stack< T, N >::size(), madness::Stack< T, N >::top(), and madness::Stack< T, N >::top().