Commit e7cde19b authored by Frederik Schwarzer's avatar Frederik Schwarzer

Define pointer ownership.

parent 98936321
...@@ -1401,15 +1401,14 @@ int Board::delay() const ...@@ -1401,15 +1401,14 @@ int Board::delay() const
void Board::madeMove(TilePos const & tilePos1, TilePos const & tilePos2, Slide slide) void Board::madeMove(TilePos const & tilePos1, TilePos const & tilePos2, Slide slide)
{ {
Move * move; std::unique_ptr<Move> move;
if (slide.empty()) { if (slide.empty()) {
move = new Move(tilePos1, tilePos2, field(tilePos1), field(tilePos2)); move = std::make_unique<Move>(tilePos1, tilePos2, field(tilePos1), field(tilePos2));
} else { } 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) { while (m_redo.size() != 0) {
delete m_redo.front();
m_redo.pop_front(); m_redo.pop_front();
} }
emit changed(); emit changed();
...@@ -1433,7 +1432,7 @@ void Board::undo() ...@@ -1433,7 +1432,7 @@ void Board::undo()
clearHighlight(); clearHighlight();
undrawConnection(); undrawConnection();
Move * move = m_undo.back(); std::unique_ptr<Move> move = std::move(m_undo.back());
m_undo.pop_back(); m_undo.pop_back();
if (gravityFlag()) { if (gravityFlag()) {
// When both tiles reside in the same column, the order of undo is // When both tiles reside in the same column, the order of undo is
...@@ -1631,7 +1630,7 @@ void Board::undo() ...@@ -1631,7 +1630,7 @@ void Board::undo()
repaintTile(TilePos(move->x1(), move->y1())); repaintTile(TilePos(move->x1(), move->y1()));
repaintTile(TilePos(move->x2(), move->y2())); repaintTile(TilePos(move->x2(), move->y2()));
m_redo.push_front(move); m_redo.push_front(std::move(move));
emit changed(); emit changed();
} }
...@@ -1640,7 +1639,7 @@ void Board::redo() ...@@ -1640,7 +1639,7 @@ void Board::redo()
if (canRedo()) { if (canRedo()) {
clearHighlight(); clearHighlight();
undrawConnection(); undrawConnection();
auto move = m_redo.front(); std::unique_ptr<Move> move = std::move(m_redo.front());
m_redo.pop_front(); m_redo.pop_front();
// redo the slide if any // redo the slide if any
if (move->hasSlide()) { if (move->hasSlide()) {
...@@ -1654,7 +1653,7 @@ void Board::redo() ...@@ -1654,7 +1653,7 @@ void Board::redo()
repaintTile(TilePos(move->x1(), move->y1())); repaintTile(TilePos(move->x1(), move->y1()));
repaintTile(TilePos(move->x2(), move->y2())); repaintTile(TilePos(move->x2(), move->y2()));
applyGravity(); applyGravity();
m_undo.push_back(move); m_undo.push_back(std::move(move));
emit changed(); emit changed();
} }
} }
...@@ -1880,7 +1879,6 @@ void Board::resetUndo() ...@@ -1880,7 +1879,6 @@ void Board::resetUndo()
if (!canUndo()) { if (!canUndo()) {
return; return;
} }
qDeleteAll(m_undo);
m_undo.clear(); m_undo.clear();
} }
...@@ -1889,7 +1887,6 @@ void Board::resetRedo() ...@@ -1889,7 +1887,6 @@ void Board::resetRedo()
if (!canRedo()) { if (!canRedo()) {
return; return;
} }
qDeleteAll(m_redo);
m_redo.clear(); m_redo.clear();
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define KSHISEN_BOARD_H #define KSHISEN_BOARD_H
// STL // STL
#include <memory>
#include <vector> #include <vector>
// Qt // Qt
...@@ -296,8 +297,8 @@ private: ...@@ -296,8 +297,8 @@ private:
KRandomSequence m_random; KRandomSequence m_random;
std::list<Move *> m_undo; ///< Undo history std::list<std::unique_ptr<Move>> m_undo; ///< Undo history
std::list<Move *> m_redo; ///< Redo history std::list<std::unique_ptr<Move>> m_redo; ///< Redo history
int m_markX; int m_markX;
int m_markY; int m_markY;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment