Skip to content

Commit a72503c

Browse files
committed
clang-tidy:
- fix more errors
1 parent 1392129 commit a72503c

File tree

6 files changed

+46
-46
lines changed

6 files changed

+46
-46
lines changed

src/helper/color.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct Color {
144144

145145
[[nodiscard]] HSVColor to_hsv_color() const;
146146

147-
explicit constexpr Color(const HSVColor& color) {
147+
constexpr Color(const HSVColor& color) { //NOLINT(google-explicit-constructor)
148148

149149
using FloatType = double; //for more precision use "long double" here
150150

src/input/game_input.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ namespace input {
5050
Tetrion* m_target_tetrion{};
5151
OnEventCallback m_on_event_callback{};
5252

53-
GameInput(GameInputType input_type) : m_input_type{ input_type } { }
53+
explicit GameInput(GameInputType input_type) : m_input_type{ input_type } { }
5454

5555
void handle_event(InputEvent event, SimulationStep simulation_step_index);
5656

5757
public:
5858
virtual void update(SimulationStep simulation_step_index);
59-
virtual void late_update(SimulationStep){};
59+
virtual void late_update(SimulationStep /*simulation_step*/){};
6060

6161
[[nodiscard]] virtual helper::optional<MenuEvent> get_menu_event(const SDL_Event& event) const = 0;
6262

src/input/guid.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#include <fmt/format.h>
66
#include <fmt/ranges.h>
77

8-
SDL::GUID::GUID(const SDL_GUID& data) : m_guid{} {
8+
sdl::GUID::GUID(const SDL_GUID& data) : m_guid{} {
99
std::copy(std::begin(data.data), std::end(data.data), std::begin(m_guid));
1010
}
1111

12-
[[nodiscard]] helper::expected<SDL::GUID, std::string> SDL::GUID::from_string(const std::string& value) {
12+
[[nodiscard]] helper::expected<sdl::GUID, std::string> sdl::GUID::from_string(const std::string& value) {
1313

1414
const auto result = detail::get_guid_from_string(value);
1515

@@ -20,12 +20,12 @@ SDL::GUID::GUID(const SDL_GUID& data) : m_guid{} {
2020
return helper::unexpected<std::string>{ result.error() };
2121
}
2222

23-
[[nodiscard]] bool SDL::GUID::operator==(const GUID& other) const {
23+
[[nodiscard]] bool sdl::GUID::operator==(const GUID& other) const {
2424
return m_guid == other.m_guid;
2525
}
2626

2727

28-
[[nodiscard]] std::string SDL::GUID::to_string(FormatType type) const {
28+
[[nodiscard]] std::string sdl::GUID::to_string(FormatType type) const {
2929
switch (type) {
3030
case FormatType::Long: {
3131
return fmt::format("{:02x}", fmt::join(m_guid, ":"));

src/input/guid.hpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef SDL_JoystickGUID SDL_GUID; //NOLINT(modernize-use-using), it's used in e
1717
}
1818

1919

20-
namespace SDL {
20+
namespace sdl {
2121

2222
struct GUID {
2323
public:
@@ -27,43 +27,43 @@ namespace SDL {
2727
ArrayType m_guid;
2828

2929
public:
30-
enum class FormatType { Long, Short };
30+
enum class FormatType : u8 { Long, Short };
3131

3232
constexpr GUID() : m_guid{} { }
33-
constexpr GUID(const ArrayType& data) : m_guid{ data } { }
33+
explicit constexpr GUID(const ArrayType& data) : m_guid{ data } { }
3434

35-
GUID(const SDL_GUID& data);
35+
explicit GUID(const SDL_GUID& data);
3636

3737
[[nodiscard]] static helper::expected<GUID, std::string> from_string(const std::string& value);
3838

3939
[[nodiscard]] bool operator==(const GUID& other) const;
4040

4141
[[nodiscard]] std::string to_string(FormatType type = FormatType::Long) const;
4242
};
43-
} // namespace SDL
43+
} // namespace sdl
4444

4545

4646
template<>
47-
struct fmt::formatter<SDL::GUID> : formatter<std::string> {
48-
auto format(const SDL::GUID& guid, format_context& ctx) {
47+
struct fmt::formatter<sdl::GUID> : formatter<std::string> {
48+
auto format(const sdl::GUID& guid, format_context& ctx) {
4949
return formatter<std::string>::format(guid.to_string(), ctx);
5050
}
5151
};
5252

53-
namespace {
53+
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 n) {
57-
if (n >= '0' && n <= '9') {
58-
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(n - '0'));
56+
[[nodiscard]] constexpr const_utils::expected<u8, std::string> single_hex_number(char input) {
57+
if (input >= '0' && input <= '9') {
58+
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(input - '0'));
5959
}
6060

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

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

6969
return const_utils::expected<u8, std::string>::error_result("the input must be a valid hex character");
@@ -72,22 +72,22 @@ namespace {
7272
// decode a single 2 digit color value in hex
7373
[[nodiscard]] constexpr const_utils::expected<u8, std::string> single_hex_color_value(const char* input) {
7474

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

7777
PROPAGATE(first, u8, std::string);
7878

79-
const auto second = single_hex_number(input[1]);
79+
const auto second = single_hex_number(input[1]); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
8080

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

8383
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,11 +102,11 @@ namespace {
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

109-
SDL::GUID::ArrayType result{};
109+
sdl::GUID::ArrayType result{};
110110

111111
for (size_t i = 0; i < amount; ++i) {
112112
size_t offset = i * (width);
@@ -115,30 +115,30 @@ namespace {
115115
const auto temp_result =
116116
single_hex_color_value(input + offset); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
117117

118-
PROPAGATE(temp_result, SDL::GUID, std::string);
118+
PROPAGATE(temp_result, sdl::GUID, std::string);
119119

120120
const auto value = temp_result.value();
121121

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
}
137137

138138
} // namespace detail
139139

140140

141-
consteval SDL::GUID operator""_guid(const char* input, std::size_t size) {
141+
consteval sdl::GUID operator""_guid(const char* input, std::size_t size) {
142142
const auto result = get_guid_from_string_impl(input, size);
143143

144144
CONSTEVAL_STATIC_ASSERT(result.has_value(), "incorrect guid literal");

src/input/joystick_input.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ input::JoystickInput::~JoystickInput() {
2323

2424

2525
[[nodiscard]] helper::optional<std::unique_ptr<input::JoystickInput>> input::JoystickInput::get_joystick_by_guid(
26-
const SDL::GUID& guid,
26+
const sdl::GUID& guid,
2727
SDL_Joystick* joystick,
2828
SDL_JoystickID instance_id,
2929
const std::string& name
@@ -78,9 +78,9 @@ input::JoystickInput::get_by_device_index(int device_index) {
7878
}
7979

8080

81-
const auto guid = SDL::GUID{ SDL_JoystickGetGUID(joystick) };
81+
const auto guid = sdl::GUID{ SDL_JoystickGetGUID(joystick) };
8282

83-
if (guid == SDL::GUID{}) {
83+
if (guid == sdl::GUID{}) {
8484
return helper::unexpected<std::string>{ fmt::format("Failed to get joystick GUID: {}", SDL_GetError()) };
8585
}
8686

@@ -99,10 +99,10 @@ input::JoystickInput::get_by_device_index(int device_index) {
9999
return m_instance_id;
100100
}
101101

102-
[[nodiscard]] SDL::GUID input::JoystickInput::guid() const {
103-
const auto guid = SDL::GUID{ SDL_JoystickGetGUID(m_joystick) };
102+
[[nodiscard]] sdl::GUID input::JoystickInput::guid() const {
103+
const auto guid = sdl::GUID{ SDL_JoystickGetGUID(m_joystick) };
104104

105-
if (guid == SDL::GUID{}) {
105+
if (guid == sdl::GUID{}) {
106106
throw std::runtime_error{ fmt::format("Failed to get joystick GUID: {}", SDL_GetError()) };
107107
}
108108

@@ -572,7 +572,7 @@ void input::JoystickGameInput::update(SimulationStep simulation_step_index) {
572572
namespace {
573573

574574
[[nodiscard]] helper::optional<std::shared_ptr<input::JoystickGameInput>> get_game_joystick_by_guid(
575-
const SDL::GUID& guid,
575+
const sdl::GUID& guid,
576576
const input::JoystickSettings& settings,
577577
EventDispatcher* event_dispatcher,
578578
input::JoystickInput* underlying_input

src/input/joystick_input.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace input {
1919

2020
// essentially a GUID
2121
struct JoystickIdentification {
22-
SDL::GUID guid;
22+
sdl::GUID guid;
2323

2424
std::string name; //optional (can be ""), just for human readable settings
2525

@@ -68,7 +68,7 @@ namespace input {
6868
SDL_JoystickID m_instance_id;
6969

7070
[[nodiscard]] static helper::optional<std::unique_ptr<JoystickInput>> get_joystick_by_guid(
71-
const SDL::GUID& guid,
71+
const sdl::GUID& guid,
7272
SDL_Joystick* joystick,
7373
SDL_JoystickID instance_id,
7474
const std::string& name
@@ -84,7 +84,7 @@ namespace input {
8484

8585
[[nodiscard]] SDL_JoystickID instance_id() const;
8686

87-
[[nodiscard]] SDL::GUID guid() const;
87+
[[nodiscard]] sdl::GUID guid() const;
8888

8989
[[nodiscard]] virtual JoystickSettings default_settings() const = 0;
9090

@@ -144,7 +144,7 @@ namespace input {
144144
#if defined(__SWITCH__)
145145
struct SwitchJoystickInput_Type1 : ConsoleJoystickInput {
146146
//TODO
147-
static constexpr SDL::GUID guid{};
147+
static constexpr sdl::GUID guid{};
148148
SwitchJoystickInput_Type1(SDL_Joystick* joystick, SDL_JoystickID instance_id, const std::string& name);
149149

150150
[[nodiscard]] helper::optional<NavigationEvent> get_navigation_event(const SDL_Event& event) const override;
@@ -166,8 +166,8 @@ namespace input {
166166
struct _3DSJoystickInput_Type1 : ConsoleJoystickInput {
167167

168168
//TODO
169-
static constexpr SDL::GUID guid{
170-
SDL::GUID::ArrayType{ 0x00, 0x00, 0x10, 0x32, 0x4e, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x6f, 0x20, 0x33,
169+
static constexpr sdl::GUID guid{
170+
sdl::GUID::ArrayType{ 0x00, 0x00, 0x10, 0x32, 0x4e, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x6f, 0x20, 0x33,
171171
0x44, 0x00 }
172172
};
173173
_3DSJoystickInput_Type1(SDL_Joystick* joystick, SDL_JoystickID instance_id, const std::string& name);
@@ -325,7 +325,7 @@ namespace nlohmann {
325325
context.get_to(input);
326326

327327

328-
const auto& value = SDL::GUID::from_string(input);
328+
const auto& value = sdl::GUID::from_string(input);
329329

330330
if (not value.has_value()) {
331331
throw nlohmann::json::type_error::create(

0 commit comments

Comments
 (0)