로딩중...
검색중...
일치하는것 없음
tmarshaling.hpp
이 파일의 문서화 페이지로 가기
1
2#pragma once
3
5#include "core/internal/coreInternal.hpp"
6
7namespace by {
8
9 struct marshalErr {};
10 template <typename T> class tbridge;
11 template <typename T, typename defaultElemType> class tarr;
12 class arr;
13
19 struct tmarshaling: public metaIf {
20 typedef T mgd;
21
22 template <typename E> static str toMgd(E& it) { throw marshalErr(); }
23
24 static T& toNative(const str& it) { throw marshalErr(); }
25
26 static const mgd& onAddParam() { return *new mgd(); }
27
28 static const mgd* onGetRet() { throw marshalErr(); }
29
30 static no canMarshal();
31 };
32
33 template <typename T, typename TACTIC> struct tmarshaling<tweak<T, TACTIC>, true>: public metaIf {
35
36 template <typename E> static str toMgd(E& it) { return it; }
37
38 static tweak<T, TACTIC> toNative(node& it) { return it; }
39
40 static const mgd& onAddParam() { return *coreInternal::makeBridge(new T()); }
41
42 static const mgd* onGetRet() { return coreInternal::makeBridge(new T()); }
43
44 static yes canMarshal();
45 };
46
47 template <typename T, typename TACTIC> struct tmarshaling<tstr<T, TACTIC>, true>: public metaIf {
49
50 template <typename E> static str toMgd(E& it) { return it; }
51
52 static tstr<T, TACTIC> toNative(node& it) { return it; }
53
54 static const mgd& onAddParam() { return *coreInternal::makeBridge(new T()); }
55
56 static const mgd* onGetRet() { return coreInternal::makeBridge(new T()); }
57
58 static yes canMarshal();
59 };
60
61 template <> struct tmarshaling<node&, true>: public metaIf {
62 typedef node mgd;
63
64 template <typename E> static str toMgd(E& it) { return it; }
65
66 static node& toNative(node& it) { return it; }
67
68 static const mgd& onAddParam() { return *new mockNode(); }
69
70 static const mgd* onGetRet() { return new mockNode(); }
71
72 static yes canMarshal();
73 };
74
75 template <> struct tmarshaling<node*, true>: public metaIf {
76 typedef node mgd;
77
78 template <typename E> static str toMgd(E* it) { return it; }
79
80 static node* toNative(node& it) { return &it; }
81
82 static const mgd& onAddParam() { return *new mockNode(); }
83
84 static const mgd* onGetRet() { return new mockNode(); }
85
86 static yes canMarshal();
87 };
88
89 template <typename T> struct tmarshaling<T&, true>: public metaIf {
90 typedef T mgd;
91
92 template <typename E> static str toMgd(E& it) { return it; }
93
94 static T& toNative(node& it) { return *it.cast<T>(); }
95
96 static const mgd& onAddParam() { return *new mgd(); }
97
98 static const mgd* onGetRet() { return new mgd(); }
99
100 static yes canMarshal();
101 };
102
103 template <typename T> struct tmarshaling<T*, true>: public metaIf {
104 typedef T mgd;
105
106 template <typename E> static str toMgd(E* it) { return it; }
107
108 static T* toNative(node& it) { return it.cast<T>(); }
109
110 static const mgd& onAddParam() { return *new mgd(); }
111
112 static const mgd* onGetRet() { return new mgd(); }
113
114 static yes canMarshal();
115 };
116
117 template <typename T> struct tmarshaling<T, true>: public metaIf {
118 typedef T mgd;
119
120 template <typename E> static str toMgd(const E& it) { return str((E*) it.clone()); }
121
122 static T& toNative(node& it) { return *it.cast<T>(); }
123
124 static const mgd& onAddParam() { return *new mgd(); }
125
126 static const mgd* onGetRet() { return new mgd(); }
127
128 static yes canMarshal();
129 };
130
135 template <typename tnativeType, typename tmarshalType> struct tnormalMarshaling: public metaIf {
136 typedef tmarshalType mgd;
137 typedef tnativeType native;
138
139 static native toNative(node& it) { return ((mgd&) it).get(); }
140
141 static str toMgd(native it) { return str(new mgd(it)); }
142
143 static const mgd& onAddParam() { return *new mgd(); }
144
145 static const mgd* onGetRet() { return new mgd(); }
146
147 static yes canMarshal();
148 };
149
150 template <> struct tnormalMarshaling<char, nStr>: public metaIf {
151 typedef nStr mgd;
152 typedef char native;
153
154 static native toNative(node& it) {
155 const std::string& cast = ((mgd&) it).get();
156 return cast.length() > 0 ? cast[0] : '\0';
157 }
158
159 static str toMgd(native it) { return str(new mgd(it)); }
160
161 static const mgd& onAddParam() { return *new mgd(); }
162
163 static const mgd* onGetRet() { return new mgd(); }
164
165 static yes canMarshal();
166 };
167
168 template <> struct tnormalMarshaling<const char*, nStr>: public metaIf {
169 typedef nStr mgd;
170 typedef const char* native;
171
172 static native toNative(node& it) { return ((mgd&) it).get().c_str(); }
173
174 static str toMgd(native it) { return str(new mgd(it)); }
175
176 static const mgd& onAddParam() { return *new mgd(); }
177
178 static const mgd* onGetRet() { return new mgd(); }
179
180 static yes canMarshal();
181 };
182
187 template <> struct _nout tnormalMarshaling<void, nVoid>: public metaIf {
188 typedef nVoid mgd;
189 typedef void native;
190
191 static str toMgd() { return str(new nVoid()); }
192
193 static const mgd& onAddParam() { return *new mgd(); }
194
195 static const mgd* onGetRet() { return new mgd(); }
196
197 static yes canMarshal();
198 };
199
200 template <> struct _nout tmarshaling<nint, false>: public tnormalMarshaling<nint, nInt> {};
201
202 template <> struct _nout tmarshaling<nint&, false>: public tnormalMarshaling<nint, nInt> {};
203
204 template <> struct _nout tmarshaling<const nint&, false>: public tnormalMarshaling<nint, nInt> {};
205
206 template <> struct _nout tmarshaling<nbool, false>: public tnormalMarshaling<nbool, nBool> {};
207
208 template <> struct _nout tmarshaling<nflt, false>: public tnormalMarshaling<nflt, nFlt> {};
209
210 template <> struct _nout tmarshaling<nchar, false>: public tnormalMarshaling<nchar, nStr> {};
211
212 template <> struct _nout tmarshaling<nchar*, false>: public tnormalMarshaling<const nchar*, nStr> {};
213
214 template <> struct _nout tmarshaling<const nchar*, false>: public tnormalMarshaling<const nchar*, nStr> {};
215
216 template <> struct _nout tmarshaling<std::string, false>: public tnormalMarshaling<const std::string&, nStr> {};
217
218 template <> struct _nout tmarshaling<std::string&, false>: public tnormalMarshaling<const std::string&, nStr> {};
219
220 template <>
221 struct _nout tmarshaling<const std::string&, false>: public tnormalMarshaling<const std::string&, nStr> {};
222
223 template <>
224 struct _nout tmarshaling<const std::string, false>: public tnormalMarshaling<const std::string&, nStr> {};
225
226 template <> struct _nout tmarshaling<void, false>: public tnormalMarshaling<void, nVoid> {};
227
228 template <typename T> struct tmarshaling<T, false>: public metaIf {
229 typedef class tbridge<T> mgd;
230
231 template <typename E> static str toMgd(const E& it) { return coreInternal::makeBridge(new E(it)); }
232
233 static T& toNative(node& it) { return *it.cast<T>(); }
234
235 static const mgd& onAddParam() { return *coreInternal::makeBridge<T>(); }
236
237 static const mgd* onGetRet() { return coreInternal::makeBridge<T>(); }
238
239 static yes canMarshal();
240 };
241
242 template <typename T> struct tmarshaling<T&, false>: public metaIf {
243 typedef class tbridge<T> mgd;
244
245 template <typename E> static str toMgd(E& it) { return coreInternal::makeBridge(&it); }
246
247 static T& toNative(node& it) { return *it.cast<tbridge<T>>()->get(); }
248
249 static const mgd& onAddParam() { return *coreInternal::makeBridge<T>(); }
250
251 static const mgd* onGetRet() { return coreInternal::makeBridge<T>(); }
252
253 static yes canMarshal();
254 };
255
256 template <typename T> struct tmarshaling<T*, false>: public metaIf {
257 typedef tbridge<T> mgd;
258
259 template <typename E> static str toMgd(E* it) { return coreInternal::makeBridge(it); }
260
261 static T* toNative(node& it) { return it.cast<tbridge<T>>()->get(); }
262
263 static const mgd& onAddParam() { return *coreInternal::makeBridge<T>(); }
264
265 static const mgd* onGetRet() { return coreInternal::makeBridge<T>(); }
266
267 static yes canMarshal();
268 };
269
270 template <typename T, typename E> struct tmarshaling<tarr<T, E>, true>: public metaIf {
271 typedef arr mgd;
272
273 static tarr<T, E> toNative(node& it);
274
275 template <typename E2> static str toMgd(E2* it);
276
277 static const mgd& onAddParam();
278 static const mgd* onGetRet();
279 static yes canMarshal();
280 };
281} // namespace by
Scripted array container for byeol language
Definition arr.hpp:15
String primitive type in byeol language
Definition nStr.hpp:14
Void primitive type in byeol language
Definition nVoid.hpp:13
Base class for all AST nodes in the byeol language
Definition node.hpp:195
Definition tarr.hpp:8
C++ native class bridge
Definition tbridge.hpp:19
Definition tnarr.hpp:9
Definition tmarshaling.hpp:9
Template marshaling interface for C++ bridge
Definition tmarshaling.hpp:19
Normal marshaling for primitive types
Definition tmarshaling.hpp:135
to Top