Skip to content

Commit cf604f8

Browse files
committed
clang-tidy:
- fix more errors
1 parent 96bef6f commit cf604f8

File tree

15 files changed

+148
-136
lines changed

15 files changed

+148
-136
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ CheckOptions:
127127
- key: readability-identifier-naming.UnionCase
128128
value: "CamelCase"
129129
- key: readability-identifier-naming.ValueTemplateParameterCase
130-
value: "lower_case"
130+
value: "CamelCase"
131131
- key: readability-identifier-naming.VariableCase
132132
value: "lower_case"
133133
- key: readability-identifier-naming.VirtualMethodCase

src/helper/color_literals.hpp

Lines changed: 79 additions & 79 deletions
Large diffs are not rendered by default.

src/helper/const_utils.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ s*/
2828
}())
2929
#endif
3030

31-
#define CONSTEVAL_STATIC_ASSERT(CHECK, MSG) \
32-
do { /*NOLINT(cppcoreguidelines-avoid-do-while)*/ \
33-
if (utils::is_constant_evaluated()) { \
34-
CONSTEVAL_ONLY_STATIC_ASSERT(CHECK, MSG); \
35-
} else { \
36-
assert(CHECK&& MSG); \
37-
} \
31+
#define CONSTEVAL_STATIC_ASSERT(CHECK, MSG) /*NOLINT(cppcoreguidelines-macro-usage)*/ \
32+
do { /*NOLINT(cppcoreguidelines-avoid-do-while)*/ \
33+
if (utils::is_constant_evaluated()) { \
34+
CONSTEVAL_ONLY_STATIC_ASSERT(CHECK, MSG); \
35+
} else { \
36+
assert((CHECK) && (MSG)); \
37+
} \
3838
} while (false)
3939

4040

@@ -44,20 +44,20 @@ namespace const_utils {
4444
#define PROPAGATE(val, V, E) /*NOLINT(cppcoreguidelines-macro-usage)*/ \
4545
do { /*NOLINT(cppcoreguidelines-avoid-do-while)*/ \
4646
if (not((val).has_value())) { \
47-
return const_utils::expected<V, E>::error_result((val).error()); \
47+
return const_utils::Expected<V, E>::error_result((val).error()); \
4848
} \
4949
} while (false)
5050

51-
// represents a sort of constexpr std::expected
51+
// represents a sort of constexpr std::Expected
5252
template<typename V, typename E>
5353
requires std::is_default_constructible_v<V> && std::is_default_constructible_v<E>
54-
struct expected {
54+
struct Expected {
5555
private:
5656
bool m_has_value;
5757
V m_value;
5858
E m_error;
5959

60-
constexpr expected(
60+
constexpr Expected(
6161
bool has_value,
6262
const V& value,
6363
const E& error
@@ -67,11 +67,11 @@ namespace const_utils {
6767
m_error{ error } { }
6868

6969
public:
70-
[[nodiscard]] constexpr static expected<V, E> good_result(const V& type) {
70+
[[nodiscard]] constexpr static Expected<V, E> good_result(const V& type) {
7171
return { true, type, E{} };
7272
}
7373

74-
[[nodiscard]] constexpr static expected<V, E> error_result(const E& error) {
74+
[[nodiscard]] constexpr static Expected<V, E> error_result(const E& error) {
7575
return { false, V{}, error };
7676
}
7777

@@ -80,13 +80,13 @@ namespace const_utils {
8080
}
8181

8282
[[nodiscard]] constexpr V value() const {
83-
CONSTEVAL_STATIC_ASSERT((has_value()), "value() call on expected without value");
83+
CONSTEVAL_STATIC_ASSERT((has_value()), "value() call on Expected without value");
8484

8585
return m_value;
8686
}
8787

8888
[[nodiscard]] constexpr E error() const {
89-
CONSTEVAL_STATIC_ASSERT((not has_value()), "error() call on expected without error");
89+
CONSTEVAL_STATIC_ASSERT((not has_value()), "error() call on Expected without error");
9090

9191
return m_error;
9292
}

src/helper/nfd.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ helper::expected<std::filesystem::path, std::string> helper::openFileDialog(
7373
) {
7474

7575
NFD::UniquePathU8 out_path{};
76-
auto filterItem = get_filter_items(allowed_files);
76+
auto filter_item = get_filter_items(allowed_files);
7777

7878
const auto path_deallocator = [](const nfdu8char_t* const char_value) {
7979
if (char_value == nullptr) {
@@ -93,7 +93,7 @@ helper::expected<std::filesystem::path, std::string> helper::openFileDialog(
9393
}
9494

9595
const nfdresult_t result = NFD::OpenDialog(
96-
out_path, filterItem.get(), static_cast<nfdfiltersize_t>(allowed_files.size()), default_path_value.get()
96+
out_path, filter_item.get(), static_cast<nfdfiltersize_t>(allowed_files.size()), default_path_value.get()
9797
);
9898
if (result == NFD_OKAY) {
9999
return std::filesystem::path{ out_path.get() };
@@ -113,7 +113,7 @@ helper::expected<std::filesystem::path, std::string> helper::openFileDialog(
113113
) {
114114

115115
NFD::UniquePathSet out_paths{};
116-
auto filterItem = get_filter_items(allowed_files);
116+
auto filter_item = get_filter_items(allowed_files);
117117

118118
const auto path_deallocator = [](const nfdu8char_t* const char_value) {
119119
if (char_value == nullptr) {
@@ -133,7 +133,7 @@ helper::expected<std::filesystem::path, std::string> helper::openFileDialog(
133133
}
134134

135135
const nfdresult_t result = NFD::OpenDialogMultiple(
136-
out_paths, filterItem.get(), static_cast<nfdfiltersize_t>(allowed_files.size()), default_path_value.get()
136+
out_paths, filter_item.get(), static_cast<nfdfiltersize_t>(allowed_files.size()), default_path_value.get()
137137
);
138138
if (result == NFD_OKAY) {
139139
std::vector<std::filesystem::path> result_vector{};

src/helper/platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace {
8484
#error "Unsupported platform"
8585
#endif
8686

87-
const auto result = system(shell_command.c_str());
87+
const auto result = system(shell_command.c_str()); //NOLINT(cert-env33-c)
8888
if (result < 0) {
8989
spdlog::error("Error in opening url: {}", get_error_from_errno());
9090
return false;

src/input/game_input.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace input {
2727

2828
enum class GameInputType : u8 { Touch, Keyboard, Controller, Recording };
2929

30-
enum class MenuEvent : u8 { OPEN_SETTINGS, PAUSE };
30+
enum class MenuEvent : u8 { OpenSettings, Pause };
3131

3232

3333
struct GameInput {
@@ -46,14 +46,23 @@ namespace input {
4646
std::unordered_map<HoldableKey, u64> m_keys_hold;
4747
GameInputType m_input_type;
4848

49-
protected:
49+
private:
5050
Tetrion* m_target_tetrion{};
5151
OnEventCallback m_on_event_callback{};
5252

53+
protected:
5354
explicit GameInput(GameInputType input_type) : m_input_type{ input_type } { }
5455

5556
void handle_event(InputEvent event, SimulationStep simulation_step_index);
5657

58+
[[nodiscard]] const Tetrion* target_tetrion() const {
59+
return m_target_tetrion;
60+
}
61+
62+
[[nodiscard]] const OnEventCallback& on_event_callback() const {
63+
return m_on_event_callback;
64+
}
65+
5766
public:
5867
virtual void update(SimulationStep simulation_step_index);
5968
virtual void late_update(SimulationStep /*simulation_step*/){};
@@ -82,6 +91,9 @@ namespace input {
8291
GameInput(const GameInput&) = delete;
8392
GameInput& operator=(const GameInput&) = delete;
8493

94+
GameInput(GameInput&&) = default;
95+
GameInput& operator=(GameInput&&) = default;
96+
8597
virtual ~GameInput() = default;
8698
};
8799
} // namespace input

src/input/guid.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,24 @@ struct fmt::formatter<sdl::GUID> : formatter<std::string> {
5353
namespace { //NOLINT(cert-dcl59-cpp,google-build-namespaces)
5454

5555
// decode a single_hex_number
56-
[[nodiscard]] constexpr const_utils::expected<u8, std::string> single_hex_number(char input) {
56+
[[nodiscard]] constexpr const_utils::Expected<u8, std::string> single_hex_number(char input) {
5757
if (input >= '0' && input <= '9') {
58-
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(input - '0'));
58+
return const_utils::Expected<u8, std::string>::good_result(static_cast<u8>(input - '0'));
5959
}
6060

6161
if (input >= 'A' && input <= 'F') {
62-
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(input - 'A' + 10));
62+
return const_utils::Expected<u8, std::string>::good_result(static_cast<u8>(input - 'A' + 10));
6363
}
6464

6565
if (input >= 'a' && input <= 'f') {
66-
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(input - 'a' + 10));
66+
return const_utils::Expected<u8, std::string>::good_result(static_cast<u8>(input - 'a' + 10));
6767
}
6868

69-
return const_utils::expected<u8, std::string>::error_result("the input must be a valid hex character");
69+
return const_utils::Expected<u8, std::string>::error_result("the input must be a valid hex character");
7070
}
7171

7272
// decode a single 2 digit color value in hex
73-
[[nodiscard]] constexpr const_utils::expected<u8, std::string> single_hex_color_value(const char* input) {
73+
[[nodiscard]] constexpr const_utils::Expected<u8, std::string> single_hex_color_value(const char* input) {
7474

7575
const auto first = single_hex_number(input[0]); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
7676

@@ -80,14 +80,14 @@ namespace { //NOLINT(cert-dcl59-cpp,google-build-namespaces)
8080

8181
PROPAGATE(second, u8, std::string);
8282

83-
return const_utils::expected<u8, std::string>::good_result((first.value() << 4) | second.value());
83+
return const_utils::Expected<u8, std::string>::good_result((first.value() << 4) | second.value());
8484
}
8585

86-
[[nodiscard]] constexpr const_utils::expected<sdl::GUID, std::string>
86+
[[nodiscard]] constexpr const_utils::Expected<sdl::GUID, std::string>
8787
get_guid_from_string_impl(const char* input, std::size_t size) {
8888

8989
if (size == 0) {
90-
return const_utils::expected<sdl::GUID, std::string>::error_result(
90+
return const_utils::Expected<sdl::GUID, std::string>::error_result(
9191
"not enough data to determine the literal type"
9292
);
9393
}
@@ -102,7 +102,7 @@ namespace { //NOLINT(cert-dcl59-cpp,google-build-namespaces)
102102
width = 3;
103103
} else {
104104

105-
return const_utils::expected<sdl::GUID, std::string>::error_result("Unrecognized guid literal");
105+
return const_utils::Expected<sdl::GUID, std::string>::error_result("Unrecognized guid literal");
106106
}
107107

108108

@@ -122,15 +122,15 @@ namespace { //NOLINT(cert-dcl59-cpp,google-build-namespaces)
122122
result.at(i) = value;
123123
}
124124

125-
return const_utils::expected<sdl::GUID, std::string>::good_result(sdl::GUID{ result });
125+
return const_utils::Expected<sdl::GUID, std::string>::good_result(sdl::GUID{ result });
126126
}
127127

128128
} // namespace
129129

130130

131131
namespace detail {
132132

133-
[[nodiscard]] constexpr const_utils::expected<sdl::GUID, std::string> get_guid_from_string(const std::string& input
133+
[[nodiscard]] constexpr const_utils::Expected<sdl::GUID, std::string> get_guid_from_string(const std::string& input
134134
) {
135135
return get_guid_from_string_impl(input.c_str(), input.size());
136136
}

src/input/joystick_input.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,10 @@ helper::optional<InputEvent> input::ConsoleJoystickGameInput::sdl_event_to_input
813813
const auto button = event.jbutton.button;
814814

815815
if (button == m_settings.pause) {
816-
return MenuEvent::PAUSE;
816+
return MenuEvent::Pause;
817817
}
818818
if (button == m_settings.open_settings) {
819-
return MenuEvent::OPEN_SETTINGS;
819+
return MenuEvent::OpenSettings;
820820
}
821821
}
822822

@@ -826,9 +826,9 @@ helper::optional<InputEvent> input::ConsoleJoystickGameInput::sdl_event_to_input
826826

827827
[[nodiscard]] std::string input::ConsoleJoystickGameInput::describe_menu_event(MenuEvent event) const {
828828
switch (event) {
829-
case input::MenuEvent::PAUSE:
829+
case input::MenuEvent::Pause:
830830
return m_underlying_joystick_input->key_to_string(m_settings.pause);
831-
case input::MenuEvent::OPEN_SETTINGS:
831+
case input::MenuEvent::OpenSettings:
832832
return m_underlying_joystick_input->key_to_string(m_settings.open_settings);
833833
default:
834834
utils::unreachable();

src/input/keyboard_input.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ SDL::Key json_helper::get_key(const nlohmann::json& j, const std::string& name)
191191
if (event.type == SDL_KEYDOWN and event.key.repeat == 0) {
192192
const auto key = SDL::Key{ event.key.keysym };
193193
if (key == m_settings.pause) {
194-
return MenuEvent::PAUSE;
194+
return MenuEvent::Pause;
195195
}
196196
if (key == m_settings.open_settings) {
197-
return MenuEvent::OPEN_SETTINGS;
197+
return MenuEvent::OpenSettings;
198198
}
199199
}
200200

@@ -203,9 +203,9 @@ SDL::Key json_helper::get_key(const nlohmann::json& j, const std::string& name)
203203

204204
[[nodiscard]] std::string input::KeyboardGameInput::describe_menu_event(MenuEvent event) const {
205205
switch (event) {
206-
case input::MenuEvent::PAUSE:
206+
case input::MenuEvent::Pause:
207207
return m_settings.pause.to_string();
208-
case input::MenuEvent::OPEN_SETTINGS:
208+
case input::MenuEvent::OpenSettings:
209209
return m_settings.open_settings.to_string();
210210
default:
211211
utils::unreachable();

src/input/replay_input.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void input::ReplayGameInput::update(const SimulationStep simulation_step_index)
1515

1616
const auto& record = m_recording_reader->at(m_next_record_index);
1717

18-
if (record.tetrion_index != m_target_tetrion->tetrion_index()) {
18+
if (record.tetrion_index != target_tetrion()->tetrion_index()) {
1919
// the current record is not for this tetrion => discard record and keep reading
2020
++m_next_record_index;
2121
continue;
@@ -46,20 +46,20 @@ void input::ReplayGameInput::late_update(const SimulationStep simulation_step_in
4646
}
4747

4848
const auto& snapshot = m_recording_reader->snapshots().at(m_next_snapshot_index);
49-
if (snapshot.tetrion_index() != m_target_tetrion->tetrion_index()) {
49+
if (snapshot.tetrion_index() != target_tetrion()->tetrion_index()) {
5050
++m_next_snapshot_index;
5151
continue;
5252
}
5353

5454
// the snapshot corresponds to this tetrion
55-
assert(snapshot.tetrion_index() == m_target_tetrion->tetrion_index());
55+
assert(snapshot.tetrion_index() == target_tetrion()->tetrion_index());
5656

5757
if (snapshot.simulation_step_index() != simulation_step_index) {
5858
break;
5959
}
6060

6161
// create a snapshot from the current state of the tetrion and compare it to the loaded snapshot
62-
const auto current_snapshot = TetrionSnapshot{ m_target_tetrion->core_information(), simulation_step_index };
62+
const auto current_snapshot = TetrionSnapshot{ target_tetrion()->core_information(), simulation_step_index };
6363

6464

6565
spdlog::info("comparing tetrion snapshots at simulation_step {}", simulation_step_index);

0 commit comments

Comments
 (0)