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

Abstract base class for sequential containers with index-based access. More...

#include <serial.h>

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

Public Member Functions

virtual TYPE get (integer index) const =0
 Retrieves the element at the specified index.
 
virtual TYPE getBegin () const
 Retrieves the first element in the container.
 
virtual TYPE getEnd () const
 Retrieves the last element in the container.
 
virtual TYPE operator[] (integer index) const
 Retrieves the element at the specified index (const version).
 
virtual TYPE & operator[] (integer index)=0
 Retrieves or sets the element at the specified index.
 
virtual void set (integer index, const TYPE &e)=0
 Sets the element at the specified index.
 
virtual u_integer indexOf (const TYPE &e) const =0
 Finds the index of the specified element.
 
bool contains (const TYPE &e) const override
 Checks if the container contains the specified element.
 
- Public Member Functions inherited from original::container< TYPE, ALLOC >
virtual u_integer size () const =0
 Gets the number of elements in the container.
 
bool empty () const
 Checks if the container is empty.
 
virtual ~container ()=default
 Destructor for the container class.
 

Protected Member Functions

bool indexOutOfBound (integer index) const
 Checks if the provided index is out of bounds.
 
integer parseNegIndex (integer index) const
 Converts negative indices into valid positive indices.
 
- Protected Member Functions inherited from original::container< TYPE, ALLOC >
 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.
 

Additional Inherited Members

- Protected Attributes inherited from original::container< TYPE, ALLOC >
ALLOC allocator
 The allocator instance used for memory management.
 

Detailed Description

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

Abstract base class for sequential containers with index-based access.

Template Parameters
TYPEType of the elements contained in the serial container
ALLOCAllocator type for memory management (default: depends on derived class)

Defines common interface for containers that support index-based access to their elements. It provides methods for element retrieval, bounds checking, and negative index handling. Derived classes must implement get(), operator[], set(), and indexOf() methods.

The allocator is inherited from the base container class and is propagated to derived classes for consistent memory management. The ALLOC type must meet the C++ allocator requirements.

Member Function Documentation

◆ contains()

template<typename TYPE, typename ALLOC>
auto original::serial< TYPE, ALLOC >::contains ( const TYPE & e) const
overridevirtual

Checks if the container contains the specified element.

Parameters
eThe element to check for.
Returns
true if the container contains the element, otherwise false.

This method uses indexOf() by default to check if the element exists within the container.

Implements original::container< TYPE, ALLOC >.

◆ get()

◆ getBegin()

template<typename TYPE, typename ALLOC>
auto original::serial< TYPE, ALLOC >::getBegin ( ) const
virtual

Retrieves the first element in the container.

Returns
The first element in the container.

This method provides a shortcut to get the first element by calling get(0).

◆ getEnd()

template<typename TYPE, typename ALLOC>
auto original::serial< TYPE, ALLOC >::getEnd ( ) const
virtual

Retrieves the last element in the container.

Returns
The last element in the container.

This method provides a shortcut to get the last element by calling get(-1).

◆ indexOf()

◆ indexOutOfBound()

template<typename TYPE, typename ALLOC>
auto original::serial< TYPE, ALLOC >::indexOutOfBound ( integer index) const
nodiscardprotected

Checks if the provided index is out of bounds.

Parameters
indexThe index to check.
Returns
true if the index is out of bounds, otherwise false.

This method accounts for negative indices by converting them to positive indices before performing the bounds check.

◆ operator[]() [1/2]

template<typename TYPE, typename ALLOC>
auto original::serial< TYPE, ALLOC >::operator[] ( integer index) const
virtual

Retrieves the element at the specified index (const version).

Parameters
indexThe index of the element.
Returns
Reference/copy of the element at the given index.

The non-const version allows direct modification of elements in allocator-managed storage. The const version returns a copy of the element.

Exceptions
Maythrow original::outOfBoundError exceptions for invalid indices

◆ operator[]() [2/2]

◆ parseNegIndex()

template<typename TYPE, typename ALLOC>
auto original::serial< TYPE, ALLOC >::parseNegIndex ( integer index) const
nodiscardprotected

Converts negative indices into valid positive indices.

Parameters
indexThe index to convert.
Returns
The corresponding positive index for negative indices, otherwise returns the original index.

For example, if the index is -1, it will be converted to the last element's index.

◆ set()


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