On Mon, Apr 26, 2010 at 8:25 AM, Sven Knoblich <[email protected]> wrote:
> Hello all,
> i have a problem by using WTimer::singleShot(..) with boost::bind.
>
> WTimer
> --------
> #ifndef WT_TARGET_JAVA
> template <class T, class V>
> void WTimer::singleShot(int msec, T *receiver, void (V::*method)())
> {
> WTimer *timer = new WTimer();
> timer->setSingleShot(true);
> timer->setInterval(msec);
> timer->setSelfDestruct();
> timer->timeout().connect(receiver, method);
> timer->start();
> }
> #endif // WT_TARGET_JAVA
>
> }
>
>
> The call has to go to a method with two parameters
>
> MyClass
> --------
> void MyClass::call( const string& rstrName, const int nValue);
>
>
> Call
> ====
>
> WTimer::singleShot( 1, this, boost::bind( &MyClass::cal,
> this,
> rstrName,
> nValue));
>
>
> ->now i get the compiler error c2784: could not cast
> boost::_bi::bind_t<R,F,L> to void (__thiscall V::* )(void)!
>
> Any idea how to cast the boost-type to the new signature?
>
> Many thanks in advance,
> Sven
Not at computer, but looking at the dosygen on the website, the signature is:
"""
template<class T, class V>
void Wt::WTimer::singleShot ( int msec,
T * receiver,
void(V::*)() method
) [inline, static]
"""
Now this would dictate that you need to use something like:
"""
WTimer::singleShot( 1, this, boost::bind( &MyClass::cal,
boost::_1,
rstrName,
nValue));
"""
However, it seems to use a raw method pointer instead of accepting
generic function pointers (honestly, this is *BAD* design and needs to
be fixed), so it will probably not work. The Wt code needs to be
changed to support another overload like:
"""
template<class F>
void Wt::WTimer::singleShot ( int msec,
F func
) [inline, static]
"""
In which case, that overload would support your thing perfectly, like:
"""
WTimer::singleShot( 1, boost::bind( &MyClass::cal,
this,
rstrName,
nValue));
"""
I have no clue why they use their current style, it vastly limits the
usefulness of that, heck, with the new style I propose, then something
like this would be possible:
"""
#include <boost/spirit/include/phoenix.hpp>
using namespace boost::phoenix;
// elswhere:
WTimer::singleShot( 1, if_(ref(i)%5)
[displayMessage(),ref(i)=0]
.else
[ref(i)++]);
"""
You can however work around the issue by just making your own
singleshot global/static function:
"""
template <F>
void mySingleShot(int msec, F func)
{
WTimer *timer = new WTimer();
timer->setSingleShot(true);
timer->setInterval(msec);
timer->setSelfDestruct();
timer->timeout().connect(func); // I am pretty sure that connect
supports that overload fine
timer->start();
}
"""
Then use it like:
"""
mySingleShot( 1, boost::bind( &MyClass::cal,
this,
rstrName,
nValue));
"""
------------------------------------------------------------------------------
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest