MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
FunctionalOperation.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Yantra {
6
7/**
8 * @class FunctionalOperation
9 * @brief Wraps a single callable as a ComputeOperation, for a wild or
10 * one-off idea that does not warrant a hand-written class.
11 *
12 * Satisfies ComputeOperation's four pure virtuals with the smallest
13 * possible surface: operation_function delegates to the supplied
14 * function; set_parameter/get_parameter store into a plain map (no
15 * type-specific defaults, since a generic wrapper has none to offer);
16 * get_operation_type always returns OperationType::CUSTOM, since a
17 * callable supplied at construction time carries no inherent verb
18 * category. Fully interchangeable with any hand-written
19 * ComputeOperation<InputType, OutputType> subclass everywhere
20 * ComputeMatrix, GPU backend attachment, and dependency graphs are
21 * concerned: none of that machinery keys off get_operation_type().
22 *
23 * @tparam InputType ComputeData type accepted.
24 * @tparam OutputType ComputeData type produced. Defaults to InputType.
25 */
26template <ComputeData InputType = std::vector<Kakshya::DataVariant>,
27 ComputeData OutputType = InputType>
28class FunctionalOperation : public ComputeOperation<InputType, OutputType> {
29public:
32 using Fn = std::function<output_type(const input_type&)>;
33
35 : m_fn(std::move(fn))
36 {
37 }
38
39 /**
40 * @brief Construct GPU-only: dispatches entirely via gpu_backend, no
41 * callable, no CPU fallback. Matches GpuAnalyzer's contract.
42 * @param gpu_backend Configured executor. Must not be null.
43 */
45 : m_fn([](const input_type&) -> output_type {
46 error<std::runtime_error>(
47 Journal::Component::Yantra,
48 Journal::Context::BufferProcessing,
49 std::source_location::current(),
50 "FunctionalOperation: GPU unavailable and no CPU fallback provided");
51 })
52 {
53 assert(gpu_backend && "FunctionalOperation: gpu_backend must not be null");
54 this->set_gpu_backend(std::move(gpu_backend));
55 }
56
57 void set_parameter(const std::string& name, std::any value) override
58 {
59 m_parameters[name] = std::move(value);
60 }
61
62 [[nodiscard]] std::any get_parameter(const std::string& name) const override
63 {
64 auto it = m_parameters.find(name);
65 return it != m_parameters.end() ? it->second : std::any {};
66 }
67
68 [[nodiscard]] std::map<std::string, std::any> get_all_parameters() const override
69 {
70 return { m_parameters.begin(), m_parameters.end() };
71 }
72
73 [[nodiscard]] OperationType get_operation_type() const override
74 {
76 }
77
78protected:
80 {
81 return m_fn(input);
82 }
83
84private:
86 std::unordered_map<std::string, std::any> m_parameters;
87};
88
89} // namespace MayaFlux::Yantra
Core::GlobalInputConfig input
Definition Config.cpp:42
glm::vec2 current
glm::vec3 value
std::string name
Definition VKDevice.cpp:123
Base interface for all computational operations in the processing pipeline.
FunctionalOperation(std::shared_ptr< GpuExecutionContext< InputType, OutputType > > gpu_backend)
Construct GPU-only: dispatches entirely via gpu_backend, no callable, no CPU fallback.
std::unordered_map< std::string, std::any > m_parameters
std::map< std::string, std::any > get_all_parameters() const override
Retrieves all parameters and their values.
output_type operation_function(const input_type &input) override
Executes the computational transformation on the input data.
OperationType get_operation_type() const override
Returns the category of this operation for grammar and registry discovery.
std::function< output_type(const input_type &)> Fn
std::any get_parameter(const std::string &name) const override
Retrieves a parameter's current value.
void set_parameter(const std::string &name, std::any value) override
Sets a named parameter that configures the operation's behavior.
Wraps a single callable as a ComputeOperation, for a wild or one-off idea that does not warrant a han...
Type-parameterised shell over GpuDispatchCore.
OperationType
Operation categories for organization and discovery.
Input/Output container for computation pipeline data flow with structure preservation.
Definition DataIO.hpp:26