SourceXtractorPlusPlus 0.19.2
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
TaskProvider.cpp
Go to the documentation of this file.
1
24#include <mutex>
26
27namespace SourceXtractor {
28
29namespace {
30 std::mutex task_provider_mutex;
31}
32
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
Identifier used to set and retrieve properties.
Definition PropertyId.h:40
std::type_index getTypeId() const
Definition PropertyId.h:66
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.
std::unordered_map< PropertyId, std::shared_ptr< Task > > m_tasks
std::shared_ptr< TaskFactoryRegistry > m_task_factory_registry
T lock(T... args)