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 object.
 
- 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.
 

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.

Implements comparison based on a custom compareTo method which compares iterators by the distance between them.

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 equal, and a positive value if after.

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 object.

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

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

◆ get() [1/2]

template<typename TYPE>
virtual TYPE original::iterator< TYPE >::get ( ) const
pure virtual

◆ get() [2/2]

template<typename TYPE>
virtual TYPE & original::iterator< TYPE >::get ( )
pure virtual

◆ 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()

template<typename TYPE>
virtual iterator * original::iterator< TYPE >::getPrev ( ) const
pure virtual

Returns a new iterator pointing to the previous element.

Returns
A new iterator pointing to the previous element.

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

◆ hasNext()

template<typename TYPE>
virtual bool original::iterator< TYPE >::hasNext ( ) const
nodiscardpure virtual

◆ hasPrev()

template<typename TYPE>
virtual bool original::iterator< TYPE >::hasPrev ( ) const
nodiscardpure virtual

◆ isValid()

template<typename TYPE>
virtual bool original::iterator< TYPE >::isValid ( ) const
nodiscardpure virtual

◆ next()

template<typename TYPE>
virtual void original::iterator< TYPE >::next ( ) const
pure virtual

◆ 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+=()

template<typename TYPE>
virtual void original::iterator< TYPE >::operator+= ( integer steps) const
pure virtual

Adds a number of steps to the current position of iterator.

Parameters
stepsThe number of steps to move forward.

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>
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.

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-=()

template<typename TYPE>
virtual void original::iterator< TYPE >::operator-= ( integer steps) const
pure virtual

Subtracts a number of steps from the current position of iterator.

Parameters
stepsThe number of steps to move backward.

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

◆ prev()

◆ set()

template<typename TYPE>
virtual void original::iterator< TYPE >::set ( const TYPE & data)
pure virtual

◆ 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>
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.


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