SourceXtractorPlusPlus  0.12
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TaskProvider.cpp
Go to the documentation of this file.
1 
24 #include <mutex>
26 
27 namespace SourceXtractor {
28 
29 namespace {
30  std::mutex task_provider_mutex;
31 }
32 
33 std::shared_ptr<const Task> TaskProvider::getTask(const PropertyId& property_id) const {
34  std::lock_guard<std::mutex> lock(task_provider_mutex);
35 
36  // tries to find the Task for the property
37  auto iterTask = m_tasks.find(property_id);
38 
39  if (iterTask != m_tasks.end()) {
40  return iterTask->second;
41  } else if (m_task_factory_registry != nullptr) {
42  // Use the TaskFactoryRegistry to get the correct factory for the requested property_id
43  auto& task_factory = m_task_factory_registry->getFactory(property_id.getTypeId());
44  auto task = task_factory.createTask(property_id);
45 
46  // Put it in the cache
47  const_cast<TaskProvider&>(*this).m_tasks[property_id] = task;
48 
49  return task;
50  } else {
51  return nullptr;
52  }
53 }
54 
55 } // SEFramework namespace
std::shared_ptr< const T > getTask(const PropertyId &property_id) const
Template version of getTask() that includes casting the returned pointer to the appropriate type...
Definition: TaskProvider.h:54
std::unordered_map< PropertyId, std::shared_ptr< Task > > m_tasks
Definition: TaskProvider.h:63
T lock(T...args)
TaskProvider(std::shared_ptr< TaskFactoryRegistry > task_factory_registry)
Definition: TaskProvider.h:49
std::shared_ptr< TaskFactoryRegistry > m_task_factory_registry
Definition: TaskProvider.h:62