mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Comply with rule-of-three
The rule-of-three says that if any of virtual destructor, copy constructor or assignment operator needs to be manually implemented, then all three should be implemented. Otherwise you can get subtle bugs which can be difficult to find. In the changed classes, changing a copy-construction to an assignment would have had surprising effects. Now they all behave consistently.
This commit is contained in:
parent
74be166499
commit
cea2d71e64
@ -65,6 +65,20 @@ InsetCommand::InsetCommand(InsetCommand const & rhs)
|
||||
{}
|
||||
|
||||
|
||||
InsetCommand & InsetCommand::operator=(InsetCommand const & rhs)
|
||||
{
|
||||
if (&rhs == this)
|
||||
return *this;
|
||||
|
||||
Inset::operator=(rhs);
|
||||
p_ = rhs.p_;
|
||||
mouse_hover_.clear();
|
||||
button_ = RenderButton();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
InsetCommand::~InsetCommand()
|
||||
{
|
||||
if (p_.code() != NO_CODE)
|
||||
|
@ -39,6 +39,8 @@ public:
|
||||
///
|
||||
InsetCommand(InsetCommand const & rhs);
|
||||
///
|
||||
InsetCommand & operator=(InsetCommand const & rhs);
|
||||
///
|
||||
virtual ~InsetCommand();
|
||||
///
|
||||
InsetCommand * asInsetCommand() { return this; }
|
||||
|
@ -54,6 +54,18 @@ InsetIPA::InsetIPA(InsetIPA const & other)
|
||||
}
|
||||
|
||||
|
||||
InsetIPA & InsetIPA::operator=(InsetIPA const & other)
|
||||
{
|
||||
if (&other == this)
|
||||
return *this;
|
||||
|
||||
InsetText::operator=(other);
|
||||
preview_.reset(new RenderPreview(*other.preview_, this));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void InsetIPA::write(ostream & os) const
|
||||
{
|
||||
os << "IPA" << "\n";
|
||||
|
@ -36,6 +36,8 @@ public:
|
||||
~InsetIPA();
|
||||
///
|
||||
InsetIPA(InsetIPA const & other);
|
||||
///
|
||||
InsetIPA & operator=(InsetIPA const & other);
|
||||
|
||||
/// \name Methods inherited from Inset class
|
||||
//@{
|
||||
|
@ -35,6 +35,10 @@ namespace support {
|
||||
|
||||
/// for including tex/lyx files
|
||||
class InsetInclude : public InsetCommand {
|
||||
// Disable assignment operator, since it is not used, and cannot be
|
||||
// implemented consistently with the copy constructor, because
|
||||
// include_label is const.
|
||||
InsetInclude & operator=(InsetInclude const &);
|
||||
public:
|
||||
///
|
||||
InsetInclude(Buffer * buf, InsetCommandParams const &);
|
||||
|
@ -54,6 +54,18 @@ InsetPreview::InsetPreview(InsetPreview const & other)
|
||||
}
|
||||
|
||||
|
||||
InsetPreview & InsetPreview::operator=(InsetPreview const & other)
|
||||
{
|
||||
if (&other == this)
|
||||
return *this;
|
||||
|
||||
InsetText::operator=(other);
|
||||
preview_.reset(new RenderPreview(*other.preview_, this));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void InsetPreview::write(ostream & os) const
|
||||
{
|
||||
os << "Preview" << "\n";
|
||||
|
@ -36,6 +36,8 @@ public:
|
||||
~InsetPreview();
|
||||
///
|
||||
InsetPreview(InsetPreview const & other);
|
||||
///
|
||||
InsetPreview & operator=(InsetPreview const & other);
|
||||
|
||||
/// \name Methods inherited from Inset class
|
||||
//@{
|
||||
|
Loading…
Reference in New Issue
Block a user