You.i Engine
YiSignal.h
Go to the documentation of this file.
1 // © You i Labs Inc. All rights reserved.
2 #ifndef _YI_SIGNAL_H_
3 #define _YI_SIGNAL_H_
4 
5 #include "signal/YiSignalBase.h"
6 
7 #include <functional>
8 #include <type_traits>
9 
168 template<typename... SignalTypes>
169 class CYISignal : public CYISignalBase
170 {
171 public:
174 
175  virtual ~CYISignal();
176 
186  template<typename HandlerType, typename SlotReturnType, typename... SlotTypes>
187  bool IsConnected(const HandlerType &rSignalHandler, SlotReturnType (HandlerType::*const pSlot)(SlotTypes...)) const;
188 
198  template<typename HandlerType, typename SlotReturnType, typename... SlotTypes>
199  inline bool IsConnected(const HandlerType &rSignalHandler, SlotReturnType (HandlerType::*const pSlot)(SlotTypes...) const) const;
200 
209  template<typename SlotReturnType, typename... SlotTypes>
210  bool IsConnected(SlotReturnType (*const pSlot)(SlotTypes...)) const;
211 
225  template<typename HandlerType, typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
226  CYISignalConnectionID Connect(HandlerType &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...), EYIConnectionType type = EYIConnectionType::Auto);
227 
243  template<typename HandlerType, typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
244  inline CYISignalConnectionID Connect(const HandlerType &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...) const, EYIConnectionType type = EYIConnectionType::Auto);
245 
257  template<typename SlotReturnType, typename... SlotTypes>
258  CYISignalConnectionID Connect(SlotReturnType (*const pSlot)(SlotTypes...), EYIConnectionType type = EYIConnectionType::Auto, CYIThreadHandle threadAffinity = CYIThread::GetCurrentThreadId());
259 
276  template<typename HandlerType, typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
277  CYISignalConnectionID Connect(HandlerType &rSignalHandler, std::function<SlotReturnType(SlotHandlerType &, SlotTypes...)> slot, EYIConnectionType type = EYIConnectionType::Auto);
278 
293  template<typename CallableType>
295 
312  template<typename CallableType>
313  CYISignalConnectionID Connect(const CYISignalHandler &rSignalHandler, CallableType &&callable, EYIConnectionType type = EYIConnectionType::Auto);
314 
326  template<typename... OtherSignalTypes>
328 
338  inline void operator()(const typename std::decay<SignalTypes>::type &... param) const;
339 
349  inline void Emit(const typename std::decay<SignalTypes>::type &... params) const;
350 
362  template<class SlotReturnType, typename SlotHandlerType, typename... SlotTypes>
363  void Disconnect(CYISignalHandler &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...));
364 
376  template<class SlotReturnType, typename SlotHandlerType, typename... SlotTypes>
377  inline void Disconnect(CYISignalHandler &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...) const);
378 
388  template<typename SlotReturnType, typename... SlotTypes>
389  void Disconnect(SlotReturnType (*const pSlot)(SlotTypes...));
390 
391 #ifndef DOXY
392  // The following definitions exist only to generate more understandable compilation errors.
396  template<typename HandlerType, typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
397  CYISignalConnectionID Connect(const HandlerType &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...), EYIConnectionType type = EYIConnectionType::Auto);
398 
402  template<typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
403  CYISignalConnectionID Connect(SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...), EYIConnectionType type = EYIConnectionType::Auto);
404 
408  template<typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
409  CYISignalConnectionID Connect(SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...) const, EYIConnectionType type = EYIConnectionType::Auto);
410 #endif
411 
412 protected:
418  void EmitForConnection(CYISignalConnectionWrapper &connection, const CYIThreadHandle &currentThreadID, EYIConnectionType connectionType, const typename std::decay<SignalTypes>::type &... params);
419 
427  virtual void Emitted();
428 
434  virtual void ConnectionAdded(CYISignalConnectionWrapper &connection);
435 
436 private:
437  template<typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
438  size_t FindConnectionIndex(const CYISignalHandler &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...)) const;
439 
440  template<typename SlotHandlerType, typename SlotReturnType, typename... SlotTypes>
441  size_t FindConnectionIndex(const CYISignalHandler &rSignalHandler, SlotReturnType (SlotHandlerType::*const pSlot)(SlotTypes...) const) const;
442 
443  template<typename SlotReturnType, typename... SlotTypes>
444  size_t FindConnectionIndex(SlotReturnType (*const pSlot)(SlotTypes...)) const;
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  template<typename CallableType>
450  typename std::enable_if<(sizeof(CallableType) > CYISignalConnectionWrapper::s_smallLambdaStorageBytes), void>::type EmplaceConnection(SignalObjects *pSignalObjects, const CYISignalHandler *pSignalHandler, CYIThreadHandle threadAffinity, CallableType &&callable, EYIConnectionType type);
451 
452  void EmitInternal(const typename std::decay<SignalTypes>::type &... params);
453 };
454 
457 #include "signal/internal/YiSignal.inl"
458 
459 #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)
virtual ~CYISignal()
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:169
Definition: YiSignalBase.h:113
Definition: YiThreadHandle.h:45
void operator()(const typename std::decay< SignalTypes >::type &... param) const
virtual void ConnectionAdded(CYISignalConnectionWrapper &connection)