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));
}
*/
+#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(); }
};