ORIGINAL
Loading...
Searching...
No Matches
original::randomAccessIterator< TYPE, ALLOC > Class Template Reference

Abstract base class for random-access iterators. More...

#include <randomAccessIterator.h>

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

Public Member Functions

 randomAccessIterator (const randomAccessIterator &other)
 Copy constructor.
 
randomAccessIteratoroperator= (const randomAccessIterator &other)
 Copy assignment operator.
 
randomAccessIteratorclone () const override
 Creates a heap-allocated copy.
 
bool hasNext () const override
 Checks forward traversal capability.
 
bool hasPrev () const override
 Checks reverse traversal capability.
 
bool atPrev (const iterator< TYPE > *other) const override
 Checks if the current iterator is at the previous position compared to another iterator.
 
bool atNext (const iterator< TYPE > *other) const override
 Checks if the current iterator is at the next position compared to another iterator.
 
void next () const override
 Advances to the next position in the container.
 
void prev () const override
 Retreats to the previous position in the container.
 
void operator+= (integer steps) const override
 Moves forward by N positions.
 
void operator-= (integer steps) const override
 Moves backward by N positions.
 
integer operator- (const iterator< TYPE > &other) const override
 Computes the distance between the current iterator and another iterator.
 
randomAccessIteratorgetNext () const override
 Gets an iterator pointing to the next element.
 
randomAccessIteratorgetPrev () const override
 Gets an iterator pointing to the previous element.
 
TYPE & get () override
 Gets the current element in the container.
 
TYPE get () const override
 Gets the current element in the container (const version)
 
void set (const TYPE &data) override
 Sets the value of the current element.
 
bool isValid () const override
 Checks if the iterator is valid (points to a valid element in the container)
 
std::string className () const override
 Gets the class name of the iterator.
 
- Public Member Functions inherited from original::baseIterator< TYPE >
 ~baseIterator () override=default
 Virtual destructor for proper cleanup of derived objects.
 
- Public Member Functions inherited from original::iterator< TYPE >
TYPE & operator* ()
 Dereferences the iterator to get the element.
 
TYPE operator* () const
 Dereferences the iterator to get a copy of the element.
 
void operator++ () const
 Moves the iterator forward by one position.
 
void operator++ (int postfix) const
 Moves the iterator forward by one position (postfix).
 
void operator-- () const
 Moves the iterator backward by one position.
 
void operator-- (int postfix) const
 Moves the iterator backward by one position (postfix).
 
integer compareTo (const iterator &other) const override
 Compares two iterators to determine their relative positions.
 
 operator bool () const
 Checks if the iterator is valid (i.e., points to a valid element).
 
bool atPrev (const iterator &other) const
 Checks if this iterator is positioned at the previous element.
 
bool atNext (const iterator &other) const
 Checks if this iterator is positioned at the next element.
 
virtual TYPE getElem () const
 Returns a copy of the element.
 
bool equal (const iterator *other) const
 Checks if two iterators are equal.
 
bool equal (const iterator &other) const
 Checks if two iterators are equal.
 
std::string toString (bool enter) const override
 Returns a string representation of the iterator.
 
 ~iterator () override=default
 Virtual destructor for proper cleanup of derived objects.
 
