tnchain.hpp
Go to the documentation of this file.
1
2#pragma once
3
5
6namespace by {
7
8 class node;
9
10 template <typename K, typename V, typename _defaultContainer = tnmap<K, V>>
11 class tnchain: public tnbicontainer<K, V> {
14 BY(CLASS(_me_, _super_))
15
16 public:
17 typedef typename super::iter iter;
18 typedef typename super::iteration iteration;
19 friend class nchainIteration;
20 typedef _defaultContainer defaultContainer;
22
23 public:
24 tnchain();
25 explicit tnchain(const super& arr);
26 explicit tnchain(const super& org, const me& next);
27 explicit tnchain(std::initializer_list<std::pair<K, V*>> elems);
28
29 public:
30 // has:
31 using super::in;
32 nbool in(const K& key) const override;
33
34 // len:
35 ncnt len() const override;
36 ncnt chainLen() const;
37
38 using super::get;
39 V* get(const K& key) override;
40
41 // add:
42 using super::add;
43 nbool add(const K& key, const V& val) override;
44
57 virtual nbool link(const iter& portion);
58 nbool link(const me& new1);
59 nbool link(const me* it) BY_SIDE_FUNC(link);
60 nbool unlink();
61
62 // del:
63 using super::del;
65 nbool del(const K& key) override;
66 nbool del(const iter& at) override;
67 nbool del(const iter& from, const iter& end) override;
68
69 // etc:
70 void rel() override;
71
72 super& getContainer();
73 const super& getContainer() const;
74
75 me* getNext();
76 const me* getNext() const BY_CONST_FUNC(getNext())
77
78 me* getPrev();
79 const me* getPrev() const BY_CONST_FUNC(getPrev())
80
82 me* getTail();
83 const me* getTail() const BY_CONST_FUNC(getTail())
84
88 void onCloneDeep(const clonable& from) override;
89
95 template <typename T> static T* wrap(const super& toShallowWrap) {
96 T* ret = (T*) toShallowWrap.template cast<T>();
97 if(!ret) {
98 ret = new T();
99 ret->_map.bind(toShallowWrap);
100 }
101
102 return ret;
103 }
104
105 template <typename T> static T* wrap(const super* it) BY_SIDE_FUNC(it, wrap<T>(*it), nullptr);
106
107 static me* wrap(const super& toShallowWrap);
108 static me* wrap(const super* it) BY_SIDE_FUNC(wrap);
109
114 me* cloneChain(const super* until) const;
115 me* cloneChain(const me* until) const;
116
118 me* cloneChain() const;
119
120 protected:
121 iteration* _onMakeIteration(const K* key, nbool isReversed, ncnt step, nbool isBoundary) const override;
122
123 void _getAll(const K& key, narr& tray) const override;
124
125 private:
126 iter* _getInnerIter(const iter& wrapper);
127 iter _getInnerBeginOfChain(me& it, const me& fromChain, const iter& from);
128 iter _getInnerEndOfChain(me& it, const me& lastChain, const iter& last);
129 iter _rendOfThisChain(nbool isReversed);
130 me& _getLastChain();
131 void _eachChain(std::function<void(me&)> closure);
132
133 private:
134 tstr<super> _map;
135 iter _next;
136 iter _prev;
137 };
138
141} // namespace by
Managed array container for byeol language.
Definition: arr.hpp:14
Interface for objects that can be cloned.
Definition: clonable.hpp:12
func closure with captured object scope
Definition: closure.hpp:19
Deferred execution utility like defer keyword in other languages.
Definition: end.hpp:14
Definition: tnbicontainer.hpp:8
Definition: tnchain.hpp:11
static T * wrap(const super &toShallowWrap)
Definition: tnchain.hpp:95
const me * getPrev() const BY_CONST_FUNC(getPrev()) me *getTail()
return most not null next element of this chain.
virtual nbool link(const iter &portion)
link to another chain instance. if iterator is not the begin of another chain, this chain won't link ...
me * cloneChain() const
mock all of this chain until 'next' is null.
const me * getTail() const BY_CONST_FUNC(getTail()) void onCloneDeep(const clonable &from) override
nbool del(const K &key) override
delete all elements matching by given key.
me * cloneChain(const super *until) const
Strong reference smart pointer with strict type checking.
Definition: tstr.hpp:13
Bidirectional iterator for key-value containers.
Definition: biter.hpp:9
Definition: biteration.hpp:5
Definition: nchainIteration.hpp:7
ncnt next(ncnt step) override
Definition: nchainIteration.hpp:40
Chain iteration implementation.