From ececfcc02e2020c2c965cb0d6edc0fc321def581 Mon Sep 17 00:00:00 2001 From: Chad Austin Date: Fri, 1 Mar 2013 17:31:44 -0800 Subject: Add support for marshalling custom smart pointer types in and out of parameters. --- system/include/emscripten/bind.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'system/include') diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 9120a095..ad11395b 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -274,14 +274,6 @@ namespace emscripten { ); } - template - typename std::shared_ptr* raw_smart_pointer_constructor( - PointerType *ptr, - std::shared_ptr* basePtr - ) { - return new std::shared_ptr(*basePtr, ptr); - } - template void raw_destructor(ClassType* ptr) { delete ptr; @@ -539,12 +531,25 @@ namespace emscripten { template struct smart_ptr_trait { typedef typename PointerType::element_type element_type; + static element_type* get(const PointerType& ptr) { return ptr.get(); } + + static PointerType share(const PointerType& r, element_type* ptr) { + return PointerType(r, ptr); + } }; namespace internal { + template + SmartPointerType* raw_smart_pointer_constructor( + typename smart_ptr_trait::element_type* ptr, + SmartPointerType* basePtr + ) { + return new SmartPointerType(smart_ptr_trait::share(*basePtr, ptr)); + } + template typename smart_ptr_trait::element_type* get_pointee(const PointerType& ptr) { return smart_ptr_trait::get(ptr); @@ -561,7 +566,7 @@ namespace emscripten { TypeID::get(), TypeID::get(), name, - reinterpret_cast(&raw_smart_pointer_constructor), + reinterpret_cast(&raw_smart_pointer_constructor), reinterpret_cast(&raw_destructor), reinterpret_cast(&get_pointee)); }; -- cgit v1.2.3-70-g09d2