- 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 char * toCString (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::cloneable
 ~cloneable () override=default
 Virtual destructor for cloneable.
 
- Public Member Functions inherited from original::baseCloneable< cloneable >
virtual ~baseCloneable ()=default
 Virtual destructor for baseCloneable.
 
- Public Member Functions inherited from original::comparable< iterator< TYPE > >
bool operator== (const iterator< TYPE > &other) const
 Checks if the current object is equal to another.
 
bool operator!= (const iterator< TYPE > &other) const
 Checks if the current object is not equal to another.
 
bool operator< (const iterator< TYPE > &other) const
 Checks if the current object is less than another.
 
bool operator> (const iterator< TYPE > &other) const
 Checks if the current object is greater than another.
 
bool operator<= (const iterator< TYPE > &other) const
 Checks if the current object is less than or equal to another.
 
bool operator>= (const iterator< TYPE > &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.
 

Protected Member Functions

 randomAccessIterator (TYPE *ptr, const container< TYPE, ALLOC > *container, integer pos)
 Protected constructor for derived classes.
 
bool equalPtr (const iterator< TYPE > *other) const override
 Equality comparison implementation.
 
- Protected Member Functions inherited from original::cloneable
 cloneable ()=default
 Default constructor for cloneable.
 
- Protected Member Functions inherited from original::baseCloneable< cloneable >
 baseCloneable ()=default
 Default constructor for baseCloneable.
 

Protected Attributes

TYPE * _ptr
 Pointer to the current element.
 
const container< TYPE, ALLOC > * _container
 Reference to the parent container.
 
integer _pos
 Absolute position in the container.
 

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.
 
template<typename TYPE>
static std::string formatString (TYPE *const &ptr)
 Pointer-specific formatting.
 
template<typename TYPE>
static const char * formatCString (const TYPE &t)
 C-string cache for temporary usage.
 
template<typename TYPE>
static std::string formatEnum (const TYPE &t)
 Enum formatting utility.
 
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
 

Detailed Description

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

Abstract base class for random-access iterators.

Template Parameters
TYPEType of elements being iterated
ALLOCAllocator type used by the parent container for memory management

Implements core functionality for iterators that support:

  • Pointer arithmetic operations (+, +=, -, -=)
  • Bidirectional traversal
  • Position validity checking
  • Element access/modification
Note
The ALLOC template parameter must match the allocator type of the parent container. It is used to ensure type compatibility between the iterator and its container.
Maintains three state markers:
  • Raw pointer to the current element
  • Reference to parent container (which uses the ALLOC allocator)
  • Absolute position index

Constructor & Destructor Documentation

◆ randomAccessIterator() [1/2]

template<typename TYPE, typename ALLOC>
original::randomAccessIterator< TYPE, ALLOC >::randomAccessIterator ( TYPE * ptr,
const container< TYPE, ALLOC > * container,
integer pos )
explicitprotected

Protected constructor for derived classes.

Parameters
ptrRaw element pointer
containerParent container reference
posInitial position index

◆ randomAccessIterator() [2/2]

template<typename TYPE, typename ALLOC>
original::randomAccessIterator< TYPE, ALLOC >::randomAccessIterator ( const randomAccessIterator< TYPE, ALLOC > & other)

Copy constructor.

Parameters
otherIterator to copy from

Member Function Documentation

◆ atNext()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::atNext ( const iterator< TYPE > * other) const
overridevirtual

Checks if the current iterator is at the next position compared to another iterator.

Parameters
otherThe iterator to compare with.
Returns
True if the iterator is at the next position, otherwise false.

Implements original::iterator< TYPE >.

◆ atPrev()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::atPrev ( const iterator< TYPE > * other) const
overridevirtual

Checks if the current iterator is at the previous position compared to another iterator.

Parameters
otherThe iterator to compare with.
Returns
True if the iterator is at the previous position, otherwise false.

Implements original::iterator< TYPE >.

◆ className()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::className ( ) const
nodiscardoverridevirtual

Gets the class name of the iterator.

Returns
The class name as a string

Reimplemented from original::iterator< TYPE >.

◆ clone()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::clone ( ) const
overridevirtual

Creates a heap-allocated copy.

Returns
New iterator instance

Implements original::baseIterator< TYPE >.

◆ equalPtr()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::equalPtr ( const iterator< TYPE > * other) const
overrideprotectedvirtual

Equality comparison implementation.

Parameters
otherIterator to compare with
Returns
True when pointing to the same memory location

Implements original::iterator< TYPE >.

◆ get() [1/2]

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::get ( ) const
overridevirtual

Gets the current element in the container (const version)

Returns
Const reference to the current element

Implements original::iterator< TYPE >.

◆ get() [2/2]

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::get ( )
overridevirtual

Gets the current element in the container.

Returns
Reference to the current element

Implements original::iterator< TYPE >.

◆ getNext()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::getNext ( ) const
overridevirtual

Gets an iterator pointing to the next element.

Returns
A new iterator pointing to the next element

Reimplemented from original::iterator< TYPE >.

◆ getPrev()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::getPrev ( ) const
overridevirtual

Gets an iterator pointing to the previous element.

Returns
A new iterator pointing to the previous element

Implements original::iterator< TYPE >.

◆ hasNext()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::hasNext ( ) const
nodiscardoverridevirtual

Checks forward traversal capability.

Returns
True if not at the end

Implements original::iterator< TYPE >.

◆ hasPrev()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::hasPrev ( ) const
nodiscardoverridevirtual

Checks reverse traversal capability.

Returns
True if not at the beginning

Implements original::iterator< TYPE >.

◆ isValid()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::isValid ( ) const
nodiscardoverridevirtual

Checks if the iterator is valid (points to a valid element in the container)

Returns
True if the iterator is valid, otherwise false

Implements original::iterator< TYPE >.

◆ next()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::next ( ) const
overridevirtual

Advances to the next position in the container.

Implements original::iterator< TYPE >.

◆ operator+=()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::operator+= ( integer steps) const
overridevirtual

Moves forward by N positions.

Parameters
stepsNumber of positions to advance

Implements original::iterator< TYPE >.

◆ operator-()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::operator- ( const iterator< TYPE > & other) const
overridevirtual

Computes the distance between the current iterator and another iterator.

Parameters
otherThe iterator to compare with
Returns
The number of positions between the two iterators

Implements original::iterator< TYPE >.

◆ operator-=()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::operator-= ( integer steps) const
overridevirtual

Moves backward by N positions.

Parameters
stepsNumber of positions to retreat

Implements original::iterator< TYPE >.

◆ operator=()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::operator= ( const randomAccessIterator< TYPE, ALLOC > & other)

Copy assignment operator.

Parameters
otherIterator to copy from
Returns
Reference to this iterator

◆ prev()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::prev ( ) const
overridevirtual

Retreats to the previous position in the container.

Implements original::iterator< TYPE >.

◆ set()

template<typename TYPE, typename ALLOC>
auto original::randomAccessIterator< TYPE, ALLOC >::set ( const TYPE & data)
overridevirtual

Sets the value of the current element.

Parameters
dataThe value to set to the current element

Implements original::iterator< TYPE >.


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