Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Cube class to use smart pointers #1619

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions avogadro/core/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@

#include "molecule.h"
#include "mutex.h"
#include <memory>

namespace Avogadro::Core {

Cube::Cube()
: m_data(0), m_min(0.0, 0.0, 0.0), m_max(0.0, 0.0, 0.0),
m_spacing(0.0, 0.0, 0.0), m_points(0, 0, 0), m_minValue(0.0),
m_maxValue(0.0), m_lock(new Mutex)
{
}
Cube::Cube()
: m_data(0), m_min(0.0, 0.0, 0.0), m_max(0.0, 0.0, 0.0),
m_spacing(0.0, 0.0, 0.0), m_points(0, 0, 0), m_minValue(0.0),
m_maxValue(0.0),
m_lock(std::make_unique<Mutex>()) // Initializes m_lock with a new Mutex instance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The basic idea is good, but if you're going to use a unique_ptr you'll need to change m_lock in the header as well as the relevant methods and calling code.

Right now it doesn't compile, for example.


Cube::~Cube()
{
delete m_lock;
m_lock = nullptr;
}
Cube:: ~Cube() = default; // With unique_ptr, default destructor is fine.

bool Cube::setLimits(const Vector3& min_, const Vector3& max_,
const Vector3i& points)
Expand Down
Loading