ORIGINAL
Loading...
Searching...
No Matches
original::iterator< TYPE > Class Template Referenceabstract

Base iterator interface that supports common operations for iteration. More...

#include <iterator.h>

Inheritance diagram for original::iterator< TYPE >:
Inheritance graph
Collaboration diagram for original::iterator< TYPE >:
Collaboration graph

Public Member Functions

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).
 
virtual void operator+= (integer steps) const =0
 Adds a number of steps to the current position of iterator.
 
virtual void operator-= (integer steps) const =0
 Subtracts a number of steps from the current position of iterator.
 
integer compareTo (const iterator &other) const override
 Compares two iterators to determine their relative positions.
 
virtual integer operator- (const iterator &other) const =0
 Returns the distance between this iterator and another iterator.
 
iteratorclone () const override=0
 Creates a clone of the iterator.
 
 operator bool () const
 Checks if the iterator is valid (i.e., points to a valid element).
 
virtual bool hasNext () const =0
 Checks if there is a next element.
 
virtual bool hasPrev () const =0
 Checks if there is a previous element.
 
virtual bool atPrev (const iterator *other) const =0
 Checks if this iterator is positioned at the previous element.
 
virtual bool atNext (const iterator *other) const =0
 Checks if this iterator is positioned at the next 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 void next () const =0
 Moves the iterator to the next element.
 
virtual void prev () const =0
 Moves the iterator to the previous element.
 
virtual iteratorgetNext () const
 Returns a new iterator pointing to the next element.
 
virtual iteratorgetPrev () const =0
 Returns a new iterator pointing to the previous element.
 
virtual TYPE & get ()=0
 Gets the element pointed to by the iterator.
 
virtual TYPE get () const =0
 Gets a copy of the element pointed to by the iterator.
 
virtual TYPE getElem () const
 Returns a copy of the element.
 
virtual void set (const TYPE &data)=0
 Sets the element pointed to by the iterator.
 
bool equal (const iterator *other) const
 Checks if two iterators are equal.
 
bool equal (const iterator &other) const
 Checks if two iterators are equal.
 
virtual bool isValid () const =0
 Checks if the iterator is valid.
 
std::string className () const override
 Returns the class name of the iterator.
 
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

virtual bool equalPtr (const iterator *other) const =0
 Checks if two iterators point to the same underlying element.
 
- 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.
 

Friends

template<typename T>
iterator< T > * operator+ (const iterator< T > &it, integer steps)
 Adds a number of steps to the iterator's current position and returns a new iterator.
 
template<typename T>
iterator< T > * operator- (const iterator< T > &it, integer steps)
 Subtracts a number of steps from the iterator's current position and returns a new iterator.
 
template<typename T>
bool operator== (const iterator< T > &l_it, const iterator< T > &r_it)
 Equality comparison operator for iterators.
 
template<typename T>
bool operator!= (const iterator< T > &l_it, const iterator< T > &r_it)
 Inequality comparison operator for iterators.
 

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>
class original::iterator< TYPE >

Base iterator interface that supports common operations for iteration.

Template Parameters
TYPEThe type of elements the iterator traverses.

This class provides common operations for iterators, including dereferencing, moving forward and backward, and comparing iterators. It also supports cloning, and printing elements.

Derived classes are expected to provide specific implementations for methods like next(), prev(), get(), and set(). These implementations define the behavior of the iterator in a particular container.

Equality comparisons (== and !=) are optimized to use the equalPtr method for constant-time comparison, while ordering comparisons (<, >, <=, >=) and distance calculations use the compareTo method which may have different time complexity depending on the container implementation.

Member Function Documentation

◆ atNext() [1/2]

template<typename TYPE>
auto original::iterator< TYPE >::atNext ( const iterator< TYPE > & other) const

Checks if this iterator is positioned at the next element.

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

◆ atNext() [2/2]

template<typename TYPE>
virtual bool original::iterator< TYPE >::atNext ( const iterator< TYPE > * other) const
pure virtual

