From 9ce5e341536a2893e3a5ee96893a2775c07886b7 Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Sun, 11 Oct 2020 13:29:16 +0900 Subject: [PATCH] fix compile error for subscribing functions #6 --- Artnet.h | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/Artnet.h b/Artnet.h index 13b9caa..b09f5c2 100644 --- a/Artnet.h +++ b/Artnet.h @@ -358,15 +358,40 @@ namespace arx return packet[HEADER_SIZE + i]; } - inline void subscribe(const uint32_t universe, const CallbackType& func) + template + inline auto subscribe(const uint32_t universe, F&& func) + -> std::enable_if_t::value> { - callbacks.insert(make_pair(universe, func)); + callbacks.insert(make_pair(universe, arx::function_traits::cast(func))); } - inline void subscribe(const CallbackAllType& func) + template + inline auto subscribe(const uint32_t universe, F* func) + -> std::enable_if_t::value> { - callback_all = func; + callbacks.insert(make_pair(universe, arx::function_traits::cast(func))); } - inline void subscribe(const uint8_t net, const uint8_t subnet, const uint8_t universe, const CallbackType& func) + template + inline auto subscribe(F&& func) + -> std::enable_if_t::value> + { + callback_all = arx::function_traits::cast(func); + } + template + inline auto subscribe(F* func) + -> std::enable_if_t::value> + { + callback_all = arx::function_traits::cast(func); + } + template + inline auto subscribe(const uint8_t net, const uint8_t subnet, const uint8_t universe, F&& func) + -> std::enable_if_t::value> + { + uint32_t u = ((uint32_t)net << 8) | ((uint32_t)subnet << 4) | (uint32_t)universe; + subscribe(u, func); + } + template + inline auto subscribe(const uint8_t net, const uint8_t subnet, const uint8_t universe, F* func) + -> std::enable_if_t::value> { uint32_t u = ((uint32_t)net << 8) | ((uint32_t)subnet << 4) | (uint32_t)universe; subscribe(u, func);