arr.hpp
Go to the documentation of this file.
1
2#pragma once
3
5
6struct arrTest;
7
8namespace by {
9
14 class _nout arr: public tbridge<narr>, public tucontainable<node>, public tarrayable<node> {
15 // arr uses instance variable 'ntype':
16 // ntype contains beanType as 'const type*' instance variable. so user should be
17 // careful when calling ttype<arr>. because it will also return ntype instance
18 // as a consequences, but it won't contain beanType.
19 //
20 // the most appropriate getter for ntype of arr is to call getType() of instance
21 // to arr.
22 BY(ME(arr, tbridge<narr>), INIT_META(arr), CLONE(arr), VISIT())
23
24 public:
25 typedef typename tucontainable<node>::iter iter;
27 typedef std::map<const node*, tstr<scope>> cache;
28 friend class interpreter; // for _cache
29 friend struct ::arrTest;
30
31 public:
32 arr();
33 arr(const node& elemType);
34 arr(const me& rhs);
35
36 public:
38 node& operator[](nidx n) override;
39
40 public:
41 const ntype& getType() const override;
42
43 using super::subs;
44 scope& subs() override;
45
46 ncnt len() const override;
47
48 using super::in;
49 nbool in(nidx n) const override;
50
51 // get:
53 using super::get;
55
56 /* TODO: can I remove this?
57 template <typename E> E* get(std::function<nbool(const E&)> l) const {
58 for(const node* elem : *this) {
59 const E& cast = elem->template cast<E>() OR_CONTINUE;
60 if(l(cast)) // elem should be typeProvidable.
61 return cast;
62 }
63
64 return nullptr;
65 }
66 node& get(std::function<nbool(const node&)> l) const;
67
68 template <typename E> tnarr<E, strTactic> getAll(std::function<nbool(const E&)> l) const {
69 tnarr<E> ret;
70 for(const node& elem: *this) {
71 const E* cast = elem.template cast<E>();
72 if(cast && l(*cast)) ret.add(cast);
73 }
74
75 return ret;
76 }
77 narr getAll(std::function<nbool(const node&)> l) const;
78 */
79
80 node* get(nidx n) override;
81
82 // set:
85 nbool set(const iter& at, const node& new1) override;
86 nbool set(nidx n, const node& new1) override;
87
88 // add:
91 nbool add(const iter& at, const node& new1) override;
92 nbool add(nidx n, const node& new1) override;
93 void add(const iter& here, const iter& from, const iter& to) override;
94
95 // del:
97 nbool del(nidx n) override;
98 nbool del(const iter& it) override;
99 nbool del(const iter& from, const iter& to) override;
100
101 // etc:
102 void rel() override;
103
104 const baseObj& getOrigin() const override;
105
106 std::string asStr() const;
107
108 protected:
109 iteration* _onMakeIteration(ncnt step, nbool isReversed) const override;
110
111 private:
112 scope& _defGeneric(const baseObj& paramType);
113 scope& _getOriginScope();
114
115 private:
116 static inline cache _cache;
117 mutable str _org;
118 mgdType _type;
119 };
120} // namespace by
Managed array container for byeol language.
Definition: arr.hpp:14
nbool del(nidx n) override
nbool add(nidx n, const node &new1) override
Base class for all objects in byeol language.
Definition: baseObj.hpp:24
High-level interpreter for byeol language.
Definition: interpreter.hpp:13
Managed type for byeol objects.
Definition: mgdType.hpp:17
Base class for all AST nodes in byeol language.
Definition: node.hpp:30
Native type system for byeol language.
Definition: ntype.hpp:19
Definition: tarrayable.hpp:10
Bridge template for C++ objects.
Definition: tbridge.hpp:17
Template unidirectional container interface.
Definition: tucontainable.hpp:19
Bidirectional iterator for key-value containers.
Definition: biter.hpp:9
Definition: biteration.hpp:5