Skip to content

Commit 1c84c21

Browse files
committed
fix: fix a few minor issues regarding the curl http backend
also fix clang-tidy warnings
1 parent 2221570 commit 1c84c21

File tree

7 files changed

+65
-41
lines changed

7 files changed

+65
-41
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# taken from https://github.com/cpp-linter/cpp-linter-action/blob/main/demo/.clang-tidy
22
---
3-
Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,google-*,llvm-*,cert-*,-modernize-use-trailing-return-type,-bugprone-argument-comment,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-readability-avoid-nested-conditional-operator,-llvm-namespace-comment,-llvm-header-guard"
3+
Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,google-*,llvm-*,cert-*,-modernize-use-trailing-return-type,-bugprone-argument-comment,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-readability-avoid-nested-conditional-operator,-llvm-namespace-comment,-llvm-header-guard,-google-build-explicit-make-pair"
44
WarningsAsErrors: ""
55
HeaderFilterRegex: "oopetris/src/.*"
66
FormatStyle: "file"

src/lobby/api.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ helper::expected<void, std::string> lobby::API::join_lobby(int lobby_id) {
129129
};
130130
}
131131

132-
auto res = m_client->Post(fmt::format("/lobbies/{}", lobby_id));
132+
auto res = m_client->Post(fmt::format("/lobbies/{}", lobby_id), std::nullopt);
133133

134134
return is_request_ok(res, 204);
135135
}
@@ -168,7 +168,7 @@ helper::expected<void, std::string> lobby::API::leave_lobby(int lobby_id) {
168168
};
169169
}
170170

171-
auto res = m_client->Put(fmt::format("/lobbies/{}/leave", lobby_id));
171+
auto res = m_client->Put(fmt::format("/lobbies/{}/leave", lobby_id), std::nullopt);
172172

173173
return is_request_ok(res, 204);
174174
}
@@ -181,7 +181,7 @@ helper::expected<void, std::string> lobby::API::start_lobby(int lobby_id) {
181181
};
182182
}
183183

184-
auto res = m_client->Post(fmt::format("/lobbies/{}/start", lobby_id));
184+
auto res = m_client->Post(fmt::format("/lobbies/{}/start", lobby_id), std::nullopt);
185185

186186
return is_request_ok(res, 204);
187187
}

src/lobby/client.hpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
namespace oopetris::http {
1919

20-
struct Result {
20+
21+
struct Result { //NOLINT(cppcoreguidelines-special-member-functions)
2122
OOPETRIS_GRAPHICS_EXPORTED virtual ~Result();
2223

2324
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] virtual std::optional<std::string> get_header(const std::string& key
@@ -30,34 +31,42 @@ namespace oopetris::http {
3031
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] virtual std::optional<std::string> get_error() const = 0;
3132
};
3233

33-
struct Client {
34+
struct Client { //NOLINT(cppcoreguidelines-special-member-functions)
3435
OOPETRIS_GRAPHICS_EXPORTED virtual ~Client();
3536

36-
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] virtual std::unique_ptr<Result> Get(const std::string& url) = 0;
37+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] virtual std::unique_ptr<Result>
38+
Get( //NOLINT(readability-identifier-naming)
39+
const std::string& url
40+
) = 0;
3741

38-
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] virtual std::unique_ptr<Result> Delete(const std::string& url) = 0;
42+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] virtual std::unique_ptr<Result>
43+
Delete( //NOLINT(readability-identifier-naming)
44+
const std::string& url
45+
) = 0;
3946

40-
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] virtual std::unique_ptr<Result> Post(
47+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] virtual std::unique_ptr<Result>
48+
Post( //NOLINT(readability-identifier-naming)
4149
const std::string& url,
42-
const std::optional<std::pair<std::string, std::string>>& payload = std::nullopt
50+
const std::optional<std::pair<std::string, std::string>>& payload
4351
) = 0;
4452

45-
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] virtual std::unique_ptr<Result> Put(
53+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] virtual std::unique_ptr<Result>
54+
Put( //NOLINT(readability-identifier-naming)
4655
const std::string& url,
47-
const std::optional<std::pair<std::string, std::string>>& payload = std::nullopt
56+
const std::optional<std::pair<std::string, std::string>>& payload
4857
) = 0;
4958

