nmapIteration.hpp
Go to the documentation of this file.
1
5class nmapIteration: public iteration {
6 BY(CLASS(nmapIteration, iteration))
7 friend class tnmap;
8
9public:
10 nmapIteration(tnmap& own, const K* key, nbool isReversed):
11 super(isReversed),
12 _own(own),
13 _citer(isReversed ? own._map.rbegin(key) : own._map.begin(key)),
14 _end(isReversed ? own._map.rend() : own._map.end()) {}
15
16 nbool isEnd() const override { return _citer == _end; }
17
18 void rel() override { _citer = _end; }
19
23 ncnt stepForward(ncnt step) override { return _step(false, step); }
24
25 ncnt stepBackward(ncnt step) override { return _step(true, step); }
26
27 const K* getKey() const override {
28 WHEN(isEnd()) .ret(nullptr);
29 return _citer.getKey();
30 }
31
32 using super::getVal;
33
34 V* getVal() override {
35 WHEN(isEnd()) .ret(nullptr);
36 return _citer.getVal() TO(get());
37 }
38
39 using super::setVal;
40
41 void setVal(const V& new1) override {
42 WHEN(isEnd()) .ret();
43 _citer->bind(new1);
44 }
45
46 using super::getContainer;
47
48 tbicontainable<K, V>* getContainer() override { return &_own; }
49
50protected:
51 nbool _onSame(const typeProvidable& rhs) const override {
52 const me& cast = (const me&) rhs;
53 return this->isFrom(cast.getContainer()) && _citer == cast._citer;
54 }
55
56private:
57 ncnt _step(nbool isReversed, ncnt step) {
58 WHEN(isEnd()) .ret(0);
59 for(int n = 0; n < step; n++) {
60 isReversed ? (this->isReversed() ? ++_citer : --_citer) : (this->isReversed() ? --_citer : ++_citer);
61 WHEN(isEnd()) .ret(n);
62 }
63 return step;
64 }
65
66private:
67 tnmap& _own;
68 citer _citer; // cpp map's iterator.
69 citer _end;
70};
Definition: biteration.hpp:5
Definition: nmapIteration.hpp:5
ncnt stepForward(ncnt step) override
Definition: nmapIteration.hpp:23
#define TO(fn)
Definition: to.hpp:171