Boost logo

Boost Users :

From: Robert Dailey (rcdailey_at_[hidden])
Date: 2008-02-06 15:40:02


Hmm, I think I found the issue. My signal object is const for some reason.
I'm doing a lot of tricks to map enums to signal objects, I'll post all the
code at the bottom of this message. My fusion::vector either must be
containing the signal objects as const, or fusion::at_c must be returning
const. I'm not really sure.

namespace detail
{
    template< InputSubscription t_sub >
    struct sub
    {
        const static InputSubscription value = t_sub;
    };

    using boost::mpl::map;
    using boost::mpl::pair;

    typedef map<
        pair< sub<INPUTSUB_KEYBOARD>, boost::signal<void (unsigned int,
bool)> >,
        pair< sub<INPUTSUB_MOUSE_MOTION>, boost::signal<void (int, int)> >,
        pair< sub<INPUTSUB_MOUSE_BUTTON>, boost::signal<void (int, int,
unsigned int, bool)> >,
        pair< sub<INPUTSUB_MOUSE_WHEEL>, boost::signal<void (int)> >
> SubMap;
}

/// Obtains a boost::signal from a matching InputSubscription identifier.
template< InputSubscription t_sub >
struct GetSignal
{
    typedef typename boost::mpl::at<detail::SubMap, detail::sub<t_sub>
>::type signal;
};

struct SignalBank
{
    boost::fusion::vector<
        GetSignal<INPUTSUB_KEYBOARD>::signal,
        GetSignal<INPUTSUB_MOUSE_MOTION>::signal,
        GetSignal<INPUTSUB_MOUSE_BUTTON>::signal,
        GetSignal<INPUTSUB_MOUSE_WHEEL>::signal
> signals;
};

template< InputSubscription t_sub >
static void subscribe( SignalBank const& bank, typename
GetSignal<t_sub>::signal::slot_type const& slot )
{
    using boost::fusion::at_c;
    const_cast<GetSignal<t_sub>::signal>( at_c<t_sub>( bank.signals )
).connect( slot );
}

void mouseCB( int, int )
{
}

void footest()
{
    SignalBank bank;

    //boost::fusion::at_c<1>( bank.signals )( 3, 4 );

    subscribe<INPUTSUB_MOUSE_MOTION>( bank, &mouseCB );
};



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