Boost logo

Boost Users :

Subject: [Boost-users] signals/slots and boost::functions
From: david.weber_at_[hidden]
Date: 2008-12-10 14:45:47


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>
}

One of my checks, is to ensure that you don't connect the same thing
multiple times. So, I have a test case that does this, and expects it
to bomb out:

VSSP getTypeSlot(std::string fqn, EncodingEnum encoding)
{
        <snip>
        return VSSP;
}

BOOST_FIXTURE_TEST_CASE(ElementBase_connectCreateType,
ElementBaseTestFixture)
{
    BOOST_CHECK(true == ebp->connectCreateTypeSignal(getTypeSlot));
    BOOST_CHECK(false == ebp->connectCreateTypeSignal(getTypeSlot));
}

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.

I just need the stupid address of the function passed in. Help!!

TIA

--dw



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