31 template <
typename TYPE>
42 class iterAdaptor final :
public iterator<TYPE> {
63 iterAdaptor*
clone()
const override;
78 friend class iterable;
84 iterAdaptor(
const iterAdaptor& other);
164 void set(
const TYPE& data)
override;
170 TYPE
get()
const override;
189 [[nodiscard]] std::string
toString(
bool enter)
const override;
271 template<
typename Callback = transform<TYPE>>
273 void forEach(Callback operation = Callback{});
280 template<
typename Callback = transform<TYPE>>
282 void forEach(
const Callback& operation = Callback{})
const;
286 template <
typename TYPE>
287 original::iterable<TYPE>::iterAdaptor::iterAdaptor(baseIterator<TYPE>* it) : it_(it) {}
289 template <
typename TYPE>
292 auto* other_it =
dynamic_cast<const iterAdaptor*
>(other);
293 if (other_it ==
nullptr)
294 return this->it_->equal(other);
295 return this->it_->equal(other_it->it_);
298 template <
typename TYPE>
301 return new iterAdaptor(*
this);
304 template <
typename TYPE>
307 auto* it = this->
clone();
312 template <
typename TYPE>
315 auto* it = this->
clone();
320 template <
typename TYPE>
321 original::iterable<TYPE>::iterAdaptor::iterAdaptor(
const iterAdaptor& other) : iterAdaptor(nullptr)
326 template <
typename TYPE>
329 if (
this == &other)
return *
this;
332 this->it_ = other.it_->clone();
336 template <
typename TYPE>
342 template <
typename TYPE>
348 template <
typename TYPE>
351 return this->it_->hasPrev();
354 template <
typename TYPE>
357 auto* other_it =
dynamic_cast<const iterAdaptor*
>(other);
358 if (other_it ==
nullptr)
359 return this->it_->atPrev(other);
360 return this->it_->atPrev(other_it->it_);
363 template <
typename TYPE>
366 auto* other_it =
dynamic_cast<const iterAdaptor*
>(other);
367 if (other_it ==
nullptr)
368 return this->it_->atNext(other);
369 return this->it_->atNext(other_it->it_);
372 template <
typename TYPE>
378 template <
typename TYPE>
384 template <
typename TYPE>
387 this->it_->operator+=(steps);
390 template <
typename TYPE>
393 this->it_->operator-=(steps);
396 template <
typename TYPE>
399 auto* other_it =
dynamic_cast<const iterAdaptor*
>(&other);
400 if (other_it ==
nullptr)
401 return this->it_->operator-(other);
402 return this->it_->operator-(*other_it->it_);
405 template <
typename TYPE>
408 return this->it_->get();
411 template <
typename TYPE>
414 this->it_->set(data);
417 template<
typename TYPE>
420 return this->it_->getElem();
423 template<
typename TYPE>
425 return this->it_->isValid();
428 template<
typename TYPE>
430 return "iterAdaptor";
433 template<
typename TYPE>
435 std::stringstream ss;
437 ss <<
"(" << *this->it_ <<
")";
438 if (enter) ss <<
"\n";
442 template<
typename TYPE>
447 template <
typename TYPE>
452 template <
typename TYPE>
454 auto* it = this->
ends();
459 template <
typename TYPE>
464 template <
typename TYPE>
466 auto* it = this->
ends();
471 template <
typename TYPE>
474 return this->
begin();
477 template <
typename TYPE>
483 template <
typename TYPE>
486 return this->
begin();
489 template <
typename TYPE>
495 template <
typename TYPE>
496 template<
typename Callback>
500 for (
auto it = this->
first(); it.
isValid(); it.next()) {
505 template<
typename TYPE>
506 template<
typename Callback>
507 requires original::Operation<Callback, TYPE>
509 for (
auto it = this->
first(); it.
isValid(); it.next()) {
510 operation(it.getElem());
A base class for basic iterators.
Definition iterator.h:259
An iterator adapter for the iterable container.
Definition iterable.h:42
const iterator< TYPE > & getIt() const
Gets the underlying iterator.
Definition iterable.h:337
TYPE & get() override
Gets the value of the element the iterator is pointing to.
Definition iterable.h:406
void operator-=(integer steps) const override
Moves the iterator backward by a specified number of steps.
Definition iterable.h:391
bool atNext(const iterator< TYPE > *other) const override
Checks if the current iterator is at the next element relative to another iterator.
Definition iterable.h:364
iterAdaptor * clone() const override
Creates a copy of the current iterator.
Definition iterable.h:299
iterAdaptor * getPrev() const override
Gets the previous iterator.
Definition iterable.h:305
void set(const TYPE &data) override
Sets the value of the element the iterator is pointing to.
Definition iterable.h:412
integer operator-(const iterator< TYPE > &other) const override
Calculates the distance between this iterator and another iterator.
Definition iterable.h:397
bool hasPrev() const override
Checks if there is a previous element.
Definition iterable.h:349
void prev() const override
Moves the iterator to the previous element.
Definition iterable.h:379
void operator+=(integer steps) const override
Advances the iterator by a specified number of steps.
Definition iterable.h:385
std::string toString(bool enter) const override
Converts the iterator to a string representation.
Definition iterable.h:434
iterAdaptor * getNext() const override
Gets the next iterator.
Definition iterable.h:313
bool equalPtr(const iterator< TYPE > *other) const override
Compares the current iterator with another iterator.
Definition iterable.h:290
void next() const override
Moves the iterator to the next element.
Definition iterable.h:373
~iterAdaptor() override
Destructor for iterAdaptor.
Definition iterable.h:443
std::string className() const override
Returns the class name.
Definition iterable.h:429
bool isValid() const override
Checks if the iterator is pointing to a valid element.
Definition iterable.h:424
bool atPrev(const iterator< TYPE > *other) const override
Checks if the current iterator is at the previous element relative to another iterator.
Definition iterable.h:355
bool hasNext() const override
Checks if there is a next element.
Definition iterable.h:343
iterAdaptor & operator=(const iterAdaptor &other)
Copy assignment operator for the iterAdaptor.
Definition iterable.h:327
A base class for iterable containers that support iterators.
Definition iterable.h:32
iterAdaptor end() const
Returns a constant iterator pointing to the end of the iterable container.
Definition iterable.h:465
void forEach(const Callback &operation=Callback{}) const
Applies a given operation to each element in the iterable container (const version).
iterAdaptor first()
Returns an iterator pointing to the first element.
Definition iterable.h:472
iterAdaptor end()
Returns an iterator pointing to the end of the iterable container.
Definition iterable.h:453
virtual baseIterator< TYPE > * begins() const =0
Returns the iterator to the beginning of the container.
iterAdaptor begin() const
Returns a constant iterator pointing to the beginning of the iterable container.
Definition iterable.h:460
iterAdaptor last() const
Returns a constant iterator pointing to the last element.
Definition iterable.h:490
iterAdaptor begin()
Returns an iterator pointing to the beginning of the iterable container.
Definition iterable.h:448
void forEach(Callback operation=Callback{})
Applies a given operation to each element in the iterable container.
iterAdaptor last()
Returns an iterator pointing to the last element.
Definition iterable.h:478
iterAdaptor first() const
Returns a constant iterator pointing to the first element.
Definition iterable.h:484
virtual baseIterator< TYPE > * ends() const =0
Returns the iterator to the end of the container.
Base iterator interface that supports common operations for iteration.
Definition iterator.h:35
virtual bool hasNext() const =0
Checks if there is a next element.
Constraint for mutating operations.
Definition types.h:117
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
Type system foundations and concept definitions.