From 8de20f42f04af1be219d7b48ff1b6309eeca7144 Mon Sep 17 00:00:00 2001 From: AnatolyKalin Date: Fri, 26 May 2023 17:14:23 +0300 Subject: [PATCH] [DXFC-402] Implement adding multiple symbols and removing symbols --- .../api/DXFeedSubscription.hpp | 31 +++++++------------ src/api/DXFeedSubscription.cpp | 9 ++++++ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp b/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp index d46f3f9f..0219bcd2 100644 --- a/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp +++ b/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp @@ -67,10 +67,12 @@ class DXFeedSubscription : public SharedEntity { void addSymbolImpl(const char *symbol) noexcept; - void addSymbolImpl(void* graalSymbol) noexcept; + void addSymbolImpl(void *graalSymbol) noexcept; void removeSymbolImpl(const char *symbol) noexcept; + void removeSymbolImpl(void *graalSymbol) noexcept; + public: std::string toString() const noexcept override; @@ -237,33 +239,24 @@ class DXFeedSubscription : public SharedEntity { if constexpr (std::is_same_v, WildcardSymbol>) { addSymbolImpl(symbol.toGraal()); - } if constexpr (ConvertibleToStringSymbol) { + } else if constexpr (ConvertibleToStringSymbol) { addSymbolImpl(StringSymbol(std::forward(symbol)).toGraal()); - } else if constexpr (std::is_same_v, std::string>) { - addSymbolImpl(symbol.c_str()); - } - else if constexpr (std::is_same_v, std::string_view>) { - addSymbolImpl(symbol.data()); - } - else { + } else { addSymbolImpl(symbol); } } template void removeSymbol(Symbol &&symbol) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug(toString() + "::removeSymbol(symbol = " + symbol + ")"); + Debugger::debug(toString() + "::removeSymbol<" + typeid(symbol).name() + + ">(symbol = " + std::string(symbol) + ")"); } - if constexpr (std::is_same_v, std::string>) { - removeSymbolImpl(symbol.c_str()); - } -#if __cpp_lib_string_view - else if constexpr (std::is_same_v, std::string_view>) { - removeSymbolImpl(symbol.data()); - } -#endif - else { + if constexpr (std::is_same_v, WildcardSymbol>) { + removeSymbolImpl(symbol.toGraal()); + } else if constexpr (ConvertibleToStringSymbol) { + removeSymbolImpl(StringSymbol(std::forward(symbol)).toGraal()); + } else { removeSymbolImpl(symbol); } } diff --git a/src/api/DXFeedSubscription.cpp b/src/api/DXFeedSubscription.cpp index 2a972d42..047c99ff 100644 --- a/src/api/DXFeedSubscription.cpp +++ b/src/api/DXFeedSubscription.cpp @@ -66,6 +66,15 @@ void DXFeedSubscription::removeSymbolImpl(const char *symbol) noexcept { false); } +void DXFeedSubscription::removeSymbolImpl(void *graalSymbol) noexcept { + runIsolatedOrElse( + [handler = bit_cast(handler_.get()), graalSymbol](auto threadHandle) { + return dxfg_DXFeedSubscription_removeSymbol(threadHandle, handler, + bit_cast(graalSymbol)) == 0; + }, + false); +} + void DXFeedSubscription::closeImpl() noexcept { if (!handler_) { return;