On Friday 30 June 2006 19:58, Paul Pogonyshev wrote: > I would like to propose conditions in libsigc. A condition is basically > a boolean vairable plus signal which is emitted each time the variable > state is changed (from true to false or vice versa.)
I like the idea (more below) but calling it 'condition' is horrible IMHO. > They are useful in e.g. GUI design because you can specify a boolean > expression, e.g. sensitivity or visibility, only once and not track when > its state changes, which can be difficult at times. So, in this case you are tracking the state of a flag, which is the condition(!) to fulfil for something to be visible or sensitive. This is an example of the use, but that is not a reason to call the whole thing a condition. > In other words, the condition itself and its state tracking are no > longer separated and chances of programming error are significantly > smaller. Okay, leaving aside the discussion of the proper naming[1] I think that it is a valuable thing, though I agree with other in that I'm not sure it should be part of libsigC++ proper. Anyhow, I'd do something like this: template<typename V> struct observed { // ctor,dtor,cctor,op=... void assign( V const& other) { do_assign(other); } V const& get() const { return m_value; } signal<void> sig_changed; private: void do_assign( V const& v) { if(v!=m_value) { m_value = v; sig_changed(); } } V m_value; }; This would extend the principle to other datatypes than bool as well. I'd even think about a possible validation signal, so that a new value can be validated before it is finally assigned (using an exception to reject values). Another question would be if it should supply an automatic conversion operator to 'V const&' and an assignment operator from 'V const&'. It depends on how much you want to hide the additional functionality/complexity or simplify conversion. just my 2cc Uli [1] I know some programminglanguages (and some C++ dialects, Borland? C#?) implement the possibility to create such values who's changes can be tracked. It might be a good idea to not invent a different name, maybe someone else has info on that. **************************************************** Visit our website at <http://www.domino-printing.com/> **************************************************** This Email and any files transmitted with it are intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any reading, redistribution, disclosure or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient please contact the sender immediately and delete the material from your computer. E-mail may be susceptible to data corruption, interception, viruses and unauthorised amendment and Domino UK Limited does not accept liability for any such corruption, interception, viruses or amendment or their consequences. **************************************************** _______________________________________________ libsigc-list mailing list libsigc-list@gnome.org http://mail.gnome.org/mailman/listinfo/libsigc-list