diff options
author | Chad Austin <chad@imvu.com> | 2013-02-25 18:29:41 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:24:09 +0300 |
commit | 07cd277b4df9308db695d8a96ab570b4205b9622 (patch) | |
tree | 443734b86214c8c6101cd1b542ce4490523202ff /system | |
parent | 176000557d9d25d6eb14511413e23321ea94e0aa (diff) |
Use standard method machinery for array access.
Diffstat (limited to 'system')
-rwxr-xr-x | system/include/emscripten/bind.h | 72 |
1 files changed, 19 insertions, 53 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index c83512c7..d99dd763 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -141,18 +141,6 @@ namespace emscripten { GenericFunction invoker, GenericFunction method); - void _embind_register_class_operator_array_get( - TYPEID classType, - TYPEID elementType, - TYPEID indexType, - GenericFunction invoker); - - void _embind_register_class_operator_array_set( - TYPEID classType, - TYPEID elementType, - TYPEID indexType, - GenericFunction invoker); - void _embind_register_enum( TYPEID enumType, const char* name); @@ -325,29 +313,6 @@ namespace emscripten { } }; - template<typename ClassType, typename ElementType, typename IndexType> - struct ArrayAccessGetInvoker { - static typename internal::BindingType<ElementType>::WireType invoke( - ClassType* ptr, - typename internal::BindingType<IndexType>::WireType index - ) { - return internal::BindingType<ElementType>::toWireType( - (*ptr)[internal::BindingType<IndexType>::fromWireType(index)] - ); - } - }; - - template<typename ClassType, typename ElementType, typename IndexType> - struct ArrayAccessSetInvoker { - static void invoke( - ClassType* ptr, - typename internal::BindingType<IndexType>::WireType index, - typename internal::BindingType<ElementType>::WireType item - ) { - (*ptr)[internal::BindingType<IndexType>::fromWireType(index)] = internal::BindingType<ElementType>::fromWireType(item); - } - }; - template<typename ClassType, typename ReturnType, typename... Args> struct FunctionInvoker { typedef ReturnType (FunctionPointer)(ClassType& ct, Args...); @@ -357,7 +322,7 @@ namespace emscripten { typename internal::BindingType<Args>::WireType... args ) { return internal::BindingType<ReturnType>::toWireType( - (*function)(*ptr, internal::BindingType<Args>::toWireType(args)...) + (*function)(*ptr, internal::BindingType<Args>::fromWireType(args)...) ); } }; @@ -370,7 +335,7 @@ namespace emscripten { FunctionPointer** function, typename internal::BindingType<Args>::WireType... args ) { - (*function)(*ptr, internal::BindingType<Args>::toWireType(args)...); + (*function)(*ptr, internal::BindingType<Args>::fromWireType(args)...); } }; @@ -472,6 +437,17 @@ namespace emscripten { setter(ptr, FieldBinding::fromWireType(value)); } }; + + template<typename ClassType, typename ElementType, typename IndexType> + struct ArrayAccess { + static ElementType get(ClassType& ptr, IndexType index) { + return ptr[index]; + } + + static void set(ClassType& ptr, IndexType index, const ElementType& value) { + ptr[index] = value; + } + }; } //////////////////////////////////////////////////////////////////////////////// @@ -796,26 +772,16 @@ namespace emscripten { template<typename ElementType, typename IndexType> class_& arrayoperatorget() { - using namespace internal; - - _embind_register_class_operator_array_get( - TypeID<ClassType>::get(), - TypeID<ElementType>::get(), - TypeID<IndexType>::get(), - reinterpret_cast<internal::GenericFunction>(&internal::ArrayAccessGetInvoker<ClassType, ElementType, IndexType>::invoke)); - return *this; + return method( + "array_get", + internal::ArrayAccess<ClassType, ElementType, IndexType>::get); } template<typename ElementType, typename IndexType> class_& arrayoperatorset() { - using namespace internal; - - _embind_register_class_operator_array_set( - TypeID<ClassType>::get(), - TypeID<ElementType>::get(), - TypeID<IndexType>::get(), - reinterpret_cast<internal::GenericFunction>(&internal::ArrayAccessSetInvoker<ClassType, ElementType, IndexType>::invoke)); - return *this; + return method( + "array_set", + internal::ArrayAccess<ClassType, ElementType, IndexType>::set); } }; |