Hello Karsten,

Karsten Schwenk wrote:
> I'd like to implement a callback that takes two references to 
> std::string and returns a bool via a Functor.
> But I can't find a function that wraps a matching member function call 
> (if I understand the naming scheme correctly, this should be something 
> like 'osgTypedMethodFunctor2ObjRef').
> 
> Am I missing something or do I have to use the pointer variant given below?
> 
> // what I want
> TypedFunctor2Base<
>      bool, RefCallArg< std::string const >, ArgsCollector< std::string& >
>  > callbackWithRef;
> 
> // what I can get to work
> TypedFunctor2Base<
>      bool, PtrCallArg< std::string const >, ArgsCollector< std::string& >
>  > callbackWithPtr;
> 
> 
> // works with CallbackWithPtr
> bool takesPtr( std::string const* arg1, std::string& arg2 )
> { return true; }
> 
> // works with CallbackWithRef
> bool takesRef( std::string const& arg1, std::string& arg2 )
> { return true; }
> 
> struct S
> {
>    // works with CallbackWithPtr
>    bool takesPtr( std::string const* arg1, std::string& arg2 )
>    {return true;}
> 
>    // works not with CallbackWithRef?
>    bool takesRef( std::string const& arg1, std::string& arg2 )
>    {return true;}
> } s;
> 
> // this works
> callbackWithPtr = osgTypedMethodFunctor2ObjPtr<
>      bool, S, std::string const, std::string&
>  >( &s, &S::takesPtr );
> 
> // can't find this function...
> callbackWithRef = osgTypedMethodFunctor2ObjRef<
>      bool, S, std::string const, std::string&
>  >( &s, &S::takesRef );

I've always had a bit of a hard time understanding the functors, so take 
the following with a grain of salt. The first argument to a functor is 
somewhat special, because the functor may wrap a member function in 
which case the first argument is the object to use as "this" for the 
member function call. Of course, if you wrap a free function the first 
argument is just like any other.
I also believe that when wrapping member functions you are limited to 
those with a single argument, since that already requires both argument 
slots (one for the object to call the function on, one for the real 
argument).
If you are using this in your own code I'd highly recommend using 
boost::function and boost:bind, they let you do the same thing (and 
more), with much easier syntax and without the limitations of OpenSG's 
functors.

        regards,
                Carsten

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to