ORIGINAL
Loading...
Searching...
No Matches
Public Member Functions | List of all members
original::stack< TYPE, SERIAL, ALLOC > Class Template Referencefinal

Last-In-First-Out (LIFO) container adapter. More...

#include <stack.h>

Inheritance diagram for original::stack< TYPE, SERIAL, ALLOC >:
Inheritance graph
Collaboration diagram for original::stack< TYPE, SERIAL, ALLOC >:
Collaboration graph

Public Member Functions

 stack (const SERIAL< TYPE, ALLOC< TYPE > > &serial=SERIAL< TYPE, ALLOC< TYPE > >{})
 Constructs a stack with specified underlying container and allocator.
 
 stack (const std::initializer_list< TYPE > &lst)
 Constructs stack from initializer list with allocator.
 
 stack (const stack &other)
 Copy constructs a stack with allocator propagation.
 
stackoperator= (const stack &other)
 Copy assignment operator.
 
 stack (stack &&other) noexcept
 Move constructs a stack with allocator propagation.
 
stackoperator= (stack &&other) noexcept
 Move assignment operator.
 
void push (const TYPE &e)
 Pushes element to the top of the stack.
 
TYPE pop ()
 Removes and returns top element from the stack.
 
TYPE top () const
 Accesses the top element of the stack.
 
std::string className () const override
 Gets the class name identifier.
 
- Public Member Functions inherited from original::containerAdapter< TYPE, SERIAL, ALLOC >
u_integer size () const override
 Returns the number of elements in the adapter.
 
void swap (containerAdapter &other) noexcept
 Swaps the contents of this container adapter with another.
 
void clear ()
 Removes all elements from the adapter.
 
bool contains (const TYPE &e) const override
 Checks for element existence in the adapter.
 
integer compareTo (const containerAdapter &other) const override
 Compares two container adapters lexicographically.
 
u_integer toHash () const noexcept override
 Computes hash value for the container adapter.
 
std::string toString (bool enter) const override
 Generates formatted string representation.
 
 ~containerAdapter () override=default
 Virtual destructor for proper polymorphic cleanup.
 
- Public Member Functions inherited from original::printable
 operator std::string () const
 Explicit conversion to std::string.
 
 operator const char * () const
 Explicit conversion to C-style string.
 
const chartoCString (bool enter) const
 Direct C-string access with formatting control.
 
template<typename TYPE >
auto formatString (const TYPE &t) -> std::string
 
template<typename TYPE >
auto formatCString (const TYPE &t) -> const char *
 
template<typename TYPE >
auto formatEnum (const TYPE &t) -> std::string
 
template<typename TYPE >
auto formatString (TYPE *const &ptr) -> std::string
 
- Public Member Functions inherited from original::container< TYPE, ALLOC< TYPE > >
bool empty () const
 Checks if the container is empty.
 
virtual ~container ()=default
 Destructor for the container class.
 
- Public Member Functions inherited from original::comparable< containerAdapter< TYPE, SERIAL, ALLOC > >
bool operator== (const containerAdapter< TYPE, SERIAL, ALLOC > &other) const
 Checks if the current object is equal to another.
 
bool operator!= (const containerAdapter< TYPE, SERIAL, ALLOC > &other) const
 Checks if the current object is not equal to another.
 
bool operator< (const containerAdapter< TYPE, SERIAL, ALLOC > &other) const
 Checks if the current object is less than another.
 
bool operator> (const containerAdapter< TYPE, SERIAL, ALLOC > &other) const
 Checks if the current object is greater than another.
 
bool operator<= (const containerAdapter< TYPE, SERIAL, ALLOC > &other) const
 Checks if the current object is less than or equal to another.
 
bool operator>= (const containerAdapter< TYPE, SERIAL, ALLOC > &other) const
 Checks if the current object is greater than or equal to another.
 
virtual ~comparable ()=default
 Virtual destructor for proper cleanup of derived objects.
 
- Public Member Functions inherited from original::hashable< containerAdapter< TYPE, SERIAL, ALLOC > >
virtual bool equals (const containerAdapter< TYPE, SERIAL, ALLOC > &other) const noexcept
 Compares two objects for equality.
 
virtual ~hashable ()=0
 Virtual destructor.
 

Additional Inherited Members

- Static Public Member Functions inherited from original::printable
template<typename TYPE >
static std::string formatString (const TYPE &t)
 Universal value-to-string conversion with type-specific formatting.
 
template<Printable TYPE>
static std::string formatString (const TYPE &t)
 Specialization for types deriving from printable.
 
template<EnumType TYPE>
static std::string formatString (const TYPE &t)
 Specialization for enum types with type-safe formatting.
 
template<typename TYPE >
static std::string formatString (TYPE *const &ptr)
 Pointer-specific formatting with null safety.
 
template<typename TYPE >
static const charformatCString (const TYPE &t)
 C-string cache for temporary usage with static storage.
 
template<typename TYPE >
static std::string formatEnum (const TYPE &t)
 Enum formatting utility with underlying value extraction.
 
template<>
auto formatString (const char &t) -> std::string
 
template<>
auto formatString (const bool &t) -> std::string
 
template<>
auto formatString (const char *const &ptr) -> std::string
 
