Skip to content

Commit

Permalink
[Code refactoring] - Move cct_const.hpp from tech -> basic-objects
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Nov 9, 2024
1 parent d8b18e4 commit 92bf4da
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ endif()
# Glaze - fast json serialization library
find_package(glaze CONFIG)
if(NOT glaze)

FetchContent_Declare(
glaze
URL https://github.com/stephenberry/glaze/archive/refs/tags/v3.6.2.tar.gz
URL_HASH SHA256=74b14656b7a47c0a03d0a857adf5059e8c2351a7a84623593be0dd16b293216c
URL https://github.com/stephenberry/glaze/archive/refs/tags/v4.0.0.tar.gz
URL_HASH SHA256=6114cd6fc2eb39e396e229c7971b2ca5aeb8a670f0dfcd37d6223d766f4afecf
)

list(APPEND fetchContentPackagesToMakeAvailable glaze)
Expand Down
20 changes: 10 additions & 10 deletions cmake/CoincenterUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ function(add_coincenter_library name)
target_set_coincenter_options(coincenter_${name})
endfunction()

function(add_coincenter_executable name)
set(oneValueArgs)
set(multiValueArgs)
cmake_parse_arguments(PARSE_ARGV 1 MY "${options}" "${oneValueArgs}" "${multiValueArgs}")

add_executable(${name} ${MY_UNPARSED_ARGUMENTS})

target_set_coincenter_options(${name})
endfunction()

function (target_set_coincenter_options name)
target_include_directories(${name} PUBLIC include)

Expand Down Expand Up @@ -46,4 +36,14 @@ function (target_set_coincenter_options name)
if(CCT_ENABLE_PROTO)
target_compile_definitions(${name} PRIVATE CCT_ENABLE_PROTO CCT_PROTOBUF_VERSION=\"${PROTOBUF_VERSION}\")
endif()
endfunction()

function(add_coincenter_executable name)
set(oneValueArgs)
set(multiValueArgs)
cmake_parse_arguments(PARSE_ARGV 1 MY "${options}" "${oneValueArgs}" "${multiValueArgs}")

add_executable(${name} ${MY_UNPARSED_ARGUMENTS})

target_set_coincenter_options(${name})
endfunction()
2 changes: 0 additions & 2 deletions src/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


add_subdirectory(common)
add_subdirectory(exchanges)
add_subdirectory(interface)
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#pragma once

#include <algorithm>
#include <cstdint>
#include <iterator>
#include <string_view>

#include "cct_json-serialization.hpp"

namespace cct {

enum class SupportedExchangeName : int8_t { binance, bithumb, huobi, kraken, kucoin, upbit };

static constexpr std::string_view kDefaultDataDir = CCT_DATA_DIR;

/// File containing all validated external addresses.
Expand All @@ -17,12 +23,30 @@ static constexpr std::string_view kDefaultDataDir = CCT_DATA_DIR;
/// field.
static constexpr std::string_view kDepositAddressesFileName = "depositaddresses.json";

static constexpr std::string_view kSupportedExchanges[] = {"binance", "bithumb", "huobi", "kraken", "kucoin", "upbit"};
/// File containing exchange configuration.
/// It has a particular format, with default values which can optionally be overriden by exchange name.
/// See ExchangeConfig in exchange-config.hpp.
static constexpr std::string_view kExchangeConfigFileName = "exchangeconfig.json";

} // namespace cct

// To make enum serializable as strings
template <>
struct glz::meta<cct::SupportedExchangeName> {
using enum cct::SupportedExchangeName;

static constexpr auto value = enumerate(binance, bithumb, huobi, kraken, kucoin, upbit);
};

namespace cct {

/// Ordered list of supported exchange names.
static constexpr auto kSupportedExchanges = json::reflect<SupportedExchangeName>::keys;

static_assert(std::ranges::is_sorted(kSupportedExchanges));

static constexpr int kNbSupportedExchanges = static_cast<int>(std::size(kSupportedExchanges));

static constexpr int kTypicalNbPrivateAccounts = kNbSupportedExchanges;

} // namespace cct
} // namespace cct
1 change: 1 addition & 0 deletions src/objects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_unit_test(
src/exchangename.cpp
test/exchangename_test.cpp
LIBRARIES
coincenter_basic-objects
coincenter_tech
)

Expand Down
6 changes: 2 additions & 4 deletions src/tech/include/threadpool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
#include <thread>
#include <type_traits>

#include "cct_const.hpp"
#include "cct_exception.hpp"
#include "cct_invalid_argument_exception.hpp"
#include "cct_log.hpp"
#include "cct_smallvector.hpp"
#include "cct_vector.hpp"

namespace cct {
Expand Down Expand Up @@ -149,7 +147,7 @@ template <std::ranges::input_range InputRange, std::weakly_incrementable OutputI
std::invoke_result_t<UnaryOperation, std::ranges::range_reference_t<InputRange>>>
inline OutputIt ThreadPool::parallelTransform(InputRange&& r, OutputIt result, UnaryOperation op) {
using FutureT = std::future<std::invoke_result_t<UnaryOperation, std::ranges::range_reference_t<InputRange>>>;
SmallVector<FutureT, kTypicalNbPrivateAccounts> futures;
vector<FutureT> futures;
if constexpr (std::ranges::sized_range<InputRange>) {
futures.reserve(std::ranges::size(r));
}
Expand All @@ -167,7 +165,7 @@ template <std::ranges::input_range InputRange1, std::ranges::input_range InputRa
inline OutputIt ThreadPool::parallelTransform(InputRange1&& r1, InputRange2&& r2, OutputIt result, BinaryOperation op) {
using FutureT = std::future<std::invoke_result_t<BinaryOperation, std::ranges::range_reference_t<InputRange1>,
std::ranges::range_reference_t<InputRange2>>>;
SmallVector<FutureT, kTypicalNbPrivateAccounts> futures;
vector<FutureT> futures;
if constexpr (std::ranges::sized_range<InputRange1>) {
futures.reserve(std::ranges::size(r1));
}
Expand Down

0 comments on commit 92bf4da

Please sign in to comment.