@ohos-ports/nbind 0.0.0-stage → 0.3.15-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/.editorconfig +7 -0
  2. package/LICENSE +22 -0
  3. package/README.md +1393 -2
  4. package/autogypi.json +11 -0
  5. package/bin/ci-trigger +40 -0
  6. package/bin/copyasm.js +77 -0
  7. package/bin/emcc +21 -0
  8. package/bin/emcc-path.js +7 -0
  9. package/bin/ndts.js +22 -0
  10. package/config.js +7 -0
  11. package/dist/Type.d.ts +92 -0
  12. package/dist/Type.js +180 -0
  13. package/dist/common.d.ts +9 -0
  14. package/dist/common.js +10 -0
  15. package/dist/em-api.js +2353 -0
  16. package/dist/int64.d.ts +9 -0
  17. package/dist/int64.js +64 -0
  18. package/dist/nbind.d.ts +49 -0
  19. package/dist/nbind.js +154 -0
  20. package/dist/reflect.d.ts +69 -0
  21. package/dist/reflect.js +261 -0
  22. package/dist/shim.d.ts +1 -0
  23. package/dist/shim.js +2 -0
  24. package/dist/todts.d.ts +5 -0
  25. package/dist/todts.js +146 -0
  26. package/include/nbind/ArgStorage.h +67 -0
  27. package/include/nbind/BindClass.h +290 -0
  28. package/include/nbind/BindDefiner.h +295 -0
  29. package/include/nbind/Buffer.h +50 -0
  30. package/include/nbind/FunctionDefiner.h +51 -0
  31. package/include/nbind/MethodDef.h +50 -0
  32. package/include/nbind/Policy.h +255 -0
  33. package/include/nbind/TypeID.h +84 -0
  34. package/include/nbind/TypeStd.h +66 -0
  35. package/include/nbind/TypeTransformer.h +38 -0
  36. package/include/nbind/api.h +100 -0
  37. package/include/nbind/common.h +22 -0
  38. package/include/nbind/em/ArgFromWire.h +31 -0
  39. package/include/nbind/em/BindingStd.h +221 -0
  40. package/include/nbind/em/BindingType.h +204 -0
  41. package/include/nbind/em/Buffer.h +37 -0
  42. package/include/nbind/em/Callback.h +186 -0
  43. package/include/nbind/em/Caller.h +61 -0
  44. package/include/nbind/em/Creator.h +30 -0
  45. package/include/nbind/em/External.h +63 -0
  46. package/include/nbind/em/Int64.h +131 -0
  47. package/include/nbind/em/NBind.h +63 -0
  48. package/include/nbind/em/Pool.h +34 -0
  49. package/include/nbind/em/StdFunction.h +40 -0
  50. package/include/nbind/em/ValueObj.h +54 -0
  51. package/include/nbind/nbind.h +19 -0
  52. package/include/nbind/noconflict.h +91 -0
  53. package/include/nbind/signature/BaseSignature.h +238 -0
  54. package/include/nbind/signature/CallbackSignature.h +59 -0
  55. package/include/nbind/signature/ConstructorSignature.h +76 -0
  56. package/include/nbind/signature/FunctionSignature.h +63 -0
  57. package/include/nbind/signature/GetterSignature.h +62 -0
  58. package/include/nbind/signature/MethodSignature.h +61 -0
  59. package/include/nbind/signature/SetterSignature.h +63 -0
  60. package/include/nbind/signature/SignatureParam.h +39 -0
  61. package/include/nbind/v8/ArgFromWire.h +69 -0
  62. package/include/nbind/v8/BindWrapper.h +295 -0
  63. package/include/nbind/v8/BindingStd.h +180 -0
  64. package/include/nbind/v8/BindingType.h +241 -0
  65. package/include/nbind/v8/Buffer.h +59 -0
  66. package/include/nbind/v8/Callback.h +165 -0
  67. package/include/nbind/v8/Caller.h +140 -0
  68. package/include/nbind/v8/Convert.h +80 -0
  69. package/include/nbind/v8/Creator.h +26 -0
  70. package/include/nbind/v8/External.h +119 -0
  71. package/include/nbind/v8/Int64.h +195 -0
  72. package/include/nbind/v8/NBind.h +63 -0
  73. package/include/nbind/v8/Output.h +36 -0
  74. package/include/nbind/v8/Overloader.h +215 -0
  75. package/include/nbind/v8/StdFunction.h +44 -0
  76. package/include/nbind/v8/ValueObj.h +137 -0
  77. package/include/nbind/wire.h +79 -0
  78. package/package.json +69 -4
  79. package/src/checkver.js +31 -0
  80. package/src/common.cc +129 -0
  81. package/src/em/Binding.cc +313 -0
  82. package/src/em/tsconfig.json +22 -0
  83. package/src/nbind-common.gypi +14 -0
  84. package/src/nbind.gypi +98 -0
  85. package/src/post.js +2 -0
  86. package/src/pre.js +48 -0
  87. package/src/reflect.cc +170 -0
  88. package/src/symbols.txt +1 -0
  89. package/src/tsconfig.json +23 -0
  90. package/src/tslint.json +86 -0
  91. package/src/v8/Binding.cc +391 -0
  92. package/src/v8/Buffer.cc +73 -0
