ソースを参照

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."
Lenny Maiorani 3 年 前
コミット
27c30ca063

+ 1 - 4
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())

+ 2 - 1
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;

+ 1 - 4
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));

+ 2 - 1
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);
 

+ 1 - 5
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);

+ 2 - 2
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; }
 

+ 1 - 5
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());

+ 2 - 2
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;

+ 1 - 4
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;

+ 2 - 1
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; }

+ 1 - 4
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;

+ 2 - 2
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*);

+ 1 - 4
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, "=====");

+ 2 - 1
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);
 

+ 1 - 4
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()
-{
-}

+ 2 - 1
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();
 

+ 1 - 12
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)
 {

+ 4 - 3
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,

+ 1 - 5
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())

+ 2 - 2
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();

+ 1 - 4
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 };

+ 2 - 1
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();
 

+ 1 - 4
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);

+ 2 - 1
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);

+ 1 - 4
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)

+ 2 - 1
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);