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

Fix IWYU warnings of clang-tidy - activate check by default #468

Merged
merged 1 commit into from
Oct 25, 2023
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
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Checks: "-*,\
google-readability-casting,\
misc-*,\
-misc-non-private-member-variables-in-classes,\
-misc-include-cleaner,\
-misc-const-correctness,\
modernize-*,\
-modernize-avoid-c-arrays,\
Expand Down
1 change: 1 addition & 0 deletions src/api-objects/include/order.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string_view>

#include "cct_string.hpp"
#include "cct_type_traits.hpp"
#include "market.hpp"
#include "monetaryamount.hpp"
#include "orderid.hpp"
Expand Down
4 changes: 4 additions & 0 deletions src/api-objects/include/withdraw.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#include <utility>

#include "monetaryamount.hpp"
#include "timedef.hpp"
#include "withdrawordeposit.hpp"

namespace cct {
Expand Down
9 changes: 9 additions & 0 deletions src/api-objects/src/apikeysprovider.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#include "apikeysprovider.hpp"

#include <algorithm>
#include <iterator>
#include <string_view>
#include <utility>

#include "accountowner.hpp"
#include "apikey.hpp"
#include "cct_exception.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_string.hpp"
#include "exchangename.hpp"
#include "exchangesecretsinfo.hpp"
#include "file.hpp"
#include "runmodes.hpp"

namespace cct::api {
namespace {
Expand Down
7 changes: 7 additions & 0 deletions src/api-objects/src/order.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include "order.hpp"

#include <string_view>
#include <utility>

#include "cct_string.hpp"
#include "monetaryamount.hpp"
#include "timedef.hpp"
#include "timestring.hpp"
#include "tradeside.hpp"

namespace cct {

Expand Down
5 changes: 5 additions & 0 deletions src/api-objects/src/ordersconstraints.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "ordersconstraints.hpp"

#include <utility>

#include "currencycode.hpp"
#include "timedef.hpp"

namespace cct {

OrdersConstraints::OrdersConstraints(CurrencyCode cur1, CurrencyCode cur2, Duration minAge, Duration maxAge,
Expand Down
1 change: 1 addition & 0 deletions src/api-objects/src/publictrade.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "publictrade.hpp"

#include "cct_string.hpp"
#include "timestring.hpp"

namespace cct {
Expand Down
3 changes: 2 additions & 1 deletion src/api-objects/src/recentdeposit.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "recentdeposit.hpp"

#include <algorithm>
#include <chrono>
#include <memory>

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

namespace cct::api {
Expand Down
12 changes: 8 additions & 4 deletions src/api-objects/src/tradeoptions.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include "tradeoptions.hpp"

#include <stdexcept>
#include <chrono>
#include <string_view>

#include "cct_invalid_argument_exception.hpp"
#include "cct_string.hpp"
#include "priceoptions.hpp"
#include "stringhelpers.hpp"
#include "timedef.hpp"
#include "tradedefinitions.hpp"
#include "unreachable.hpp"

namespace cct {
Expand Down Expand Up @@ -75,9 +79,9 @@ string TradeOptions::str(bool placeRealOrderInSimulationMode) const {
ret.append(", ");
ret.append(tradeSyncPolicyStr());
ret.append(" mode, timeout of ");
AppendString(ret, std::chrono::duration_cast<std::chrono::seconds>(_maxTradeTime).count());
AppendString(ret, std::chrono::duration_cast<TimeInS>(_maxTradeTime).count());
ret.append("s, ").append(timeoutActionStr()).append(" at timeout, min time between two price updates of ");
AppendString(ret, std::chrono::duration_cast<std::chrono::seconds>(_minTimeBetweenPriceUpdates).count());
AppendString(ret, std::chrono::duration_cast<TimeInS>(_minTimeBetweenPriceUpdates).count());
ret.push_back('s');
return ret;
}
Expand Down
6 changes: 6 additions & 0 deletions src/api-objects/src/withdrawinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include "withdrawinfo.hpp"

#include <string_view>
#include <utility>

#include "cct_exception.hpp"
#include "monetaryamount.hpp"
#include "timedef.hpp"
#include "wallet.hpp"

namespace cct {
namespace api {
Expand Down
3 changes: 3 additions & 0 deletions src/api-objects/src/withdrawoptions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "withdrawoptions.hpp"

#include <string_view>

#include "timedef.hpp"
#include "unreachable.hpp"

namespace cct {
Expand Down
3 changes: 3 additions & 0 deletions src/api-objects/src/withdrawordeposit.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "withdrawordeposit.hpp"

#include <string_view>

#include "cct_string.hpp"
#include "timestring.hpp"
#include "unreachable.hpp"

Expand Down
7 changes: 7 additions & 0 deletions src/api-objects/src/withdrawsordepositsconstraints.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "withdrawsordepositsconstraints.hpp"

#include <string_view>
#include <utility>

#include "baseconstraints.hpp"
#include "currencycode.hpp"
#include "timedef.hpp"

namespace cct {
WithdrawsOrDepositsConstraints::WithdrawsOrDepositsConstraints(CurrencyCode currencyCode, Duration minAge,
Duration maxAge, IdSet &&idSet)
Expand Down
18 changes: 13 additions & 5 deletions src/api-objects/test/deposit_test.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#include "deposit.hpp"

#include <gtest/gtest.h>

#include <algorithm>
#include <cstdint>
#include <limits>

#include "cct_vector.hpp"
#include "gtest/gtest.h"
#include "monetaryamount.hpp"
#include "timedef.hpp"

namespace cct {
class DepositTest : public ::testing::Test {
protected:
TimePoint tp1{std::chrono::milliseconds{std::numeric_limits<int64_t>::max() / 10000000}};
TimePoint tp2{std::chrono::milliseconds{std::numeric_limits<int64_t>::max() / 9000000}};
TimePoint tp3{std::chrono::milliseconds{std::numeric_limits<int64_t>::max() / 8000000}};
TimePoint tp4{std::chrono::milliseconds{std::numeric_limits<int64_t>::max() / 7000000}};
TimePoint tp1{TimeInMs{std::numeric_limits<int64_t>::max() / 10000000}};
TimePoint tp2{TimeInMs{std::numeric_limits<int64_t>::max() / 9000000}};
TimePoint tp3{TimeInMs{std::numeric_limits<int64_t>::max() / 8000000}};
TimePoint tp4{TimeInMs{std::numeric_limits<int64_t>::max() / 7000000}};

Deposit deposit1{"id1", tp2, MonetaryAmount("0.045", "BTC"), Deposit::Status::kSuccess};
Deposit deposit2{"id2", tp4, MonetaryAmount(37, "XRP"), Deposit::Status::kSuccess};
Expand All @@ -22,6 +29,7 @@ class DepositTest : public ::testing::Test {

TEST_F(DepositTest, SortByTimeFirst) {
std::ranges::sort(deposits);

EXPECT_EQ(deposits.front(), deposit3);
EXPECT_EQ(deposits.back(), deposit4);
}
Expand Down
2 changes: 2 additions & 0 deletions src/api-objects/test/ordersconstraints_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <gtest/gtest.h>

#include "market.hpp"

namespace cct {
TEST(OrderConstraintsBitmapTest, Empty) {
OrderConstraintsBitmap bmp;
Expand Down
5 changes: 5 additions & 0 deletions src/api-objects/test/recentdeposit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

#include <gtest/gtest.h>

#include <chrono>

#include "monetaryamount.hpp"
#include "timedef.hpp"

namespace cct::api {

inline bool operator==(const RecentDeposit &lhs, const RecentDeposit &rhs) {
Expand Down
18 changes: 13 additions & 5 deletions src/api-objects/test/withdraw_test.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#include "withdraw.hpp"

#include <gtest/gtest.h>

#include <algorithm>
#include <cstdint>
#include <limits>

#include "cct_vector.hpp"
#include "gtest/gtest.h"
#include "monetaryamount.hpp"
#include "timedef.hpp"

namespace cct {
class WithdrawTest : public ::testing::Test {
protected:
TimePoint tp1{std::chrono::milliseconds{std::numeric_limits<int64_t>::max() / 10000000}};
TimePoint tp2{std::chrono::milliseconds{std::numeric_limits<int64_t>::max() / 9000000}};
TimePoint tp3{std::chrono::milliseconds{std::numeric_limits<int64_t>::max() / 8000000}};
TimePoint tp4{std::chrono::milliseconds{std::numeric_limits<int64_t>::max() / 7000000}};
TimePoint tp1{TimeInMs{std::numeric_limits<int64_t>::max() / 10000000}};
TimePoint tp2{TimeInMs{std::numeric_limits<int64_t>::max() / 9000000}};
TimePoint tp3{TimeInMs{std::numeric_limits<int64_t>::max() / 8000000}};
TimePoint tp4{TimeInMs{std::numeric_limits<int64_t>::max() / 7000000}};

Withdraw withdraw1{"id1", tp2, MonetaryAmount("0.045", "BTC"), Withdraw::Status::kSuccess,
MonetaryAmount("0.001", "BTC")};
Expand All @@ -26,6 +33,7 @@ class WithdrawTest : public ::testing::Test {

TEST_F(WithdrawTest, SortByTimeFirst) {
std::ranges::sort(withdraws);

EXPECT_EQ(withdraws.front(), withdraw3);
EXPECT_EQ(withdraws.back(), withdraw4);
}
Expand Down
1 change: 1 addition & 0 deletions src/api/common/include/commonapi.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <chrono>
#include <cstdint>
#include <mutex>

#include "cachedresult.hpp"
Expand Down
3 changes: 3 additions & 0 deletions src/api/common/include/exchangebase.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <memory>
#include <utility>

#include "cachedresultvault.hpp"

namespace cct::api {
Expand Down
10 changes: 10 additions & 0 deletions src/api/common/include/exchangeprivateapi_mock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

#include <gmock/gmock.h>

#include "balanceoptions.hpp"
#include "balanceportfolio.hpp"
#include "currencycode.hpp"
#include "depositsconstraints.hpp"
#include "exchangeprivateapi.hpp"
#include "exchangeprivateapitypes.hpp"
#include "monetaryamount.hpp"
#include "ordersconstraints.hpp"
#include "tradeinfo.hpp"
#include "wallet.hpp"
#include "withdrawinfo.hpp"
#include "withdrawsconstraints.hpp"

namespace cct::api {

Expand Down
21 changes: 13 additions & 8 deletions src/api/common/src/commonapi.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#include "commonapi.hpp"

#include <cctype>
#include <cstdint>
#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 "coincenterinfo.hpp"
#include "curloptions.hpp"
#include "currencycode.hpp"
#include "file.hpp"
#include "httprequesttype.hpp"
#include "permanentcurloptions.hpp"
#include "timedef.hpp"

Expand All @@ -35,7 +40,7 @@ CommonAPI::CommonAPI(const CoincenterInfo& config, Duration fiatsUpdateFrequency
fiats.emplace_hint(fiats.end(), std::move(val.get_ref<string&>()));
}
log::debug("Loaded {} fiats from cache file", fiats.size());
_fiatsCache.set(std::move(fiats), TimePoint(std::chrono::seconds(timeEpoch)));
_fiatsCache.set(std::move(fiats), TimePoint(TimeInS(timeEpoch)));
}
}
}
Expand Down Expand Up @@ -70,13 +75,13 @@ CommonAPI::Fiats CommonAPI::FiatsFunc::operator()() {
}

void CommonAPI::updateCacheFile() const {
File fiatsCacheFile = GetFiatCacheFile(_coincenterInfo.dataDir());
json data = fiatsCacheFile.readAllJson();
auto fiatsPtrLastUpdatedTimePair = _fiatsCache.retrieve();
auto timeEpochIt = data.find("timeepoch");
const auto fiatsCacheFile = GetFiatCacheFile(_coincenterInfo.dataDir());
auto data = fiatsCacheFile.readAllJson();
const auto fiatsPtrLastUpdatedTimePair = _fiatsCache.retrieve();
const auto timeEpochIt = data.find("timeepoch");
if (timeEpochIt != data.end()) {
int64_t lastTimeFileUpdated = timeEpochIt->get<int64_t>();
if (TimePoint(std::chrono::seconds(lastTimeFileUpdated)) >= fiatsPtrLastUpdatedTimePair.second) {
const int64_t lastTimeFileUpdated = timeEpochIt->get<int64_t>();
if (TimePoint(TimeInS(lastTimeFileUpdated)) >= fiatsPtrLastUpdatedTimePair.second) {
return; // No update
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/api/common/src/exchangepublicapi.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
#include "exchangepublicapi.hpp"

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <optional>
#include <string_view>
#include <unordered_set>
#include <utility>

#include "cct_allocator.hpp"
#include "cct_exception.hpp"
#include "cct_smallvector.hpp"
#include "cct_vector.hpp"
#include "coincenterinfo.hpp"
#include "commonapi.hpp"
#include "currencycode.hpp"
#include "exchangeinfo.hpp"
#include "exchangepublicapitypes.hpp"
#include "fiatconverter.hpp"
#include "unreachable.hpp"
#include "market.hpp"
#include "marketorderbook.hpp"
#include "monetaryamount.hpp"
#include "priceoptions.hpp"
#include "priceoptionsdef.hpp"

namespace cct::api {
ExchangePublic::ExchangePublic(std::string_view name, FiatConverter &fiatConverter, CommonAPI &commonApi,
Expand Down
Loading