mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +00:00
MathAtom is a unique_ptr
Fix coverity suggestion of defining a move constructor
This commit is contained in:
parent
723f0e14d9
commit
b382b246b6
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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(); }
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user