Loading...
Searching...
No Matches
tnmap.inl
1#pragma once
2
4#include "core/ast/node.hpp"
5#include "core/builtin/container/native/tnbicontainer.inl"
6
7namespace by {
8
9#define TEMPL template <typename K, typename V, typename TACTIC>
10#define ME tnmap<K, V, TACTIC>
11
12 TEMPL
13 ME::tnmap() {}
14
15 TEMPL
16 ME::tnmap(const std::initializer_list<std::pair<K, V*>>& elems) {
17 for(const auto& e: elems)
18 add(e.first, *e.second);
19 }
20
21 TEMPL
22 nbool ME::in(const K& key) const { return _map.begin(key) != _map.end(); }
23
24 TEMPL
25 V* ME::get(const K& key) {
26 WHEN(!in(key)) .ret(nullptr);
27
28 return _map.begin(key).getVal() TO(get());
29 }
30
31 TEMPL
32 typename ME::iteration* ME::_onMakeIteration(const K* key, nbool isReversed, ncnt step, nbool) const {
33 me* unconst = const_cast<me*>(this);
34 auto* ret = new nmapIteration(*unconst, key, isReversed);
35 ret->next(step);
36 return ret;
37 }
38
39 TEMPL
40 void ME::_getAll(const K& key, narr& tray) const {
41 auto end = _map.end();
42 for(auto e = _map.begin(key); e != end; ++e)
43 tray.add(e.getVal() TO(get()));
44 }
45
46 TEMPL
47 typename ME::nmapIteration* ME::_getIterationFrom(const iter& it) {
48 WHEN(!it.isFrom(*this)) .warn("from is not an iterator of this container.").ret(nullptr);
49 return (nmapIteration*) it._iteration.get();
50 }
51
52 TEMPL
53 nbool ME::add(const K& key, const V& new1) {
54 _map.insert(key, wrap(new1));
55 return true;
56 }
57
58 TEMPL
59 nbool ME::del(const K& key) {
60 _map.erase(key);
61 return true;
62 }
63
64 TEMPL
65 nbool ME::del(const iter& at) {
66 WHEN(at.isEnd()) .warn("at is end of the container. skip function.").ret(false);
67
68 nmapIteration& e = _getIterationFrom(at) OR.ret(false);
69 _map.erase(e._citer);
70
71 return true;
72 }
73
74 TEMPL
75 nbool ME::del(const iter& from, const iter& end) {
76 nmapIteration& fromE = _getIterationFrom(from) OR.ret(false);
77 nmapIteration& endE = _getIterationFrom(end) OR.ret(false);
78 _map.erase(fromE._citer, endE._citer);
79
80 return true;
81 }
82
83 TEMPL
84 ncnt ME::len() const { return _map.size(); };
85
86 TEMPL
87 void ME::rel() { _map.clear(); }
88
89 TEMPL
90 void ME::onCloneDeep(const clonable& from) {
91 me& rhs = (me&) from;
92 rel();
93 for(iter e = rhs.begin(); e; ++e)
94 add(e.getKey(), (V*) (e.getVal() TO(cloneDeep())));
95 }
96
97#undef TEMPL
98#undef ME
99} // namespace by
Bidirectional iterator for key-value containers.
Definition biter.hpp:10
Definition nmapIteration.hpp:6
to Top