On Thursday 01 August 2002 12:53 pm, Lars Gullik Bjønnes wrote:

It appears you aren't against the basic idea. Good.

> | I'd like, therefore, to change the LyXView store
> | public:
> |     /// return the current buffer view
> |     BufferView * view() const { return bufferview_,get(); }
>
> I'd rather change this one to
>
> a. return a shared_ptr
> b. return a weak_ptr

Then I think it should be
        boost::shared_ptr<BufferView> const & view() const { return bufferview_; }

No more expensive than before, but may lead to more extensive changes to the 
rest of the code base than I'd anticipated.

> | and to make it accessible through BufferView:
> | boost::weak_ptr<BufferView> const BufferView::cachablePtr() const
> | {
> |     return pimpl_->owner_->cachablePtr();
> | }
>
> and you really need this?

Yes. Only now it would be

boost::shared_ptr<BufferView> const & BufferView::cachablePtr() const
{
        return pimpl_->owner_->view();
}

Think of all those times when a BufferView * (or even a BufferView &) is 
passed to an inset. It makes no sense at all to pass a shared_ptr in these 
cases, but if the inset wants to cache this BufferView * then it can do so as

        struct Inset::Cache {
                boost::weak_ptr<BufferView> view_;
        }
        Inset::Cache * cache_;
        cache_->view_ = bv->cachablePtr();

This cache stuff has been bugging me for ages. I'd really like to bury it 
properly.
Angus

Reply via email to