Skip to content

Commit 55f6c4b

Browse files
committed
clang-tidy:
- fix more errors
1 parent 9fc93e3 commit 55f6c4b

22 files changed

+185
-113
lines changed

src/helper/errors.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ helper::GeneralError::GeneralError(const GeneralError& error) noexcept = default
1414
[[nodiscard]] helper::GeneralError& helper::GeneralError::operator=(const GeneralError& error) noexcept = default;
1515

1616
helper::GeneralError::GeneralError(GeneralError&& error) noexcept = default;
17-
1817
[[nodiscard]] helper::GeneralError& helper::GeneralError::operator=(GeneralError&& error) noexcept = default;
1918

2019

src/helper/parse_json.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ std::string json::get_json_type(const nlohmann::json::value_t& type) {
3434
}
3535
}
3636

37-
void json::check_for_no_additional_keys(const nlohmann::json& j, const std::vector<std::string>& keys) {
37+
void json::check_for_no_additional_keys(const nlohmann::json& obj, const std::vector<std::string>& keys) {
3838

39-
if (not j.is_object()) {
39+
if (not obj.is_object()) {
4040
throw nlohmann::json::type_error::create(
41-
302, fmt::format("expected an object, but got type '{}'", get_json_type(j.type())), &j
41+
302, fmt::format("expected an object, but got type '{}'", get_json_type(obj.type())), &obj
4242
);
4343
}
4444

45-
const auto& object = j.get<nlohmann::json::object_t>();
45+
const auto& object = obj.get<nlohmann::json::object_t>();
4646

4747

4848
for (const auto& [key, _] : object) {
4949
if (std::ranges::find(keys, key) == keys.cend()) {
5050
throw nlohmann::json::type_error::create(
51-
302, fmt::format("object may only contain expected keys, but contained '{}'", key), &j
51+
302, fmt::format("object may only contain expected keys, but contained '{}'", key), &obj
5252
);
5353
}
5454
}

src/helper/parse_json.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
NLOHMANN_JSON_NAMESPACE_BEGIN
2424
template<typename T>
2525
struct adl_serializer<helper::optional<T>> {
26-
static void to_json(json& j, const helper::optional<T>& opt) {
26+
static void to_json(json& obj, const helper::optional<T>& opt) {
2727
if (not opt) {
28-
j = nullptr;
28+
obj = nullptr;
2929
} else {
30-
j = *opt; // this will call adl_serializer<T>::to_json which will
31-
// find the free function to_json in T's namespace!
30+
obj = *opt; // this will call adl_serializer<T>::to_json which will
31+
// find the free function to_json in T's namespace!
3232
}
3333
}
3434

35-
static void from_json(const json& j, helper::optional<T>& opt) {
36-
if (j.is_null()) {
35+
static void from_json(const json& obj, helper::optional<T>& opt) {
36+
if (obj.is_null()) {
3737
opt = helper::nullopt;
3838
} else {
39-
opt = j.template get<T>(); // same as above, but with
40-
// adl_serializer<T>::from_json
39+
opt = obj.template get<T>(); // same as above, but with
40+
// adl_serializer<T>::from_json
4141
}
4242
}
4343
};
@@ -111,7 +111,7 @@ namespace json {
111111

112112
std::string get_json_type(const nlohmann::json::value_t& type);
113113

114-
void check_for_no_additional_keys(const nlohmann::json& j, const std::vector<std::string>& keys);
114+
void check_for_no_additional_keys(const nlohmann::json& obj, const std::vector<std::string>& keys);
115115

116116

117117
} // namespace json

src/input/game_input.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ namespace input {
4545

4646
std::unordered_map<HoldableKey, u64> m_keys_hold;
4747
GameInputType m_input_type;
48-
49-
private:
5048
Tetrion* m_target_tetrion{};
51-
OnEventCallback m_on_event_callback{};
49+
OnEventCallback m_on_event_callback;
5250

5351
protected:
5452
explicit GameInput(GameInputType input_type) : m_input_type{ input_type } { }

src/input/guid.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ namespace { //NOLINT(cert-dcl59-cpp,google-build-namespaces)
109109
sdl::GUID::ArrayType result{};
110110

111111
for (size_t i = 0; i < amount; ++i) {
112-
size_t offset = i * (width);
112+
const size_t offset = i * width;
113113

114114

115115
const auto temp_result =

src/input/input.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ input::Input::Input(std::string name, InputType type) : m_name{ std::move(name)
2020

2121
input::Input::~Input() = default;
2222

23+
input::Input::Input(const Input& input) noexcept = default;
24+
[[nodiscard]] input::Input& input::Input::operator=(const Input& input) noexcept = default;
25+
26+
input::Input::Input(Input&& input) noexcept = default;
27+
[[nodiscard]] input::Input& input::Input::operator=(Input&& input) noexcept = default;
28+
2329
input::PointerEventHelper::PointerEventHelper(shapes::IPoint pos, PointerEvent event)
2430
: m_pos{ pos },
2531
m_event{ event } { }
@@ -306,7 +312,8 @@ namespace {
306312
} // namespace
307313

308314

309-
[[nodiscard]] helper::optional<std::shared_ptr<input::GameInput>> input::InputManager::get_game_input(
315+
[[nodiscard]] helper::optional<std::shared_ptr<input::GameInput>>
316+
input::InputManager::get_game_input( //NOLINT(readability-convert-member-functions-to-static)
310317
ServiceProvider* service_provider
311318
) {
312319

src/input/input.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@ namespace input {
3333

3434
public:
3535
Input(std::string name, InputType type);
36+
3637
virtual ~Input();
3738

39+
Input(const Input& input) noexcept;
40+
Input& operator=(const Input& input) noexcept;
41+
42+
Input(Input&& input) noexcept;
43+
Input& operator=(Input&& input) noexcept;
44+
3845
[[nodiscard]] const std::string& name() const;
3946
[[nodiscard]] InputType type();
4047

@@ -76,7 +83,7 @@ namespace input {
7683

7784
struct InputManager {
7885
private:
79-
std::vector<std::unique_ptr<Input>> m_inputs{};
86+
std::vector<std::unique_ptr<Input>> m_inputs;
8087

8188
public:
8289
explicit InputManager(const std::shared_ptr<Window>& window);

src/input/joystick_input.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ input::JoystickInput::~JoystickInput() {
2222
}
2323

2424

25+
input::JoystickInput::JoystickInput(const JoystickInput& input) noexcept = default;
26+
input::JoystickInput& input::JoystickInput::operator=(const JoystickInput& input) noexcept = default;
27+
28+
input::JoystickInput::JoystickInput(JoystickInput&& input) noexcept = default;
29+
input::JoystickInput& input::JoystickInput::operator=(JoystickInput&& input) noexcept = default;
30+
2531
[[nodiscard]] helper::optional<std::unique_ptr<input::JoystickInput>> input::JoystickInput::get_joystick_by_guid(
2632
const sdl::GUID& guid,
2733
SDL_Joystick* joystick,
@@ -558,6 +564,22 @@ input::_3DSJoystickInput_Type1::default_settings_raw() const {
558564
#endif
559565
#endif
560566

567+
input::JoystickGameInput::JoystickGameInput(EventDispatcher* event_dispatcher, JoystickInput* underlying_input)
568+
: GameInput{ GameInputType::Controller },
569+
m_event_dispatcher{ event_dispatcher },
570+
m_underlying_input{ underlying_input } {
571+
m_event_dispatcher->register_listener(this);
572+
}
573+
574+
575+
input::JoystickGameInput::~JoystickGameInput() {
576+
m_event_dispatcher->unregister_listener(this);
577+
}
578+
579+
input::JoystickGameInput::JoystickGameInput(JoystickGameInput&& input) noexcept = default;
580+
[[nodiscard]] input::JoystickGameInput& input::JoystickGameInput::operator=(JoystickGameInput&& input
581+
) noexcept = default;
582+
561583
void input::JoystickGameInput::handle_event(const SDL_Event& event) {
562584
m_event_buffer.push_back(event);
563585
}

src/input/joystick_input.hpp

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ namespace input {
6161
* @note regarding the NOLINT: the destructor just cleans up the SDL_Joystick, it has nothing to do with class members that would need special member functions to be explicitly defined
6262
*
6363
*/
64-
struct JoystickInput //NOLINT(cppcoreguidelines-special-member-functions)
65-
: Input {
64+
struct JoystickInput : Input {
6665
private:
6766
SDL_Joystick* m_joystick;
6867
SDL_JoystickID m_instance_id;
@@ -76,7 +75,14 @@ namespace input {
7675

7776
public:
7877
JoystickInput(SDL_Joystick* joystick, SDL_JoystickID instance_id, const std::string& name);
79-
~JoystickInput();
78+
79+
~JoystickInput() override;
80+
81+
JoystickInput(const JoystickInput& input) noexcept;
82+
JoystickInput& operator=(const JoystickInput& input) noexcept;
83+
84+
JoystickInput(JoystickInput&& input) noexcept;
85+
JoystickInput& operator=(JoystickInput&& input) noexcept;
8086

8187
[[nodiscard]] static helper::expected<std::unique_ptr<JoystickInput>, std::string> get_by_device_index(
8288
int device_index
@@ -204,21 +210,21 @@ namespace input {
204210
X_LIST_MACRO(open_settings)
205211

206212

207-
#define TRY_CONVERT(original, target, map, key) \
208-
do /*NOLINT(cppcoreguidelines-avoid-do-while)*/ { \
209-
if (map.contains(original.key)) { \
210-
target.key = map.at(original.key); \
211-
} else { \
212-
return helper::unexpected<std::string>{ \
213-
fmt::format("While parsing key '{}': '{}' is not a valid joystick input", #key, original.key) \
214-
}; \
215-
} \
213+
#define TRY_CONVERT(original, target, map, key) /*NOLINT(cppcoreguidelines-macro-usage)*/ \
214+
do /*NOLINT(cppcoreguidelines-avoid-do-while)*/ { \
215+
if ((map).contains((original).key)) { \
216+
(target).key = (map).at((original).key); \
217+
} else { \
218+
return helper::unexpected<std::string>{ \
219+
fmt::format("While parsing key '{}': '{}' is not a valid joystick input", #key, (original).key) \
220+
}; \
221+
} \
216222
} while (false)
217223

218224

219-
#define SETTINGS_TO_STRING(original, target, fn, key) \
220-
do /*NOLINT(cppcoreguidelines-avoid-do-while)*/ { \
221-
target.key = fn(original.key); \
225+
#define SETTINGS_TO_STRING(original, target, fn, key) /*NOLINT(cppcoreguidelines-macro-usage)*/ \
226+
do /*NOLINT(cppcoreguidelines-avoid-do-while)*/ { \
227+
(target).key = fn((original).key); \
222228
} while (false)
223229

224230

@@ -227,20 +233,23 @@ namespace input {
227233
std::vector<SDL_Event> m_event_buffer;
228234
EventDispatcher* m_event_dispatcher;
229235

230-
protected:
236+
231237
JoystickInput* m_underlying_input;
232238

239+
protected:
240+
[[nodiscard]] const JoystickInput* underlying_input() const;
241+
242+
233243
public:
234-
JoystickGameInput(EventDispatcher* event_dispatcher, JoystickInput* underlying_input)
235-
: GameInput{ GameInputType::Controller },
236-
m_event_dispatcher{ event_dispatcher },
237-
m_underlying_input{ underlying_input } {
238-
m_event_dispatcher->register_listener(this);
239-
}
244+
JoystickGameInput(EventDispatcher* event_dispatcher, JoystickInput* underlying_input);
240245

241-
~JoystickGameInput() override {
242-
m_event_dispatcher->unregister_listener(this);
243-
}
246+
~JoystickGameInput() override;
247+
248+
JoystickGameInput(const JoystickGameInput& input) = delete;
249+
[[nodiscard]] JoystickGameInput& operator=(const JoystickGameInput& input) = delete;
250+
251+
JoystickGameInput(JoystickGameInput&& input) noexcept;
252+
[[nodiscard]] JoystickGameInput& operator=(JoystickGameInput&& input) noexcept;
244253

245254
void handle_event(const SDL_Event& event) override;
246255

@@ -264,7 +273,7 @@ namespace input {
264273
AbstractJoystickSettings<T> result{};
265274

266275

267-
#define X_LIST_MACRO(x) TRY_CONVERT(settings, result, map, x);
276+
#define X_LIST_MACRO(x) TRY_CONVERT(settings, result, map, x); //NOLINT(cppcoreguidelines-macro-usage)
268277

269278
X_LIST_OF_SETTINGS_KEYS
270279

@@ -343,8 +352,8 @@ namespace nlohmann {
343352
return input::JoystickIdentification{ .guid = value.value(), .name = name };
344353
}
345354

346-
static void to_json(json& j, const input::JoystickIdentification& identification) {
347-
j = nlohmann::json{
355+
static void to_json(json& obj, const input::JoystickIdentification& identification) {
356+
obj = nlohmann::json{
348357
{ "guid", identification.guid.to_string(), { "name", identification.name } },
349358
};
350359
}
@@ -359,7 +368,7 @@ namespace nlohmann {
359368
"move_down", "drop", "hold", "menu" }
360369
);
361370

362-
input::JoystickIdentification identification =
371+
const input::JoystickIdentification identification =
363372
adl_serializer<input::JoystickIdentification>::from_json(obj.at("identification"));
364373

365374
const auto rotate_left = json_helper::get_key_from_object(obj, "rotate_left");

src/input/keyboard_input.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ input::KeyboardGameInput::~KeyboardGameInput() {
158158
}
159159

160160

161+
input::KeyboardGameInput::KeyboardGameInput(KeyboardGameInput&& input) noexcept = default;
162+
[[nodiscard]] input::KeyboardGameInput& input::KeyboardGameInput::operator=(KeyboardGameInput&& input
163+
) noexcept = default;
164+
165+
161166
[[nodiscard]] helper::expected<bool, std::string> input::KeyboardSettings::validate() const {
162167

163168
const std::vector<sdl::Key> to_use{ rotate_left, rotate_right, move_left, move_right, move_down,
@@ -166,9 +171,9 @@ input::KeyboardGameInput::~KeyboardGameInput() {
166171
return input::InputSettings::has_unique_members(to_use);
167172
}
168173

169-
sdl::Key json_helper::get_key(const nlohmann::json& j, const std::string& name) {
174+
sdl::Key json_helper::get_key(const nlohmann::json& obj, const std::string& name) {
170175

171-
auto context = j.at(name);
176+
auto context = obj.at(name);
172177

173178
std::string input;
174179
context.get_to(input);

0 commit comments

Comments
 (0)