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 * @param dt Time delta or sample count passed through to each operator.
85 */
86 void process(float dt);
87
88 // -------------------------------------------------------------------------
89 // Query
90 // -------------------------------------------------------------------------
91
92 /**
93 * @brief Returns true when the chain contains no operators.
94 */
95 [[nodiscard]] bool empty() const { return m_operators.empty(); }
96
97 /**
98 * @brief Number of operators currently in the chain.
99 */
100 [[nodiscard]] size_t size() const { return m_operators.size(); }
101
102 /**
103 * @brief Return the operator at the given index, or nullptr if out of range.
104 * @param index Zero-based position in insertion order.
105 */
106 [[nodiscard]] std::shared_ptr<NetworkOperator> get(size_t index) const;
107
108 /**
109 * @brief Return the first operator whose dynamic type matches OpType, or nullptr.
110 * @tparam OpType Type to search for.
111 */
112 template <typename OpType>
113 [[nodiscard]] std::shared_ptr<OpType> find() const
114 {
115 for (const auto& op : m_operators) {
116 if (auto cast = std::dynamic_pointer_cast<OpType>(op))
117 return cast;
118 }
119 return nullptr;
120 }
121
122 /**
123 * @brief Read-only access to the underlying operator vector.
124 *
125 * Used by NodeNetwork::get_graphics_operator() to scan the chain
126 * without embedding domain assumptions inside OperatorChain itself.
127 */
128 [[nodiscard]] const std::vector<std::shared_ptr<NetworkOperator>>& operators() const
129 {
130 return m_operators;
131 }
132
133private:
134 std::vector<std::shared_ptr<NetworkOperator>> m_operators;
135};
136
137} // namespace MayaFlux::Nodes::Network
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.