Loading...
Searching...
No Matches
tbridger.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "core/ast/obj.hpp"
12#include "core/ast/ctor.hpp"
13
14namespace by {
15
62 BY(ME(tbridger))
63
64 private:
65 tbridger() = default;
66
67 public:
68 static scope& subs() { return _get()._subs; }
69
70 static me& extend(const scope& src) {
71 subs().link(src);
72 return _get();
73 }
74
75 static me& func(const std::string& name, const baseFunc& bridgeFunc) {
76 _get().subs().add(name, bridgeFunc);
77 return _get();
78 }
79
80 static me& func(const std::string* name, const baseFunc& bridgeFunc)
81 BY_SIDE_FUNC(name, func(*name, bridgeFunc), _get());
82 static me& func(const std::string& name, const baseFunc* bridgeFunc)
83 BY_SIDE_FUNC(bridgeFunc, func(name, *bridgeFunc), _get());
84 static me& func(const std::string* name, const baseFunc* bridgeFunc)
85 BY_SIDE_FUNC(name&& bridgeFunc, func(*name, *bridgeFunc), _get());
86
87 template <typename... Args> static me& ctor() {
88 return func(func::CTOR_NAME, new tbridgeCtor<T, tmarshaling, Args...>());
89 }
90
91 template <typename Ret, typename... Args> static me& func(const std::string& name, Ret (T::*fptr)(Args...)) {
92 return funcNonConst(name, fptr);
93 }
94
95 template <typename Ret, typename... Args>
96 static me& func(const std::string* name, Ret (T::*fptr)(Args...)) BY_SIDE_FUNC(name, func(*name, fptr), _get());
97
98 template <typename Ret, typename... Args>
99 static me& func(const std::string& name, Ret (T::*fptr)(Args...) const) {
100 return funcConst(name, fptr);
101 }
102
103 template <typename Ret, typename... Args>
104 static me& func(const std::string* name, Ret (T::*fptr)(Args...) const)
105 BY_SIDE_FUNC(name, func(*name, fptr), _get());
106
107 template <typename Ret, typename... Args>
108 static me& funcNonConst(const std::string& name, Ret (T::*fptr)(Args...)) {
110 }
111
112 template <typename Ret, typename... Args>
113 static me& funcNonConst(const std::string* name, Ret (T::*fptr)(Args...))
114 BY_SIDE_FUNC(name, funcNonConst(*name, fptr), _get());
115
116 template <typename Ret, typename... Args>
117 static me& funcConst(const std::string& name, Ret (T::*fptr)(Args...) const) {
118 return func(name, new tbridgeFunc<Ret, T, isBaseObj, tmarshaling, Args...>((Ret(T::*)(Args...)) fptr));
119 }
120
121 template <typename Ret, typename... Args>
122 static me& funcConst(const std::string* name, Ret (T::*fptr)(Args...) const)
123 BY_SIDE_FUNC(name, funcConst(*name, fptr), _get());
124
125 static me& genericCtor() { return func(func::CTOR_NAME, new tbridgeCtor<T, tgenericMarshaling>()); }
126
127 template <typename... Args> static me& genericCtor() {
128 return func(func::CTOR_NAME, new tbridgeCtor<T, tgenericMarshaling, Args...>());
129 }
130
131 template <typename Ret, typename... Args>
132 static me& genericFunc(const std::string& name, Ret (T::*fptr)(Args...)) {
134 }
135
136 template <typename Ret, typename... Args>
137 static me& genericFunc(const std::string* name, Ret (T::*fptr)(Args...))
138 BY_SIDE_FUNC(name, genericFunc(*name, fptr), _get());
139
140 template <typename Ret, typename... Args>
141 static me& genericFunc(const std::string& name, Ret (T::*fptr)(Args...) const) {
142 return func(name,
144 }
145
146 template <typename Ret, typename... Args>
147 static me& genericFunc(const std::string* name, Ret (T::*fptr)(Args...) const)
148 BY_SIDE_FUNC(name, genericFunc(*name, fptr), _get());
149
150 template <typename Ret, typename... Args>
151 static me& genericFuncNonConst(const std::string& name, Ret (T::*fptr)(Args...)) {
152 return func(name,
154 }
155
156 template <typename Ret, typename... Args>
157 static me& genericFuncNonConst(const std::string* name, Ret (T::*fptr)(Args...))
158 BY_SIDE_FUNC(name, genericFuncNonConst(*name, fptr), _get());
159
160 template <typename Ret, typename... Args>
161 static me& genericFuncConst(const std::string& name, Ret (T::*fptr)(Args...) const) {
162 return func(name,
164 }
165
166 template <typename Ret, typename... Args>
167 static me& genericFuncConst(const std::string* name, Ret (T::*fptr)(Args...) const)
168 BY_SIDE_FUNC(name, genericFuncConst(*name, fptr), _get());
169
170 template <typename Ret, typename T1 = T, typename... Args>
171 static me& closure(const std::string& name, std::function<Ret(T1&, Args...)> c) {
173 }
174
175 template <typename Ret, typename T1 = T, typename... Args>
176 static me& closure(const std::string* name, std::function<Ret(T1&, Args...)> c)
177 BY_SIDE_FUNC(name, closure(*name, c), _get());
178
179 template <typename Ret, typename T1 = T>
180 static me& closure(const std::string& name, std::function<Ret(T1&)> c) {
182 }
183
184 template <typename Ret, typename T1 = T>
185 static me& closure(const std::string* name, std::function<Ret(T1&)> c)
186 BY_SIDE_FUNC(name, closure(*name, c), _get());
187
188 static tbridge<T>* make(T* real) { return coreInternal::makeBridge(real); }
189
190 private:
191 static me& _get() {
192 static me _inner;
193 return _inner;
194 }
195
196 private:
197 scope _subs;
198 };
199
200 template <typename T> class tbridger<T, true> {
201 BY(ME(tbridger))
202
203 private:
204 tbridger() = default;
205
206 public:
207 static scope& subs() { return _get()._subs; }
208
209 static me& extend(const scope& src) {
210 subs().link(src);
211 return _get();
212 }
213
214 static me& func(const std::string& name, const baseFunc& bridgeFunc) {
215 _get().subs().add(name, bridgeFunc);
216 return _get();
217 }
218
219 static me& func(const std::string& name, const baseFunc* bridgeFunc) { return func(name, *bridgeFunc); }
220
221 static me& ctor() { return func(func::CTOR_NAME, new tbridgeCtor<T>()); }
222
223 template <typename... Args> static me& ctor() {
224 return func(func::CTOR_NAME, new tbridgeCtor<T, tmarshaling, Args...>());
225 }
226
227 /*template <typename T1, typename... Args> static me& ctorIndirect() {
228 return func(func::CTOR_NAME, new tbridgeCtor<T1, Args...>());
229 }*/
230
231 template <typename Ret, typename T1 = T, typename... Args>
232 static me& closure(const std::string& name, std::function<Ret(T1&, Args...)> c) {
234 }
235
236 template <typename Ret, typename T1 = T>
237 static me& closure(const std::string& name, std::function<Ret(T1&)> c) {
239 }
240
241 template <typename Ret, typename... Args> static me& func(const std::string& name, Ret (T::*fptr)(Args...)) {
242 return funcNonConst(name, fptr);
243 }
244
245 template <typename Ret, typename... Args>
246 static me& func(const std::string& name, Ret (T::*fptr)(Args...) const) {
247 return funcConst(name, fptr);
248 }
249
250 template <typename Ret, typename... Args>
251 static me& funcNonConst(const std::string& name, Ret (T::*fptr)(Args...)) {
253 }
254
255 template <typename Ret, typename... Args>
256 static me& funcConst(const std::string& name, Ret (T::*fptr)(Args...) const) {
257 typedef typename T::super s;
258 auto* fun = new tbridgeFunc<Ret, T, true, tmarshaling, Args...>((Ret(T::*)(Args...)) fptr);
259 fun->setSrc(*new src(dumSrcFile::singleton(), name, point{0, 0}));
260 return func(name, fun);
261 }
262
263 template <typename Ret, typename... Args>
264 static me& genericFunc(const std::string& name, Ret (T::*fptr)(Args...)) {
265 auto* fun = new tbridgeFunc<Ret, T, true, tgenericMarshaling, Args...>(fptr);
266 fun->setSrc(*new src(dumSrcFile::singleton(), name, point{0, 0}));
267 return func(name, fun);
268 }
269
270 template <typename Ret, typename... Args>
271 static me& genericFuncNonConst(const std::string& name, Ret (T::*fptr)(Args...)) {
272 auto* fun = new tbridgeFunc<Ret, T, true, tgenericMarshaling, Args...>((Ret(T::*)(Args...)) fptr);
273 fun->setSrc(*new src(dumSrcFile::singleton(), name, point{0, 0}));
274 return func(name, fun);
275 }
276
277 template <typename Ret, typename... Args>
278 static me& genericFunc(const std::string& name, Ret (T::*fptr)(Args...) const) {
279 auto* fun = new tbridgeFunc<Ret, T, true, tgenericMarshaling, Args...>((Ret(T::*)(Args...)) fptr);
280 fun->setSrc(*new src(dumSrcFile::singleton(), name, point{0, 0}));
281 return func(name, fun);
282 }
283
284 template <typename Ret, typename... Args>
285 static me& genericFuncConst(const std::string& name, Ret (T::*fptr)(Args...) const) {
286 auto* fun = new tbridgeFunc<Ret, T, true, tgenericMarshaling, Args...>((Ret(T::*)(Args...)) fptr);
287 fun->setSrc(*new src(dumSrcFile::singleton(), name, point{0, 0}));
288 return func(name, fun);
289 }
290
291 private:
292 static me& _get() {
293 static me _inner;
294 return _inner;
295 }
296
297 private:
298 scope _subs;
299 };
300} // namespace by
Base class for all function types.
Definition baseFunc.hpp:41
Base class for representing byeol objects.
Definition baseObj.hpp:73
func closure with captured object scope
Definition closure.hpp:20
Constructor function for byeol objects.
Definition ctor.hpp:12
Function definition in byeol language.
Definition func.hpp:38
Source location information.
Definition src.hpp:15
Definition tbridgeFunc.hpp:74
C++ to byeol bridge builder.
Definition tbridger.hpp:61
Definition tnarr.hpp:9
Definition tgenericMarshaling.hpp:10
Template marshaling interface for C++ bridge.
Definition tmarshaling.hpp:19
to Top