Angus Leeming wrote: > Andre Poenitz wrote: > >> What is that? > > It is a safe way of holding a pointer whose memory is allocated elsewhere: > >> [Especially: Why is it used in FormulaBase, Angus?] > > class LyXView { > /** return the current buffer view > Returned as a shared_ptr so that anything wanting to cache the > buffer view can do so safely using a boost::weak_ptr. > */ > boost::shared_ptr<BufferView> const & view() const; > protected: > /// view of a buffer. Eventually there will be several. > boost::shared_ptr<BufferView> bufferview_; > }; > > If formulabase stores its cached BufferView in a boost::weak_ptr, then > destruction of LyXView::bufferview_ will cause the FormulaBase's > boost::weak_ptr<BufferView> view_ to return 0 in a call > BufferView * cachedbv = view_.get(); > if (cachedbv == 0) > // do nothing. the parent pointer has been destroyed.
Perhaps you need an addendum: WHY? The previewed images are drawn 2 seconds after the call to Inset::draw, but only if the inset is still visible in the BufferView. Ie, we need to cache the BufferView, but have to be sure that we don't do something illegal if it is destroyed in the intervening 2 seconds. I got really nervous about all this over the summer and Lars' proposal was the only safe way I could think of. -- Angus