20#define DECLARE_OPERATION_TRAITS(CATEGORY) \
21 static constexpr OperationType operation_category = OperationType::CATEGORY; \
22 using base_input_type = typename base_type::input_type; \
23 using base_output_type = typename base_type::output_type; \
24 static constexpr const char* operation_name = #CATEGORY;
42 using Factory = std::function<std::any()>;
48 template <
typename OpClass>
52 "Operation must have intrinsic type information. Use DECLARE_OPERATION_TRAITS macro.");
55 register_operation<OpClass>(category);
63 template <
typename OpClass>
68 .operation_type = std::type_index(
typeid(OpClass))
72 return static_pointer_cast<void>(std::make_shared<OpClass>());
76 std::type_index(
typeid(
typename OpClass::input_type)),
77 std::type_index(
typeid(
typename OpClass::output_type))
87 template <
typename OpClass>
89 std::function<std::shared_ptr<OpClass>()> factory)
93 .operation_type = std::type_index(
typeid(OpClass))
97 return std::static_pointer_cast<void>(factory());
101 std::type_index(
typeid(
typename OpClass::input_type)),
102 std::type_index(
typeid(
typename OpClass::output_type))
111 template <
typename OpClass>
115 TypeKey key { OpClass::operation_category, std::type_index(
typeid(OpClass)) };
118 return std::static_pointer_cast<OpClass>(
119 std::any_cast<std::shared_ptr<void>>(it->second()));
124 if (key.operation_type == std::type_index(
typeid(OpClass))) {
125 return std::static_pointer_cast<OpClass>(
126 std::any_cast<std::shared_ptr<void>>(factory()));
138 template <
typename OpClass>
141 return std::ranges::any_of(
m_factories, [](
const auto& pair) {
142 const auto& key = pair.first;
143 return key.operation_type == std::type_index(
typeid(OpClass));
155 std::type_index input_type,
156 std::type_index output_type)
const
158 std::vector<std::type_index> results;
161 if (key.category == category && type_info.first == input_type && type_info.second == output_type) {
162 results.push_back(key.operation_type);
176 std::vector<std::type_index> results;
179 if (key.category == category) {
180 results.push_back(key.operation_type);
192 template <
typename OpClass>
195 auto type_idx = std::type_index(
typeid(OpClass));
198 if (key.operation_type == type_idx) {
237 return std::hash<int>()(
static_cast<int>(key.
category)) ^ std::hash<std::type_index>()(key.
operation_type);
244 template <
typename T,
typename =
void>
247 template <
typename T>
249 : std::true_type { };
251 template <
typename T,
typename =
void>
254 template <
typename T>
255 struct has_operation_traits<T,
std::void_t<decltype(T::operation_category), typename T::input_type, typename T::output_type>> : std::true_type { };
264 static auto registry = std::make_shared<OperationRegistry>();
272template <
typename OpClass>
284#define REGISTER_OPERATION(OpClass) \
285 static MayaFlux::Yantra::AutoRegisterOperation<OpClass> _auto_register_##OpClass;
size_t size() const
Get total number of registered operations.
void register_operation(OperationType category)
Register with explicit category (for operations without traits)
bool is_registered() const
Check if an operation type is registered.
std::unordered_map< TypeKey, Factory, TypeKeyHash > m_factories
void register_operation()
Register an operation using its intrinsic traits.
std::unordered_map< TypeKey, std::pair< std::type_index, std::type_index >, TypeKeyHash > m_type_info
void register_operation_with_factory(OperationType category, std::function< std::shared_ptr< OpClass >()> factory)
Register with custom factory function.
std::vector< std::type_index > get_operations_by_category(OperationType category) const
Get all registered operations of a specific category.
std::function< std::any()> Factory
std::vector< std::type_index > discover_operations(OperationType category, std::type_index input_type, std::type_index output_type) const
Discover operations matching specific criteria.
std::shared_ptr< OpClass > create()
Create an operation instance.
void clear()
Clear all registrations.
std::optional< OperationType > get_category() const
Get category for a registered operation type.
Manages operation type registration, discovery, and factory creation.
OperationType
Operation categories for organization and discovery.
std::shared_ptr< OperationRegistry > get_operation_registry()
Global operation registry accessor Similar to how Engine provides global access to core systems.
Automatic registration helper Operations can use this in their implementation files for auto-registra...
std::size_t operator()(const TypeKey &key) const
std::type_index operation_type
bool operator==(const TypeKey &other) const