FlexSignal updated too (Re: sslot version 0.2)
Bill Baxter
dnewsgroup at billbaxter.com
Sat Nov 18 07:32:00 PST 2006
Lutger wrote:
> Bill Baxter wrote:
>> In the mean time, I've also updated FlexSignal to support connecting a
>> function like:
>> bool foo_slot(char[] s) { ... }
>>
>> to the signal:
>> FlexSignal!(int, char[], float);
>>
>> I.e. the foo_slot can be connected to only get the char[] argument if
>> that's all it's interested in. Unfortunately the syntax for this is a
>> little cumbersome right now due to bug #540:
>>
>> thesignal.fconnect!(typeof(&foo_slot),1)(&foo_slot);
>>
>> When/if #540 is fixed this can become:
>>
>> thesignal.fconnect!(1)(&foo_slot);
>>
>> The '1' indicates foo_slot wants to skip the 1st argument emitted by
>> the signal.
>
> It's sort of a reverse bind?
Yeh, it is sort of bind-like.
> Would it be possible to write a seperate
> adapter so it could be used with std.signals and allow for garbage
> collection / deletion before disconnection?
It does actually use a separate adaptor. See the SlotAdaptor template
in the code.
But right now the SlotAdaptor template only returns the pointer to the
delegate it makes, not the class itself. But I guess you could get that
from the .ptr prop.
> Boost::signals works nicely with boost bind like this but it's a little
> less flexible iirc.
>
> Something like this perhaps:
> thesignal.connect(adapt(thesignal, &foo_slot, 1));
The problem with that is that it creates some adapted thingy but unless
you keep a pointer to it yourself you won't have a way to disconnect it.
> and / or more concise:
> connect(thesignal, &foo_slot, 1);
That doesn't work because the '1' has to be a compile time constant in
order to muck with the signal's argument tuple. I don't think there's a
way to convince D that it is constant without making it a template
parameter. At least I couldn't figure one out.
> btw. there is a way to get the type of the .ptr property of a delegate
> but I was reluctant to use it as it seemed a little too hackish:
> http://www.digitalmars.com/d/archives/digitalmars/D/learn/delegate_type_info_5001.html
Ah yes. I remember seeing that one go by. Hopefully some official
support for that will be added, or else the distinction between Object
and non-object delegates will be removed.
--bb
More information about the Digitalmars-d-announce
mailing list