diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a84f7b..1d02744 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR) -project("orderbook" LANGUAGES CXX) +set(CPP_ORDERBOOK orderbook) +project(${CPP_ORDERBOOK} LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_COMPILER "/usr/bin/clang++") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -std=c++17 -stdlib=libc++ -lc++abi") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -stdlib=libc++") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -std=c++20 -stdlib=libc++ -lc++abi") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -stdlib=libc++") set(CMAKE_THREAD_LIBS_INIT "-lpthread") @@ -25,21 +26,21 @@ CPMUsePackageLock(package-lock.cmake) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) -CPMAddPackage( NAME Boost VERSION 1.80.0 GITHUB_REPOSITORY "boostorg/boost" GIT_TAG "boost-1.80.0") -CPMAddPackage( NAME udecimal VERSION 0.6.1 GITHUB_REPOSITORY "geseq/cpp-udecimal" GIT_TAG "v0.7.0") +CPMAddPackage( NAME Boost VERSION 1.80.0 GITHUB_REPOSITORY "boostorg/boost" GIT_TAG "boost-1.80.0") +CPMAddPackage( NAME decimal VERSION 2.1.0 GITHUB_REPOSITORY "geseq/cpp-decimal" GIT_TAG "v2.1.0") CPMAddPackage( NAME pool VERSION 0.6.1 GITHUB_REPOSITORY "geseq/cpp-pool" GIT_TAG "v0.5.0") -include_directories(udecimal_SOURCE_DIR) +include_directories(decimal_SOURCE_DIR) include_directories(pool_SOURCE_DIR) file(GLOB SOURCES "src/*.cpp") include_directories(include) -add_library(orderbook STATIC ${SOURCES}) -target_sources(orderbook INTERFACE include/orderbook.hpp) -target_include_directories(orderbook INTERFACE include/) -target_link_libraries(orderbook PRIVATE Boost::intrusive udecimal pool) +add_library(${CPP_ORDERBOOK} STATIC ${SOURCES}) +target_sources(${CPP_ORDERBOOK} INTERFACE include/orderbook.hpp) +target_include_directories(${CPP_ORDERBOOK} INTERFACE include/) +target_link_libraries(${CPP_ORDERBOOK} PRIVATE Boost::intrusive decimal pool) if (ENABLE_TESTING) CPMAddPackage( NAME googletest GITHUB_REPOSITORY google/googletest VERSION 1.14.0 ) @@ -52,10 +53,10 @@ if (ENABLE_TESTING) get_filename_component(test_name ${test} NAME) message("Adding test: " ${test_name}) add_executable(${test_name} ${SOURCES} ${PROJECT_SOURCE_DIR}/test/${test_name}) - target_link_libraries(${test_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} orderbook gtest gtest_main Boost::algorithm Boost::intrusive udecimal pool) + target_link_libraries(${test_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${CPP_ORDERBOOK} gtest gtest_main Boost::algorithm Boost::intrusive decimal pool) add_test(${test_name} ${test_name}) set_property(TEST ${test_name} PROPERTY LABELS "test") ENDFOREACH () endif() -target_link_libraries(main PRIVATE Boost::intrusive udecimal pool) +target_link_libraries(main PRIVATE Boost::intrusive decimal pool) diff --git a/include/orderbook.hpp b/include/orderbook.hpp index 6f521e9..60c6723 100644 --- a/include/orderbook.hpp +++ b/include/orderbook.hpp @@ -311,7 +311,7 @@ std::string OrderBook::toString() { auto loop = (b != bids.end() || a != asks.end()); while (loop) { if (b != bids.end()) { - ss << b->totalQty().to_string() << "\t" << b->price().to_string(); + ss << b->totalQty() << "\t" << b->price(); ++b; } else { ss << "\t\t\t"; @@ -319,7 +319,7 @@ std::string OrderBook::toString() { ss << " | "; if (a != asks.end()) { - ss << a->price().to_string() << "\t" << a->totalQty().to_string(); + ss << a->price() << "\t" << a->totalQty(); ++a; } diff --git a/include/types.hpp b/include/types.hpp index 8ac775d..bd3ff33 100644 --- a/include/types.hpp +++ b/include/types.hpp @@ -3,11 +3,11 @@ #include #include -#include "udecimal.hpp" +#include "decimal.hpp" namespace orderbook { -using Decimal = udecimal::Decimal<8>; +using Decimal = decimal::U8; using OrderID = uint64_t; enum class Type : uint8_t { diff --git a/package-lock.cmake b/package-lock.cmake deleted file mode 100644 index c72a624..0000000 --- a/package-lock.cmake +++ /dev/null @@ -1,23 +0,0 @@ -# CPM Package Lock -# This file should be committed to version control - -# Boost -CPMDeclarePackage(Boost - NAME Boost - VERSION 1.80.0 - GIT_TAG boost-1.80.0 - GITHUB_REPOSITORY boostorg/boost -) -# cpp-udecimal -CPMDeclarePackage(cpp-udecimal - NAME cpp-udecimal - VERSION 0.2.1 - GIT_TAG v0.2.1 - GITHUB_REPOSITORY geseq/cpp-udecimal -) -# cpp-fastchan -CPMDeclarePackage(cpp-fastchan - VERSION 0.2.0 - GITHUB_REPOSITORY geseq/cpp-fastchan - EXCLUDE_FROM_ALL YES -) diff --git a/test/util.cpp b/test/util.cpp index ca22a3c..fc3a833 100644 --- a/test/util.cpp +++ b/test/util.cpp @@ -19,8 +19,8 @@ using orderbook::Type; class NotificationBase { public: - virtual ~NotificationBase() {} - virtual std::string to_string() const = 0; + virtual ~NotificationBase() = default; + [[nodiscard]] virtual std::string to_string() const = 0; }; struct OrderNotification : public NotificationBase { @@ -30,16 +30,16 @@ struct OrderNotification : public NotificationBase { orderbook::Decimal qty_; std::optional error_; - OrderNotification(orderbook::MsgType msg_type, orderbook::OrderStatus status, orderbook::OrderID order_id, orderbook::Decimal qty, + OrderNotification(orderbook::MsgType msg_type, orderbook::OrderStatus status, orderbook::OrderID order_id, orderbook::Decimal& qty, std::optional error) : msg_type_(msg_type), status_(status), order_id_(order_id), qty_(qty), error_(error){}; - std::string to_string() const override { + [[nodiscard]] std::string to_string() const override { std::ostringstream os; if (error_.has_value()) { - os << msg_type_ << " " << status_ << " " << order_id_ << " " << qty_.to_string() << " Err" << *error_; + os << msg_type_ << " " << status_ << " " << order_id_ << " " << qty_ << " Err" << *error_; } else { - os << msg_type_ << " " << status_ << " " << order_id_ << " " << qty_.to_string(); + os << msg_type_ << " " << status_ << " " << order_id_ << " " << qty_; } return os.str(); }