tbridge.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "core/ast/obj.hpp"
9
10namespace by {
11
17 template <typename T> class tbridge: public baseObj {
18 // TODO: how to impement 'as()' on bridge obj:
19 // each tbridge obj has its unique type object. when it got called 'getType()'
20 // it returns its type object.
21 //
22 // however, type object is dynamically belongs to this bridge object, when user
23 // tries to get ttype<T>, it's not derived from ntype so it won't have any 'as()'
24 // func. user can't operate conversion in this way.
25 BY(CLASS(tbridge, baseObj))
26
27 public:
28 template <typename Ret, typename T1, nbool, template <typename, nbool> class Marshaling, typename... Args>
29 friend class tbridgeFunc;
30 template <typename T1, nbool> friend class tbridger;
31 template <typename T1, nbool> friend struct tmarshaling;
32
33 static_assert(!tifSub<T, baseObj>::is,
34 "parameterized type 'T' shouldn't be a derived class to baseObj. override subs() if it "
35 "is.");
36
37 protected:
39 tbridge(): me(nullptr) {}
40
41 tbridge(T* real, const baseObj* origin = nullptr): super(origin, false), _real(real) {}
42
43 public:
44 tbridge(const me& rhs): super(rhs), _real(rhs._real ? new T(*rhs._real) : nullptr) {}
45
46 ~tbridge() override {
47 if(_ownReal && _real) delete _real;
48 }
49
50 public:
51 T& get() { return *_real; }
52
53 const T& get() const { return *_real; }
54
55 const baseObj& getOrigin() const override {
56 static tbaseObjOrigin<tbridge<T>> org(
57 tbridger<T, tifSub<typename tadaptiveSuper<T>::super, baseObj>::is>::subs());
58 const baseObj& supers = super::getOrigin();
59 return &supers == this ? org : supers;
60 }
61
62 private:
63 T* _real;
64 nbool _ownReal = _real;
65 };
66} // namespace by
Base class for all objects in byeol language.
Definition: baseObj.hpp:24
baseObj()=default
User-defined class origin in byeol language.
Definition: origin.hpp:17
Definition: tbridgeFunc.hpp:72
Bridge template for C++ objects.
Definition: tbridge.hpp:17
tbridge()
@hidden this api is only available to tmarshaling.
Definition: tbridge.hpp:39
Bridge builder for C++ classes.
Definition: tbridger.hpp:18
Type trait to check if T is subclass of super.
Definition: rtti.hpp:48
Template marshaling interface for C++ bridge.
Definition: tmarshaling.hpp:18