ORIGINAL
Loading...
Searching...
No Matches
original::container< TYPE, ALLOC > Class Template Referenceabstract

Abstract base class for containers. More...

#include <container.h>

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

Public Member Functions

virtual u_integer size () const =0
 Gets the number of elements in the container.
 
bool empty () const
 Checks if the container is empty.
 
virtual bool contains (const TYPE &e) const =0
 Checks if an element is contained in the container.
 
virtual ~container ()=default
 Destructor for the container class.
 

Protected Member Functions

 container (ALLOC alloc=ALLOC{})
 Constructs a container with specified allocator.
 
TYPE * allocate (u_integer size)
 Allocates raw memory for elements.
 
void deallocate (TYPE *ptr, u_integer size)
 Deallocates memory previously allocated by allocate()
 
template<typename O_TYPE, typename... Args>
void construct (O_TYPE *o_ptr, Args &&... args)
 Constructs an element in-place.
 
template<typename O_TYPE>
void destroy (O_TYPE *o_ptr)
 Destroys an element.
 

Protected Attributes

ALLOC allocator
 The allocator instance used for memory management.
 

Detailed Description

template<typename TYPE, typename ALLOC>
class original::container< TYPE, ALLOC >

Abstract base class for containers.

Template Parameters
TYPEType of the elements stored in the container.
ALLOCAllocator type for memory management (default is allocator<TYPE>)

Provides a common interface for container classes to manage a collection of elements. Supports querying the size, checking for emptiness, and checking if an element is contained. Uses the provided allocator for all memory management operations.

Constructor & Destructor Documentation

◆ container()

template<typename TYPE, typename ALLOC>
original::container< TYPE, ALLOC >::container ( ALLOC alloc = ALLOC{})
explicitprotected

Constructs a container with specified allocator.

Parameters
allocAllocator instance to use for memory management (has default-constructed ALLOC)

Initializes the container with the given allocator. The allocator will be used for all memory operations performed by the container.

◆ ~container()

template<typename TYPE, typename ALLOC>
virtual original::container< TYPE, ALLOC >::~container ( )
virtualdefault

Destructor for the container class.

Ensures proper cleanup of resources if necessary.

Member Function Documentation

◆ allocate()

template<typename TYPE, typename ALLOC>
TYPE * original::container< TYPE, ALLOC >::allocate ( u_integer size)
protected

Allocates raw memory for elements.

Parameters
sizeNumber of elements to allocate memory for
Returns
Pointer to the allocated memory
Note
The memory is allocated but elements are not constructed

◆ construct()

template<typename TYPE, typename ALLOC>
template<typename O_TYPE, typename... Args>
void original::container< TYPE, ALLOC >::construct ( O_TYPE * o_ptr,
Args &&... args )
protected

Constructs an element in-place.

Template Parameters
O_TYPEType of object to construct (must be compatible with TYPE)
ArgsTypes of constructor arguments
Parameters
o_ptrPointer to the memory where the object should be constructed
argsArguments to forward to the constructor

Uses the container's allocator to construct an object of type O_TYPE

◆ contains()

template<typename TYPE, typename ALLOC>
virtual bool original::container< TYPE, ALLOC >::contains ( const TYPE & e) const
pure virtual

Checks if an element is contained in the container.

Parameters
eElement to check for presence in the container.
Returns
True if the element is found in the container, false otherwise.

This method must be implemented by derived classes to provide the actual containment check.

bool contains = c->contains(42); // Returns true if 42 is in the container
container(ALLOC alloc=ALLOC{})
Constructs a container with specified allocator.
Definition container.h:129
virtual bool contains(const TYPE &e) const =0
Checks if an element is contained in the container.
Dynamic array container with amortized constant time operations.
Definition vector.h:42

Implemented in original::containerAdapter< TYPE, SERIAL, ALLOC >, original::containerAdapter< TYPE, blocksList, allocator >, original::containerAdapter< TYPE, chain, allocator >, original::serial< TYPE, ALLOC >, original::serial< bool, allocator< bool > >, original::serial< opts, allocator< opts > >, original::serial< TYPE, allocator< TYPE > >, and original::serial< underlying_type, rebind_alloc_underlying >.

◆ deallocate()

template<typename TYPE, typename ALLOC>
void original::container< TYPE, ALLOC >::deallocate ( TYPE * ptr,
u_integer size )
protected

Deallocates memory previously allocated by allocate()

Parameters
ptrPointer to the memory to deallocate
sizeNumber of elements the memory was allocated for
Note
Elements must be destroyed before de-allocation

◆ destroy()

template<typename TYPE, typename ALLOC>
template<typename O_TYPE>
void original::container< TYPE, ALLOC >::destroy ( O_TYPE * o_ptr)
protected

Destroys an element.

Template Parameters
O_TYPEType of object to destroy (must be compatible with TYPE)
Parameters
o_ptrPointer to the object to destroy

Uses the container's allocator to properly destroy the object

◆ empty()

template<typename TYPE, typename ALLOC>
bool original::container< TYPE, ALLOC >::empty ( ) const
nodiscard

Checks if the container is empty.

Returns
True if the container contains no elements, false otherwise.

This is implemented using size(), so it returns true if size() is zero.

bool isEmpty = c->empty(); // Returns true if the container is empty
bool empty() const
Checks if the container is empty.
Definition container.h:155

◆ size()

template<typename TYPE, typename ALLOC>
virtual u_integer original::container< TYPE, ALLOC >::size ( ) const
nodiscardpure virtual

Member Data Documentation

◆ allocator

template<typename TYPE, typename ALLOC>
ALLOC original::container< TYPE, ALLOC >::allocator
protected

The allocator instance used for memory management.

Used by derived classes to allocate/deallocate memory and construct/destroy elements


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