◆ atPrev() [1/2]

template<typename TYPE>
auto original::iterator< TYPE >::atPrev ( const iterator< TYPE > & other) const

Checks if this iterator is positioned at the previous element.

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

◆ atPrev() [2/2]

template<typename TYPE>
virtual bool original::iterator< TYPE >::atPrev ( const iterator< TYPE > * other) const
pure virtual

◆ className()

template<typename TYPE>
auto original::iterator< TYPE >::className ( ) const
nodiscardoverridevirtual

Returns the class name of the iterator.

Returns
A string representing the class name.

Reimplemented from original::printable.

Reimplemented in original::randomAccessIterator< TYPE, ALLOC >, and original::stepIterator< TYPE >.

◆ clone()

◆ compareTo()

template<typename TYPE>
auto original::iterator< TYPE >::compareTo ( const iterator< TYPE > & other) const
overridevirtual

Compares two iterators to determine their relative positions.

Parameters
otherThe iterator to compare with.
Returns
A negative value if this iterator is before the other, zero if at the same position, and a positive value if after the other.

This method provides ordering comparison between iterators, typically by calculating the distance between positions. Used by comparison operators (<, >, <=, >=) and three-way comparison (<=>).

Note this may be more expensive than pointer equality checks (equalPtr), as it may need to compute relative distances in the container.

Note
For simple equality checks, prefer using equalPtr via operator==/!= instead.

Implements original::comparable< iterator< TYPE > >.

◆ equal() [1/2]

template<typename TYPE>
auto original::iterator< TYPE >::equal ( const iterator< TYPE > & other) const

Checks if two iterators are equal.

Parameters
otherThe iterator to compare with.
Returns
True if the iterators are equal, false otherwise.

◆ equal() [2/2]

template<typename TYPE>
auto original::iterator< TYPE >::equal ( const iterator< TYPE > * other) const

Checks if two iterators are equal.

Parameters
otherThe iterator to compare with.
Returns
True if the iterators are equal, false otherwise.

◆ equalPtr()

template<typename TYPE>
virtual bool original::iterator< TYPE >::equalPtr ( const iterator< TYPE > * other) const
protectedpure virtual

Checks if two iterators point to the same underlying element.

Parameters
otherThe iterator to compare with.
Returns
True if the iterators point to the same object, false otherwise.

This method provides an optimized way to check iterator equality by comparing their underlying pointers or positions directly. It is used by the equality operators (== and !=) to provide constant-time comparison. Derived classes must implement this to compare their internal representation directly for optimal performance.

Note
This should be a lightweight comparison that doesn't involve distance calculations or complex logic. For ordering comparisons, use compareTo instead.

Implemented in original::iterable< TYPE >::iterAdaptor, original::randomAccessIterator< TYPE, ALLOC >, and original::stepIterator< TYPE >.

◆ get() [1/2]

◆ get() [2/2]

◆ getElem()

template<typename TYPE>
auto original::iterator< TYPE >::getElem ( ) const
virtual

Returns a copy of the element.

Returns
A copy of the element.

◆ getNext()

template<typename TYPE>
auto original::iterator< TYPE >::getNext ( ) const
virtual

Returns a new iterator pointing to the next element.

Returns
A new iterator pointing to the next element.

Reimplemented in original::bitSet< ALLOC >::Iterator, original::blocksList< TYPE, ALLOC >::Iterator, original::iterable< TYPE >::iterAdaptor, original::randomAccessIterator< TYPE, ALLOC >, and original::stepIterator< TYPE >.

◆ getPrev()

◆ hasNext()

◆ hasPrev()

◆ isValid()

◆ next()

◆ operator bool()

template<typename TYPE>
original::iterator< TYPE >::operator bool ( ) const
explicit

Checks if the iterator is valid (i.e., points to a valid element).

Returns
True if the iterator is valid, false otherwise.

◆ operator*() [1/2]

template<typename TYPE>
auto original::iterator< TYPE >::operator* ( )