50-
OOPETRIS_GRAPHICS_EXPORTED virtual void SetBearerAuth(const std::string& token) = 0;
59+
OOPETRIS_GRAPHICS_EXPORTED virtual void SetBearerAuth( //NOLINT(readability-identifier-naming)
60+
const std::string& token
61+
) = 0;
5162
};
5263

53-
5464
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::string status_message(int status);
5565

5666
OOPETRIS_GRAPHICS_EXPORTED helper::expected<std::string, std::string> is_json_response(
5767
const std::unique_ptr<oopetris::http::Result>& result
5868
);
5969

60-
6170
OOPETRIS_GRAPHICS_EXPORTED helper::expected<lobby::ErrorResponse, std::string> is_error_message_response(
6271
const std::unique_ptr<oopetris::http::Result>& result
6372
);

src/lobby/curl_client.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
#include "./curl_client.hpp"
33

44

5-
#define TRANSFORM_RESULT(result) std::make_unique<ActualResult>((result))
5+
#define TRANSFORM_RESULT(result) std::make_unique<ActualResult>((result)) //NOLINT(cppcoreguidelines-macro-usage)
66

77

88
oopetris::http::implementation::ActualResult::ActualResult(cpr::Response&& result) : m_result{ std::move(result) } { }
99

1010
oopetris::http::implementation::ActualResult::~ActualResult() = default;
1111

12+
oopetris::http::implementation::ActualResult::ActualResult(ActualResult&& other) noexcept
13+
: m_result{ std::move(other.m_result) } { }
14+
1215
[[nodiscard]] std::optional<std::string> oopetris::http::implementation::ActualResult::get_header(const std::string& key
1316
) const {
1417

@@ -24,7 +27,7 @@ oopetris::http::implementation::ActualResult::~ActualResult() = default;
2427
}
2528

2629
[[nodiscard]] int oopetris::http::implementation::ActualResult::status() const {
27-
return m_result.status_code;
30+
return static_cast<int>(m_result.status_code);
2831
}
2932

