FAST.Framework  1.0.0
FThread.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 FTHREAD_H
12 #define FTHREAD_H
13 
14 #include <thread>
15 
16 using namespace std;
17 
18 #include "FObject.h"
19 #include "FString.h"
20 #include "FSignal.h"
21 
25 class FThread : public FObject
26 {
27  public:
28  FThread(const FThread&) = delete;
29 
30  template <class Function, class... Args>
31  explicit FThread(Function&& function, Args&&... args) noexcept;
32  FThread() noexcept;
33  virtual ~FThread();
34 
35  template <class Function, class... Args>
36  void Start(Function&& function, Args&&... args) noexcept;
37 
38  void Join() const noexcept;
39  void Detach() const noexcept;
40  void Abord() const noexcept;
41 
42  std::thread::id Id() const noexcept;
43 
44  void operator=(FThread&& thread) noexcept;
46 
47  Boolean operator==(const FThread& thread) const noexcept;
48  Boolean operator!=(const FThread& thread) const noexcept;
49 
50  void StartedHandle(FSlot<int>& slot);
51  void CompletedHandle(FSlot<int>& slot);
52 
53  static void Sleep(UInt duration);
54 
55  inline const type_info& GetType() override { return typeid(FThread); }
56  inline FString GetName() const override
57  {
58  return typeid(FThread).name();
59  }
60 
61  private:
62  std::thread* buffer;
63  FSignal<Int> started;
64  FSignal<Int> completed;
65 };
66 
67 #endif // FTHREAD_H
68 
69 template <class Function, class... Args>
70 inline FThread::FThread(Function&& function, Args&&... args) noexcept
71 {
72  this->buffer = new std::thread(function, args...);
73  this->started.Send(SUCCESSFULL);
74 }
75 
76 template<class Function, class ...Args>
77 inline void FThread::Start(Function&& function, Args&& ...args) noexcept
78 {
79  this->buffer = new std::thread(function, args...);
80  this->started.Send(SUCCESSFULL);
81 }
Definition: FObject.h:50
Definition: FSlot.h:26
Definition: FString.h:22
Definition: FThread.h:26
FString GetName() const override
< Returns the name of object
Definition: FThread.h:56
FThread(const FThread &)=delete
Delete standard constructor.
void Start(Function &&function, Args &&... args) noexcept
< Start the thread with parameters
Definition: FThread.h:77
FThread() noexcept
Constructor of thread object.
Definition: FThread.cpp:6