diff --git a/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp b/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp index a8fe18b8..316ca5d3 100644 --- a/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp +++ b/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp @@ -75,6 +75,10 @@ class DXFeedSubscription : public std::enable_shared_from_this&)` + * @param listener The event listener + * @return The listener id + */ template std::size_t addEventListener(EventListener &&listener) noexcept #if __cpp_concepts @@ -205,31 +223,59 @@ class DXFeedSubscription : public std::enable_shared_from_this void addSymbol(Symbol &&symbol) noexcept { + if constexpr (isDebug) { + debug("{}::addSymbol(symbol = {})", toString(), symbol); + } + + if constexpr (std::is_same_v, std::string>) { + addSymbolImpl(symbol.c_str()); + } #if __cpp_lib_string_view - void addSymbol(std::string_view symbol) noexcept; + else if constexpr (std::is_same_v, std::string_view>) { + addSymbolImpl(symbol.data()); + } #endif + else { + addSymbolImpl(symbol); + } + } - void addSymbol(const char *symbol) noexcept; - - void addSymbol(const std::string &symbol) noexcept; - - template void addSymbols(SymbolsCollection &&collection) noexcept; - - template void addSymbols(std::initializer_list collection) noexcept; - - template void removeSymbol(Symbol &&symbol) noexcept; + template void removeSymbol(Symbol &&symbol) noexcept { + if constexpr (isDebug) { + debug("{}::removeSymbol(symbol = {})", toString(), symbol); + } + if constexpr (std::is_same_v, std::string>) { + removeSymbolImpl(symbol.c_str()); + } #if __cpp_lib_string_view - void removeSymbol(std::string_view symbol) noexcept; + else if constexpr (std::is_same_v, std::string_view>) { + removeSymbolImpl(symbol.data()); + } #endif + else { + removeSymbolImpl(symbol); + } + } - void removeSymbol(const char *symbol) noexcept; + template void addSymbols(SymbolsCollection &&collection) noexcept; - void removeSymbol(const std::string &symbol) noexcept; + template void addSymbols(std::initializer_list collection) noexcept; template void removeSymbols(SymbolsCollection &&collection) noexcept; diff --git a/include/dxfeed_graal_cpp_api/internal/Isolate.hpp b/include/dxfeed_graal_cpp_api/internal/Isolate.hpp index 39fbd89b..9671d777 100644 --- a/include/dxfeed_graal_cpp_api/internal/Isolate.hpp +++ b/include/dxfeed_graal_cpp_api/internal/Isolate.hpp @@ -249,7 +249,9 @@ class Isolate final { } template +#if __cpp_concepts requires std::convertible_to> +#endif auto runIsolatedOrElse(F &&f, R defaultValue) { return std::visit( [defaultValue = @@ -280,7 +282,9 @@ class Isolate final { template auto runIsolated(F &&f) { return Isolate::getInstance()->runIsolated(std::forward(f)); } template +#if __cpp_concepts requires std::convertible_to> +#endif auto runIsolatedOrElse(F &&f, R defaultValue) { return Isolate::getInstance()->runIsolatedOrElse(std::forward(f), std::move(defaultValue)); } diff --git a/samples/cpp/PrintQuoteEvents/src/main.cpp b/samples/cpp/PrintQuoteEvents/src/main.cpp index 0abc29ea..77cb5f69 100644 --- a/samples/cpp/PrintQuoteEvents/src/main.cpp +++ b/samples/cpp/PrintQuoteEvents/src/main.cpp @@ -21,6 +21,11 @@ auto cApiStateToString(dxfc_dxendpoint_state_t state) { return ""; } +#if !defined(__PRETTY_FUNCTION__) && !defined(__GNUC__) +#define __PRETTY_FUNCTION__ __FUNCSIG__ +#endif + + int main() { { using namespace std::string_literals; diff --git a/src/api/DXFeedSubscription.cpp b/src/api/DXFeedSubscription.cpp index 6a4dff0f..f542c0f6 100644 --- a/src/api/DXFeedSubscription.cpp +++ b/src/api/DXFeedSubscription.cpp @@ -6,6 +6,7 @@ #include #include +#include namespace dxfcpp { @@ -25,27 +26,13 @@ void DXFeedSubscription::detach(std::shared_ptr feed) noexcept { feed->detachSubscription(shared_from_this()); } -#if __cpp_lib_string_view -void DXFeedSubscription::addSymbol(std::string_view symbol) noexcept { +template auto symbolDataRetriever(Symbol &&s) { if constexpr (isDebug) { - debug("{}::addSymbol(symbol = {})", toString(), symbol); + debug("{}", typeid(decltype(s)).name()); } - - runIsolatedOrElse( - [handler = bit_cast(handler_.get()), symbol](auto threadHandle) { - dxfg_string_symbol_t s{{STRING}, symbol.data()}; - - return dxfg_DXFeedSubscription_addSymbol(threadHandle, handler, (dxfg_symbol_t *)&s) == 0; - }, - false); } -#endif - -void DXFeedSubscription::addSymbol(const char *symbol) noexcept { - if constexpr (isDebug) { - debug("{}::addSymbol(symbol = {})", toString(), symbol); - } +void DXFeedSubscription::addSymbolImpl(const char *symbol) noexcept { runIsolatedOrElse( [handler = bit_cast(handler_.get()), symbol](auto threadHandle) { dxfg_string_symbol_t s{{STRING}, symbol}; @@ -55,41 +42,7 @@ void DXFeedSubscription::addSymbol(const char *symbol) noexcept { false); } -void DXFeedSubscription::addSymbol(const std::string &symbol) noexcept { - if constexpr (isDebug) { - debug("{}::addSymbol(symbol = {})", toString(), symbol); - } - - runIsolatedOrElse( - [handler = bit_cast(handler_.get()), symbol](auto threadHandle) { - dxfg_string_symbol_t s{{STRING}, symbol.c_str()}; - - return dxfg_DXFeedSubscription_addSymbol(threadHandle, handler, (dxfg_symbol_t *)&s) == 0; - }, - false); -} - -#if __cpp_lib_string_view -void DXFeedSubscription::removeSymbol(std::string_view symbol) noexcept { - if constexpr (isDebug) { - debug("{}::removeSymbol(symbol = {})", toString(), symbol); - } - - runIsolatedOrElse( - [handler = bit_cast(handler_.get()), symbol](auto threadHandle) { - dxfg_string_symbol_t s{{STRING}, symbol.data()}; - - return dxfg_DXFeedSubscription_removeSymbol(threadHandle, handler, (dxfg_symbol_t *)&s) == 0; - }, - false); -} -#endif - -void DXFeedSubscription::removeSymbol(const char *symbol) noexcept { - if constexpr (isDebug) { - debug("{}::removeSymbol(symbol = {})", toString(), symbol); - } - +void DXFeedSubscription::removeSymbolImpl(const char *symbol) noexcept { runIsolatedOrElse( [handler = bit_cast(handler_.get()), symbol](auto threadHandle) { dxfg_string_symbol_t s{{STRING}, symbol}; @@ -99,20 +52,6 @@ void DXFeedSubscription::removeSymbol(const char *symbol) noexcept { false); } -void DXFeedSubscription::removeSymbol(const std::string &symbol) noexcept { - if constexpr (isDebug) { - debug("{}::removeSymbol(symbol = {})", toString(), symbol); - } - - runIsolatedOrElse( - [handler = bit_cast(handler_.get()), symbol](auto threadHandle) { - dxfg_string_symbol_t s{{STRING}, symbol.c_str()}; - - return dxfg_DXFeedSubscription_removeSymbol(threadHandle, handler, (dxfg_symbol_t *)&s) == 0; - }, - false); -} - void DXFeedSubscription::closeImpl() noexcept { if (!handler_) { return;