Restructure and generalize tuple accessors.

This commit is contained in:
Chad Austin 2013-04-01 17:42:50 -07:00 коммит произвёл Jukka Jylänki
Родитель 8b1b35d8e3
Коммит e30dd3017a
2 изменённых файлов: 31 добавлений и 57 удалений

Просмотреть файл

@ -419,30 +419,34 @@ function __embind_register_tuple_element(
function __embind_register_tuple_element_accessor( function __embind_register_tuple_element_accessor(
rawTupleType, rawTupleType,
rawElementType, getterReturnType,
rawStaticGetter, getter,
getterContext, getterContext,
rawStaticSetter, setterArgumentType,
setter,
setterContext setterContext
) { ) {
var tupleType = requireRegisteredType(rawTupleType, 'tuple'); var tupleType = requireRegisteredType(rawTupleType, 'tuple');
rawStaticGetter = FUNCTION_TABLE[rawStaticGetter]; getter = FUNCTION_TABLE[getter];
rawStaticSetter = FUNCTION_TABLE[rawStaticSetter]; setter = FUNCTION_TABLE[setter];
whenDependentTypesAreResolved([], [rawElementType], function(elementType) { // TODO: test incomplete registration of value tuples
elementType = elementType[0]; whenDependentTypesAreResolved([], [getterReturnType, setterArgumentType], function(types) {
var getterReturnType = types[0];
var setterArgumentType = types[1];
tupleType.elements.push({ tupleType.elements.push({
read: function(ptr) { read: function(ptr) {
return elementType.fromWireType(rawStaticGetter( return getterReturnType.fromWireType(
getterContext, getter(
ptr)); getterContext,
ptr));
}, },
write: function(ptr, o) { write: function(ptr, o) {
var destructors = []; var destructors = [];
rawStaticSetter( setter(
setterContext, setterContext,
ptr, ptr,
elementType.toWireType(destructors, o)); setterArgumentType.toWireType(destructors, o));
runDestructors(destructors); runDestructors(destructors);
} }
}); });

Просмотреть файл

@ -77,9 +77,10 @@ namespace emscripten {
void _embind_register_tuple_element_accessor( void _embind_register_tuple_element_accessor(
TYPEID tupleType, TYPEID tupleType,
TYPEID elementType, TYPEID getterReturnType,
GenericFunction staticGetter, GenericFunction staticGetter,
void* getterContext, void* getterContext,
TYPEID setterArgumentType,
GenericFunction staticSetter, GenericFunction staticSetter,
void* setterContext); void* setterContext);
@ -419,54 +420,23 @@ namespace emscripten {
return *this; return *this;
} }
template<typename ElementType> template<typename GetterReturnType, typename SetterArgumentType>
value_tuple& element(ElementType (*getter)(const ClassType&), void (*setter)(ClassType&, ElementType)) { value_tuple& element(
GetterReturnType (*getter)(const ClassType&),
void (*setter)(ClassType&, SetterArgumentType)
) {
using namespace internal; using namespace internal;
_embind_register_tuple_element_accessor( _embind_register_tuple_element_accessor(
TypeID<ClassType>::get(), TypeID<ClassType>::get(),
TypeID<ElementType>::get(), TypeID<GetterReturnType>::get(),
reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, ElementType>::template propertyGet<ElementType(*)(const ClassType&)>), reinterpret_cast<GenericFunction>(
&MemberAccess<ClassType, GetterReturnType>
::template propertyGet<GetterReturnType(*)(const ClassType&)>),
getContext(getter), getContext(getter),
reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, ElementType>::template propertySet<void(*)(ClassType&, ElementType)>), TypeID<SetterArgumentType>::get(),
getContext(setter)); reinterpret_cast<GenericFunction>(
return *this; &MemberAccess<ClassType, SetterArgumentType>
} ::template propertySet<void(*)(ClassType&, SetterArgumentType)>),
template<typename ElementType>
value_tuple& element(ElementType (*getter)(const ClassType&), void (*setter)(ClassType&, const ElementType&)) {
using namespace internal;
_embind_register_tuple_element_accessor(
TypeID<ClassType>::get(),
TypeID<ElementType>::get(),
reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, ElementType>::template propertyGet<ElementType(*)(const ClassType&)>),
getContext(getter),
reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, ElementType>::template propertySet<void(*)(ClassType&, ElementType)>),
getContext(setter));
return *this;
}
template<typename ElementType>
value_tuple& element(ElementType (*getter)(const ClassType&), void (*setter)(ClassType&, const ElementType&&)) {
using namespace internal;
_embind_register_tuple_element_accessor(
TypeID<ClassType>::get(),
TypeID<ElementType>::get(),
reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, ElementType>::template propertyGet<ElementType(*)(const ClassType&)>),
getContext(getter),
reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, ElementType>::template propertySet<void(*)(ClassType&, ElementType)>),
getContext(setter));
return *this;
}
template<typename ElementType>
value_tuple& element(ElementType (*getter)(const ClassType&), void (*setter)(ClassType&, ElementType&)) {
using namespace internal;
_embind_register_tuple_element_accessor(
TypeID<ClassType>::get(),
TypeID<ElementType>::get(),
reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, ElementType>::template propertyGet<ElementType(*)(const ClassType&)>),
getContext(getter),
reinterpret_cast<GenericFunction>(&MemberAccess<ClassType, ElementType>::template propertySet<void(*)(ClassType&, ElementType)>),
getContext(setter)); getContext(setter));
return *this; return *this;
} }