MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ add()

template<typename OpClass >
bool MayaFlux::Yantra::OperationPool::add ( const std::string &  name,
std::shared_ptr< OpClass >  op 
)
inline

Add named operation to pool.

Template Parameters
OpClassOperation class type
Parameters
nameUnique name for the operation
opShared pointer to the operation
Returns
true if added successfully, false if name already exists

Definition at line 65 of file OperationPool.hpp.

66 {
67 if (!op) {
68 return false;
69 }
70
71 std::unique_lock lock(m_mutex);
72
73 if (m_operations.contains(name)) {
74 return false;
75 }
76
77 m_operations[name] = std::static_pointer_cast<void>(op);
78
79 PooledOperationInfo info;
80 info.name = name;
81 info.type = std::type_index(typeid(OpClass));
82 info.created_at = std::chrono::steady_clock::now();
83 info.last_accessed = info.created_at;
84 info.access_count = 0;
85
86 m_info[name] = std::move(info);
87
89 m_on_add_callback(name, info.type);
90 }
91
92 return true;
93 }
std::function< void(const std::string &, std::type_index)> m_on_add_callback
std::unordered_map< std::string, PooledOperationInfo > m_info
std::unordered_map< std::string, OperationPtr > m_operations

References MayaFlux::Yantra::PooledOperationInfo::access_count, MayaFlux::Yantra::PooledOperationInfo::created_at, MayaFlux::Yantra::PooledOperationInfo::last_accessed, m_info, m_mutex, m_on_add_callback, m_operations, MayaFlux::Yantra::PooledOperationInfo::name, and MayaFlux::Yantra::PooledOperationInfo::type.