You.i Engine
YiSignal.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_SIGNAL_H_
3 #define _YI_SIGNAL_H_
4 
5 #include "signal/YiSignalBase.h"
6 
7 #include <functional>
8 
167 template<typename... SignalTypes>
168 class CYISignal : public CYISignalBase
169 {
170 public:
173 
183  template<typename HandlerType, typename SlotReturnType, typename... SlotTypes>
184  bool IsConnected(const HandlerType &rSignalHandler, SlotReturnType (HandlerType::*const pSlot)(SlotTypes...)) const;
185 
195  template<typename HandlerType, typename SlotReturnType, typename... SlotTypes>
196  inline bool IsConnected(const HandlerType &rSignalHandler, SlotReturnType (HandlerType::*const pSlot)(SlotTypes...) const) const;
197 
206  template<typename SlotReturnType, typename... SlotTypes>
207  bool IsConnected(SlotReturnType (*const pSlot)(SlotTypes...)) const;
208 
222  template<typename HandlerType, typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
223  CYISignalConnectionID Connect(HandlerType &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...), EYIConnectionType type = EYIConnectionType::Auto);
224 
240  template<typename HandlerType, typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
241  inline CYISignalConnectionID Connect(const HandlerType &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...) const, EYIConnectionType type = EYIConnectionType::Auto);
242 
254  template<typename SlotReturnType, typename... SlotTypes>
255  CYISignalConnectionID Connect(SlotReturnType (*const pSlot)(SlotTypes...), EYIConnectionType type = EYIConnectionType::Auto, CYIThreadHandle threadAffinity = CYIThread::GetCurrentThreadId());
256 
273  template<typename HandlerType, typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
274  CYISignalConnectionID Connect(HandlerType &rSignalHandler, std::function<SlotReturnType(SlotHandlerType &, SlotTypes...)> slot, EYIConnectionType type = EYIConnectionType::Auto);
275 
290  template<typename CallableType>
292 
309  template<typename CallableType>
310  CYISignalConnectionID Connect(const CYISignalHandler &rSignalHandler, CallableType callable, EYIConnectionType type = EYIConnectionType::Auto);
311 
323  template<typename... OtherSignalTypes>
325 
335  inline void operator()(const typename std::decay<SignalTypes>::type &... param) const;
336 
346  inline void Emit(const typename std::decay<SignalTypes>::type &... params) const;
347 
359  template<class SlotReturnType, typename SlotHandlerType, typename... SlotTypes>
360  void Disconnect(CYISignalHandler &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...));
361 
373  template<class SlotReturnType, typename SlotHandlerType, typename... SlotTypes>
374  inline void Disconnect(CYISignalHandler &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...) const);
375 
385  template<typename SlotReturnType, typename... SlotTypes>
386  void Disconnect(SlotReturnType (*const pSlot)(SlotTypes...));
387 
388 #ifndef DOXY
389  // The following definitions exist only to generate more understandable compilation errors.
393  template<typename HandlerType, typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
394  CYISignalConnectionID Connect(const HandlerType &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...), EYIConnectionType type = EYIConnectionType::Auto);
395 
399  template<typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
400  CYISignalConnectionID Connect(SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...), EYIConnectionType type = EYIConnectionType::Auto);
401 
405  template<typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
406  CYISignalConnectionID Connect(SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...) const, EYIConnectionType type = EYIConnectionType::Auto);
407 #endif
408 
409 protected:
415  void EmitForConnection(CYISignalConnectionWrapper &connection, const CYIThreadHandle &currentThreadID, EYIConnectionType connectionType, const typename std::decay<SignalTypes>::type &... params);
416 
424  virtual void Emitted();
425 
431  virtual void ConnectionAdded(CYISignalConnectionWrapper &connection);
432 
433 private:
434  template<typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
435  size_t FindConnectionIndex(const CYISignalHandler &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...)) const;
436 
437  template<typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
438  size_t FindConnectionIndex(const CYISignalHandler &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...) const) const;
439 
440  template<typename SlotReturnType, typename... SlotTypes>
441  size_t FindConnectionIndex(SlotReturnType (*const pSlot)(SlotTypes...)) const;
442 
443  template<typename CallableType>
444  typename std::enable_if<(sizeof(CallableType) <= CYISignalConnectionWrapper::s_smallLambdaStorageBytes), void>::type EmplaceConnection(SignalObjects *pSignalObjects, const CYISignalHandler *pSignalHandler, CYIThreadHandle threadAffinity, CallableType &&callable, EYIConnectionType type);
445 
446  template<typename CallableType>
447  typename std::enable_if<(sizeof(CallableType) > CYISignalConnectionWrapper::s_smallLambdaStorageBytes), void>::type EmplaceConnection(SignalObjects *pSignalObjects, const CYISignalHandler *pSignalHandler, CYIThreadHandle threadAffinity, CallableType &&callable, EYIConnectionType type);
448 
449  void EmitInternal(const typename std::decay<SignalTypes>::type &... params);
450 };
451 
454 #include "signal/internal/YiSignal.inl"
455 
456 #endif /* _YI_SIGNAL_H_ */
virtual bool IsConnected() const override
void EmitForConnection(CYISignalConnectionWrapper &connection, const CYIThreadHandle &currentThreadID, EYIConnectionType connectionType, const typename std::decay< SignalTypes >::type &... params)
EYIConnectionType
Definition: YiSignalAbstractConnection.h:19
void Disconnect(CYISignalHandler &rSignalHandler)
The base abstract class for CYISignal.
Definition: YiSignalBase.h:20
An object used to identify a specific CYISignal connection.
Definition: YiSignalConnectionID.h:19
Definition: YiSignalConnectionWrapper.h:7
CYISignalConnectionID Connect(HandlerType &rSignalHandler, SlotReturnType(SlotHandlerType::*const pSlot)(SlotTypes...), EYIConnectionType type=EYIConnectionType::Auto)
void Disconnect(CYISignalHandler &rSignalHandler, SlotReturnType(SlotHandlerType::*const pSlot)(SlotTypes...))
static CYIThreadHandle GetCurrentThreadId()
void Emit(const typename std::decay< SignalTypes >::type &... params) const
Definition: YiSignalHandler.h:175
virtual void Emitted()
static constexpr size_t s_smallLambdaStorageBytes
Definition: YiSignalConnectionWrapper.h:13
Signals and slots are a thread-safe and flexible communication framework that will allow various obje...
Definition: YiSignal.h:168
Definition: YiSignalBase.h:113
Definition: YiThreadHandle.h:45
void operator()(const typename std::decay< SignalTypes >::type &... param) const
virtual void ConnectionAdded(CYISignalConnectionWrapper &connection)