From d075cb25b89b7bd2ac3d293c9db7c825d58770dd Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 31 May 2007 12:30:17 +0000 Subject: [PATCH] This patch transfer Inset::destroyed signal to InsetText and InsetMathNest thus freeing some memory as normal math chars and symbols won't have it. It also solve a crash with non disconnect boost::signal and gcc-3.3 or 3.4. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18592 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CursorSlice.cpp | 15 +++++++++++---- src/CursorSlice.h | 4 ++++ src/insets/Inset.cpp | 13 ------------- src/insets/Inset.h | 15 ++++++++------- src/insets/InsetText.cpp | 1 + src/insets/InsetText.h | 7 +++++++ src/mathed/InsetMathNest.cpp | 14 ++++++++++++++ src/mathed/InsetMathNest.h | 14 ++++++++++++++ 8 files changed, 59 insertions(+), 24 deletions(-) diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp index f8d72eea13..2b1164e99d 100644 --- a/src/CursorSlice.cpp +++ b/src/CursorSlice.cpp @@ -42,7 +42,9 @@ CursorSlice::CursorSlice(Inset & p) : inset_(&p), idx_(0), pit_(0), pos_(0) { BOOST_ASSERT(inset_); - inset_->destroyed.connect( + boost::signal * destroyed_signal = inset_->destroyedSignal(); + if (destroyed_signal) + inset_connection_ = destroyed_signal->connect( boost::bind(&CursorSlice::invalidate, this)); } @@ -53,15 +55,20 @@ CursorSlice::CursorSlice(CursorSlice const & cs) } +CursorSlice::~CursorSlice() +{ + inset_connection_.disconnect(); +} + + CursorSlice & CursorSlice::operator=(CursorSlice const & cs) { inset_ = cs.inset_; idx_ = cs.idx_; pit_ = cs.pit_; pos_ = cs.pos_; - if (inset_) { - BOOST_ASSERT(inset_); - inset_->destroyed.connect( + if (inset_ && inset_->destroyedSignal()) { + inset_connection_ = inset_->destroyedSignal()->connect( boost::bind(&CursorSlice::invalidate, this)); } return *this; diff --git a/src/CursorSlice.h b/src/CursorSlice.h index cdd13ecec0..89fd6f5219 100644 --- a/src/CursorSlice.h +++ b/src/CursorSlice.h @@ -63,6 +63,8 @@ public: /// explicit CursorSlice(Inset &); /// + virtual ~CursorSlice(); + /// CursorSlice & operator=(CursorSlice const &); /// bool isValid() const; @@ -156,6 +158,8 @@ private: bool pit_valid_; /// position in this cell pos_type pos_; + /// connection to referred \c inset_ destruction signal. + boost::signals::connection inset_connection_; }; /// test for equality diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 4d36c27012..24760dbb6e 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -121,19 +121,6 @@ Inset::Inset() {} -Inset::Inset(Inset const & inset) - : dim_(inset.dim_), background_color_(inset.background_color_) -{} - - -Inset & Inset::operator=(Inset const & inset) -{ - dim_ = inset.dim_; - background_color_ = inset.background_color_; - return *this; -} - - std::auto_ptr Inset::clone() const { std::auto_ptr b = doClone(); diff --git a/src/insets/Inset.h b/src/insets/Inset.h index c77efa52e0..a6b5090ef4 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -56,7 +56,7 @@ namespace graphics { class PreviewLoader; } // everything storing large quantities of insets. Mathed e.g. would // suffer. -class Inset : public boost::noncopyable { +class Inset { public: /// typedef ptrdiff_t difference_type; @@ -72,7 +72,7 @@ public: typedef size_t col_type; /// virtual base class destructor - virtual ~Inset() { destroyed();} + virtual ~Inset() {} /// replicate ourselves std::auto_ptr clone() const; @@ -477,14 +477,15 @@ public: // enum { TEXT_TO_INSET_OFFSET = 4 }; - /// This signal is emitted when the inset is destroyed. - boost::signal destroyed; + /// Signal for inset destruction. + /** This signal is emitted at the inset destruction for insets that + * support this. + */ + virtual boost::signal * destroyedSignal() { return 0; } protected: Inset(); - Inset(Inset const & i); - /// - Inset & operator=(Inset const &); + /** The real dispatcher. * Gets normally called from Cursor::dispatch(). Cursor::dispatch() * assumes the common case of 'LFUN handled, need update'. diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 2682a8a63e..8af5ada648 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -51,6 +51,7 @@ #include #include +#include #include diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 232476fb2e..87998f39b7 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -42,6 +42,8 @@ public: explicit InsetText(BufferParams const &); /// InsetText(); + /// + virtual ~InsetText() { destroyed(); } /// empty inset to empty par void clear(); @@ -138,6 +140,8 @@ public: virtual bool wide() const { return wide_inset_; } /// void setWide(bool wide_inset) { wide_inset_ = wide_inset; } + /// + boost::signal * destroyedSignal() { return &destroyed; } protected: /// @@ -159,6 +163,9 @@ private: mutable pit_type old_pit; /// bool wide_inset_; + /// This signal is emitted when the inset is destroyed. + boost::signal destroyed; + public: /// mutable Text text_; diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 26b6eb1d10..14c817d3b9 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -78,6 +78,20 @@ InsetMathNest::InsetMathNest(idx_type nargs) {} +InsetMathNest::InsetMathNest(InsetMathNest const & inset) + : InsetMath(inset), cells_(inset.cells_), lock_(inset.lock_) +{} + + +InsetMathNest & InsetMathNest::operator=(InsetMathNest const & inset) +{ + cells_ = inset.cells_; + lock_ = inset.lock_; + InsetMath::operator=(inset); + return *this; +} + + InsetMath::idx_type InsetMathNest::nargs() const { return cells_.size(); diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h index 41387136d6..3770bccd0d 100644 --- a/src/mathed/InsetMathNest.h +++ b/src/mathed/InsetMathNest.h @@ -27,6 +27,8 @@ class InsetMathNest : public InsetMath { public: /// nestinsets have a fixed size to start with explicit InsetMathNest(idx_type ncells); + /// + virtual ~InsetMathNest() { destroyed(); } /// the size is usually some sort of convex hull of the cells /// hides inset::metrics() intentionally! @@ -104,7 +106,15 @@ public: int latex(Buffer const &, odocstream & os, OutputParams const & runparams) const; + /// This signal is emitted when the inset is destroyed. + boost::signal * destroyedSignal() { return &destroyed; } + protected: + /// + InsetMathNest(InsetMathNest const & inset); + /// + InsetMathNest & operator=(InsetMathNest const &); + /// virtual void doDispatch(Cursor & cur, FuncRequest & cmd); /// do we want to handle this event? @@ -146,6 +156,10 @@ protected: cells_type cells_; /// if the inset is locked, it can't be entered with the cursor bool lock_; + +private: + /// This signal is emitted when the inset is destroyed. + boost::signal destroyed; };