MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
OperatorChain.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "NetworkOperator.hpp"
4
6
7/**
8 * @class OperatorChain
9 * @brief Ordered sequence of secondary operators applied after the primary operator.
10 *
11 * Mirrors the role of BufferProcessingChain relative to a Buffer's default processor.
12 * NodeNetwork subclasses hold one primary operator (m_operator / create_operator<T>)
13 * whose contract and external API remain unchanged. OperatorChain holds zero or more
14 * additional operators that run in insertion order immediately after the primary.
15 *
16 * Ownership is shared: callers receive a shared_ptr<OpType> from emplace() and may
17 * retain it for runtime reconfiguration (rebinding Tendency fields, adjusting
18 * parameters) while the chain also holds a reference. Removal by pointer identity
19 * is supported via remove().
20 *
21 * The chain has no knowledge of vertex layouts, domains, or which operator holds
22 * final vertex state. Those concerns belong to the owning NodeNetwork subclass,
23 * exposed via NodeNetwork::get_graphics_operator().
24 *
25 * Thread safety: not internally synchronised. All mutations must occur outside the
26 * network's process_batch() call.
27 */
28class MAYAFLUX_API OperatorChain {
29public:
30 OperatorChain() = default;
31 ~OperatorChain() = default;
32
33 OperatorChain(const OperatorChain&) = delete;
37
38 // -------------------------------------------------------------------------
39 // Insertion
40 // -------------------------------------------------------------------------
41
42 /**
43 * @brief Append an already-constructed operator to the chain.
44 * @param op Operator to append. Must be non-null.
45 */
46 void add(std::shared_ptr<NetworkOperator> op);
47
48 /**
49 * @brief Construct an operator in-place and append it.
50 * @tparam OpType Concrete operator type.
51 * @tparam Args Constructor argument types.
52 * @param args Arguments forwarded to OpType constructor.
53 * @return Shared pointer to the newly constructed operator.
54 */
55 template <typename OpType, typename... Args>
56 std::shared_ptr<OpType> emplace(Args&&... args)
57 {
58 auto op = std::make_shared<OpType>(std::forward<Args>(args)...);
59 m_operators.push_back(op);
60 return op;
61 }
62
63 // -------------------------------------------------------------------------
64 // Removal
65 // -------------------------------------------------------------------------
66
67 /**
68 * @brief Remove a specific operator by pointer identity.
69 * @param op Operator to remove. No-op if not found.
70 */
71 void remove(const std::shared_ptr<NetworkOperator>& op);
72
73 /**
74 * @brief Remove all operators from the chain.
75 */
76 void clear();
77
78 // -------------------------------------------------------------------------
79 // Processing
80 // -------------------------------------------------------------------------
81
82 /**
83 * @brief Call process(dt) on each operator in insertion order.
84 *
85 * @param dt Time delta or sample count passed to each operator.
86 * @param upstream Primary operator output to offer as upstream context.
87 * Passed to each chain operator that declares
88 * consumes_upstream() == true before its process() call.
89 * Null is valid (no upstream available).
90 */
91 void process(float dt, const NetworkOperator* upstream = nullptr);
92
93 // -------------------------------------------------------------------------
94 // Query
95 // -------------------------------------------------------------------------
96
97 /**
98 * @brief Returns true when the chain contains no operators.
99 */
100 [[nodiscard]] bool empty() const { return m_operators.empty(); }
101
102 /**
103 * @brief Number of operators currently in the chain.
104 */
105 [[nodiscard]] size_t size() const { return m_operators.size(); }
106
107 /**
108 * @brief Return the operator at the given index, or nullptr if out of range.
109 * @param index Zero-based position in insertion order.
110 */
111 [[nodiscard]] std::shared_ptr<NetworkOperator> get(size_t index) const;
112
113 /**
114 * @brief Return the first operator whose dynamic type matches OpType, or nullptr.
115 * @tparam OpType Type to search for.
116 */
117 template <typename OpType>
118 [[nodiscard]] std::shared_ptr<OpType> find() const
119 {
120 for (const auto& op : m_operators) {
121 if (auto cast = std::dynamic_pointer_cast<OpType>(op))
122 return cast;
123 }
124 return nullptr;
125 }
126
127 /**
128 * @brief Read-only access to the underlying operator vector.
129 *
130 * Used by NodeNetwork::get_graphics_operator() to scan the chain
131 * without embedding domain assumptions inside OperatorChain itself.
132 */
133 [[nodiscard]] const std::vector<std::shared_ptr<NetworkOperator>>& operators() const
134 {
135 return m_operators;
136 }
137
138private:
139 std::vector<std::shared_ptr<NetworkOperator>> m_operators;
140};
141
142} // namespace MayaFlux::Nodes::Network
Domain-agnostic interpretive lens for network processing.
std::vector< std::shared_ptr< NetworkOperator > > m_operators
std::shared_ptr< OpType > emplace(Args &&... args)
Construct an operator in-place and append it.
const std::vector< std::shared_ptr< NetworkOperator > > & operators() const
Read-only access to the underlying operator vector.
OperatorChain & operator=(const OperatorChain &)=delete
std::shared_ptr< OpType > find() const
Return the first operator whose dynamic type matches OpType, or nullptr.
OperatorChain(OperatorChain &&)=default
size_t size() const
Number of operators currently in the chain.
OperatorChain & operator=(OperatorChain &&)=default
bool empty() const
Returns true when the chain contains no operators.
OperatorChain(const OperatorChain &)=delete
Ordered sequence of secondary operators applied after the primary operator.