Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code refactoring] Fix clang-tidy warnings #509

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/api/common/src/commonapi.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "commonapi.hpp"

#include <cstdint>
#include <mutex>
#include <string_view>
#include <utility>

#include "cachedresult.hpp"
#include "cct_exception.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_string.hpp"
#include "cct_vector.hpp"
#include "coincenterinfo.hpp"
#include "curloptions.hpp"
#include "currencycode.hpp"
Expand Down
5 changes: 4 additions & 1 deletion src/api/common/src/exchangepublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

#include <algorithm>
#include <cmath>
#include <compare>
#include <cstddef>
#include <functional>
#include <mutex>
#include <optional>
#include <ranges>
#include <string_view>
Expand Down Expand Up @@ -104,7 +107,7 @@ namespace {
// Struct containing a currency and additional information to create markets with detailed information (order, market
// type)
struct CurrencyDir {
constexpr auto operator<=>(const CurrencyDir &) const noexcept = default;
constexpr std::strong_ordering operator<=>(const CurrencyDir &) const noexcept = default;

CurrencyCode cur;
bool isLastRealMarketReversed = false;
Expand Down
5 changes: 5 additions & 0 deletions src/api/common/src/withdrawalfees-crawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@

#include "cachedresultvault.hpp"
#include "cct_cctype.hpp"
#include "cct_const.hpp"
#include "cct_exception.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_string.hpp"
#include "coincenterinfo.hpp"
#include "curloptions.hpp"
#include "currencycode.hpp"
#include "file.hpp"
#include "httprequesttype.hpp"
#include "monetaryamount.hpp"
#include "timedef.hpp"

namespace cct {
Expand Down
1 change: 1 addition & 0 deletions src/api/common/test/commonapi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "coincenterinfo.hpp"
#include "runmodes.hpp"
#include "timedef.hpp"

namespace cct::api {

Expand Down
3 changes: 2 additions & 1 deletion src/api/common/test/exchangepublicapi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "cct_const.hpp"
#include "cct_exception.hpp"
#include "cct_string.hpp"
#include "coincenterinfo.hpp"
#include "commonapi.hpp"
#include "currencycode.hpp"
Expand All @@ -28,7 +29,7 @@
namespace cct::api {
namespace {
class StableCoinReader : public Reader {
string readAll() const override { return R"({"USDT": "USD"})"; }
[[nodiscard]] string readAll() const override { return R"({"USDT": "USD"})"; }
};
} // namespace
class ExchangePublicTest : public ::testing::Test {
Expand Down
2 changes: 1 addition & 1 deletion src/api/common/test/fiatconverter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CurlHandle::CurlHandle([[maybe_unused]] BestURLPicker bestURLPicker,
[[maybe_unused]] AbstractMetricGateway *pMetricGateway,
[[maybe_unused]] const PermanentCurlOptions &permanentCurlOptions,
[[maybe_unused]] settings::RunMode runMode)
: _handle(nullptr), _bestUrlPicker(kSomeFakeURL) {}
: _bestURLPicker(kSomeFakeURL) {}

// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
std::string_view CurlHandle::query([[maybe_unused]] std::string_view endpoint, const CurlOptions &opts) {
Expand Down
1 change: 1 addition & 0 deletions src/api/exchanges/src/binanceprivateapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "httprequesttype.hpp"
#include "market.hpp"
#include "monetaryamount.hpp"
#include "monetaryamountbycurrencyset.hpp"
#include "order.hpp"
#include "orderid.hpp"
#include "ordersconstraints.hpp"
Expand Down
3 changes: 1 addition & 2 deletions src/api/exchanges/src/huobipublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
#include <algorithm>
#include <array>
#include <cstdint>
#include <memory>
#include <optional>
#include <string_view>
#include <unordered_map>
#include <utility>

#include "apiquerytypeenum.hpp"
#include "cachedresult.hpp"
#include "cct_exception.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_string.hpp"
Expand All @@ -34,6 +32,7 @@
#include "market.hpp"
#include "marketorderbook.hpp"
#include "monetaryamount.hpp"
#include "monetaryamountbycurrencyset.hpp"
#include "permanentcurloptions.hpp"
#include "timedef.hpp"
#include "toupperlower-string.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/api/exchanges/src/krakenpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "market.hpp"
#include "marketorderbook.hpp"
#include "monetaryamount.hpp"
#include "monetaryamountbycurrencyset.hpp"
#include "permanentcurloptions.hpp"
#include "timedef.hpp"
#include "tradeside.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/src/kucoinpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "apiquerytypeenum.hpp"
#include "cachedresult.hpp"
#include "cct_exception.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_string.hpp"
Expand All @@ -32,6 +31,7 @@
#include "market.hpp"
#include "marketorderbook.hpp"
#include "monetaryamount.hpp"
#include "monetaryamountbycurrencyset.hpp"
#include "permanentcurloptions.hpp"
#include "stringhelpers.hpp"
#include "timedef.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/src/upbitprivateapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ OrderInfo UpbitPrivate::queryOrderInfo(OrderIdView orderId, const TradeContext&
std::optional<MonetaryAmount> UpbitPrivate::WithdrawFeesFunc::operator()(CurrencyCode currencyCode) {
auto curStr = currencyCode.str();
json result = PrivateQuery(_curlHandle, _apiKey, HttpRequestType::kGet, "/v1/withdraws/chance",
{{"currency", std::string_view(curStr)}, {"net_type", std::string_view(curStr)}});
{{"currency", std::string_view{curStr}}, {"net_type", std::string_view{curStr}}});
std::string_view amountStr = result["currency"]["withdraw_fee"].get<std::string_view>();
return MonetaryAmount(amountStr, currencyCode);
}
Expand Down
1 change: 1 addition & 0 deletions src/api/exchanges/src/upbitpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "market.hpp"
#include "marketorderbook.hpp"
#include "monetaryamount.hpp"
#include "monetaryamountbycurrencyset.hpp"
#include "permanentcurloptions.hpp"
#include "timedef.hpp"
#include "tradeside.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/engine/src/exchangesorchestrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "market.hpp"
#include "marketorderbook.hpp"
#include "monetaryamount.hpp"
#include "monetaryamountbycurrencyset.hpp"
#include "ordersconstraints.hpp"
#include "queryresulttypes.hpp"
#include "requestsconfig.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/engine/src/queryresultprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "apioutputtype.hpp"
#include "balanceperexchangeportfolio.hpp"
#include "cct_const.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_string.hpp"
Expand All @@ -32,6 +31,7 @@
#include "orderid.hpp"
#include "ordersconstraints.hpp"
#include "priceoptions.hpp"
#include "priceoptionsdef.hpp"
#include "publictrade.hpp"
#include "queryresulttypes.hpp"
#include "simpletable.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/engine/test/queryresultprinter_public_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "exchangepublicapitypes.hpp"
#include "market.hpp"
#include "marketorderbook.hpp"
#include "monetaryamountbycurrencyset.hpp"
#include "publictrade.hpp"
#include "queryresultprinter.hpp"
#include "queryresultprinter_base_test.hpp"
Expand Down
4 changes: 2 additions & 2 deletions src/http-request/include/curlhandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CurlHandle {
/// The pointed memory is valid until a next call to 'query'.
std::string_view query(std::string_view endpoint, const CurlOptions &opts);

std::string_view getNextBaseUrl() const { return _bestUrlPicker.getNextBaseURL(); }
std::string_view getNextBaseUrl() const { return _bestURLPicker.getNextBaseURL(); }

Duration minDurationBetweenQueries() const { return _minDurationBetweenQueries; }

Expand All @@ -78,7 +78,7 @@ class CurlHandle {
AbstractMetricGateway *_pMetricGateway = nullptr; // non-owning pointer
Duration _minDurationBetweenQueries{};
TimePoint _lastQueryTime{};
BestURLPicker _bestUrlPicker;
BestURLPicker _bestURLPicker;
string _queryData;
log::level::level_enum _requestCallLogLevel = log::level::level_enum::off;
log::level::level_enum _requestAnswerLogLevel = log::level::level_enum::off;
Expand Down
14 changes: 7 additions & 7 deletions src/http-request/src/curlhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ CurlHandle::CurlHandle(BestURLPicker bestURLPicker, AbstractMetricGateway *pMetr
const PermanentCurlOptions &permanentCurlOptions, settings::RunMode runMode)
: _pMetricGateway(pMetricGateway),
_minDurationBetweenQueries(permanentCurlOptions.minDurationBetweenQueries()),
_bestUrlPicker(std::move(bestURLPicker)),
_bestURLPicker(std::move(bestURLPicker)),
_requestCallLogLevel(permanentCurlOptions.requestCallLogLevel()),
_requestAnswerLogLevel(permanentCurlOptions.requestAnswerLogLevel()),
_nbMaxRetries(permanentCurlOptions.nbMaxRetries()),
Expand Down Expand Up @@ -120,7 +120,7 @@ CurlHandle::CurlHandle(BestURLPicker bestURLPicker, AbstractMetricGateway *pMetr
#endif

log::debug("Initialize CurlHandle for {} with {} as minimum duration between queries",
bestURLPicker.getNextBaseURL(), DurationToString(_minDurationBetweenQueries));
_bestURLPicker.getNextBaseURL(), DurationToString(_minDurationBetweenQueries));

if (settings::IsProxyRequested(runMode)) {
if (IsProxyAvailable()) {
Expand Down Expand Up @@ -151,8 +151,8 @@ std::string_view CurlHandle::query(std::string_view endpoint, const CurlOptions
const bool appendParametersInQueryStr =
!postData.empty() && (opts.requestType() != HttpRequestType::kPost || queryResponseOverrideMode);

const int8_t baseUrlPos = _bestUrlPicker.nextBaseURLPos();
const std::string_view baseUrl = _bestUrlPicker.getBaseURL(baseUrlPos);
const int8_t baseUrlPos = _bestURLPicker.nextBaseURLPos();
const std::string_view baseUrl = _bestURLPicker.getBaseURL(baseUrlPos);
const std::string_view postDataStr = postData.str();
string modifiedURL(baseUrl.size() + endpoint.size() + (appendParametersInQueryStr ? (1U + postDataStr.size()) : 0U),
'?');
Expand Down Expand Up @@ -262,7 +262,7 @@ std::string_view CurlHandle::query(std::string_view endpoint, const CurlOptions

// Store stats
const auto queryRTInMs = static_cast<uint32_t>(GetTimeFrom<TimeInMs>(t1).count());
_bestUrlPicker.storeResponseTimePerBaseURL(baseUrlPos, queryRTInMs);
_bestURLPicker.storeResponseTimePerBaseURL(baseUrlPos, queryRTInMs);

if (_pMetricGateway != nullptr) {
_pMetricGateway->add(MetricType::kCounter, MetricOperation::kIncrement,
Expand All @@ -274,7 +274,7 @@ std::string_view CurlHandle::query(std::string_view endpoint, const CurlOptions

// Periodic memory release to avoid memory leak for a very large number of requests
static constexpr int kReleaseMemoryRequestsFrequency = 100;
if ((_bestUrlPicker.nbRequestsDone() % kReleaseMemoryRequestsFrequency) == 0) {
if ((_bestURLPicker.nbRequestsDone() % kReleaseMemoryRequestsFrequency) == 0) {
_queryData.shrink_to_fit();
}

Expand Down Expand Up @@ -332,7 +332,7 @@ void CurlHandle::swap(CurlHandle &rhs) noexcept {
swap(_pMetricGateway, rhs._pMetricGateway);
swap(_minDurationBetweenQueries, rhs._minDurationBetweenQueries);
swap(_lastQueryTime, rhs._lastQueryTime);
swap(_bestUrlPicker, rhs._bestUrlPicker);
swap(_bestURLPicker, rhs._bestURLPicker);
_queryData.swap(rhs._queryData);
swap(_requestCallLogLevel, rhs._requestCallLogLevel);
swap(_requestAnswerLogLevel, rhs._requestAnswerLogLevel);
Expand Down
1 change: 1 addition & 0 deletions src/http-request/test/curlhandle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <gtest/gtest.h>

#include <string_view>
#include <utility>

#include "cct_exception.hpp"
#include "curloptions.hpp"
Expand Down
5 changes: 4 additions & 1 deletion src/objects/include/file.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <cstdint>
#include <string_view>

#include "cct_json.hpp"
#include "cct_string.hpp"
#include "reader.hpp"
Expand All @@ -14,7 +17,7 @@ class File : public Reader, public Writer {

File(std::string_view dataDir, Type type, std::string_view name, IfError ifError);

string readAll() const override;
[[nodiscard]] string readAll() const override;

int write(const json &data, Writer::Mode mode = Writer::Mode::FromStart) const override;

Expand Down
2 changes: 1 addition & 1 deletion src/objects/include/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Reader {
virtual ~Reader() = default;

// Read all content and return a string of it.
virtual string readAll() const { return {}; }
[[nodiscard]] virtual string readAll() const { return {}; }

// Read all content, and constructs a json object from it.
json readAllJson() const;
Expand Down
1 change: 1 addition & 0 deletions src/objects/src/exchangeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "monetaryamount.hpp"
#include "monetaryamountbycurrencyset.hpp"
#include "timedef.hpp"
#include "tradeconfig.hpp"

namespace cct {

Expand Down
2 changes: 2 additions & 0 deletions src/objects/src/exchangeconfigmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "parseloglevel.hpp"
#include "priceoptionsdef.hpp"
#include "timedef.hpp"
#include "tradeconfig.hpp"
#include "tradedefinitions.hpp"

namespace cct {

Expand Down
1 change: 1 addition & 0 deletions src/objects/src/marketorderbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "priceoptions.hpp"
#include "priceoptionsdef.hpp"
#include "simpletable.hpp"
#include "timedef.hpp"
#include "unreachable.hpp"
#include "volumeandpricenbdecimals.hpp"

Expand Down
1 change: 1 addition & 0 deletions src/objects/src/priceoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "cct_invalid_argument_exception.hpp"
#include "cct_string.hpp"
#include "monetaryamount.hpp"
#include "priceoptionsdef.hpp"
#include "tradeconfig.hpp"

Expand Down
1 change: 1 addition & 0 deletions src/objects/test/exchangename_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <gtest/gtest.h>

#include "cct_exception.hpp"
#include "cct_log.hpp"

namespace cct {
TEST(ExchangeName, NoKeyName) {
Expand Down
3 changes: 3 additions & 0 deletions src/objects/test/market_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <gtest/gtest.h>

#include "cct_exception.hpp"
#include "currencycode.hpp"

namespace cct {
TEST(MarketTest, DefaultConstructor) {
Market market;
Expand Down
12 changes: 6 additions & 6 deletions src/tech/include/fbstring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class fbstring_core {

void push_back(Char c) { *expandNoinit(1, /* expGrowth = */ true) = c; }

size_t size() const {
size_t size() const noexcept {
size_t ret = ml_.size_;
if constexpr (kIsLittleEndian) {
// We can save a couple instructions, because the category is
Expand All @@ -549,7 +549,7 @@ class fbstring_core {
return ret;
}

size_t capacity() const {
size_t capacity() const noexcept {
FOLLY_PUSH_WARNING
FOLLY_CLANG_DISABLE_WARNING("-Wcovered-switch-default")
switch (category()) {
Expand Down Expand Up @@ -1338,15 +1338,15 @@ class basic_fbstring {
}

// C++11 21.4.4 capacity:
size_type size() const { return store_.size(); }
size_type size() const noexcept { return store_.size(); }

size_type length() const { return size(); }
size_type length() const noexcept { return size(); }

size_type max_size() const { return std::numeric_limits<size_type>::max(); }
size_type max_size() const noexcept { return std::numeric_limits<size_type>::max(); }

void resize(size_type n, value_type c = value_type());

size_type capacity() const { return store_.capacity(); }
size_type capacity() const noexcept { return store_.capacity(); }

void reserve(size_type res_arg = 0) {
enforce<std::length_error>(res_arg <= max_size(), "");
Expand Down
Loading
Loading