Dirk Gerrits wrote:
> > So, the corrected example would be:
> >
> >     class widget
> >     {
> >     public:
> >         // ...
> >         typedef boost::function bool_arg_t;
> >
> >         self_t&     is_enabled(bool_arg_t a_enabled); // note the 
> > signature!
> >         bool        is_enabled() const;
> >     };
> >
> >     int main()
> >     {
> >         widget w;
> >         w.is_enabled(true); // ordinary syntax/semantics
> >         assert(w.is_enabled())
> >
> >         widget w2;
> >         w.is_enabled(boost::bind(&widget::is_enabled, 
> &w2)); // here!
> >         w2.is_enabled(false);
> >         assert(!w.is_enabled()) // !
> >     }
> >
> > I hope the name change makes the semantics of the above clearer.
> 
> I still don't get it. Have I used to few widget libraries? ;)

OK, we are drifting from the actual topic here, but I really don't like the
fact that I can't express myself clearly tonight :). So, here we go:

    class widget_model
    {
     public:
        // ...
        typedef boost::function<bool ()> bool_arg_t;
        
        self_t&     is_enabled(bool_arg_t a_enabled)
        {
            is_enabled_ = a_enabled;
            return *this;
        }
        
        bool        is_enabled() const
        {
            return is_enabled_();
        }
        
     private:
        bool_arg_t  is_enabled_;
    };


    class win32_widget_impl
    {
     public:
        win32_widget_impl( /* ... */)
        {
            // setup this->on_idle() to be called, well, on idle
        }
     
        void on_idle()
        {
            // sync itself with the model
            ::EnableWindow(hwnd_, model_->is_enabled());
        }
        
     private:
        HWND hwnd_;
        ref_ptr<widget_model,!0> model_;
    };

Since the model is passive here, everything works as per my first example
(given 'widget' -> 'widget_model' substitution).

Aleksey
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to