Loading...
Searching...
No Matches
nseqIteration.hpp
Go to the documentation of this file.
1
6class nseqIteration: public iteration {
7 BY(CLASS(nseqIteration, iteration))
8 friend class tnseq;
9
10public:
11 nseqIteration(nseq& own, nidx n, nbool isReversed):
12 super(isReversed), _n(isReversed ? own.len() - 1 - n : n), _own(own) {}
13
14 using super::operator*;
15
16 nInt operator*() override { return get(); }
17
18public:
19 nbool isEnd() const override { return !_own.in(_n); }
20
21 void rel() override { _n = this->isReversed() ? -1 : _own.len(); }
22
28 ncnt stepForward(ncnt step) override {
29 WHEN(step <= 0) .ret(0);
30 WHEN(isEnd()) .ret(0);
31 int len = _own.len();
32 int toLast = len - 1 - _n;
33
34 _n += step;
35 if(_n >= len) {
36 _n = len;
37 step = toLast;
38 }
39 return step;
40 }
41
42 ncnt stepBackward(ncnt step) override {
43 WHEN(step <= 0) .ret(0);
44 WHEN(isEnd()) .ret(0);
45 int toLast = _n;
46
47 _n -= step;
48 if(_n < 0) {
49 _n = -1;
50 step = toLast;
51 }
52 return step;
53 }
54
55 using super::get;
56
57 nInt get() override {
58 WHEN(isEnd()) .ret(nInt(0));
59 return _own[_n];
60 }
61
62 using super::getContainer;
63
64 tucontainable<nInt, nInt, nInt>* getContainer() override { return &_own; }
65
66protected:
67 nbool _onSame(const typeProvidable& rhs) const override {
68 const me& cast = (const me&) rhs;
69 return this->isFrom(cast.getContainer()) && _n == cast._n;
70 }
71
72private:
73 nidx _n;
74 nseq& _own;
75};
Definition biteration.hpp:5
Definition nseqIteration.hpp:6
ncnt stepForward(ncnt step) override
Definition nseqIteration.hpp:28
to Top