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(
rawTupleType,
rawElementType,
rawStaticGetter,
getterReturnType,
getter,
getterContext,
rawStaticSetter,
setterArgumentType,
setter,
setterContext
) {
var tupleType = requireRegisteredType(rawTupleType, 'tuple');
rawStaticGetter = FUNCTION_TABLE[rawStaticGetter];
rawStaticSetter = FUNCTION_TABLE[rawStaticSetter];
getter = FUNCTION_TABLE[getter];
setter = FUNCTION_TABLE[setter];
whenDependentTypesAreResolved([], [rawElementType], function(elementType) {
elementType = elementType[0];
// TODO: test incomplete registration of value tuples
whenDependentTypesAreResolved([], [getterReturnType, setterArgumentType], function(types) {
var getterReturnType = types[0];
var setterArgumentType = types[1];
tupleType.elements.push({
read: function(ptr) {
return elementType.fromWireType(rawStaticGetter(
getterContext,
ptr));
return getterReturnType.fromWireType(
getter(
getterContext,
ptr));
},
write: function(ptr, o) {
var destructors = [];
rawStaticSetter(
setter(
setterContext,
ptr,
elementType.toWireType(destructors, o));
setterArgumentType.toWireType(destructors, o));
runDestructors(destructors);
}
});

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

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