3033
[[nodiscard]] std::optional<std::string> oopetris::http::implementation::ActualResult::get_error() const {
@@ -40,7 +43,7 @@ oopetris::http::implementation::ActualResult::~ActualResult() = default;
4043
namespace {
4144
std::string normalize_url(const std::string& value) {
4245
if (value.ends_with("/")) {
43-
value.substr(0, value.size() - 1);
46+
return value.substr(0, value.size() - 1);
4447
}
4548

4649
return value;
@@ -52,9 +55,9 @@ oopetris::http::implementation::ActualClient::ActualClient(ActualClient&& other)
5255

5356
oopetris::http::implementation::ActualClient::~ActualClient() = default;
5457

58+
5559
oopetris::http::implementation::ActualClient::ActualClient(const std::string& api_url)
56-
: m_session{},
57-
m_base_url{ normalize_url(api_url) } {
60+
: m_base_url{ normalize_url(api_url) } {
5861

5962
m_session.SetUrl(cpr::Url{ api_url });
6063
m_session.SetAcceptEncoding(cpr::AcceptEncoding{

src/lobby/curl_client.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ namespace oopetris::http::implementation {
1414

1515

1616
public:
17-
OOPETRIS_GRAPHICS_EXPORTED ActualResult(cpr::Response&& result);
17+
OOPETRIS_GRAPHICS_EXPORTED explicit ActualResult(cpr::Response&& result);
1818

1919
OOPETRIS_GRAPHICS_EXPORTED ~ActualResult() override;
2020

21+
OOPETRIS_GRAPHICS_EXPORTED ActualResult(ActualResult&& other) noexcept;
22+
OOPETRIS_GRAPHICS_EXPORTED ActualResult& operator=(ActualResult&& other) noexcept = delete;
23+
24+
OOPETRIS_GRAPHICS_EXPORTED ActualResult(const ActualResult& other) = delete;
25+
OOPETRIS_GRAPHICS_EXPORTED ActualResult& operator=(const ActualResult& other) = delete;
26+
2127
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::optional<std::string> get_header(const std::string& key
2228
) const override;
2329

@@ -51,15 +57,11 @@ namespace oopetris::http::implementation {
5157

5258
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<Result> Delete(const std::string& url) override;
5359

54-
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<Result> Post(
55-
const std::string& url,
56-
const std::optional<std::pair<std::string, std::string>>& payload = std::nullopt
57-
) override;
60+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<Result>
61+
Post(const std::string& url, const std::optional<std::pair<std::string, std::string>>& payload) override;
5862

59-
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<Result> Put(
60-
const std::string& url,
61-
const std::optional<std::pair<std::string, std::string>>& payload = std::nullopt
62-
) override;
63+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<Result>
64+
Put(const std::string& url, const std::optional<std::pair<std::string, std::string>>& payload) override;
6365

6466
OOPETRIS_GRAPHICS_EXPORTED void SetBearerAuth(const std::string& token) override;
6567
};

src/lobby/httplib_client.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
#include "./httplib_client.hpp"
33

44

5-
#define TRANSFORM_RESULT(result) std::make_unique<ActualResult>((result))
5+
#define TRANSFORM_RESULT(result) std::make_unique<ActualResult>((result)) //NOLINT(cppcoreguidelines-macro-usage
66

77

88
oopetris::http::implementation::ActualResult::ActualResult(httplib::Result&& result) : m_result{ std::move(result) } { }
99

1010
oopetris::http::implementation::ActualResult::~ActualResult() = default;
1111

12+
13+
oopetris::http::implementation::ActualResult::ActualResult(ActualResult&& other) noexcept
14+
: m_result{ std::move(other.m_result) } { }
15+
1216
[[nodiscard]] std::optional<std::string> oopetris::http::implementation::ActualResult::get_header(const std::string& key
1317
) const {
1418
if (m_result->has_header(key)) {
@@ -67,11 +71,15 @@ oopetris::http::implementation::ActualClient::ActualClient(const std::string& ap
6771
#endif
6872
}
6973

70-
[[nodiscard]] std::unique_ptr<oopetris::http::Result> oopetris::http::implementation::ActualClient::Get(const std::string& url) {
74+
[[nodiscard]] std::unique_ptr<oopetris::http::Result> oopetris::http::implementation::ActualClient::Get(
75+
const std::string& url
76+
) {
7177
return TRANSFORM_RESULT(m_client.Get(url));
7278
}
7379

74-
[[nodiscard]] std::unique_ptr<oopetris::http::Result> oopetris::http::implementation::ActualClient::Delete(const std::string& url) {
80+
[[nodiscard]] std::unique_ptr<oopetris::http::Result> oopetris::http::implementation::ActualClient::Delete(
81+
const std::string& url
82+
) {
7583
return TRANSFORM_RESULT(m_client.Delete(url));
7684
}
7785

src/lobby/httplib_client.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ namespace oopetris::http::implementation {
2929
httplib::Result m_result;
3030

3131
public:
32-
OOPETRIS_GRAPHICS_EXPORTED ActualResult(httplib::Result&& result);
32+
OOPETRIS_GRAPHICS_EXPORTED explicit ActualResult(httplib::Result&& result);
3333

3434
OOPETRIS_GRAPHICS_EXPORTED ~ActualResult() override;
3535

36+
OOPETRIS_GRAPHICS_EXPORTED ActualResult(ActualResult&& other) noexcept;
37+
OOPETRIS_GRAPHICS_EXPORTED ActualResult& operator=(ActualResult&& other) noexcept = delete;
38+
39+
OOPETRIS_GRAPHICS_EXPORTED ActualResult(const ActualResult& other) = delete;
40+
OOPETRIS_GRAPHICS_EXPORTED ActualResult& operator=(const ActualResult& other) = delete;
41+
3642
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::optional<std::string> get_header(const std::string& key
3743
) const override;
3844

@@ -63,15 +69,11 @@ namespace oopetris::http::implementation {
6369

6470
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<Result> Delete(const std::string& url) override;
6571

66-
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<Result> Post(
67-
const std::string& url,
68-
const std::optional<std::pair<std::string, std::string>>& payload = std::nullopt
69-
) override;
72+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<Result>
73+
Post(const std::string& url, const std::optional<std::pair<std::string, std::string>>& payload) override;
7074

71-
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<Result> Put(
72-
const std::string& url,
73-
const std::optional<std::pair<std::string, std::string>>& payload = std::nullopt
74-
) override;
75+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<Result>
76+
Put(const std::string& url, const std::optional<std::pair<std::string, std::string>>& payload) override;
7577

7678
OOPETRIS_GRAPHICS_EXPORTED void SetBearerAuth(const std::string& token) override;
7779
};

0 commit comments

Comments
 (0)