summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Schwarzer <[email protected]>2016-05-22 01:27:39 +0200
committerFrederik Schwarzer <[email protected]>2016-05-22 01:27:39 +0200
commite7cde19b505e4be4d6dc335486f1f6119e88bd05 (patch)
tree95a7f12a55d7930c47d8067c7bc7600d996ce4b6
parent98936321ef264457822e936c5f70dd49d11a14c1 (diff)
Define pointer ownership.
-rw-r--r--src/board.cpp19
-rw-r--r--src/board.h5
2 files changed, 11 insertions, 13 deletions
diff --git a/src/board.cpp b/src/board.cpp
index 3f370b2..81d3d53 100644
--- a/src/board.cpp
+++ b/src/board.cpp
@@ -1401,15 +1401,14 @@ int Board::delay() const
void Board::madeMove(TilePos const & tilePos1, TilePos const & tilePos2, Slide slide)
{
- Move * move;
+ std::unique_ptr<Move> move;
if (slide.empty()) {
- move = new Move(tilePos1, tilePos2, field(tilePos1), field(tilePos2));
+ move = std::make_unique<Move>(tilePos1, tilePos2, field(tilePos1), field(tilePos2));
} else {
- move = new Move(tilePos1, tilePos2, field(tilePos1), field(tilePos2), slide);
+ move = std::make_unique<Move>(tilePos1, tilePos2, field(tilePos1), field(tilePos2), slide);
}
- m_undo.push_back(move);
+ m_undo.push_back(std::move(move));
while (m_redo.size() != 0) {
- delete m_redo.front();
m_redo.pop_front();
}
emit changed();
@@ -1433,7 +1432,7 @@ void Board::undo()
clearHighlight();
undrawConnection();
- Move * move = m_undo.back();
+ std::unique_ptr<Move> move = std::move(m_undo.back());
m_undo.pop_back();
if (gravityFlag()) {
// When both tiles reside in the same column, the order of undo is
@@ -1631,7 +1630,7 @@ void Board::undo()
repaintTile(TilePos(move->x1(), move->y1()));
repaintTile(TilePos(move->x2(), move->y2()));
- m_redo.push_front(move);
+ m_redo.push_front(std::move(move));
emit changed();
}
@@ -1640,7 +1639,7 @@ void Board::redo()
if (canRedo()) {
clearHighlight();
undrawConnection();
- auto move = m_redo.front();
+ std::unique_ptr<Move> move = std::move(m_redo.front());
m_redo.pop_front();
// redo the slide if any
if (move->hasSlide()) {
@@ -1654,7 +1653,7 @@ void Board::redo()
repaintTile(TilePos(move->x1(), move->y1()));
repaintTile(TilePos(move->x2(), move->y2()));
applyGravity();
- m_undo.push_back(move);
+ m_undo.push_back(std::move(move));
emit changed();
}
}
@@ -1880,7 +1879,6 @@ void Board::resetUndo()
if (!canUndo()) {
return;
}
- qDeleteAll(m_undo);
m_undo.clear();
}
@@ -1889,7 +1887,6 @@ void Board::resetRedo()
if (!canRedo()) {
return;
}
- qDeleteAll(m_redo);
m_redo.clear();
}
diff --git a/src/board.h b/src/board.h
index 99ad83a..5cd4688 100644
--- a/src/board.h
+++ b/src/board.h
@@ -25,6 +25,7 @@
#define KSHISEN_BOARD_H
// STL
+#include <memory>
#include <vector>
// Qt
@@ -296,8 +297,8 @@ private:
KRandomSequence m_random;
- std::list<Move *> m_undo; ///< Undo history
- std::list<Move *> m_redo; ///< Redo history
+ std::list<std::unique_ptr<Move>> m_undo; ///< Undo history
+ std::list<std::unique_ptr<Move>> m_redo; ///< Redo history
int m_markX;
int m_markY;