FAST.Framework  1.0.0
FSignal.h
1 /******************************************************************************
2 **
3 ** FAST.Framework
4 **
5 ** Created: 2023-10-11
6 ** Author: Boris Fast
7 ** Mail: support@fast-framework.com
8 **
9 ******************************************************************************/
10 
11 #ifndef FSIGNAL_H
12 #define FSIGNAL_H
13 
14 #include <vector>
15 
16 using namespace std;
17 
18 #include "FObject.h"
19 #include "FString.h"
20 #include "FSlot.h"
21 
25 template <typename ...Args>
26 class FSignal : public FObject
27 {
28  public:
29  FSignal(const FSignal&) = delete;
30  FSignal(FSignal&&) = delete;
31  FSignal& operator=(const FSignal&) = delete;
32 
33  FSignal() = default;
34  virtual ~FSignal() { Disconnect(); }
35 
36  inline void Connect(FSlot<Args...>& slot)
37  {
38  this->slots.push_back(&slot);
39  }
40 
41  inline void Disconnect(FSlot<Args...>& slot) const
42  {
43  for (auto it = this->slots.begin(); it != this->slots.end(); )
44  {
45  if (*it == slot) { it = this->slots.erase(); return; }
46  else ++it;
47  }
48  }
49 
50  inline void Disconnect() { this->slots.clear(); }
51 
52  inline void Send(Args... args) const
53  {
54  for (auto& slot : this->slots)
55  {
56  slot->Call(args...);
57  }
58  }
59 
60  inline const type_info& GetType() override
61  {
62  return typeid(FSignal);
63  }
64 
65  inline FString GetName() const override
66  {
67  return typeid(FSignal).name();
68  }
69 
70  private:
71  std::vector<FSlot<Args...>*> slots;
72 };
73 
74 #endif // FSIGNAL_H
Definition: FObject.h:50
Definition: FSignal.h:27
const type_info & GetType() override
< Returns the type info over object
Definition: FSignal.h:60
void Disconnect(FSlot< Args... > &slot) const
< Disconnect from slot
Definition: FSignal.h:41
void Connect(FSlot< Args... > &slot)
Definition: FSignal.h:36
FSignal(const FSignal &)=delete
Delete copy constructor.
FSignal(FSignal &&)=delete
Delete copy constructor.
void Send(Args... args) const
< Send value
Definition: FSignal.h:52
FString GetName() const override
< Returns the name of object
Definition: FSignal.h:65
FSignal & operator=(const FSignal &)=delete
Delete copy operator.
FSignal()=default
Constructor of signal object.
void Disconnect()
Disconnect from all slots.
Definition: FSignal.h:50
virtual ~FSignal()
Destroy signal object.
Definition: FSignal.h:34
Definition: FSlot.h:26
Definition: FString.h:22