로딩중...
검색중...
일치하는것 없음
tnarr.inl
1#pragma once
2
3#include "core/ast/node.hpp"
6#include "core/builtin/container/native/tnucontainer.inl"
7
8namespace by {
9
10 class thread;
11 class baseErr;
12
13#define TEMPL template <typename T, typename TACTIC>
14#define ME tnarr<T, TACTIC>
15
16 TEMPL
17 ME::tnarr() {}
18
19 TEMPL
20 ME::tnarr(const me& rhs): super(rhs) { add(rhs); }
21
22 TEMPL
23 ncnt ME::len() const { return _vec.size(); };
24
25 TEMPL
26 nbool ME::in(nidx n) const { return 0 <= n && n < len(); }
27
28 TEMPL
29 T* ME::get(nidx n) {
30 WHEN(!in(n)) .exErr(OUT_OF_RANGE, n, len()).ret(nullptr);
31
32 binder& ret = _vec[n];
33 return (T*) ret.get();
34 }
35
36 TEMPL
37 nbool ME::set(const iter& at, const T& new1) {
38 narrIteration& cast = _getIteration(at) OR.ret(false);
39 WHEN(cast.isEnd()) .ret(false);
40
41 return set(cast._n, new1);
42 }
43
44 TEMPL
45 nbool ME::set(nidx n, const T& new1) {
46 WHEN(!in(n)) .exErr(OUT_OF_RANGE, n, len()).ret(false);
47
48 return _vec[n].bind(new1);
49 }
50
51 TEMPL
52 nbool ME::add(const iter& e, const T& new1) {
53 narrIteration& cast = _getIteration(e) OR.ret(false);
54 return add(cast._n, new1);
55 }
56
57 TEMPL
58 nbool ME::add(nidx n, const T& new1) {
59 WHEN(n < 0 || n > len()) .exErr(OUT_OF_RANGE, n, len()).ret(false);
60
61 _vec.insert(_vec.begin() + n, wrap(new1));
62 return true;
63 }
64
65 TEMPL
66 void ME::add(const iter& here, const iter& from, const iter& to) {
67 WHEN(!from.isFrom(to.getContainer())) .exErr(ITERATOR_NOT_BELONG_TO_CONTAINER).ret();
68 const narrIteration& hereCast = _getIteration(here) OR.ret();
69 const narrIteration& fromCast = (narrIteration*) from._iteration.get() OR.ret();
70 const narrIteration& toCast = (narrIteration*) to._iteration.get() OR.ret();
71
72 WHEN(hereCast._n < 0 || hereCast._n > len())
73 .ret(); // if n equals to len(), it means that will be added at end of container.
74
75 auto fromBegin = ((me*) from.getContainer())->_vec.begin();
76 _vec.insert(_vec.begin() + hereCast._n, fromBegin + fromCast._n, fromBegin + toCast._n);
77 }
78
79 TEMPL
80 nbool ME::del(const iter& at) {
81 narrIteration& cast = _getIteration(at) OR.ret(false);
82 WHEN(cast.isEnd()) .ret(false);
83
84 return del(cast._n);
85 }
86
87 TEMPL
88 nbool ME::del(nidx n) {
89 WHEN(!in(n)) .exErr(OUT_OF_RANGE, n, len()).ret(false);
90
91 _vec.erase(_vec.begin() + n);
92 return true;
93 }
94
95 TEMPL
96 nbool ME::del(const iter& from, const iter& end) {
97 narrIteration& endIter = _getIteration(end) OR.ret(false);
98 narrIteration& fromIter = _getIteration(from) OR.ret(false);
99
100 nidx fromN = fromIter.isEnd() ? len() - 1 : fromIter._n;
101 ncnt cnt = endIter._n - fromN;
102 WHEN(cnt <= 0) .ret(false);
103
104 for(int n = 0; n < cnt; n++)
105 _vec.erase(_vec.begin() + fromN);
106 return true;
107 }
108
109 TEMPL
110 void ME::rel() { _vec.clear(); }
111
112 TEMPL
113 void ME::onCloneDeep(const clonable& from) {
114 const me& rhs = (const me&) from;
115 rel();
116 for(const auto& e: rhs)
117 add((T*) e.cloneDeep());
118 }
119
120 TEMPL
121 std::string ME::asStr() const {
122 std::string ret;
123 nbool first = true;
124 for(const auto& e: *this) {
125 ret += (first ? "" : ",") + e.getType().getName();
126 first = false;
127 }
128
129 return ret;
130 }
131
132 TEMPL
133 typename ME::iteration* ME::_onMakeIteration(ncnt step, nbool isReversed) const {
134 me* unconst = const_cast<me*>(this);
135 return new narrIteration(*unconst, step, isReversed);
136 }
137
138 TEMPL
139 typename ME::narrIteration* ME::_getIteration(const iter& it) {
140 WHEN(!it.isFrom(*this)) .exErr(ITERATOR_NOT_BELONG_TO_CONTAINER).ret(nullptr);
141 auto* ret = (narrIteration*) it._iteration.get();
142 WHEN_NUL(ret).exErr(ITERATOR_IS_NUL).ret(nullptr);
143 return ret;
144 }
145
146#undef TEMPL
147#undef ME
148} // namespace by
Bidirectional iterator for key-value containers
Definition biter.hpp:10
Definition narrIteration.hpp:8
to Top