1#ifndef RANDOMACCESSITERATOR_H
2#define RANDOMACCESSITERATOR_H
38 template<
typename TYPE,
typename ALLOC>
85 [[nodiscard]]
bool hasNext()
const override;
91 [[nodiscard]]
bool hasPrev()
const override;
110 void next()
const override;
115 void prev()
const override;
152 TYPE&
get()
override;
158 TYPE
get()
const override;
164 void set(
const TYPE& data)
override;
170 [[nodiscard]]
bool isValid()
const override;
176 [[nodiscard]] std::string
className()
const override;
180 template<
typename TYPE,
typename ALLOC>
185 template<
typename TYPE,
typename ALLOC>
188 return other_it !=
nullptr &&
_ptr == other_it->_ptr;
191 template<
typename TYPE,
typename ALLOC>
196 template<
typename TYPE,
typename ALLOC>
199 if (
this == &other) {
202 this->
_ptr = other._ptr;
204 this->
_pos = other._pos;
208 template<
typename TYPE,
typename ALLOC>
213 template<
typename TYPE,
typename ALLOC>
218 template<
typename TYPE,
typename ALLOC>
223 template<
typename TYPE,
typename ALLOC>
228 template<
typename TYPE,
typename ALLOC>
233 template<
typename TYPE,
typename ALLOC>
239 template<
typename TYPE,
typename ALLOC>
245 template<
typename TYPE,
typename ALLOC>
251 template<
typename TYPE,
typename ALLOC>
257 template<
typename TYPE,
typename ALLOC>
261 if (other_it ==
nullptr)
262 return this > &other ?
263 std::numeric_limits<integer>::max() :
264 std::numeric_limits<integer>::min();
266 return this->
_container > other_it->_container ?
267 std::numeric_limits<integer>::max() :
268 std::numeric_limits<integer>::min();
269 return this->
_ptr - other_it->_ptr;
272 template<
typename TYPE,
typename ALLOC>
275 auto it = this->
clone();
280 template<
typename TYPE,
typename ALLOC>
283 auto it = this->
clone();
288 template<
typename TYPE,
typename ALLOC>
294 template<
typename TYPE,
typename ALLOC>
300 template<
typename TYPE,
typename ALLOC>
307 template<
typename TYPE,
typename ALLOC>
312 template<
typename TYPE,
typename ALLOC>
314 return "RandomAccessIterator";
A base class for basic iterators.
Definition iterator.h:259
Abstract base class for containers.
Definition container.h:28
Base iterator interface that supports common operations for iteration.
Definition iterator.h:35
Exception for container index out-of-range errors.
Definition error.h:84
randomAccessIterator * getNext() const override
Gets an iterator pointing to the next element.
Definition randomAccessIterator.h:273
std::string className() const override
Gets the class name of the iterator.
Definition randomAccessIterator.h:313
integer operator-(const iterator< TYPE > &other) const override
Computes the distance between the current iterator and another iterator.
Definition randomAccessIterator.h:258
bool hasNext() const override
Checks forward traversal capability.
Definition randomAccessIterator.h:214
void set(const TYPE &data) override
Sets the value of the current element.
Definition randomAccessIterator.h:295
bool equalPtr(const iterator< TYPE > *other) const override
Equality comparison implementation.
Definition randomAccessIterator.h:186
bool hasPrev() const override
Checks reverse traversal capability.
Definition randomAccessIterator.h:219
bool atNext(const iterator< TYPE > *other) const override
Checks if the current iterator is at the next position compared to another iterator.
Definition randomAccessIterator.h:229
void prev() const override
Retreats to the previous position in the container.
Definition randomAccessIterator.h:240
randomAccessIterator(TYPE *ptr, const container< TYPE, ALLOC > *container, integer pos)
Protected constructor for derived classes.
Definition randomAccessIterator.h:181
void operator+=(integer steps) const override
Moves forward by N positions.
Definition randomAccessIterator.h:246
void next() const override
Advances to the next position in the container.
Definition randomAccessIterator.h:234
randomAccessIterator * getPrev() const override
Gets an iterator pointing to the previous element.
Definition randomAccessIterator.h:281
randomAccessIterator * clone() const override
Creates a heap-allocated copy.
Definition randomAccessIterator.h:209
const container< TYPE, ALLOC > * _container
Reference to the parent container.
Definition randomAccessIterator.h:42
void operator-=(integer steps) const override
Moves backward by N positions.
Definition randomAccessIterator.h:252
randomAccessIterator & operator=(const randomAccessIterator &other)
Copy assignment operator.
Definition randomAccessIterator.h:197
bool atPrev(const iterator< TYPE > *other) const override
Checks if the current iterator is at the previous position compared to another iterator.
Definition randomAccessIterator.h:224
TYPE * _ptr
Pointer to the current element.
Definition randomAccessIterator.h:41
TYPE & get() override
Gets the current element in the container.
Definition randomAccessIterator.h:289
bool isValid() const override
Checks if the iterator is valid (points to a valid element in the container)
Definition randomAccessIterator.h:308
integer _pos
Absolute position in the container.
Definition randomAccessIterator.h:43
Exception for unimplemented method calls.
Definition error.h:123
Abstract base class for container types.
Custom exception classes and callback validation utilities.
Defines the iterator class for traversing and manipulating container elements.
Main namespace for the project Original.
Definition algorithms.h:21
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:15