- Protected Member Functions inherited from original::containerAdapter< TYPE, SERIAL, ALLOC >
 containerAdapter (const SERIAL< TYPE, ALLOC< TYPE > > &serial)
 Constructs a container adapter with specified underlying container.
 
- Protected Member Functions inherited from original::container< TYPE, ALLOC< TYPE > >
 container (ALLOC< TYPE > alloc=ALLOC< TYPE > {})
 Constructs a container with specified allocator.
 
TYPEallocate (u_integer size)
 Allocates raw memory for elements.
 
void deallocate (TYPE *ptr, u_integer size)
 Deallocates memory previously allocated by allocate()
 
void construct (O_TYPE *o_ptr, Args &&... args)
 Constructs an element in-place.
 
void destroy (O_TYPE *o_ptr)
 Destroys an element.
 
- Protected Attributes inherited from original::containerAdapter< TYPE, SERIAL, ALLOC >
SERIAL< TYPE, ALLOC< TYPE > > serial_
 The underlying container instance.
 
- Protected Attributes inherited from original::container< TYPE, ALLOC< TYPE > >
ALLOC< TYPEallocator
 The allocator instance used for memory management.
 

Detailed Description

template<typename TYPE, template< typename, typename > typename SERIAL = chain, template< typename > typename ALLOC = allocator>
class original::stack< TYPE, SERIAL, ALLOC >

Last-In-First-Out (LIFO) container adapter.

Template Parameters
TYPEType of elements stored in the stack
SERIALUnderlying container type (default: chain)
ALLOCAllocator type for memory management (default: allocator<TYPE>)

Implements stack operations using the specified underlying container type. Provides standard stack interface including push, pop, top, and comparison operations. The adapter maintains elements through composition with the specified SERIAL container.

The allocator is propagated to both the stack adapter and the underlying serial container for consistent memory management. The ALLOC type must meet the C++ allocator requirements and provide:

Constructor & Destructor Documentation

◆ stack() [1/4]

original::stack< TYPE, SERIAL, ALLOC >::stack ( const SERIAL< TYPE, ALLOC< TYPE > > &  serial = SERIAL<TYPEALLOC<TYPE>>{})
explicit

Constructs a stack with specified underlying container and allocator.

Parameters
serialContainer instance to initialize stack (default: empty)

The allocator from the provided container will be used for all memory operations. If no container is provided, a default-constructed container with default allocator will be used.

◆ stack() [2/4]

original::stack< TYPE, SERIAL, ALLOC >::stack ( const std::initializer_list< TYPE > &  lst)

Constructs stack from initializer list with allocator.

Parameters
lstList of elements to initialize the stack

Uses the default allocator to construct the underlying container and populate it with elements from the initializer list.

◆ stack() [3/4]

original::stack< TYPE, SERIAL, ALLOC >::stack ( const stack< TYPE, SERIAL, ALLOC > &  other)

Copy constructs a stack with allocator propagation.

Parameters
otherStack instance to copy from
Note
The allocator is copied if ALLOC::propagate_on_container_copy_assignment is true

◆ stack() [4/4]

original::stack< TYPE, SERIAL, ALLOC >::stack ( stack< TYPE, SERIAL, ALLOC > &&  other)
noexcept

Move constructs a stack with allocator propagation.

Parameters
otherStack instance to move from
Note
The allocator is moved if ALLOC::propagate_on_container_move_assignment is true
noexcept guarantees exception safety during move

Member Function Documentation

◆ className()

std::string original::stack< TYPE, SERIAL, ALLOC >::className ( ) const
overridevirtual

Gets the class name identifier.

Returns
"stack" string identifier

Reimplemented from original::containerAdapter< TYPE, SERIAL, ALLOC >.

◆ operator=() [1/2]

auto original::stack< TYPE, SERIAL, ALLOC >::operator= ( const stack< TYPE, SERIAL, ALLOC > &  other)

Copy assignment operator.

Parameters
otherStack instance to copy from
Returns
Reference to this stack
Note
The allocator is copied if ALLOC::propagate_on_container_copy_assignment is true

◆ operator=() [2/2]

auto original::stack< TYPE, SERIAL, ALLOC >::operator= ( stack< TYPE, SERIAL, ALLOC > &&  other)
noexcept

Move assignment operator.

Parameters
otherStack instance to move from
Returns
Reference to this stack
Note
noexcept guarantees no exceptions during move
The allocator is moved if ALLOC::propagate_on_container_move_assignment is true

◆ pop()

Removes and returns top element from the stack.

Returns
The element removed from top of stack
Precondition
Stack should not be empty

Uses the stack's allocator to destroy the removed element.

Exceptions
original::noElementErrorif stack is empty
Note
No-throw guarantee if TYPE's destructor doesn't throw @complexity Depends on underlying container (typically O(1))

◆ push()

Pushes element to the top of the stack.

Parameters
eElement to be pushed

Uses the stack's allocator to construct the new element at the top.

Note
Strong exception guarantee - if an exception is thrown, the stack remains unchanged @complexity Depends on underlying container (typically O(1) amortized)

◆ top()

auto original::stack< TYPE, SERIAL, ALLOC >::top ( ) const

Accesses the top element of the stack.

Returns
Const reference to the top element
Precondition
Stack should not be empty

Provides O(1) access to the top element.

Exceptions
original::noElementErrorif stack is empty @complexity O(1)

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