Best practices for boost:signal
What is the best practice for using boost::signal? Should the signal be a public field? Should an accessor method be used? Should there be some special connection methods for every signal, like the following: private: signal<void()> x; public: void connectX(const signal<void()>::slot_type& slot); void disconnectX(const signal<void()>::slot_type& slot); If you use boost:signal, how do you do it? (Okay, actually connectX should return a connection object and disconnectX should take the it as its parameter, but it's about the general idea) -- Memfis
2006/11/15, Memfis <memfis+news@mbjk.pl>:
What is the best practice for using boost::signal? Should the signal be a public field? Should an accessor method be used? Should there be some special connection methods for every signal, like the following:
private: signal<void()> x; public: void connectX(const signal<void()>::slot_type& slot); void disconnectX(const signal<void()>::slot_type& slot);
If you use boost:signal, how do you do it?
I used public signals in my project (http://vaca.sf.net), but I would like to known what people think about it. Personally, I don't like the idea to have two methods to connect and disconnect slots.
On Wed, 15 Nov 2006, David Capello wrote:
2006/11/15, Memfis <memfis+news@mbjk.pl>:
What is the best practice for using boost::signal? Should the signal be a public field? Should an accessor method be used? Should there be some special connection methods for every signal, like the following:
private: signal<void()> x; public: void connectX(const signal<void()>::slot_type& slot); void disconnectX(const signal<void()>::slot_type& slot);
If you use boost:signal, how do you do it?
I used public signals in my project (http://vaca.sf.net), but I would like to known what people think about it.
Personally, I don't like the idea to have two methods to connect and disconnect slots.
Another practice is to use proxies. This is what they do in gtkmm, albeit with libsigc++ instead of boost::signal, but it's quite similar. -- François Duranleau LIGUM, Université de Montréal
"Memfis" wrote:
What is the best practice for using boost::signal? Should the signal be a public field? Should an accessor method be used?
I hardly know what "best practises" to use. I submitted something recently for comments. It tries to be somewhat thread-safe. See [Boost.Signals] in Multithreaded Environment, submitted on Nov 11. (I don't know how to put a link here, sorry). terry begin 666 [Boost.Signals] in Multithreaded Environment.nws M4&%T:#H@;F5W<RYG;6%N92YO<F<A;F]T+69O<BUM86EL#0I&<F]M.B B5&5R M<GD@1R(@/'1J9V]L=6)I0&YE=&EN<RYN970^#0I.97=S9W)O=7!S.B!G;6%N M92YC;VUP+FQI8BYB;V]S="YU<V5R#0I3=6)J96-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;W-T.CIS:&%R961?<'1R/%0^*' L M(&)O;W-T.CIM96U?9FXH)E0Z.G-U9F9I>"DI.PT*(" @?2 O+R!G970-"B @ M(&)O;W-T.CIS:&%R961?<'1R/%0^(&]P97)A=&]R+3XH*2!C;VYS="![(')E M='5R;B!G970H*3L@?0T*?3L@+R]7<F%P<&5R#0H-"B\O(%!R;W9I9&5S('-I M9VYA;',@=&AR;W5G:" B<V%F92(@=W)A<'!E<BX@*#\I#0IC;&%S<R!4:650 M;VEN="![#0IP=6)L:6,Z#0H@(&-L87-S($5V96YT<R![#0H@(" @375T97@@ M;&]C:SL@("\O(%!R;W9I9&5D(&5L<V5W:&5R92X-"B @("!V;VED('!R969I M>"@I('L@;&]C:RYA8W%U:7)E*"D[('T-"B @("!V;VED('-U9F9I>"@I("![ M(&QO8VLN<F5L96%S92@I.R!]#0H@(" @9G)I96YD(&-L87-S(%=R87!P97(\ M179E;G1S/CL-"B @<'5B;&EC.@T*(" @(&)O;W-T.CIS:6=N86P\=F]I9" H M4VEG;F%L,4%R9W,I/B!S:6=N86PQ.PT*(" @(&)O;W-T.CIS:6=N86P\=F]I M9" H4VEG;F%L,D%R9W,I/B!S:6=N86PR.PT*(" @("\O(&5T8RXN+@T*(" @ M('1E;7!L871E(#QC;&%S<R!)=&5R/@T*(" @('9O:60@9&ES8V]N;F5C="A) M=&5R(&)E9VEN7RP@271E<B!E;F1?*2![#0H@(" @("!S=&0Z.F9O<E]E86-H M*&)E9VEN7RP@96YD7RP-"B @(" @(" @(&)O;W-T.CIM96U?9FXH)F)O;W-T M.CIS:6=N86QS.CIC;VYN96-T:6]N.CID:7-C;VYN96-T*3L-"B @("!]("\O M(&1I<V-O;FYE8W0-"B @?3L@+R\@179E;G1S#0IP<FEV871E.@T*("!%=F5N M=',@7V5V96YT<SL-"G!U8FQI8SH-"B @5W)A<'!E<CQ%=F5N=',^(&5V96YT M<SL-"B @5&EE4&]I;G0H*2 Z(%]E=F5N=',H*2P@979E;G0H7V5V96YT<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YT<R ]('1I95!T+F5V96YT<RYG970H*3L-"B @("!E=F5N=',M/G-I9VYA M;#$H<VEG;F%L,6%R9W,I.PT*(" @(&5V96YT<RT^<VEG;F%L,BAS:6=N86PR M87)G<RD[#0H@(" @+BXN#0H@('T@+R\@<VEG;F%L36%N>0T*?3L@+R\@57-E (<U-I9VYA;',` ` end
participants (4)
-
David Capello
-
François Duranleau
-
Memfis
-
Terry G