Re: Syntax for Pointer-to-member-VARIABLE?
On Mar 16, 8:40 pm, Stephan Beal <sgb...@googlemail.com> wrote:
On Mar 16, 8:31 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
b) Can such a pointer be used as a template parameter argument, like =
a
function pointer can?
Mmm... I am not sure. Probably yes. I think I've never needed =
that.
i had never needed it until now, either. :) i'll give it a try and see
if it does the trick.
(i'm using member function pointers to map C++ functions to their
JavaScript-side counterparts using the Google v8 JS engine. Now i'd
like to try binding access to data members to JS.)
The answer to (b) appears to be yes! Woohoo! That just saved me tons
of work...
template <typename WrappedType, typename PropertyType, PropertyType
WrappedType::*MemVar>
Handle<Value> GetMemVar(Local<String> property,
const AccessorInfo &info)
{
WrappedType * self
= ::v8::juice::WeakJSClassCreator<WrappedType>::GetSelf( info.This
() );
if( ! self ) return v8::ThrowException( v8::String::New( "Getter
function could not access native object!" ) );
return convert::CastToJS( (self->*MemVar) );
}
template <typename WrappedType, typename PropertyType, PropertyType
WrappedType::*MemVar>
void SetMemVar(Local<String> property, Local<Value> value,
const AccessorInfo& info)
{
WrappedType * self
= ::v8::juice::WeakJSClassCreator<WrappedType>::GetSelf( info.This
() );
if( self )
{
self->*MemVar = convert::CastFromJS<PropertyType>( value );
}
else
{
CERR << "Setter function could not access native object!\n";
}
}