|
Boost : |
Subject: Re: [boost] Interest in non-intrusive signal/slot lib?
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2015-05-18 13:39:44
On Mon, May 18, 2015 at 8:42 AM, Edward Diener <eldiener_at_[hidden]>
wrote:
> On 5/18/2015 12:35 AM, Emil Dotchevski wrote:
>
>> On Sun, May 17, 2015 at 7:40 PM, Gavin Lambert <gavinl_at_[hidden]>
>> wrote:
>>
>>> On 17/05/2015 09:35, Edward Diener wrote:
>>>
>>>> typedef void (*button_down)(int x, int y);
>>>> typedef void (*button_up)(int x, int y);
>>>>
>>>> void handle_button_down( int x, int y );
>>>> void handle_button_up( int x, int y );
>>>>
>>>> auto c1=connect<button_down>(e,&handle_button_down);
>>>> auto c2=connect<button_up>(e,&handle_button_up);
>>>>
>>>> Is there some reason why the above would not work ? The fact that
>>>> button_down and button_up are the same types above but different types
>>>> the way synapse is currently designed seems irrelevant. I am enquiring
>>>> whether there is an internal reason for that.
>>>>
>>>
>>> I had the same confusion at first. The issue is that there is no "signal
>>> container" instance within the emitter itself, which is how you'd
>>> normally
>>> distinguish between signals with the same signature.
>>>
>>> This library stores all signals centrally in the management object,
>>> indexed by type, rather than having members of the emitter object (that's
>>> the "non-intrusive" part). As a result the types need to be unique as
>>> they're the only differentiating feature.
>>>
>>
>> I now understand where the confusion comes from, too. In Boost Signals 2,
>> a
>> signal (emitter) is an actual object, and it is the address of that object
>> that identifies different signals independently from their signature.
>> Indeed, in Synapse signals are *not* objects, they're types.
>>
>
> That's not where the confusion existed for me. Gavin Lambert explained why
> each signal must be a different type. I realized that a signal is a type,
> but not why the same signal could not be used for more than one event (
> button down, button up etc. ).
>
The signal *is* the event though. So I guess I still don't understand. If
you have two events, "button up" and "button down", then you need two
Synapse signals or else you wouldn't be able to tell them apart.
BTW you could provide a fairly simple variadic macro for creating signals
> which might be a little easier on the end-user:
>
> #define SYNAPSE_SIGNAL(name,...) typedef struct name ## _
> (*name)(__VA_ARGS__);
>
Maybe I'll add something like this, since I've had a couple of instances
where through copy&paste I ended up with:
typedef struct foo_(*foo)();
typedef struct foo_(*bar)();
BTW I don't think I'd need vaargs even.
> In your documentation I think you should explain that when you emit a
> signal you pass a pointer to the object doing the emitting. Also when you
> connect you are passing a shared_ptr ( or weak_ptr ) to the object doing
> the emitting. I think I have this correct.
>
You mean more than I have already in
http://www.revergestudios.com/boost-synapse/connect.html and
http://www.revergestudios.com/boost-synapse/emit.html?
-- Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk