diff options
author | Lenny Maiorani <lenny@serenityos.org> | 2022-02-16 11:44:57 -0700 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-02-16 22:08:55 +0000 |
commit | 27c30ca06344cc686130155aad10095ad009d7d7 (patch) | |
tree | fe76f87680d22ea7c41effb6c22f314f646d6fe4 | |
parent | 9521f719440d3ecbb5f06dbd86ca646f14bf862b (diff) | |
download | serenity-27c30ca06344cc686130155aad10095ad009d7d7.zip |
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."
26 files changed, 41 insertions, 82 deletions
diff --git a/Userland/Games/2048/BoardView.cpp b/Userland/Games/2048/BoardView.cpp index 3608f0aa44..ab1c97e2c3 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 9b97632f67..5a3b7a27d0 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<void(Game::Direction)> on_move; diff --git a/Userland/Games/Breakout/Game.cpp b/Userland/Games/Breakout/Game.cpp index 4ddd6b3342..c8720ef22b 100644 --- a/Userland/Games/Breakout/Game.cpp +++ b/Userland/Games/Breakout/Game.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * 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 2bf95a17ac..7e68afe4f7 100644 --- a/Userland/Games/Breakout/Game.h +++ b/Userland/Games/Breakout/Game.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * 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 e3ae74676b..dfbc5c49d4 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 2904702db3..e3321936a8 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 61b79b911d..ee2ea37db7 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 256e201f9b..251aeed437 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 897f30c340..1e693809c6 100644 --- a/Userland/Games/GameOfLife/Board.cpp +++ b/Userland/Games/GameOfLife/Board.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2021, Andres Crucitti <dasc495@gmail.com> * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> + * 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 bcd3425e99..227311c1bb 100644 --- a/Userland/Games/GameOfLife/Board.h +++ b/Userland/Games/GameOfLife/Board.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2021, Andres Crucitti <dasc495@gmail.com> * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> + * 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 35376c6375..5c26c6dc84 100644 --- a/Userland/Games/GameOfLife/Pattern.cpp +++ b/Userland/Games/GameOfLife/Pattern.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Ryan Wilson <ryan@rdwilson.xyz> + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -16,10 +17,6 @@ Pattern::Pattern(Vector<String> 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 9fa3ce1c8b..c7b1514963 100644 --- a/Userland/Games/GameOfLife/Pattern.h +++ b/Userland/Games/GameOfLife/Pattern.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Ryan Wilson <ryan@rdwilson.xyz> + * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,10 +12,9 @@ #include <LibGUI/Event.h> #include <LibGUI/Forward.h> -class Pattern { +class Pattern final { public: Pattern(Vector<String>); - virtual ~Pattern(); Vector<String> 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 b73b1c53fc..01ad9dfc43 100644 --- a/Userland/Games/Hearts/Game.cpp +++ b/Userland/Games/Hearts/Game.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Till Mayer <till.mayer@web.de> * Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org> + * 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 dfb4bdbce6..c3d39c8c28 100644 --- a/Userland/Games/Hearts/Game.h +++ b/Userland/Games/Hearts/Game.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Till Mayer <till.mayer@web.de> * Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org> + * 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 3e5e24b46a..7cdafb2ed3 100644 --- a/Userland/Games/Minesweeper/CustomGameDialog.cpp +++ b/Userland/Games/Minesweeper/CustomGameDialog.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Pedro Pereira <pmh.pereira@gmail.com> + * 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 ef0d4f0eea..786a3252d3 100644 --- a/Userland/Games/Minesweeper/CustomGameDialog.h +++ b/Userland/Games/Minesweeper/CustomGameDialog.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Pedro Pereira <pmh.pereira@gmail.com> + * 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 7084c2542b..09bf9dc394 100644 --- a/Userland/Games/Minesweeper/Field.cpp +++ b/Userland/Games/Minesweeper/Field.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> + * 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<typename Callback> void Field::for_each_square(Callback callback) { diff --git a/Userland/Games/Minesweeper/Field.h b/Userland/Games/Minesweeper/Field.h index 34e1e0ae11..681e2d364b 100644 --- a/Userland/Games/Minesweeper/Field.h +++ b/Userland/Games/Minesweeper/Field.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * 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 bfb13207d5..d020a16c37 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 4ff0a4e535..61a301b43a 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 b5cb1e6fd5..059e97125d 100644 --- a/Userland/Games/Snake/SnakeGame.cpp +++ b/Userland/Games/Snake/SnakeGame.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org> + * 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 bdddb924c6..4b7e36ec4a 100644 --- a/Userland/Games/Snake/SnakeGame.h +++ b/Userland/Games/Snake/SnakeGame.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * 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 b079e47f03..56bac80518 100644 --- a/Userland/Games/Solitaire/Game.cpp +++ b/Userland/Games/Solitaire/Game.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Till Mayer <till.mayer@web.de> * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> + * 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<float>(RAND_MAX); diff --git a/Userland/Games/Solitaire/Game.h b/Userland/Games/Solitaire/Game.h index d4391e8b84..06da854500 100644 --- a/Userland/Games/Solitaire/Game.h +++ b/Userland/Games/Solitaire/Game.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Till Mayer <till.mayer@web.de> * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> + * 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 fdb238ec01..f68225e494 100644 --- a/Userland/Games/Spider/Game.cpp +++ b/Userland/Games/Spider/Game.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2021, Jamie Mansfield <jmansfield@cadixdev.org> * Copyright (c) 2022, Jonas Höpner <me@jonashoepner.de> + * 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 f122c7f934..b11156b6d0 100644 --- a/Userland/Games/Spider/Game.h +++ b/Userland/Games/Spider/Game.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Jamie Mansfield <jmansfield@cadixdev.org> + * 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); |