58 template <
typename TYPE>
74 class iterAdaptor final :
public iterator<TYPE> {
95 iterAdaptor*
clone()
const override;
110 friend class iterable;
116 iterAdaptor(
const iterAdaptor& other);
196 void set(
const TYPE& data)
override;
202 TYPE
get()
const override;
221 [[nodiscard]] std::string
toString(
bool enter)
const override;
360 template<
typename Callback = transform<TYPE>>
362 void forEach(Callback operation = Callback{});
369 template<
typename Callback = transform<TYPE>>
371 void forEach(
const Callback& operation = Callback{})
const;
375 template <
typename TYPE>
376 original::iterable<TYPE>::iterAdaptor::iterAdaptor(baseIterator<TYPE>* it) : it_(it) {}
378 template <
typename TYPE>
381 auto* other_it =
dynamic_cast<const iterAdaptor*
>(other);
382 if (other_it ==
nullptr)
383 return this->it_->equal(other);
384 return this->it_->equal(other_it->it_);
387 template <
typename TYPE>
390 return new iterAdaptor(*
this);
393 template <
typename TYPE>
396 auto* it = this->
clone();
401 template <
typename TYPE>
404 auto* it = this->
clone();
409 template <
typename TYPE>
410 original::iterable<TYPE>::iterAdaptor::iterAdaptor(
const iterAdaptor& other) : iterAdaptor(nullptr)
415 template <
typename TYPE>
418 if (
this == &other)
return *
this;
421 this->it_ = other.it_->clone();
425 template <
typename TYPE>
431 template <
typename TYPE>
437 template <
typename TYPE>
440 return this->it_->hasPrev();
443 template <
typename TYPE>
446 auto* other_it =
dynamic_cast<const iterAdaptor*
>(other);
447 if (other_it ==
nullptr)
448 return this->it_->atPrev(other);
449 return this->it_->atPrev(other_it->it_);
452 template <
typename TYPE>
455 auto* other_it =
dynamic_cast<const iterAdaptor*
>(other);
456 if (other_it ==
nullptr)
457 return this->it_->atNext(other);
458 return this->it_->atNext(other_it->it_);
461 template <
typename TYPE>
467 template <
typename TYPE>
473 template <
typename TYPE>
476 this->it_->operator+=(steps);
479 template <
typename TYPE>
482 this->it_->operator-=(steps);
485 template <
typename TYPE>
488 auto* other_it =
dynamic_cast<const iterAdaptor*
>(&other);
489 if (other_it ==
nullptr)
490 return this->it_->operator-(other);
491 return this->it_->operator-(*other_it->it_);
494 template <
typename TYPE>
497 return this->it_->get();
500 template <
typename TYPE>
503 this->it_->set(data);
506 template<
typename TYPE>
509 return this->it_->getElem();
512 template<
typename TYPE>
514 return this->it_->isValid();
517 template<
typename TYPE>
519 return "iterAdaptor";
522 template<
typename TYPE>
524 std::stringstream ss;
526 ss <<
"(" << *this->it_ <<
")";
527 if (enter) ss <<
"\n";
531 template<
typename TYPE>
536 template <
typename TYPE>
541 template <
typename TYPE>
543 auto* it = this->
ends();
548 template <
typename TYPE>
553 template <
typename TYPE>
555 auto* it = this->
ends();
560 template <
typename TYPE>
563 return this->
begin();
566 template <
typename TYPE>
572 template <
typename TYPE>
575 return this->
begin();
578 template <
typename TYPE>
584 template <
typename TYPE>
585 template<
typename Callback>
589 for (
auto it = this->
first(); it.
isValid(); it.next()) {
594 template<
typename TYPE>
595 template<
typename Callback>
596 requires original::Operation<Callback, TYPE>
598 for (
auto it = this->
first(); it.
isValid(); it.next()) {
599 operation(it.getElem());
A base class for basic iterators.
Definition iterator.h:296
RAII wrapper for base iterators that provides standard iteration interface.
Definition iterable.h:74
const iterator< TYPE > & getIt() const
Gets the underlying iterator.
Definition iterable.h:426
TYPE & get() override
Gets the value of the element the iterator is pointing to.
Definition iterable.h:495
void operator-=(integer steps) const override
Moves the iterator backward by a specified number of steps.
Definition iterable.h:480
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:453
iterAdaptor * clone() const override
Creates a copy of the current iterator.
Definition iterable.h:388
iterAdaptor * getPrev() const override
Gets the previous iterator.
Definition iterable.h:394
void set(const TYPE &data) override
Sets the value of the element the iterator is pointing to.
Definition iterable.h:501
integer operator-(const iterator< TYPE > &other) const override
Calculates the distance between this iterator and another iterator.
Definition iterable.h:486
bool hasPrev() const override
Checks if there is a previous element.
Definition iterable.h:438
void prev() const override
Moves the iterator to the previous element.
Definition iterable.h:468
void operator+=(integer steps) const override
Advances the iterator by a specified number of steps.
Definition iterable.h:474
std::string toString(bool enter) const override
Converts the iterator to a string representation.
Definition iterable.h:523
iterAdaptor * getNext() const override
Gets the next iterator.
Definition iterable.h:402
bool equalPtr(const iterator< TYPE > *other) const override
Compares the current iterator with another iterator.
Definition iterable.h:379
void next() const override
Moves the iterator to the next element.
Definition iterable.h:462
~iterAdaptor() override
Destructor for iterAdaptor.
Definition iterable.h:532
std::string className() const override
Returns the class name.
Definition iterable.h:518
bool isValid() const override
Checks if the iterator is pointing to a valid element.
Definition iterable.h:513
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:444
bool hasNext() const override
Checks if there is a next element.
Definition iterable.h:432
iterAdaptor & operator=(const iterAdaptor &other)
Copy assignment operator for the iterAdaptor.
Definition iterable.h:416
A base class for iterable containers that support multiple iteration patterns.
Definition iterable.h:59
iterAdaptor end() const
Returns a const iterator adapter pointing to the end sentinel of the container.
Definition iterable.h:554
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 adapter pointing to the first element.
Definition iterable.h:561
iterAdaptor end()
Returns an iterator adapter pointing to the end sentinel of the container.
Definition iterable.h:542
virtual baseIterator< TYPE > * begins() const =0
Returns the iterator to the beginning of the container.
iterAdaptor begin() const
Returns a const iterator adapter pointing to the beginning of the container.
Definition iterable.h:549
iterAdaptor last() const
Returns a const iterator adapter pointing to the last element.
Definition iterable.h:579
iterAdaptor begin()
Returns an iterator adapter pointing to the beginning of the container.
Definition iterable.h:537
void forEach(Callback operation=Callback{})
Applies a given operation to each element in the iterable container.
iterAdaptor last()
Returns an iterator adapter pointing to the last element.
Definition iterable.h:567
iterAdaptor first() const
Returns a const iterator adapter pointing to the first element.
Definition iterable.h:573
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:37
virtual bool hasNext() const =0
Checks if there is a next element.
Constraint for mutating operations.
Definition types.h:133
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:35
Core type system foundations and concept definitions.