diff options
Diffstat (limited to 'include/libcamera/base/signal.h')
-rw-r--r-- | include/libcamera/base/signal.h | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/include/libcamera/base/signal.h b/include/libcamera/base/signal.h index c2521769..bbff1495 100644 --- a/include/libcamera/base/signal.h +++ b/include/libcamera/base/signal.h @@ -2,21 +2,21 @@ /* * Copyright (C) 2019, Google Inc. * - * signal.h - Signal & slot implementation + * Signal & slot implementation */ -#ifndef __LIBCAMERA_BASE_SIGNAL_H__ -#define __LIBCAMERA_BASE_SIGNAL_H__ + +#pragma once #include <functional> #include <list> #include <type_traits> -#include <vector> #include <libcamera/base/bound_method.h> -#include <libcamera/base/object.h> namespace libcamera { +class Object; + class SignalBase { public: @@ -44,7 +44,7 @@ public: } #ifndef __DOXYGEN__ - template<typename T, typename R, typename std::enable_if_t<std::is_base_of<Object, T>::value> * = nullptr> + template<typename T, typename R, std::enable_if_t<std::is_base_of<Object, T>::value> * = nullptr> void connect(T *obj, R (T::*func)(Args...), ConnectionType type = ConnectionTypeAuto) { @@ -52,7 +52,7 @@ public: SignalBase::connect(new BoundMethodMember<T, R, Args...>(obj, object, func, type)); } - template<typename T, typename R, typename std::enable_if_t<!std::is_base_of<Object, T>::value> * = nullptr> + template<typename T, typename R, std::enable_if_t<!std::is_base_of<Object, T>::value> * = nullptr> #else template<typename T, typename R> #endif @@ -61,6 +61,33 @@ public: SignalBase::connect(new BoundMethodMember<T, R, Args...>(obj, nullptr, func)); } +#ifndef __DOXYGEN__ + template<typename T, typename Func, + std::enable_if_t<std::is_base_of<Object, T>::value +#if __cplusplus >= 201703L + && std::is_invocable_v<Func, Args...> +#endif + > * = nullptr> + void connect(T *obj, Func func, ConnectionType type = ConnectionTypeAuto) + { + Object *object = static_cast<Object *>(obj); + SignalBase::connect(new BoundMethodFunctor<T, void, Func, Args...>(obj, object, func, type)); + } + + template<typename T, typename Func, + std::enable_if_t<!std::is_base_of<Object, T>::value +#if __cplusplus >= 201703L + && std::is_invocable_v<Func, Args...> +#endif + > * = nullptr> +#else + template<typename T, typename Func> +#endif + void connect(T *obj, Func func) + { + SignalBase::connect(new BoundMethodFunctor<T, void, Func, Args...>(obj, nullptr, func)); + } + template<typename R> void connect(R (*func)(Args...)) { @@ -128,5 +155,3 @@ public: }; } /* namespace libcamera */ - -#endif /* __LIBCAMERA_BASE_SIGNAL_H__ */ |