Dereferences the iterator to get the element.

Returns
A reference to the element pointed to by the iterator.

◆ operator*() [2/2]

template<typename TYPE>
auto original::iterator< TYPE >::operator* ( ) const

Dereferences the iterator to get a copy of the element.

Returns
A copy of the element pointed to by the iterator.

◆ operator++()

template<typename TYPE>
auto original::iterator< TYPE >::operator++ ( int postfix) const

Moves the iterator forward by one position (postfix).

Parameters
postfixUnused parameter for postfix syntax.

◆ operator+=()

◆ operator-()

template<typename TYPE>
virtual integer original::iterator< TYPE >::operator- ( const iterator< TYPE > & other) const
pure virtual

Returns the distance between this iterator and another iterator.

Parameters
otherThe iterator to compare against.
Returns
The number of steps between the two iterators. Positive if this iterator is after the other, negative if before, zero if at same position.

This is the fundamental operation for iterator ordering comparisons. Used by compareTo() to implement relational operators.

Time complexity depends on container type:

  • O(1) for random-access iterators
  • O(n) for forward/bidirectional iterators
Note
For equality comparison only, operator==/!= using equalPtr is more efficient.

Implemented in original::bitSet< ALLOC >::Iterator, original::blocksList< TYPE, ALLOC >::Iterator, original::iterable< TYPE >::iterAdaptor, original::randomAccessIterator< TYPE, ALLOC >, and original::stepIterator< TYPE >.

◆ operator--()

template<typename TYPE>
auto original::iterator< TYPE >::operator-- ( int postfix) const

Moves the iterator backward by one position (postfix).

Parameters
postfixUnused parameter for postfix syntax.

◆ operator-=()

◆ prev()

◆ set()

◆ toString()

template<typename TYPE>
auto original::iterator< TYPE >::toString ( bool enter) const
nodiscardoverridevirtual

Returns a string representation of the iterator.

Parameters
enterIf true, adds a newline after the string.
Returns
A string representing the iterator.

Reimplemented from original::printable.

Friends And Related Symbol Documentation

◆ operator!=

template<typename TYPE>
template<typename T>
bool operator!= ( const iterator< T > & l_it,
const iterator< T > & r_it )
friend

Inequality comparison operator for iterators.

Template Parameters
TThe type of elements the iterator traverses.
Parameters
l_itLeft-hand side iterator.
r_itRight-hand side iterator.
Returns
True if the iterators point to different elements, false otherwise.
Note
This operation uses equalPtr for optimal constant-time comparison.

◆ operator+

template<typename TYPE>
template<typename T>
iterator< T > * operator+ ( const iterator< T > & it,
integer steps )
friend

Adds a number of steps to the iterator's current position and returns a new iterator.

Template Parameters
TThe type of the elements the iterator will traverse.
Parameters
itThe iterator to move.
stepsThe number of steps to move forward.
Returns
A new iterator that is moved forward by the specified steps from the original iterator.

This operator does not modify the original iterator, but creates a new one that is advanced by steps positions.

◆ operator-

template<typename TYPE>
template<typename T>
iterator< T > * operator- ( const iterator< T > & it,
integer steps )
friend

Subtracts a number of steps from the iterator's current position and returns a new iterator.

Template Parameters
TThe type of the elements the iterator will traverse.
Parameters
itThe iterator to move.
stepsThe number of steps to move backward.
Returns
A new iterator that is moved backward by the specified steps from the original iterator.

This operator does not modify the original iterator, but creates a new one that is moved backward by steps positions.

◆ operator==

template<typename TYPE>
template<typename T>
bool operator== ( const iterator< T > & l_it,
const iterator< T > & r_it )
friend

Equality comparison operator for iterators.

Template Parameters
TThe type of elements the iterator traverses.
Parameters
l_itLeft-hand side iterator.
r_itRight-hand side iterator.
Returns
True if the iterators point to the same element, false otherwise.
Note
This operation uses equalPtr for optimal constant-time comparison.

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