@@ -0,0 +1,295 @@
1
+ // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd.
2
+ // Released under the MIT license, see LICENSE.
3
+
4
+ #pragma once
5
+
6
+ #include <type_traits>
7
+ #include <forward_list>
8
+ #include <vector>
9
+ #include <stdexcept>
10
+
11
+ #include "api.h"
12
+ #include "wire.h"
13
+ #include "MethodDef.h"
14
+ #include "ArgStorage.h"
15
+
16
+ #if defined(BUILDING_NODE_EXTENSION)
17
+
18
+ # include "v8/Caller.h"
19
+ # include "signature/SignatureParam.h"
20
+ # include "signature/BaseSignature.h" // Needs Caller
21
+ # include "v8/Overloader.h" // Needs ArgStorage
22
+ # include "BindClass.h" // Needs Overloader and BaseSignature
23
+ # include "v8/ValueObj.h" // Needs BindClass
24
+ # include "v8/Int64.h"
25
+ # include "v8/Creator.h" // Needs ArgStorage
26
+
27
+ #elif defined(__EMSCRIPTEN__)
28
+
29
+ # include "em/Caller.h"
30
+ # include "signature/BaseSignature.h"
31
+ # include "BindClass.h"
32
+ # include "em/ValueObj.h"
33
+ # include "em/Int64.h"
34
+ # include "em/Creator.h" // Needs ArgStorage
35
+
36
+ #endif
37
+
38
+ #include "common.h"
39
+
40
+ #include "signature/FunctionSignature.h"
41
+ #include "signature/MethodSignature.h"
42
+ #include "signature/GetterSignature.h"
43
+ #include "signature/SetterSignature.h"
44
+ #include "signature/ConstructorSignature.h"
45
+
46
+ namespace nbind {
47
+
48
+ // extern const char *emptyGetter; unused for now.
49
+ extern const char *emptySetter;
50
+
51
+ template <typename PolicyList>
52
+ struct SkipNamePolicy {
53
+ typedef PolicyList Type;
54
+ };
55
+
56
+ template <typename... Policies>
57
+ struct SkipNamePolicy<PolicyListType<const char *, Policies...>> {
58
+ typedef PolicyListType<Policies...> Type;
59
+ };
60
+
61
+ template <typename... Policies>
62
+ const char *executeNamePolicy(const char *name, Policies... policies) {
63
+ return(name);
64
+ }
65
+
66
+ template <typename... Policies>
67
+ const char *executeNamePolicy(const char *name, const char *boundName, Policies... policies) {
68
+ return(boundName);
69
+ }
70
+
71
+ // BindDefiner is a helper class to allow making
72
+ // class definition syntax match embind.
73
+
74
+ template <class Bound>
75
+ class BindDefiner {
76
+
77
+ public:
78
+
79
+ BindDefiner(const char *name) : bindClass(BindClass<Bound>::getInstance()) {
80
+ bindClass.init(name);
81
+
82
+ # if defined(BUILDING_NODE_EXTENSION)
83
+ // Set up handler to wrap object pointers instantiated in C++
84
+ // for use in JavaScript.
85
+
86
+ bindClass.wrapPtr = BindWrapper<Bound>::wrapPtr;
87
+ # endif
88
+
89
+ registerClass(bindClass);
90
+ }
91
+
92
+ template <class SuperType>
93
+ BindDefiner &inherit() {
94
+ bindClass.template addSuperClass<SuperType>();
95
+
96
+ return(*this);
97
+ }
98
+
99
+ template <
100
+ class Signature,
101
+ typename MethodType
102
+ > void addMethod(
103
+ const char *name,
104
+ MethodType method,
105
+ TypeFlags flags = TypeFlags::none
106
+ ) {
107
+ bindClass.addMethod(
108
+ name,
109
+ &Signature::getInstance(),
110
+ Signature::getDirect(method),
111
+ Signature::addMethod(method, flags),
112
+ flags
113
+ );
114
+ }
115
+
116
+ template <
117
+ template <typename, class, typename, typename...> class Signature,
118
+ typename ReturnType,
119
+ typename... Args,
120
+ typename... Policies
121
+ > void addMethodMaybeConst(
122
+ const char* name,
123
+ ReturnType(Bound::*method)(Args...),
124
+ Policies... policies
125
+ ) {
126
+ addMethod<
127
+ Signature<
128
+ decltype(method),
129
+ Bound,
130
+ typename SkipNamePolicy<PolicyListType<Policies...>>::Type,
131
+ ReturnType,
132
+ Args...
133
+ >,
134
+ decltype(method)
135
+ >(executeNamePolicy(name, policies...), method);
136
+ }
137
+
138
+ template <
139
+ template <typename, class, typename, typename...> class Signature,
140
+ typename ReturnType,
141
+ typename... Args,
142
+ typename... Policies
143
+ > void addMethodMaybeConst(
144
+ const char* name,
145
+ ReturnType(Bound::*method)(Args...) const,
146
+ Policies... policies
147
+ ) {
148
+ addMethod<
149
+ Signature<
150
+ decltype(method),
151
+ Bound,
152
+ typename SkipNamePolicy<PolicyListType<Policies...>>::Type,
153
+ ReturnType,
154
+ Args...
155
+ >,
156
+ decltype(method)
157
+ >(
158
+ executeNamePolicy(name, policies...),
159
+ method,
160
+ TypeFlags::isConst
161
+ );
162
+ }
163
+
164
+ template <typename... Args, typename... Policies>
165
+ BindDefiner &constructor(Policies...) {
166
+ typedef ConstructorSignature<
167
+ Bound,
168
+ typename SkipNamePolicy<PolicyListType<Policies...>>::Type,
169
+ Args...
170
+ > Signature;
171
+
172
+ bindClass.addConstructor(&Signature::getInstance());
173
+
174
+ return(*this);
175
+ }
176
+
177
+ // Static method.
178
+
179
+ template <typename ReturnType, typename... Args, typename... Policies>
180
+ BindDefiner &method(
181
+ const char* name,
182
+ ReturnType(*func)(Args...),
183
+ Policies... policies
184
+ ) {
185
+ addMethod<
186
+ FunctionSignature<
187
+ decltype(func),
188
+ std::nullptr_t,
189
+ typename SkipNamePolicy<PolicyListType<Policies...>>::Type,
190
+ ReturnType,
191
+ Args...
192
+ >,
193
+ decltype(func)
194
+ >(executeNamePolicy(name, policies...), func);
195
+
196
+ return(*this);
197
+ }
198
+
199
+ // Dynamic method.
200
+
201
+ template <typename MethodType, typename... Policies>
202
+ BindDefiner &method(
203
+ const char* name,
204
+ MethodType (Bound::*method),
205
+ Policies... policies
206
+ ) {
207
+ addMethodMaybeConst<MethodSignature>(name, method, policies...);
208
+
209
+ return(*this);
210
+ }
211
+
212
+ template <typename... Args>
213
+ struct Overloaded {
214
+
215
+ Overloaded(BindDefiner &parentDefiner) : parentDefiner(parentDefiner), definer(*this) {}
216
+
217
+ Overloaded(const Overloaded &other) : parentDefiner(other.parentDefiner), definer(*this) {}
218
+
219
+ Overloaded(Overloaded &&other) : parentDefiner(other.parentDefiner), definer(*this) {}
220
+
221
+ // Overloaded static method.
222
+
223
+ template <typename ReturnType, typename... Policies>
224
+ BindDefiner &method(
225
+ const char* name,
226
+ ReturnType(*func)(Args...),
227
+ Policies... policies
228
+ ) {
229
+ return(parentDefiner.method(name, func, policies...));
230
+ }
231
+
232
+ // Overloaded dynamic non-const method.
233
+
234
+ template <typename ReturnType, typename... Policies>
235
+ BindDefiner &method(
236
+ const char* name,
237
+ ReturnType (Bound::*method)(Args...),
238
+ Policies... policies
239
+ ) {
240
+ return(parentDefiner.method(name, method, policies...));
241
+ }
242
+
243
+ // Overloaded dynamic const method.
244
+
245
+ template <typename ReturnType, typename... Policies>
246
+ BindDefiner &method(
247
+ const char* name,
248
+ ReturnType (Bound::*method)(Args...) const,
249
+ Policies... policies
250
+ ) {
251
+ return(parentDefiner.method(name, method, policies...));
252
+ }
253
+
254
+ BindDefiner &parentDefiner;
255
+ Overloaded &definer;
256
+ };
257
+
258
+ template <typename... Args>
259
+ Overloaded<Args...> overloaded() {
260
+ return(Overloaded<Args...>(*this));
261
+ }
262
+
263
+ template <typename GetterType, typename... Policies>
264
+ BindDefiner &property(
265
+ const char* name,
266
+ GetterType (Bound::*getter),
267
+ Policies... policies
268
+ ) {
269
+ addMethodMaybeConst<GetterSignature>(name, getter, policies...);
270
+
271
+ bindClass.addMethod(emptySetter);
272
+
273
+ return(*this);
274
+ }
275
+
276
+ template <typename GetterType, typename SetterType, typename... Policies>
277
+ BindDefiner &property(
278
+ const char* name,
279
+ GetterType (Bound::*getter),
280
+ SetterType (Bound::*setter),
281
+ Policies... policies
282
+ ) {
283
+ addMethodMaybeConst<SetterSignature>(name, setter, policies...);
284
+ addMethodMaybeConst<GetterSignature>(name, getter, policies...);
285
+
286
+ return(*this);
287
+ }
288
+
289
+ private:
290
+
291
+ BindClass<Bound> &bindClass;
292
+
293
+ };
294
+
295
+ } // namespace
@@ -0,0 +1,50 @@
1
+ // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd.
2
+ // Released under the MIT license, see LICENSE.
3
+
4
+ #pragma once
5
+
6
+ namespace nbind {
7
+
8
+ class Buffer {
9
+
10
+ friend struct BindingType<Buffer>;
11
+
12
+ public:
13
+
14
+ #if defined(BUILDING_NODE_EXTENSION)
15
+
16
+ Buffer(unsigned char *ptr = nullptr, size_t len = 0) :
17
+ ptr(ptr), len(len) {}
18
+
19
+ Buffer(unsigned char *ptr, size_t len, v8::Local<v8::Object> obj) :
20
+ ptr(ptr), len(len), handle(obj) {}
21
+
22
+ # if NODE_MODULE_VERSION < 45 // < IO.js 3.0
23
+
24
+ static void destroy(unsigned char *ptr) { free(ptr); }
25
+
26
+ # endif
27
+
28
+ #elif defined(__EMSCRIPTEN__)
29
+
30
+ Buffer(unsigned char *ptr = nullptr, size_t len = 0, unsigned int num = 0) :
31
+ ptr(ptr), len(len), handle(num) {}
32
+
33
+ #endif
34
+
35
+ inline unsigned char *data() const { return(ptr); }
36
+
37
+ inline size_t length() const { return(len); }
38
+
39
+ inline void commit();
40
+
41
+ private:
42
+
43
+ unsigned char *ptr;
44
+ size_t len;
45
+ // Reference the JavaScript object to protect it from garbage collection.
46
+ External handle;
47
+
48
+ };
49
+
50
+ } // namespace
@@ -0,0 +1,51 @@
1
+ // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd.
2
+ // Released under the MIT license, see LICENSE.
3
+
4
+ #pragma once
5
+
6
+ namespace nbind {
7
+
8
+ class FunctionDefiner {
9
+
10
+ public:
11
+
12
+ template <typename ReturnType, typename... Args, typename... Policies>
13
+ FunctionDefiner(
14
+ const char* name,
15
+ ReturnType(*func)(Args...),
16
+ Policies... policies
17
+ ) {
18
+ typedef FunctionSignature<
19
+ decltype(func),
20
+ std::nullptr_t,
21
+ typename SkipNamePolicy<PolicyListType<Policies...>>::Type,
22
+ ReturnType,
23
+ Args...
24
+ > Signature;
25
+
26
+ registerFunction(
27
+ executeNamePolicy(name, policies...),
28
+ Signature::getDirect(func),
29
+ Signature::addMethod(func, TypeFlags::none),
30
+ &Signature::getInstance(),
31
+ TypeFlags::none
32
+ );
33
+ }
34
+
35
+ template <typename... Args>
36
+ struct Overloaded {
37
+
38
+ template <typename ReturnType, typename... Policies>
39
+ Overloaded(
40
+ const char* name,
41
+ ReturnType(*func)(Args...),
42
+ Policies... policies
43
+ ) {
44
+ FunctionDefiner definer(name, func, policies...);
45
+ (void)definer; // Silence compiler warning about unused variable.
46
+ }
47
+
48
+ };
49
+ };
50
+
51
+ } // namespace
@@ -0,0 +1,50 @@
1
+ // This file is part of nbind, copyright (C) 2014-2015 BusFaster Ltd.
2
+ // Released under the MIT license, see LICENSE.
3
+
4
+ #pragma once
5
+
6
+ namespace nbind {
7
+
8
+ // Storage format for method definitions.
9
+
10
+ class BaseSignature;
11
+
12
+ class MethodDef {
13
+
14
+ public:
15
+
16
+ MethodDef(
17
+ const char *name,
18
+ funcPtr ptr,
19
+ unsigned int num,
20
+ BaseSignature *signature,
21
+ TypeFlags flags
22
+ ) : name(name), ptr(ptr), num(num), signature(signature), flags(flags) {}
23
+
24
+ const char *getName() const { return(name); }
25
+ funcPtr getPtr() const { return(ptr); }
26
+ unsigned int getNum() const { return(num); }
27
+ const BaseSignature *getSignature() const { return(signature); }
28
+ TypeFlags getFlags() const { return(flags); }
29
+
30
+ private:
31
+
32
+ const char *name;
33
+
34
+ // Pointer to call C++ function directly, sometimes used in Emscripten.
35
+
36
+ const funcPtr ptr;
37
+
38
+ // Index to distinguish between functions with identical signatures.
39
+
40
+ const unsigned int num;
41
+
42
+ // Signature represents return and argument types.
43
+
44
+ const BaseSignature *signature;
45
+
46
+ const TypeFlags flags;
47
+
48
+ };
49
+
50
+ } // namespace
@@ -0,0 +1,255 @@
1
+ // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd.
2
+ // Released under the MIT license, see LICENSE.
3
+
4
+ #pragma once
5
+
6
+ namespace nbind {
7
+
8
+ // This is effectively an enum with members accessible using dot notation.
9
+ // It allows copy-pasting the later TypeFlags definition between
10
+ // C++ and TypeScript using identical syntax.
11
+
12
+ struct TypeFlagBaseType {
13
+ constexpr TypeFlagBaseType() {}
14
+
15
+ // GCC bug workaround.
16
+ // Constexpr struct instance members cannot refer to each other.
17
+
18
+ struct inner {
19
+ static constexpr uint32_t flag = 1;
20
+ static constexpr uint32_t num = flag * 8;
21
+ static constexpr uint32_t ref = num * 16;
22
+ static constexpr uint32_t kind = ref * 8;
23
+ };
24
+
25
+ uint32_t flag = inner::flag;
26
+ uint32_t ref = inner::ref;
27
+ uint32_t kind = inner::kind;
28
+ uint32_t num = inner::num;
29
+ };
30
+
31
+ // Visual Studio bug workaround. The struct must be defined separately.
32
+
33
+ constexpr struct TypeFlagBaseType TypeFlagBase;
34
+
35
+ // These must match Type.ts.
36
+
37
+ enum class TypeFlags : uint32_t {
38
+ none = 0,
39
+
40
+ flagMask = TypeFlagBase.flag * 7,
41
+ isConst = TypeFlagBase.flag * 1,
42
+ isValueObject = TypeFlagBase.flag * 2,
43
+ isMethod = TypeFlagBase.flag * 4,
44
+
45
+ numMask = TypeFlagBase.num * 15,
46
+ isUnsigned = TypeFlagBase.num * 1,
47
+ isSignless = TypeFlagBase.num * 2,
48
+ isFloat = TypeFlagBase.num * 4,
49
+ isBig = TypeFlagBase.num * 8,
50
+
51
+ refMask = TypeFlagBase.ref * 7,
52
+ isPointer = TypeFlagBase.ref * 1,
53
+ isReference = TypeFlagBase.ref * 2,
54
+ isRvalueRef = TypeFlagBase.ref * 3,
55
+ isSharedPtr = TypeFlagBase.ref * 4,
56
+ isUniquePtr = TypeFlagBase.ref * 5,
57
+
58
+ kindMask = TypeFlagBase.kind * 15,
59
+ isArithmetic = TypeFlagBase.kind * 1,
60
+ isClass = TypeFlagBase.kind * 2,
61
+ isClassPtr = TypeFlagBase.kind * 3,
62
+ isSharedClassPtr = TypeFlagBase.kind * 4,
63
+ isVector = TypeFlagBase.kind * 5,
64
+ isArray = TypeFlagBase.kind * 6,
65
+ isCString = TypeFlagBase.kind * 7,
66
+ isString = TypeFlagBase.kind * 8,
67
+ isCallback = TypeFlagBase.kind * 9,
68
+ isOther = TypeFlagBase.kind * 10
69
+ };
70
+
71
+ inline TypeFlags operator& (TypeFlags a, TypeFlags b) {
72
+ return(static_cast<TypeFlags>(
73
+ static_cast<uint32_t>(a) & static_cast<uint32_t>(b)
74
+ ));
75
+ }
76
+ inline TypeFlags operator| (TypeFlags a, TypeFlags b) {
77
+ return(static_cast<TypeFlags>(
78
+ static_cast<uint32_t>(a) | static_cast<uint32_t>(b)
79
+ ));
80
+ }
81
+
82
+ inline bool operator! (TypeFlags f) { return(f == TypeFlags::none); }
83
+
84
+ inline TypeFlags operator~ (TypeFlags f) {
85
+ return(static_cast<TypeFlags>(
86
+ ~static_cast<uint32_t>(f)
87
+ ));
88
+ }
89
+
90
+ // Nullable policy
91
+
92
+ template <typename ArgType>
93
+ struct NullableType {};
94
+
95
+ struct Nullable {
96
+ template <typename ArgType, typename Transformed>
97
+ struct Transform {
98
+ typedef Transformed Type;
99
+ };
100
+
101
+ template<typename ArgType, typename Transformed>
102
+ struct Transform<ArgType *, Transformed> {
103
+ typedef NullableType<Transformed> Type;
104
+ };
105
+
106
+ static const char *getName() {
107
+ static const char *name = "Nullable";
108
+ return(name);
109
+ }
110
+ };
111
+
112
+ // Strict policy
113
+
114
+ #define DEFINE_STRICT_BINDING_TYPE(ArgType) \
115
+ template<typename Transformed> \
116
+ struct Transform<ArgType, Transformed> { \
117
+ typedef StrictType<Transformed> Type; \
118
+ }
119
+
120
+ template <typename ArgType>
121
+ struct StrictType {};
122
+
123
+ struct Strict {
124
+ template <typename ArgType, typename Transformed>
125
+ struct Transform {
126
+ typedef Transformed Type;
127
+ };
128
+
129
+ DEFINE_STRICT_BINDING_TYPE(bool);
130
+
131
+ DEFINE_STRICT_BINDING_TYPE(double);
132
+ DEFINE_STRICT_BINDING_TYPE(float);
133
+
134
+ DEFINE_STRICT_BINDING_TYPE(unsigned int);
135
+ DEFINE_STRICT_BINDING_TYPE(unsigned short);
136
+ DEFINE_STRICT_BINDING_TYPE(unsigned char);
137
+
138
+ DEFINE_STRICT_BINDING_TYPE(signed int);
139
+ DEFINE_STRICT_BINDING_TYPE(signed short);
140
+ DEFINE_STRICT_BINDING_TYPE(signed char);
141
+
142
+ DEFINE_STRICT_BINDING_TYPE(char);
143
+
144
+ DEFINE_STRICT_BINDING_TYPE(unsigned char *);
145
+ DEFINE_STRICT_BINDING_TYPE(char *);
146
+ DEFINE_STRICT_BINDING_TYPE(const unsigned char *);
147
+ DEFINE_STRICT_BINDING_TYPE(const char *);
148
+
149
+ DEFINE_STRICT_BINDING_TYPE(std::string);
150
+
151
+ static const char *getName() {
152
+ static const char *name = "Strict";
153
+ return(name);
154
+ }
155
+ };
156
+
157
+ // Policy list
158
+
159
+ template <typename...>
160
+ struct PolicyListType {};
161
+
162
+ template <typename PolicyList>
163
+ struct PolicyLister {};
164
+
165
+ template <typename... Policies>
166
+ struct PolicyLister<PolicyListType<Policies...>> {
167
+ static const char **getNameList() {
168
+ static const char *nameList[] = { Policies::getName()..., nullptr };
169
+ return(nameList);
170
+ }
171
+ };
172
+
173
+ // Policy autodetection part 1
174
+
175
+ struct NoPolicy {
176
+ template <typename ArgType, typename Transformed>
177
+ struct Transform {
178
+ typedef Transformed Type;
179
+ };
180
+
181
+ static const char *getName() {
182
+ return(nullptr);
183
+ }
184
+ };
185
+
186
+ template <typename ArgType>
187
+ NoPolicy detectPolicies(const ArgType &, int);
188
+
189
+ // Value object policy (autodetected)
190
+
191
+ template<typename ArgType>
192
+ struct ValueType {};
193
+
194
+ struct ValuePolicy {
195
+ template <typename ArgType, typename Transformed>
196
+ struct Transform {
197
+ typedef ValueType<Transformed> Type;
198
+ };
199
+
200
+ static const char *getName() {
201
+ static const char *name = "Value";
202
+ return(name);
203
+ }
204
+ };
205
+
206
+ class cbOutput;
207
+
208
+ // SFINAE test if the class has a toJS method with cbOutput parameter.
209
+
210
+ template <typename ArgType, typename = decltype(std::declval<ArgType>().toJS(std::declval<cbOutput>()))>
211
+ ValuePolicy detectPolicies(const ArgType &, double);
212
+
213
+ // Policy autodetection part 2
214
+
215
+ template <typename ArgType>
216
+ struct DetectPolicies {
217
+ typedef decltype(detectPolicies(std::declval<ArgType>(), 0.0)) Policy;
218
+
219
+ typedef typename Policy::template Transform<ArgType, ArgType>::Type Type;
220
+
221
+ static const char **getPolicies() {
222
+ return(PolicyLister<PolicyListType<Policy>>::getNameList());
223
+ }
224
+ };
225
+
226
+ template<>
227
+ struct DetectPolicies<void> {
228
+ typedef void Type;
229
+ };
230
+
231
+ // Policy execution
232
+
233
+ template<typename... Policies>
234
+ struct ExecutePolicies;
235
+
236
+ template<>
237
+ struct ExecutePolicies<PolicyListType<>> {
238
+ template<typename ArgType>
239
+ struct Transformed {
240
+ typedef ArgType Type;
241
+ };
242
+ };
243
+
244
+ template<typename Policy, typename... Remaining>
245
+ struct ExecutePolicies<PolicyListType<Policy, Remaining...>> {
246
+ template<typename ArgType>
247
+ struct Transformed {
248
+ typedef typename Policy::template Transform<
249
+ ArgType,
250
+ typename ExecutePolicies<PolicyListType<Remaining...>>::template Transformed<ArgType>::Type
251
+ >::Type Type;
252
+ };
253
+ };
254
+
255
+ } // namespace