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
This commit is contained in:
Abdelrazak Younes 2007-05-31 12:30:17 +00:00
parent 24fb9c5214
commit d075cb25b8
8 changed files with 59 additions and 24 deletions

View File

@ -42,7 +42,9 @@ CursorSlice::CursorSlice(Inset & p)
: inset_(&p), idx_(0), pit_(0), pos_(0) : inset_(&p), idx_(0), pit_(0), pos_(0)
{ {
BOOST_ASSERT(inset_); BOOST_ASSERT(inset_);
inset_->destroyed.connect( boost::signal<void()> * destroyed_signal = inset_->destroyedSignal();
if (destroyed_signal)
inset_connection_ = destroyed_signal->connect(
boost::bind(&CursorSlice::invalidate, this)); 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) CursorSlice & CursorSlice::operator=(CursorSlice const & cs)
{ {
inset_ = cs.inset_; inset_ = cs.inset_;
idx_ = cs.idx_; idx_ = cs.idx_;
pit_ = cs.pit_; pit_ = cs.pit_;
pos_ = cs.pos_; pos_ = cs.pos_;
if (inset_) { if (inset_ && inset_->destroyedSignal()) {
BOOST_ASSERT(inset_); inset_connection_ = inset_->destroyedSignal()->connect(
inset_->destroyed.connect(
boost::bind(&CursorSlice::invalidate, this)); boost::bind(&CursorSlice::invalidate, this));
} }
return *this; return *this;

View File

@ -63,6 +63,8 @@ public:
/// ///
explicit CursorSlice(Inset &); explicit CursorSlice(Inset &);
/// ///
virtual ~CursorSlice();
///
CursorSlice & operator=(CursorSlice const &); CursorSlice & operator=(CursorSlice const &);
/// ///
bool isValid() const; bool isValid() const;
@ -156,6 +158,8 @@ private:
bool pit_valid_; bool pit_valid_;
/// position in this cell /// position in this cell
pos_type pos_; pos_type pos_;
/// connection to referred \c inset_ destruction signal.
boost::signals::connection inset_connection_;
}; };
/// test for equality /// test for equality

View File

@ -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> Inset::clone() const std::auto_ptr<Inset> Inset::clone() const
{ {
std::auto_ptr<Inset> b = doClone(); std::auto_ptr<Inset> b = doClone();

View File

@ -56,7 +56,7 @@ namespace graphics { class PreviewLoader; }
// everything storing large quantities of insets. Mathed e.g. would // everything storing large quantities of insets. Mathed e.g. would
// suffer. // suffer.
class Inset : public boost::noncopyable { class Inset {
public: public:
/// ///
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
@ -72,7 +72,7 @@ public:
typedef size_t col_type; typedef size_t col_type;
/// virtual base class destructor /// virtual base class destructor
virtual ~Inset() { destroyed();} virtual ~Inset() {}
/// replicate ourselves /// replicate ourselves
std::auto_ptr<Inset> clone() const; std::auto_ptr<Inset> clone() const;
@ -477,14 +477,15 @@ public:
// //
enum { TEXT_TO_INSET_OFFSET = 4 }; enum { TEXT_TO_INSET_OFFSET = 4 };
/// This signal is emitted when the inset is destroyed. /// Signal for inset destruction.
boost::signal<void()> destroyed; /** This signal is emitted at the inset destruction for insets that
* support this.
*/
virtual boost::signal<void()> * destroyedSignal() { return 0; }
protected: protected:
Inset(); Inset();
Inset(Inset const & i);
///
Inset & operator=(Inset const &);
/** The real dispatcher. /** The real dispatcher.
* Gets normally called from Cursor::dispatch(). Cursor::dispatch() * Gets normally called from Cursor::dispatch(). Cursor::dispatch()
* assumes the common case of 'LFUN handled, need update'. * assumes the common case of 'LFUN handled, need update'.

View File

@ -51,6 +51,7 @@
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/current_function.hpp> #include <boost/current_function.hpp>
#include <boost/signal.hpp>
#include <sstream> #include <sstream>

View File

@ -42,6 +42,8 @@ public:
explicit InsetText(BufferParams const &); explicit InsetText(BufferParams const &);
/// ///
InsetText(); InsetText();
///
virtual ~InsetText() { destroyed(); }
/// empty inset to empty par /// empty inset to empty par
void clear(); void clear();
@ -138,6 +140,8 @@ public:
virtual bool wide() const { return wide_inset_; } virtual bool wide() const { return wide_inset_; }
/// ///
void setWide(bool wide_inset) { wide_inset_ = wide_inset; } void setWide(bool wide_inset) { wide_inset_ = wide_inset; }
///
boost::signal<void()> * destroyedSignal() { return &destroyed; }
protected: protected:
/// ///
@ -159,6 +163,9 @@ private:
mutable pit_type old_pit; mutable pit_type old_pit;
/// ///
bool wide_inset_; bool wide_inset_;
/// This signal is emitted when the inset is destroyed.
boost::signal<void()> destroyed;
public: public:
/// ///
mutable Text text_; mutable Text text_;

View File

@ -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 InsetMath::idx_type InsetMathNest::nargs() const
{ {
return cells_.size(); return cells_.size();

View File

@ -27,6 +27,8 @@ class InsetMathNest : public InsetMath {
public: public:
/// nestinsets have a fixed size to start with /// nestinsets have a fixed size to start with
explicit InsetMathNest(idx_type ncells); explicit InsetMathNest(idx_type ncells);
///
virtual ~InsetMathNest() { destroyed(); }
/// the size is usually some sort of convex hull of the cells /// the size is usually some sort of convex hull of the cells
/// hides inset::metrics() intentionally! /// hides inset::metrics() intentionally!
@ -104,7 +106,15 @@ public:
int latex(Buffer const &, odocstream & os, int latex(Buffer const &, odocstream & os,
OutputParams const & runparams) const; OutputParams const & runparams) const;
/// This signal is emitted when the inset is destroyed.
boost::signal<void()> * destroyedSignal() { return &destroyed; }
protected: protected:
///
InsetMathNest(InsetMathNest const & inset);
///
InsetMathNest & operator=(InsetMathNest const &);
/// ///
virtual void doDispatch(Cursor & cur, FuncRequest & cmd); virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
/// do we want to handle this event? /// do we want to handle this event?
@ -146,6 +156,10 @@ protected:
cells_type cells_; cells_type cells_;
/// if the inset is locked, it can't be entered with the cursor /// if the inset is locked, it can't be entered with the cursor
bool lock_; bool lock_;
private:
/// This signal is emitted when the inset is destroyed.
boost::signal<void()> destroyed;
}; };