Helios++
Helios software for LiDAR simulations
SharedSubTask.h
1 #pragma once
2 
3 #include <SharedSubTaskCompletionHandler.h>
4 
5 #include <boost/thread.hpp>
6 
7 #include <memory>
8 
17 protected:
18  // *** ATTRIBUTES *** //
19  // ******************** //
28  std::shared_ptr<SharedSubTaskCompletionHandler> ch;
35  size_t key = 0;
41  std::shared_ptr<boost::thread> thread = nullptr;
42 
43 public:
44  // *** CONSTRUCTION / DESTRUCTION *** //
45  // ************************************ //
50  SharedSubTask(std::shared_ptr<SharedSubTaskCompletionHandler> ch) :
51  ch(ch),
52  key(0)
53  {}
54  virtual ~SharedSubTask() = default;
55 
56  // *** FUNCTOR *** //
57  // ***************** //
64  virtual inline void operator() (){
65  run();
66  if(ch != nullptr) ch->onSharedSubTaskCompletion(key);
67  }
68 
69  // *** RUNNABLE SHARED TASK *** //
70  // ****************************** //
76  virtual void run() = 0;
82  virtual void postProcess() {}
83 
84  // *** GETTERs and SETTERs *** //
85  // ***************************** //
93  virtual size_t getKey() {return key;}
101  virtual void setKey(size_t const key) {this->key = key;}
107  virtual std::shared_ptr<boost::thread> getThread() {return thread;}
113  virtual void setThread(std::shared_ptr<boost::thread> thread)
114  {this->thread = thread;}
115 };
A shared task is said to be a collection of shared sub-tasks. Each shared sub-task can be computed in...
Definition: SharedSubTask.h:16
virtual void setThread(std::shared_ptr< boost::thread > thread)
Set the thread associated to the shared sub-task.
Definition: SharedSubTask.h:113
size_t key
The key identifying the shared sub task inside the shared task sequencer context.
Definition: SharedSubTask.h:35
virtual void postProcess()
Post-processing to be applied after shared sub-task has finished. By default it is a void function wh...
Definition: SharedSubTask.h:82
virtual void setKey(size_t const key)
Set the key of the shared sub-task inside the shared task sequencer context.
Definition: SharedSubTask.h:101
std::shared_ptr< boost::thread > thread
The thread associated with the shared sub-tasks. It is nullptr until the shared sub-task has been sta...
Definition: SharedSubTask.h:41
virtual void operator()()
The functor that will be called by any thread. It calls the SharedSubTask::run method to solve/comput...
Definition: SharedSubTask.h:64
virtual size_t getKey()
Obtain the key of the shared sub-task inside the shared task sequencer context.
Definition: SharedSubTask.h:93
virtual void run()=0
Abstract run function that must be implemented by any derived class which pretends to provide a concr...
SharedSubTask(std::shared_ptr< SharedSubTaskCompletionHandler > ch)
Default constructor for shared sub-task.
Definition: SharedSubTask.h:50
std::shared_ptr< SharedSubTaskCompletionHandler > ch
The shared sub-task completion handler that handles what must be done after a shared sub-task executi...
Definition: SharedSubTask.h:28
virtual std::shared_ptr< boost::thread > getThread()
Get the thread associated to the shared sub-task.
Definition: SharedSubTask.h:107