]> git.lyx.org Git - features.git/commitdiff
Comply with rule-of-three
authorGeorg Baum <baum@lyx.org>
Sun, 11 Oct 2015 09:16:09 +0000 (11:16 +0200)
committerGeorg Baum <baum@lyx.org>
Sun, 11 Oct 2015 09:16:09 +0000 (11:16 +0200)
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.

src/insets/InsetCommand.cpp
src/insets/InsetCommand.h
src/insets/InsetIPA.cpp
src/insets/InsetIPA.h
src/insets/InsetInclude.h
src/insets/InsetPreview.cpp
src/insets/InsetPreview.h

index dadab6ab930a992e33537bdd412629c968a6b0c5..dbbaed1253ed2f0cd6754bf49ce7c5b61bb60dc1 100644 (file)
@@ -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)
index ae6fc3ec05da3f75675f88df881ab9831da62808..1be72a8ec856db9c0e55c221dd2d9e1b6d1c1868 100644 (file)
@@ -39,6 +39,8 @@ public:
        ///
        InsetCommand(InsetCommand const & rhs);
        ///
+       InsetCommand & operator=(InsetCommand const & rhs);
+       ///
        virtual ~InsetCommand();
        ///
        InsetCommand * asInsetCommand() { return this; }
index e1f57299145376fc64ed89b04cc816d93a888e95..8bc3d46eecc2aad15dc68f9a740777bf65882e59 100644 (file)
@@ -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";
index f100c663f9e6856af060f7ba8656df4a0c304e91..b3b90ee4333ce941f76164969663c4a8ef58296b 100644 (file)
@@ -36,6 +36,8 @@ public:
        ~InsetIPA();
        ///
        InsetIPA(InsetIPA const & other);
+       ///
+       InsetIPA & operator=(InsetIPA const & other);
 
        /// \name Methods inherited from Inset class
        //@{
index ce93c7104c0eb321eec2f4e2f2ae789ad788933c..78d308008ce4d0f5ad233400112b78978ba7fdcf 100644 (file)
@@ -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 &);
index b8fd0aea8c3dda430b57567aae95bc8bd45fb51b..d327fe5b52bd17ce41b6ba32285d84270d0f58b1 100644 (file)
@@ -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";
index 15380ba543ea75613ee6f3a2e91ff99a48bfb4ef..a7076c4b6fe96803e481fff69b8166b4619a08e6 100644 (file)
@@ -36,6 +36,8 @@ public:
        ~InsetPreview();
        ///
        InsetPreview(InsetPreview const & other);
+       ///
+       InsetPreview & operator=(InsetPreview const & other);
 
        /// \name Methods inherited from Inset class
        //@{