On Tuesday 13 August 2002 4:24 pm, Lars Gullik Bjønnes wrote:

> | Connect these boost::functions to the appropriate methods hidden deep
> | within frontends. Eg
> |     showAboutLyX=boost::bind(&ControlAboutLyX::show, this);
> | (I'd like to do this in the Dialogs c-tor, but we'll see...)
>
> and where do you setup the Dialog constructor?

Various options are available to us:

1. In the various frontends' Dialogs.C c-tor as before. Have a publiclly 
acessible
        boost:function0<void> show_aboutlyx; 
that is connected in the c-tor.

2. Lazy construction. Don't use boost::function.

Dialogs.h
========
class DialogBase;

class Dialogs {
        void showAboutLyX()

private:
        /// Each Dialog will have it's own pointer.
        boost::scoped_ptr<DialogBase> showaboutlyx_;
};


Dialogs.C
========

void Dialogs::showAboutLyX()
{
        typedef GUI<ControlAboutlyx, FormAboutlyx, OkCancelPolicy, xformsBC> Dialog;
        if (!showaboutlyx_.get()) {
                showaboutlyx_.reset(new Dialog(lv_, *this));
        }
        static_cast<Dialog *>(showaboutlyx_.get()>->controller().show();
}

3. Lazy construction. Use boost::function privately.

The Dialogs are stored as a vector<boost::shared_ptr<DialogBase> > dialogs_;
We also store boost::function0<void> show_aboutlyx_;

void Dialogs::showAboutLyX()
{
        typedef GUI<ControlAboutlyx, FormAboutlyx, OkCancelPolicy, xformsBC> Dialog;
        if (!showaboutlyx_.connected()) {
                boost::shared_ptr<Dialog> dialog(new Dialog(lv_, *this));
                // not sure about the semantics here.
                show_aboutlyx_ = boost::bind(dialog->controller().show()...);
        }
        show_aboutlyx();
}

Which would you prefer?
Angus


Reply via email to