MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Yantra::OperationPool Class Reference

Thread-safe pool for managing named operation instances. More...

#include <OperationPool.hpp>

+ Collaboration diagram for MayaFlux::Yantra::OperationPool:

Public Types

using OperationPtr = std::shared_ptr< void >
 
using TypePredicate = std::function< bool(std::type_index)>
 
using NamePredicate = std::function< bool(const std::string &)>
 

Public Member Functions

 OperationPool ()=default
 Default constructor.
 
template<typename OpClass >
bool add (const std::string &name, std::shared_ptr< OpClass > op)
 Add named operation to pool.
 
template<typename OpClass >
void set (const std::string &name, std::shared_ptr< OpClass > op)
 Add or replace operation in pool.
 
template<typename OpClass >
std::shared_ptr< OpClass > get (const std::string &name)
 Get operation from pool with type safety.
 
template<typename OpClass >
std::optional< std::shared_ptr< OpClass > > try_get (const std::string &name)
 Try to get operation, return optional.
 
bool remove (const std::string &name)
 Remove operation from pool.
 
template<typename OpClass >
size_t remove_by_type ()
 Remove all operations of a specific type.
 
void clear ()
 Clear all operations from the pool.
 
std::vector< std::string > list_names () const
 List all operation names.
 
template<typename OpClass >
std::vector< std::string > list_names_by_type () const
 Get names of operations matching a type.
 
std::vector< std::string > find_names (const NamePredicate &predicate) const
 Get names matching a predicate.
 
bool has (const std::string &name) const
 Check if operation exists.
 
template<typename OpClass >
bool has_type () const
 Check if any operations of a type exist.
 
std::optional< std::type_index > get_type (const std::string &name) const
 Get type of named operation.
 
std::optional< PooledOperationInfoget_info (const std::string &name) const
 Get metadata about an operation.
 
size_t size () const
 Get pool size.
 
bool empty () const
 Check if pool is empty.
 
std::unordered_map< std::string, std::any > get_statistics () const
 Get statistics about pool usage.
 
void on_add (std::function< void(const std::string &, std::type_index)> callback)
 Set callback for when operations are added.
 
void on_remove (std::function< void(const std::string &, std::type_index)> callback)
 Set callback for when operations are removed.
 
void on_replace (std::function< void(const std::string &, std::type_index)> callback)
 Set callback for when operations are replaced.
 
template<typename OpClass >
size_t add_batch (const std::unordered_map< std::string, std::shared_ptr< OpClass > > &operations)
 Add multiple operations at once.
 
size_t remove_if (const NamePredicate &predicate)
 Remove operations matching a predicate.
 

Private Attributes

std::shared_mutex m_mutex
 
std::unordered_map< std::string, OperationPtrm_operations
 
std::unordered_map< std::string, PooledOperationInfom_info
 
std::function< void(const std::string &, std::type_index)> m_on_add_callback
 
std::function< void(const std::string &, std::type_index)> m_on_remove_callback
 
std::function< void(const std::string &, std::type_index)> m_on_replace_callback
 

Detailed Description

Thread-safe pool for managing named operation instances.

The OperationPool provides efficient storage and retrieval of operation instances by name. It includes thread safety, access tracking, and advanced query capabilities.

Key Features:

  • Type-safe storage and retrieval
  • Thread-safe operations with reader/writer locks
  • Access tracking and statistics
  • Bulk operations for efficiency
  • Query and filtering capabilities
  • Operation lifecycle callbacks

Definition at line 46 of file OperationPool.hpp.


The documentation for this class was generated from the following file: