Boost logo

Boost Users :

Subject: Re: [Boost-users] signals/slots and boost::functions
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-12-10 15:00:35


AMDG

david.weber_at_[hidden] wrote:
>
> I have a class, where I want callers to be able to register/deregister
> signals/slots. They will pass in a function pointer, and we'll hook
> it up to the signal, and manage the connection object.
>
> Part of the management, is I need to map the function pointer to the
> actual connection object. This is where the trouble comes in. Since
> a boost::function doesn't have an operator <, the simplest way is to
> just map it to an unsigned long long, and store the raw address of the
> underlying function.
>
> So, my connect function:
>
>
> typedef VSSP (*TargetType) ( std::string, EncodingEnum);
> typedef boost::function < VSSP ( std::string, EncodingEnum) >
> CreateTypeFunc;
>
> bool ElementBase::connectCreateTypeSignal(const CreateTypeFunc& slot)
> {
> LOG4CXX_DEBUG(logger_, "connectCreateTypeSignal in");
> bool retValue = false;
>
> unsigned long long slotAddr = (unsigned long long)slot.target<
> TargetType >();
> LOG4CXX_DEBUG(logger_, "*** slotAddr = " + (boost::format("%08X")
> % slotAddr).str());
>
> <snip>
> }
>
>
> My debug printouts, are shoing unexpected behavior. The address that
> I am getting from target is different every time it is called, even
> though I'm calling with the same function (getTypeSlot). I would
> expect this if I was getting the address of the function object,
> because I'm creating one implicitly through the call, but not
> dereferencing via target(), unless I'm misunderstanding what target()
> does.
>

target returns a pointer to the function object. If TargetType is
void(*)() target
will return an object of type void(**)().

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net