]> git.lyx.org Git - features.git/commitdiff
MathAtom is a unique_ptr
authorGuillaume MM <gm@lyx.org>
Sun, 2 Apr 2017 19:04:06 +0000 (21:04 +0200)
committerGuillaume MM <gm@lyx.org>
Fri, 7 Apr 2017 21:31:34 +0000 (23:31 +0200)
Fix coverity suggestion of defining a move constructor

src/mathed/MathAtom.cpp
src/mathed/MathAtom.h

index a8483ea212cd0b07e91840dbfd05420282dc93e5..cbf26ec9f764ff4ac03dc84c0038a7dd05fb21c0 100644 (file)
@@ -18,37 +18,20 @@ using namespace std;
 namespace lyx {
 
 
-MathAtom::MathAtom()
-       : nucleus_(0)
-{}
-
-
 MathAtom::MathAtom(InsetMath * p)
-       : nucleus_(p)
+       : unique_ptr<InsetMath>(p)
 {}
 
 
 MathAtom::MathAtom(MathAtom const & at)
-       : nucleus_(0)
-{
-       if (at.nucleus_)
-               nucleus_ = static_cast<InsetMath*>(at.nucleus_->clone());
-}
+       : unique_ptr<InsetMath>(at ? static_cast<InsetMath*>(at->clone()) : nullptr)
+{}
 
 
 MathAtom & MathAtom::operator=(MathAtom const & at)
 {
-       if (&at == this)
-               return *this;
-       MathAtom tmp(at);
-       swap(tmp.nucleus_, nucleus_);
-       return *this;
-}
-
-
-MathAtom::~MathAtom()
-{
-       delete nucleus_;
+       // copy then move-assign
+       return operator=(MathAtom(at));
 }
 
 
index b11d75da182b3da122fae03dfbee869d0411773f..7801fe6c5d268d7f7eef43e4add1ca0d79d13117 100644 (file)
@@ -40,33 +40,27 @@ Andre'
 
 */
 
+#include <memory>
+
+
 namespace lyx {
 
 class Inset;
 class InsetMath;
 
-class MathAtom {
+class MathAtom : public std::unique_ptr<InsetMath> {
 public:
-       /// default constructor, object is useless, but we need it to put it into
-       /// std::containers
-       MathAtom();
+       MathAtom() = default;
+       MathAtom(MathAtom &&) = default;
+       MathAtom & operator=(MathAtom &&) = default;
        /// the "real constructor"
        explicit MathAtom(InsetMath * p);
-       /// copy constructor, invokes nucleus_->clone()
+       /// copy constructor, invokes clone()
        MathAtom(MathAtom const &);
-       /// we really need to clean up
-       ~MathAtom();
-       /// assignment invokes nucleus_->clone()
        MathAtom & operator=(MathAtom const &);
-       /// access to the inset (checked with gprof)
-       InsetMath       * nucleus()       { return nucleus_; }
-       InsetMath const * nucleus() const { return nucleus_; }
        /// access to the inset
-       InsetMath const * operator->() const { return nucleus_; }
-
-private:
-       ///
-       InsetMath * nucleus_;
+       InsetMath * nucleus() { return get(); }
+       InsetMath const * nucleus() const { return get(); }
 };