Loading...
Searching...
No Matches
binder.hpp
Go to the documentation of this file.
1
2#pragma once
3
5
6struct binderTest;
7
8namespace by {
9
10 class bindTacticable;
11 class life;
12
108 class _nout binder: public typeProvidable, public tbindable<instance> {
109 BY(ME(binder, instance), INIT_META(me))
110 friend class memliteInternal;
111 friend struct ::binderTest;
112
113 public:
120 binder(const me& rhs);
121 virtual ~binder();
122
123 public:
132 const instance* operator->() const BY_CONST_FUNC(operator->())
133 instance& operator*();
142 me& operator=(const me& rhs);
143
144 public:
145 // binder:
150 id getItsId() const;
151 // tbindable:
152 nbool isBind() const override;
153 void rel() override;
154 using tbindable::canBind;
155
162 using tbindable::bind;
163
170
171 instance* get();
172 const instance* get() const BY_CONST_FUNC(get())
173
174 template <typename E> E* get() { return get()->template cast<E>(); }
175 template <typename E> const E* get() const BY_CONST_FUNC(get<E>())
176
177 // typeProvidable:
178 const type& getType() const override;
179
180 using typeProvidable::cast;
181 void* cast(const type& to) override;
182
183 protected:
190
197
203 life* _getBindTag() const;
204
205 protected:
206 id _itsId; // id for binded one
207 const type* _type;
208 bindTacticable* _tactic;
209 };
210
211 // extension for OR macro:
213 f(t);
214 // this returns null-reference but take it easy.
215 // it'll never be used.
216 return t.get();
217 }
218
219 template <typename F> tmedium<instance> operator|(const binder& t, F&& f) {
220 f(t);
221 // this returns null-reference but take it easy.
222 // it'll never be used.
223 return t.get();
224 }
225
226 // extension for typeTrait:
227 template <> struct typeTrait<binder> {
228 typedef binder Org;
229 typedef binder& Ref;
230 typedef binder* Ptr;
231
232 static nbool isNul(const binder& it) { return !it.isBind(); }
233
234 static constexpr nbool is_ptr = false;
235 static constexpr nbool is_ref = false;
236 static constexpr nbool is_like_ptr = true;
237 };
238
239 template <> struct typeTrait<binder*> {
240 typedef binder Org;
241 typedef binder& Ref;
242 typedef binder* Ptr;
243
244 static binder* ret() { return nullptr; }
245
246 static nbool isNul(const binder* it) { return !it || !it->isBind(); }
247
248 static constexpr nbool is_ptr = true;
249 static constexpr nbool is_ref = false;
250 static constexpr nbool is_like_ptr = is_ptr;
251 };
252
253 template <> struct typeTrait<binder&> {
254 typedef binder Org;
255 typedef binder& Ref;
256 typedef binder* Ptr;
257
258 static nbool isNul(const binder& it) { return it.isBind(); }
259
260 static constexpr nbool is_ptr = false;
261 static constexpr nbool is_ref = true;
262 static constexpr nbool is_like_ptr = true;
263 };
264
265 // extension for TO macro:
266 template <typename T, typename F> auto operator->*(binder* t, F&& f) {
267 return t ? f(**t) : typeTrait<std::decay_t<decltype(f(**t))>>::ret();
268 }
269
270 template <typename T, typename F> auto operator->*(const binder* t, F&& f) {
271 return t ? f(**t) : typeTrait<std::decay_t<decltype(f(**t))>>::ret();
272 }
273
274 template <typename T, typename F> auto operator->*(binder& t, F&& f) {
275 return t ? f(*t) : typeTrait<std::decay_t<decltype(f(*t))>>::ret();
276 }
277} // namespace by
Interface for binding tactics in memory management.
Definition bindTacticable.hpp:16
Generalized binding class for managing instance lifecycles.
Definition binder.hpp:108
instance * operator->()
Dereference operator to access bound instance.
Base class for all managed instances in memlite system.
Definition instance.hpp:41
Binding tag for instance reference tracking and lifecycle management.
Definition life.hpp:21
Definition memliteInternal.hpp:12
Template interface for bindable objects.
Definition tbindable.hpp:13
Core class for runtime type information in byeol language.
Definition type.hpp:100
Interface for objects that can provide their type information.
Definition typeProvidable.hpp:13
Rich logging support with polymorphic type conversion.
Definition richLog.hpp:34