224
227
struct allow_raw_pointer : public allow_raw_pointers {
230
////////////////////////////////////////////////////////////////////////////////
231
// select_overload and select_const
232
////////////////////////////////////////////////////////////////////////////////
227
234
template<typename Signature>
228
235
typename std::add_pointer<Signature>::type select_overload(typename std::add_pointer<Signature>::type fn) {
251
template<typename ClassType, typename ReturnType, typename... Args>
252
auto select_const(ReturnType (ClassType::*method)(Args...) const) -> decltype(method) {
256
////////////////////////////////////////////////////////////////////////////////
258
////////////////////////////////////////////////////////////////////////////////
244
260
namespace internal {
245
261
template<typename ReturnType, typename... Args>
402
418
// TODO: This could do a reinterpret-cast if sizeof(T) === sizeof(void*)
403
419
template<typename T>
404
inline void* getContext(const T& t) {
420
inline T* getContext(const T& t) {
405
421
// not a leak because this is called once per binding
406
void* p = malloc(sizeof(T));
408
memcpy(p, &t, sizeof(T));
422
T* p = reinterpret_cast<T*>(malloc(sizeof(T)));
737
752
template<typename ReturnType, typename... Args>
738
753
ReturnType call(const char* name, Args&&... args) const {
739
return Caller<ReturnType, Args...>::call(wrapped, name, std::forward<Args>(args)...);
754
return wrapped.call<ReturnType>(name, std::forward<Args>(args)...);
742
757
template<typename ReturnType, typename... Args, typename Default>
743
758
ReturnType optional_call(const char* name, Default def, Args&&... args) const {
744
if (has_function(name)) {
745
return Caller<ReturnType, Args...>::call(wrapped, name, std::forward<Args>(args)...);
759
if (wrapped.has_function(name)) {
760
return call<ReturnType>(name, std::forward<Args>(args)...);
752
bool has_function(const char* name) const {
753
return wrapped.has_function(name);
756
// this class only exists because you can't partially specialize function templates
757
template<typename ReturnType, typename... Args>
759
static ReturnType call(const val& v, const char* name, Args&&... args) {
760
return v.call(name, std::forward<Args>(args)...).template as<ReturnType>();
764
template<typename... Args>
765
struct Caller<void, Args...> {
766
static void call(const val& v, const char* name, Args&&... args) {
767
v.call_void(name, std::forward<Args>(args)...);
917
template<typename... Args, typename... Policies>
918
class_& constructor(ClassType* (*factory)(Args...), Policies...) {
897
template<typename... Args, typename ReturnType, typename... Policies>
898
class_& constructor(ReturnType (*factory)(Args...), Policies...) {
919
899
using namespace internal;
921
typename WithPolicies<Policies...>::template ArgTypeList<AllowedRawPointer<ClassType>, Args...> args;
901
// TODO: allows all raw pointers... policies need a rethink
902
typename WithPolicies<allow_raw_pointers, Policies...>::template ArgTypeList<ReturnType, Args...> args;
922
903
_embind_register_class_constructor(
923
904
TypeID<ClassType>::get(),
926
reinterpret_cast<GenericFunction>(&Invoker<ClassType*, Args...>::invoke),
907
reinterpret_cast<GenericFunction>(&Invoker<ReturnType, Args...>::invoke),
927
908
reinterpret_cast<GenericFunction>(factory));
1220
1201
TypeID<const ConstantType&>::get(),
1221
1202
asGenericValue(BindingType<const ConstantType&>::toWireType(v)));
1224
namespace internal {
1225
template<typename T>
1229
: initialized(false)
1238
optional(const optional& rhs)
1239
: initialized(false)
1245
assert(initialized);
1249
const T& operator*() const {
1250
assert(initialized);
1254
explicit operator bool() const {
1258
optional& operator=(const T& v) {
1267
optional& operator=(const optional& o) {
1271
if (o.initialized) {
1274
initialized = o.initialized;
1280
return reinterpret_cast<T*>(&data);
1283
T const* get() const {
1284
return reinterpret_cast<T const*>(&data);
1288
typename std::aligned_storage<sizeof(T)>::type data;
1293
namespace emscripten {
1294
namespace internal {
1295
class BindingsDefinition {
1297
template<typename Function>
1298
BindingsDefinition(Function fn) {
1305
1206
#define EMSCRIPTEN_BINDINGS(name) \
1306
static struct BindingInitializer_##name { \
1307
BindingInitializer_##name(); \
1308
} BindingInitializer_##name##_instance; \
1309
BindingInitializer_##name::BindingInitializer_##name()
1207
static struct EmscriptenBindingInitializer_##name { \
1208
EmscriptenBindingInitializer_##name(); \
1209
} EmscriptenBindingInitializer_##name##_instance; \
1210
EmscriptenBindingInitializer_##name::EmscriptenBindingInitializer_##name()