diff options
author | Chad Austin <chad@imvu.com> | 2013-03-01 12:52:54 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:24:44 +0300 |
commit | 1a352601847328eb9f60b5c7068b8f18ab28ddc6 (patch) | |
tree | 5001eee961446e3a9ea6aab290630db248a2e6b8 | |
parent | d824fcb7ba3f28987761a80a9645ca7c630eb97b (diff) |
Preliminary support for custom smart pointers.
-rwxr-xr-x | system/include/emscripten/bind.h | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index f6b640d1..e8f21be4 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -284,12 +284,6 @@ namespace emscripten { delete ptr; } - template<typename PointerType> - typename PointerType::element_type* get_pointee(const PointerType& ptr) { - // TODO: replace with general pointer traits implementation - return ptr.get(); - } - template<typename ClassType, typename ReturnType, typename... Args> struct FunctionInvoker { typedef ReturnType (*FunctionPointer)(ClassType& ct, Args...); @@ -540,14 +534,24 @@ namespace emscripten { // specialize if you have a different pointer type template<typename PointerType> - struct get_element_type { - typedef typename PointerType::element_type type; + struct smart_ptr_trait { + typedef typename PointerType::element_type element_type; + static element_type* get(const PointerType& ptr) { + return ptr.get(); + } }; + namespace internal { + template<typename PointerType> + typename smart_ptr_trait<PointerType>::element_type* get_pointee(const PointerType& ptr) { + return smart_ptr_trait<PointerType>::get(ptr); + } + } + template<typename PointerType> void smart_ptr(const char* name) { using namespace internal; - typedef typename get_element_type<PointerType>::type PointeeType; + typedef typename smart_ptr_trait<PointerType>::element_type PointeeType; registerStandardTypes(); _embind_register_smart_ptr( |