Skip to content

Commit

Permalink
test potential windows msvc fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Dec 8, 2024
1 parent 0d6d8ed commit bb0459c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 49 deletions.
13 changes: 10 additions & 3 deletions src/api-objects/src/tradeoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

namespace cct {

namespace {
auto ComputeTimeoutAction(TradeTimeoutAction tradeTimeoutAction, bool timeoutMatch) {
if (tradeTimeoutAction != TradeTimeoutAction::kDefault) {
return tradeTimeoutAction;
}
return timeoutMatch ? TradeTimeoutAction::kMatch : TradeTimeoutAction::kCancel;
}
} // namespace

TradeOptions::TradeOptions(const PriceOptions &priceOptions, TradeTimeoutAction timeoutAction, TradeMode tradeMode,
Duration maxTradeTime, Duration minTimeBetweenPriceUpdates, TradeTypePolicy tradeTypePolicy,
TradeSyncPolicy tradeSyncPolicy)
Expand All @@ -29,9 +38,7 @@ TradeOptions::TradeOptions(const TradeOptions &rhs, const schema::ExchangeQueryT
? exchangeTradeConfig.minPriceUpdateDuration.duration
: rhs._minTimeBetweenPriceUpdates),
_priceOptions(rhs._priceOptions.isDefault() ? PriceOptions(exchangeTradeConfig) : rhs._priceOptions),
_timeoutAction(rhs._timeoutAction == TradeTimeoutAction::kDefault
? (exchangeTradeConfig.timeoutMatch ? TradeTimeoutAction::kMatch : TradeTimeoutAction::kCancel)
: rhs._timeoutAction),
_timeoutAction(ComputeTimeoutAction(rhs._timeoutAction, exchangeTradeConfig.timeoutMatch)),
_tradeMode(rhs._tradeMode),
_tradeTypePolicy(rhs._tradeTypePolicy),
_tradeSyncPolicy(rhs._tradeSyncPolicy) {}
Expand Down
49 changes: 12 additions & 37 deletions src/basic-objects/include/coincentercommandtype.hpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
#pragma once

#include <cstdint>
#include <glaze/glaze.hpp> // IWYU pragma: export
#include <string_view>

#include "cct_json-serialization.hpp"

namespace cct {

enum class CoincenterCommandType : int8_t {
HealthCheck,
Currencies,
Markets,
Conversion,
ConversionPath,
LastPrice,
Ticker,
Orderbook,
LastTrades,
Last24hTradedVolume,
WithdrawFees,

Balance,
DepositInfo,
OrdersClosed,
OrdersOpened,
OrdersCancel,
RecentDeposits,
RecentWithdraws,
Trade,
Buy,
Sell,
Withdraw,
DustSweeper,
MarketData,
Replay,
ReplayMarkets
};
#define CCT_COINCENTER_COMMAND_TYPES \
HealthCheck, Currencies, Markets, Conversion, ConversionPath, LastPrice, Ticker, Orderbook, LastTrades, \
Last24hTradedVolume, WithdrawFees, \
\
Balance, DepositInfo, OrdersClosed, OrdersOpened, OrdersCancel, RecentDeposits, RecentWithdraws, Trade, Buy, \
Sell, Withdraw, DustSweeper, \
\
MarketData, Replay, ReplayMarkets

enum class CoincenterCommandType : int8_t { CCT_COINCENTER_COMMAND_TYPES };

std::string_view CoincenterCommandTypeToString(CoincenterCommandType coincenterCommandType);

Expand All @@ -45,12 +25,7 @@ bool IsAnyTrade(CoincenterCommandType coincenterCommandType);
template <>
struct glz::meta<::cct::CoincenterCommandType> {
using enum ::cct::CoincenterCommandType;
static constexpr auto value =
enumerate(HealthCheck, Currencies, Markets, Conversion, ConversionPath, LastPrice, Ticker, Orderbook, LastTrades,
Last24hTradedVolume, WithdrawFees,

Balance, DepositInfo, OrdersClosed, OrdersOpened, OrdersCancel, RecentDeposits, RecentWithdraws, Trade,
Buy, Sell, Withdraw, DustSweeper, MarketData, Replay, ReplayMarkets);
static constexpr auto value = enumerate(CCT_COINCENTER_COMMAND_TYPES);
};

#undef CCT_COINCENTER_COMMAND_TYPES
6 changes: 2 additions & 4 deletions src/basic-objects/src/coincentercommandtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
#include "cct_json-serialization.hpp"

namespace cct {
namespace {
constexpr auto kCommandTypeNames = json::reflect<CoincenterCommandType>::keys;
} // namespace

std::string_view CoincenterCommandTypeToString(CoincenterCommandType coincenterCommandType) {
return kCommandTypeNames[static_cast<std::underlying_type_t<CoincenterCommandType>>(coincenterCommandType)];
return json::reflect<CoincenterCommandType>::keys[static_cast<std::underlying_type_t<CoincenterCommandType>>(
coincenterCommandType)];
}

bool IsAnyTrade(CoincenterCommandType coincenterCommandType) {
Expand Down
8 changes: 8 additions & 0 deletions src/schema/test/exchange-config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,24 @@ TEST_F(ExchangeConfigTest, DirectRead) {
EXPECT_EQ(exchangeConfigOptional.query.def.acceptEncoding, "");
EXPECT_EQ(exchangeConfigOptional.query.def.dustAmountsThreshold.size(), 5);
EXPECT_EQ(exchangeConfigOptional.query.def.dustSweeperMaxNbTrades, 7);
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
EXPECT_EQ(exchangeConfigOptional.query.def.http->timeout->duration, std::chrono::seconds(15));
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
EXPECT_EQ(exchangeConfigOptional.query.def.logLevels->requestsCall, log::level::level_enum::info);
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
EXPECT_EQ(exchangeConfigOptional.query.def.logLevels->requestsAnswer, log::level::level_enum::trace);
EXPECT_EQ(exchangeConfigOptional.query.def.marketDataSerialization, true);
EXPECT_EQ(exchangeConfigOptional.query.def.multiTradeAllowedByDefault, false);
EXPECT_EQ(exchangeConfigOptional.query.def.placeSimulateRealOrder, false);
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
EXPECT_EQ(exchangeConfigOptional.query.def.trade->minPriceUpdateDuration->duration, std::chrono::seconds(5));
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
EXPECT_EQ(exchangeConfigOptional.query.def.trade->strategy, PriceStrategy::maker);
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
EXPECT_EQ(exchangeConfigOptional.query.def.trade->timeout->duration, std::chrono::seconds(30));
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
EXPECT_EQ(exchangeConfigOptional.query.def.trade->timeoutMatch, false);
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
EXPECT_EQ(exchangeConfigOptional.query.def.updateFrequency->size(), 9);
EXPECT_EQ(exchangeConfigOptional.query.def.validateApiKey, false);
EXPECT_EQ(exchangeConfigOptional.query.exchange.size(), 6);
Expand Down
12 changes: 7 additions & 5 deletions src/tech/src/levenshteindistancecalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ int LevenshteinDistanceCalculator::operator()(std::string_view word1, std::strin
std::swap(word1, word2);
}

const auto l1 = static_cast<int>(word1.size()) + 1;
if (l1 > static_cast<int>(_minDistance.size())) {
using size_type = std::string_view::size_type;

const auto l1 = word1.size() + static_cast<size_type>(1);
if (l1 > _minDistance.size()) {
// Favor insert instead of resize to ensure reallocations are exponential
_minDistance.insert(_minDistance.end(), l1 - _minDistance.size(), 0);
}

std::iota(_minDistance.begin(), _minDistance.end(), 0);

const auto l2 = static_cast<int>(word2.size()) + 1;
for (auto word2Pos = 1; word2Pos < l2; ++word2Pos) {
const auto l2 = word2.size() + static_cast<size_type>(1);
for (size_type word2Pos = 1; word2Pos < l2; ++word2Pos) {
auto previousDiagonal = _minDistance[0];

++_minDistance[0];

for (auto word1Pos = 1; word1Pos < l1; ++word1Pos) {
for (size_type word1Pos = 1; word1Pos < l1; ++word1Pos) {
const auto previousDiagonalSave = _minDistance[word1Pos];
if (word1[word1Pos - 1] == word2[word2Pos - 1]) {
_minDistance[word1Pos] = previousDiagonal;
Expand Down
1 change: 1 addition & 0 deletions src/tech/test/utf8_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <gtest/gtest.h>

#include <cstring>
#include <string_view>

#include "cct_string.hpp"
#include "cct_vector.hpp"
Expand Down

0 comments on commit bb0459c

Please sign in to comment.