From 27c30ca06344cc686130155aad10095ad009d7d7 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Wed, 16 Feb 2022 11:44:57 -0700 Subject: [PATCH] Games: Use default constructors/destructors https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler." --- Userland/Games/2048/BoardView.cpp | 5 +---- Userland/Games/2048/BoardView.h | 3 ++- Userland/Games/Breakout/Game.cpp | 5 +---- Userland/Games/Breakout/Game.h | 3 ++- Userland/Games/Breakout/LevelSelectDialog.cpp | 6 +----- Userland/Games/Breakout/LevelSelectDialog.h | 4 ++-- Userland/Games/Chess/ChessWidget.cpp | 6 +----- Userland/Games/Chess/ChessWidget.h | 4 ++-- Userland/Games/GameOfLife/Board.cpp | 5 +---- Userland/Games/GameOfLife/Board.h | 3 ++- Userland/Games/GameOfLife/Pattern.cpp | 5 +---- Userland/Games/GameOfLife/Pattern.h | 4 ++-- Userland/Games/Hearts/Game.cpp | 5 +---- Userland/Games/Hearts/Game.h | 3 ++- Userland/Games/Minesweeper/CustomGameDialog.cpp | 5 +---- Userland/Games/Minesweeper/CustomGameDialog.h | 3 ++- Userland/Games/Minesweeper/Field.cpp | 13 +------------ Userland/Games/Minesweeper/Field.h | 7 ++++--- Userland/Games/Pong/Game.cpp | 6 +----- Userland/Games/Pong/Game.h | 4 ++-- Userland/Games/Snake/SnakeGame.cpp | 5 +---- Userland/Games/Snake/SnakeGame.h | 3 ++- Userland/Games/Solitaire/Game.cpp | 5 +---- Userland/Games/Solitaire/Game.h | 3 ++- Userland/Games/Spider/Game.cpp | 5 +---- Userland/Games/Spider/Game.h | 3 ++- 26 files changed, 41 insertions(+), 82 deletions(-) diff --git a/Userland/Games/2048/BoardView.cpp b/Userland/Games/2048/BoardView.cpp index 3608f0aa44b..ab1c97e2c39 100644 --- a/Userland/Games/2048/BoardView.cpp +++ b/Userland/Games/2048/BoardView.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, the SerenityOS developers. + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,10 +16,6 @@ BoardView::BoardView(Game::Board const* board) { } -BoardView::~BoardView() -{ -} - void BoardView::set_board(Game::Board const* board) { if (has_timer()) diff --git a/Userland/Games/2048/BoardView.h b/Userland/Games/2048/BoardView.h index 9b97632f670..5a3b7a27d08 100644 --- a/Userland/Games/2048/BoardView.h +++ b/Userland/Games/2048/BoardView.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, the SerenityOS developers. + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -13,7 +14,7 @@ class BoardView final : public GUI::Frame { C_OBJECT(BoardView); public: - virtual ~BoardView() override; + virtual ~BoardView() override = default; void set_board(Game::Board const* board); Function on_move; diff --git a/Userland/Games/Breakout/Game.cpp b/Userland/Games/Breakout/Game.cpp index 4ddd6b3342f..c8720ef22bb 100644 --- a/Userland/Games/Breakout/Game.cpp +++ b/Userland/Games/Breakout/Game.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -26,10 +27,6 @@ Game::Game() reset(); } -Game::~Game() -{ -} - void Game::reset_paddle() { update(enclosing_int_rect(m_paddle.rect)); diff --git a/Userland/Games/Breakout/Game.h b/Userland/Games/Breakout/Game.h index 2bf95a17ac4..7e68afe4f7b 100644 --- a/Userland/Games/Breakout/Game.h +++ b/Userland/Games/Breakout/Game.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -18,7 +19,7 @@ public: static const int game_width = 480; static const int game_height = 500; - virtual ~Game() override; + virtual ~Game() override = default; void set_paused(bool paused); diff --git a/Userland/Games/Breakout/LevelSelectDialog.cpp b/Userland/Games/Breakout/LevelSelectDialog.cpp index e3ae74676bc..dfbc5c49d4a 100644 --- a/Userland/Games/Breakout/LevelSelectDialog.cpp +++ b/Userland/Games/Breakout/LevelSelectDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, the SerenityOS developers. + * Copyright (c) 2020-2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -20,10 +20,6 @@ LevelSelectDialog::LevelSelectDialog(Window* parent_window) build(); } -LevelSelectDialog::~LevelSelectDialog() -{ -} - int LevelSelectDialog::show(int& board_number, Window* parent_window) { auto box = LevelSelectDialog::construct(parent_window); diff --git a/Userland/Games/Breakout/LevelSelectDialog.h b/Userland/Games/Breakout/LevelSelectDialog.h index 2904702db32..e3321936a80 100644 --- a/Userland/Games/Breakout/LevelSelectDialog.h +++ b/Userland/Games/Breakout/LevelSelectDialog.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, the SerenityOS developers. + * Copyright (c) 2020-2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -12,7 +12,7 @@ namespace Breakout { class LevelSelectDialog : public GUI::Dialog { C_OBJECT(LevelSelectDialog) public: - virtual ~LevelSelectDialog() override; + virtual ~LevelSelectDialog() override = default; static int show(int& board_number, Window* parent_window); int level() const { return m_level; } diff --git a/Userland/Games/Chess/ChessWidget.cpp b/Userland/Games/Chess/ChessWidget.cpp index 61b79b911d6..ee2ea37db77 100644 --- a/Userland/Games/Chess/ChessWidget.cpp +++ b/Userland/Games/Chess/ChessWidget.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, the SerenityOS developers. + * Copyright (c) 2020-2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -22,10 +22,6 @@ ChessWidget::ChessWidget() set_piece_set("stelar7"); } -ChessWidget::~ChessWidget() -{ -} - void ChessWidget::paint_event(GUI::PaintEvent& event) { const int min_size = min(width(), height()); diff --git a/Userland/Games/Chess/ChessWidget.h b/Userland/Games/Chess/ChessWidget.h index 256e201f9b7..251aeed4379 100644 --- a/Userland/Games/Chess/ChessWidget.h +++ b/Userland/Games/Chess/ChessWidget.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, the SerenityOS developers. + * Copyright (c) 2020-2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -18,7 +18,7 @@ class ChessWidget final : public GUI::Frame { C_OBJECT(ChessWidget); public: - virtual ~ChessWidget() override; + virtual ~ChessWidget() override = default; virtual void paint_event(GUI::PaintEvent&) override; virtual void mousedown_event(GUI::MouseEvent&) override; diff --git a/Userland/Games/GameOfLife/Board.cpp b/Userland/Games/GameOfLife/Board.cpp index 897f30c340a..1e693809c6c 100644 --- a/Userland/Games/GameOfLife/Board.cpp +++ b/Userland/Games/GameOfLife/Board.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2021, Andres Crucitti * Copyright (c) 2021, Linus Groh + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,10 +15,6 @@ Board::Board(size_t rows, size_t columns) resize(rows, columns); } -Board::~Board() -{ -} - void Board::run_generation() { m_stalled = true; diff --git a/Userland/Games/GameOfLife/Board.h b/Userland/Games/GameOfLife/Board.h index bcd3425e996..227311c1bb3 100644 --- a/Userland/Games/GameOfLife/Board.h +++ b/Userland/Games/GameOfLife/Board.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2021, Andres Crucitti * Copyright (c) 2021, Linus Groh + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,7 +15,7 @@ class Board { public: Board(size_t rows, size_t columns); - ~Board(); + ~Board() = default; size_t columns() const { return m_columns; } size_t rows() const { return m_rows; } diff --git a/Userland/Games/GameOfLife/Pattern.cpp b/Userland/Games/GameOfLife/Pattern.cpp index 35376c63759..5c26c6dc849 100644 --- a/Userland/Games/GameOfLife/Pattern.cpp +++ b/Userland/Games/GameOfLife/Pattern.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Ryan Wilson + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -16,10 +17,6 @@ Pattern::Pattern(Vector pattern) m_pattern = move(pattern); } -Pattern::~Pattern() -{ -} - void Pattern::set_action(GUI::Action* action) { m_action = action; diff --git a/Userland/Games/GameOfLife/Pattern.h b/Userland/Games/GameOfLife/Pattern.h index 9fa3ce1c8b3..c7b15149637 100644 --- a/Userland/Games/GameOfLife/Pattern.h +++ b/Userland/Games/GameOfLife/Pattern.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Ryan Wilson + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,10 +12,9 @@ #include #include -class Pattern { +class Pattern final { public: Pattern(Vector); - virtual ~Pattern(); Vector pattern() { return m_pattern; }; GUI::Action* action() { return m_action; } void set_action(GUI::Action*); diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp index b73b1c53fcd..01ad9dfc439 100644 --- a/Userland/Games/Hearts/Game.cpp +++ b/Userland/Games/Hearts/Game.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Till Mayer * Copyright (c) 2021, Gunnar Beutner + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -92,10 +93,6 @@ Game::Game() reset(); }; -Game::~Game() -{ -} - void Game::reset() { dbgln_if(HEARTS_DEBUG, "====="); diff --git a/Userland/Games/Hearts/Game.h b/Userland/Games/Hearts/Game.h index dfb4bdbce67..c3d39c8c287 100644 --- a/Userland/Games/Hearts/Game.h +++ b/Userland/Games/Hearts/Game.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Till Mayer * Copyright (c) 2021, Gunnar Beutner + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -22,7 +23,7 @@ public: static constexpr int width = 640; static constexpr int height = 480; - virtual ~Game() override; + virtual ~Game() override = default; void setup(String player_name, int hand_number = 0); diff --git a/Userland/Games/Minesweeper/CustomGameDialog.cpp b/Userland/Games/Minesweeper/CustomGameDialog.cpp index 3e5e24b46a9..7cdafb2ed31 100644 --- a/Userland/Games/Minesweeper/CustomGameDialog.cpp +++ b/Userland/Games/Minesweeper/CustomGameDialog.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Pedro Pereira + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -74,7 +75,3 @@ CustomGameDialog::CustomGameDialog(Window* parent_window) set_max_mines(); } - -CustomGameDialog::~CustomGameDialog() -{ -} diff --git a/Userland/Games/Minesweeper/CustomGameDialog.h b/Userland/Games/Minesweeper/CustomGameDialog.h index ef0d4f0eea6..786a3252d31 100644 --- a/Userland/Games/Minesweeper/CustomGameDialog.h +++ b/Userland/Games/Minesweeper/CustomGameDialog.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Pedro Pereira + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -20,7 +21,7 @@ public: private: CustomGameDialog(GUI::Window* parent_window); - virtual ~CustomGameDialog() override; + virtual ~CustomGameDialog() override = default; void set_max_mines(); diff --git a/Userland/Games/Minesweeper/Field.cpp b/Userland/Games/Minesweeper/Field.cpp index 7084c2542b2..09bf9dc3941 100644 --- a/Userland/Games/Minesweeper/Field.cpp +++ b/Userland/Games/Minesweeper/Field.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -155,10 +156,6 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b } } -Field::~Field() -{ -} - void Field::set_face(Face face) { switch (face) { @@ -530,14 +527,6 @@ void Field::set_single_chording(bool enabled) Config::write_bool("Minesweeper", "Game", "SingleChording", m_single_chording); } -Square::Square() -{ -} - -Square::~Square() -{ -} - template void Field::for_each_square(Callback callback) { diff --git a/Userland/Games/Minesweeper/Field.h b/Userland/Games/Minesweeper/Field.h index 34e1e0ae11a..681e2d364be 100644 --- a/Userland/Games/Minesweeper/Field.h +++ b/Userland/Games/Minesweeper/Field.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -19,8 +20,8 @@ class Square { AK_MAKE_NONCOPYABLE(Square); public: - Square(); - ~Square(); + Square() = default; + ~Square() = default; Field* field { nullptr }; bool is_swept { false }; @@ -43,7 +44,7 @@ class Field final : public GUI::Frame { friend class SquareLabel; public: - virtual ~Field() override; + virtual ~Field() override = default; enum class Difficulty { Beginner, diff --git a/Userland/Games/Pong/Game.cpp b/Userland/Games/Pong/Game.cpp index bfb13207d5b..d020a16c37c 100644 --- a/Userland/Games/Pong/Game.cpp +++ b/Userland/Games/Pong/Game.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, the SerenityOS developers. + * Copyright (c) 2020-2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,10 +15,6 @@ Game::Game() reset(); } -Game::~Game() -{ -} - void Game::reset_paddles() { if (m_cursor_paddle_target_y.has_value()) diff --git a/Userland/Games/Pong/Game.h b/Userland/Games/Pong/Game.h index 4ff0a4e5351..61a301b43a8 100644 --- a/Userland/Games/Pong/Game.h +++ b/Userland/Games/Pong/Game.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, the SerenityOS developers. + * Copyright (c) 2020-2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -26,7 +26,7 @@ public: static const int game_width = 560; static const int game_height = 480; - virtual ~Game() override; + virtual ~Game() override = default; private: Game(); diff --git a/Userland/Games/Snake/SnakeGame.cpp b/Userland/Games/Snake/SnakeGame.cpp index b5cb1e6fd54..059e97125df 100644 --- a/Userland/Games/Snake/SnakeGame.cpp +++ b/Userland/Games/Snake/SnakeGame.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Mustafa Quraish + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -26,10 +27,6 @@ SnakeGame::SnakeGame() m_high_score_text = String::formatted("Best: {}", m_high_score); } -SnakeGame::~SnakeGame() -{ -} - void SnakeGame::reset() { m_head = { m_rows / 2, m_columns / 2 }; diff --git a/Userland/Games/Snake/SnakeGame.h b/Userland/Games/Snake/SnakeGame.h index bdddb924c6c..4b7e36ec4a7 100644 --- a/Userland/Games/Snake/SnakeGame.h +++ b/Userland/Games/Snake/SnakeGame.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,7 +15,7 @@ class SnakeGame : public GUI::Frame { C_OBJECT(SnakeGame); public: - virtual ~SnakeGame() override; + virtual ~SnakeGame() override = default; void reset(); diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp index b079e47f03a..56bac805187 100644 --- a/Userland/Games/Solitaire/Game.cpp +++ b/Userland/Games/Solitaire/Game.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Till Mayer * Copyright (c) 2021, Sam Atkins + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -36,10 +37,6 @@ Game::Game() m_stacks.append(adopt_ref(*new CardStack({ 10 + 6 * Card::width + 60, 10 + Card::height + 10 }, CardStack::Type::Normal))); } -Game::~Game() -{ -} - static float rand_float() { return get_random_uniform(RAND_MAX) / static_cast(RAND_MAX); diff --git a/Userland/Games/Solitaire/Game.h b/Userland/Games/Solitaire/Game.h index d4391e8b84e..06da854500f 100644 --- a/Userland/Games/Solitaire/Game.h +++ b/Userland/Games/Solitaire/Game.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Till Mayer * Copyright (c) 2021, Sam Atkins + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -34,7 +35,7 @@ public: static constexpr int width = 640; static constexpr int height = 480; - virtual ~Game() override; + virtual ~Game() override = default; Mode mode() const { return m_mode; } void setup(Mode); diff --git a/Userland/Games/Spider/Game.cpp b/Userland/Games/Spider/Game.cpp index fdb238ec01e..f68225e4944 100644 --- a/Userland/Games/Spider/Game.cpp +++ b/Userland/Games/Spider/Game.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2021, Jamie Mansfield * Copyright (c) 2022, Jonas Höpner + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -29,10 +30,6 @@ Game::Game() } } -Game::~Game() -{ -} - void Game::setup(Mode mode) { if (m_new_game_animation) diff --git a/Userland/Games/Spider/Game.h b/Userland/Games/Spider/Game.h index f122c7f934f..b11156b6d03 100644 --- a/Userland/Games/Spider/Game.h +++ b/Userland/Games/Spider/Game.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Jamie Mansfield + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -33,7 +34,7 @@ public: static constexpr int width = 10 + 10 * Card::width + 90 + 10; static constexpr int height = 480; - ~Game() override; + ~Game() override = default; Mode mode() const { return m_mode; } void setup(Mode);