[wesnoth-commits] [wesnoth/wesnoth] b63b8a: Convert the editor_action framework to use std::un...

Steve Cotton noreply at github.com
Fri Nov 20 10:51:27 UTC 2020


  Branch: refs/heads/master
  Home:   https://github.com/wesnoth/wesnoth
  Commit: b63b8a959a7b217228d44029466486e135cfdfb5
      https://github.com/wesnoth/wesnoth/commit/b63b8a959a7b217228d44029466486e135cfdfb5
  Author: Steve Cotton <steve at octalot.co.uk>
  Date:   2020-11-20 (Fri, 20 Nov 2020)

  Changed paths:
    M src/editor/action/action.cpp
    M src/editor/action/action.hpp
    M src/editor/action/action_base.hpp
    M src/editor/action/action_item.cpp
    M src/editor/action/action_item.hpp
    M src/editor/action/action_label.cpp
    M src/editor/action/action_label.hpp
    M src/editor/action/action_select.cpp
    M src/editor/action/action_select.hpp
    M src/editor/action/action_unit.cpp
    M src/editor/action/action_unit.hpp
    M src/editor/action/action_village.cpp
    M src/editor/action/action_village.hpp
    M src/editor/action/mouse/mouse_action.cpp
    M src/editor/action/mouse/mouse_action.hpp
    M src/editor/action/mouse/mouse_action_item.cpp
    M src/editor/action/mouse/mouse_action_item.hpp
    M src/editor/action/mouse/mouse_action_map_label.cpp
    M src/editor/action/mouse/mouse_action_map_label.hpp
    M src/editor/action/mouse/mouse_action_select.cpp
    M src/editor/action/mouse/mouse_action_select.hpp
    M src/editor/action/mouse/mouse_action_unit.cpp
    M src/editor/action/mouse/mouse_action_unit.hpp
    M src/editor/action/mouse/mouse_action_village.cpp
    M src/editor/action/mouse/mouse_action_village.hpp
    M src/editor/controller/editor_controller.cpp
    M src/editor/controller/editor_controller.hpp
    M src/editor/editor_common.hpp
    M src/editor/map/map_context.cpp

  Log Message:
  -----------
  Convert the editor_action framework to use std::unique_ptr instead of raw pointers

When returning std::unique_ptr instead of raw pointers, the return type can't
be a co-variant, which is why the clone() functions are all being changed to
return the base class.

All of the instances of editor_action_ptr were replaced, except those in
commented-out code. Many of these replacements were with the `auto` keyword;
for the others the reason that I didn't use editor_action_ptr was that I find
`std::unique_ptr<editor_action>` quicker to read than remembering if
editor_action_ptr is a unique_ptr, a shared_ptr or a plain raw pointer.

A large amount of commented-out code in mouse_action_item.cpp and
mouse_action_unit.cpp gets removed, but the commented-out code in
action_item.cpp is left for a future refactor. I think the classes in these
files should end up being refactored with the responsibilty for putting items
on the map moving from mouse_action_item.cpp to action_item.cpp, leaving only
the parts specific to the input method in mouse_action_item.cpp. However,
that's for a separate commit (and separate PR).





More information about the Commits mailing list