MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Logic.hpp
Go to the documentation of this file.
1#pragma once
2
4
6
7/**
8 * @enum LogicMode
9 * @brief Defines the computational model for digital signal evaluation
10 */
11enum class LogicMode : uint8_t {
12 DIRECT, ///< Stateless evaluation of current input only (combinational logic)
13 SEQUENTIAL, ///< State-based evaluation using history of inputs (sequential logic)
14 TEMPORAL, ///< Time-dependent evaluation with timing constraints
15 MULTI_INPUT ///< Parallel evaluation of multiple input signals
16};
17
18/**
19 * @enum LogicOperator
20 * @brief Digital operators for boolean computation
21 */
22enum class LogicOperator : uint8_t {
23 AND, ///< Logical AND - true only when all inputs are true
24 OR, ///< Logical OR - true when any input is true
25 XOR, ///< Logical XOR - true when odd number of inputs are true
26 NOT, ///< Logical NOT - inverts the input
27 NAND, ///< Logical NAND - inverted AND operation
28 NOR, ///< Logical NOR - inverted OR operation
29 IMPLIES, ///< Logical implication - false only when A is true and B is false
30 THRESHOLD, ///< Binary quantization - true when input exceeds threshold
31 HYSTERESIS, ///< Threshold with memory - prevents rapid oscillation at boundary
32 EDGE, ///< Transition detector - identifies state changes
33 CUSTOM ///< User-defined boolean function
34};
35
36/**
37 * @enum EdgeType
38 * @brief Digital transition patterns to detect
39 */
40enum class EdgeType : uint8_t {
41 RISING, ///< Low-to-high transition (0→1)
42 FALLING, ///< High-to-low transition (1→0)
43 BOTH ///< Any state transition
44};
45
46/**
47 * @enum LogicEventType
48 * @brief Events that can trigger callbacks
49 */
50enum class LogicEventType : uint8_t {
51 TICK, // Every sample
52 CHANGE, // Any state change
53 TRUE, // Change to true
54 FALSE, // Change to false
55 WHILE_TRUE, // Every tick while true
56 WHILE_FALSE, // Every tick while false
57 CONDITIONAL // Custom condition
58};
59
60class MAYAFLUX_API LogicContext : public NodeContext {
61public:
62 /**
63 * @brief Constructs a LogicContext with complete state information
64 * @param value Current output value (0.0 for false, 1.0 for true)
65 * @param mode Current computational model
66 * @param operator_type Current boolean operator
67 * @param history Buffer of previous boolean states
68 * @param threshold Decision boundary for binary quantization
69 * @param edge_detected Whether a state transition was detected
70 * @param edge_type Type of transition being monitored
71 * @param inputs Current input values for multi-input evaluation
72 */
73 LogicContext(double value,
74 LogicMode mode,
75 LogicOperator operator_type,
76 std::span<bool> history,
77 double threshold,
78 bool edge_detected = false,
79 EdgeType edge_type = EdgeType::BOTH,
80 const std::vector<double>& inputs = {})
81 : NodeContext(value, typeid(LogicContext).name())
82 , m_mode(mode)
83 , m_operator(operator_type)
84 , m_history(history)
85 , m_threshold(threshold)
86 , m_edge_detected(edge_detected)
87 , m_edge_type(edge_type)
88 , m_inputs(inputs)
89 , m_input(value)
90 {
91 }
92
93 // Getters for context properties
94 LogicMode get_mode() const { return m_mode; }
95 LogicOperator get_operator() const { return m_operator; }
96 std::span<bool> get_history() const { return m_history; }
97 double get_threshold() const { return m_threshold; }
98 bool is_edge_detected() const { return m_edge_detected; }
99 EdgeType get_edge_type() const { return m_edge_type; }
100 const std::vector<double>& get_inputs() const { return m_inputs; }
101 const double& get_value() const { return m_input; }
102
103 // Boolean conversion of the current value
104 bool as_bool() const { return get_value() > 0.5; }
105
106private:
107 LogicMode m_mode; ///< Current computational model
108 LogicOperator m_operator; ///< Current boolean operator
109 std::span<bool> m_history; ///< History of boolean states
110 double m_threshold; ///< Decision boundary for binary quantization
111 bool m_edge_detected; ///< Whether a state transition was detected
112 EdgeType m_edge_type; ///< Type of transition being monitored
113 const std::vector<double>& m_inputs; ///< Current input values (for multi-input mode)
114 double m_input; ///< Current input value for multi-input mode
115
116 friend class Logic;
117};
118
119/**
120 * @class LogicContextGpu
121 * @brief GPU-accelerated context for logic node callbacks
122 */
123class MAYAFLUX_API LogicContextGpu
124 : public LogicContext,
125 public GpuVectorData {
126public:
128 double value,
129 LogicMode mode,
130 LogicOperator operator_type,
131 std::span<bool> history,
132 double threshold,
133 bool edge_detected,
134 EdgeType edge_type,
135 const std::vector<double>& inputs,
136 std::span<const float> gpu_data)
137 : LogicContext(value, mode, operator_type, history, threshold, edge_detected, edge_type, inputs)
138 , GpuVectorData(gpu_data)
139 {
140 type_id = typeid(LogicContextGpu).name();
141 }
142};
143
144/**
145 * @class Logic
146 * @brief Digital signal processor implementing boolean logic operations
147 *
148 * The Logic node transforms continuous signals into discrete binary outputs
149 * using configurable boolean operations. It supports multiple computational models:
150 *
151 * - Combinational logic: Stateless evaluation based solely on current inputs
152 * - Sequential logic: State-based evaluation using history of previous inputs
153 * - Temporal logic: Time-dependent evaluation with timing constraints
154 * - Multi-input logic: Parallel evaluation of multiple input signals
155 *
156 * Applications include:
157 * - Binary signal generation
158 * - Event detection and triggering
159 * - State machine implementation
160 * - Digital pattern recognition
161 * - Signal quantization and discretization
162 * - Conditional processing chains
163 */
164class MAYAFLUX_API Logic : public Generator {
165public:
166 /**
167 * @brief Function type for stateless boolean evaluation
168 */
169 using DirectFunction = std::function<bool(double)>;
170
171 /**
172 * @brief Function type for parallel input evaluation
173 */
174 using MultiInputFunction = std::function<bool(const std::vector<double>&)>;
175
176 /**
177 * @brief Function type for state-based evaluation
178 */
179 using SequentialFunction = std::function<bool(std::span<bool>)>;
180
181 /**
182 * @brief Function type for time-dependent evaluation
183 */
184 using TemporalFunction = std::function<bool(double, double)>; // input, time
185
186 /**
187 * @brief Constructs a Logic node with threshold quantization
188 * @param threshold Decision boundary for binary quantization
189 *
190 * Creates a basic binary quantizer that outputs 1.0 when input exceeds
191 * the threshold and 0.0 otherwise.
192 */
193 explicit Logic(double threshold = 0.5);
194
195 /**
196 * @brief Constructs a Logic node with a specific boolean operator
197 * @param op Boolean operator to apply
198 * @param threshold Decision boundary for binary quantization
199 *
200 * Creates a Logic node configured with one of the standard boolean
201 * operations (AND, OR, XOR, etc.) using the specified threshold
202 * for binary quantization of inputs.
203 */
204 Logic(LogicOperator op, double threshold = 0.5);
205
206 /**
207 * @brief Constructs a Logic node with a custom combinational function
208 * @param function Custom function implementing stateless boolean logic
209 *
210 * Creates a Logic node that applies a user-defined function to each input
211 * sample, enabling custom combinational logic operations beyond the
212 * standard operators.
213 */
214 explicit Logic(DirectFunction function);
215
216 /**
217 * @brief Constructs a Logic node for parallel input evaluation
218 * @param function Function implementing multi-input boolean logic
219 * @param input_count Number of parallel inputs to process
220 *
221 * Creates a Logic node that evaluates multiple inputs simultaneously,
222 * enabling implementation of complex decision functions like voting
223 * systems, majority logic, or custom multi-input boolean operations.
224 */
225 Logic(MultiInputFunction function, size_t input_count);
226
227 /**
228 * @brief Constructs a Logic node for state-based evaluation
229 * @param function Function implementing sequential boolean logic
230 * @param history_size Size of the state history buffer
231 *
232 * Creates a Logic node that maintains a history of previous states
233 * and evaluates new inputs in the context of this history. This enables
234 * implementation of sequential logic circuits, pattern detectors,
235 * and finite state machines.
236 */
237 Logic(SequentialFunction function, size_t history_size);
238
239 /**
240 * @brief Constructs a Logic node for time-dependent evaluation
241 * @param function Function implementing temporal boolean logic
242 *
243 * Creates a Logic node that evaluates inputs based on both their value
244 * and the time at which they occur. This enables implementation of
245 * timing-sensitive operations like pulse width detection, timeout
246 * monitoring, and rate-of-change analysis.
247 */
248 explicit Logic(TemporalFunction function);
249
250 virtual ~Logic() = default;
251
252 /**
253 * @brief Processes a single input sample through the logic function
254 * @param input Input value to evaluate
255 * @return 1.0 for true result, 0.0 for false result
256 *
257 * Evaluates the input according to the configured logic operation
258 * and computational model, producing a binary output (0.0 or 1.0).
259 */
260 double process_sample(double input = 0.) override;
261
262 /**
263 * @brief Processes multiple samples in batch mode
264 * @param num_samples Number of samples to generate
265 * @return Vector of binary outputs (1.0 for true, 0.0 for false)
266 *
267 * Generates a sequence of binary values by repeatedly applying
268 * the configured logic operation. In stateful modes, each output
269 * depends on previous results.
270 */
271 std::vector<double> process_batch(unsigned int num_samples) override;
272
273 /**
274 * @brief Processes multiple parallel inputs
275 * @param inputs Vector of input values to evaluate together
276 * @return 1.0 for true result, 0.0 for false result
277 *
278 * Evaluates multiple inputs simultaneously according to the configured
279 * multi-input logic function, producing a single binary output.
280 */
281 double process_multi_input(const std::vector<double>& inputs);
282
283 /**
284 * @brief Resets internal state to initial conditions
285 *
286 * Clears history buffers, resets state variables, and returns
287 * the node to its initial configuration. Essential for restarting
288 * sequential processing or clearing accumulated state.
289 */
290 void reset();
291
292 /**
293 * @brief Sets the decision boundary for binary quantization
294 * @param threshold Value above which input is considered true
295 * @param create_default_direct_function Whether to create a default direct function if none is set
296 *
297 * Configures the threshold used to convert continuous input values
298 * to binary states (true/false). Critical for accurate digital
299 * interpretation of analog-like signals.
300 */
301 void set_threshold(double threshold, bool create_default_direct_function = false);
302
303 /**
304 * @brief Configures noise-resistant binary quantization with memory
305 * @param low_threshold Value below which input becomes false
306 * @param high_threshold Value above which input becomes true
307 * @param create_default_direct_function Whether to create a default direct function if none is set
308 *
309 * Implements a Schmitt trigger with separate thresholds for rising and falling
310 * transitions, preventing rapid oscillation when input hovers near the threshold.
311 * Essential for stable binary quantization of noisy signals.
312 */
313 void set_hysteresis(double low_threshold, double high_threshold, bool create_default_direct_function = false);
314
315 /**
316 * @brief Configures digital transition detection
317 * @param type Type of transition to detect (rising, falling, or both)
318 * @param threshold Decision boundary for state changes
319 *
320 * Sets up the node to detect specific types of state transitions
321 * (edges) in the input signal. Useful for event detection, trigger
322 * generation, and synchronization with external events.
323 */
324 void set_edge_detection(EdgeType type, double threshold = 0.5);
325
326 /**
327 * @brief Sets the boolean operation to perform
328 * @param op Boolean operator to apply
329 * @param create_default_direct_function Whether to create a default direct function if none is set
330 *
331 * Configures the node to use one of the standard boolean operations
332 * (AND, OR, XOR, etc.) for evaluating inputs.
333 */
334 void set_operator(LogicOperator op, bool create_default_direct_function = false);
335
336 /**
337 * @brief Sets a custom combinational logic function
338 * @param function Custom function implementing stateless boolean logic
339 *
340 * Configures the node to use a user-defined function for stateless
341 * evaluation of inputs, enabling custom combinational logic beyond
342 * the standard operators.
343 */
344 void set_direct_function(DirectFunction function);
345
346 /**
347 * @brief Sets a custom parallel input evaluation function
348 * @param function Function implementing multi-input boolean logic
349 * @param input_count Number of parallel inputs to process
350 *
351 * Configures the node to evaluate multiple inputs simultaneously
352 * using a user-defined function, enabling implementation of complex
353 * decision functions like voting systems or custom multi-input operations.
354 */
355 void set_multi_input_function(MultiInputFunction function, size_t input_count);
356
357 /**
358 * @brief Sets a custom state-based evaluation function
359 * @param function Function implementing sequential boolean logic
360 * @param history_size Size of the state history buffer
361 *
362 * Configures the node to maintain a history of previous states and
363 * evaluate new inputs in this context using a user-defined function.
364 * Enables implementation of sequential logic, pattern detectors, and
365 * finite state machines.
366 */
367 void set_sequential_function(SequentialFunction function, size_t history_size);
368
369 /**
370 * @brief Sets a custom time-dependent evaluation function
371 * @param function Function implementing temporal boolean logic
372 *
373 * Configures the node to evaluate inputs based on both their value
374 * and timing using a user-defined function. Enables implementation of
375 * timing-sensitive operations like pulse width detection and rate analysis.
376 */
377 void set_temporal_function(TemporalFunction function);
378
379 /**
380 * @brief Preloads the state history buffer
381 * @param initial_values Vector of initial boolean states
382 *
383 * Initializes the history buffer with specified values, allowing
384 * sequential logic to begin operation with a predefined state sequence.
385 * Useful for testing specific patterns or starting from known states.
386 */
387 void set_initial_conditions(const std::vector<bool>& initial_values);
388
389 /**
390 * @brief Sets the input node to generate logic values from
391 * @param input_node Node providing the input values
392 *
393 * Configures the node to receive input from another node
394 */
395 inline void set_input_node(const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
396
397 /**
398 * @brief Gets the current computational model
399 * @return Current logic mode
400 */
401 LogicMode get_mode() const { return m_mode; }
402
403 /**
404 * @brief Gets the current boolean operator
405 * @return Current logic operator
406 */
407 LogicOperator get_operator() const { return m_operator; }
408
409 /**
410 * @brief Gets the decision boundary for binary quantization
411 * @return Current threshold value
412 */
413 double get_threshold() const { return m_threshold; }
414
415 /**
416 * @brief Gets the state history buffer capacity
417 * @return Current history buffer size
418 */
419 size_t get_history_size() const { return m_history_size; }
420
421 /**
422 * @brief Gets the current state history
423 * @return Reference to the history buffer
424 */
425 std::span<bool> get_history();
426
427 /**
428 * @brief Gets the number of parallel inputs expected
429 * @return Number of expected inputs
430 */
431 size_t get_input_count() const { return m_input_count; }
432
433 /**
434 * @brief Checks if a state transition was detected
435 * @return True if a transition matching the configured edge type was detected
436 */
437 bool was_edge_detected() const { return m_edge_detected; }
438
439 /**
440 * @brief Gets the type of transitions being monitored
441 * @return Current edge detection type
442 */
443 EdgeType get_edge_type() const { return m_edge_type; }
444
445 /**
446 * @brief Prints a visual representation of the logic function
447 */
448 inline void printGraph() override { }
449
450 /**
451 * @brief Prints the current state and parameters
452 */
453 inline void printCurrent() override { }
454
455 /**
456 * @brief Registers a callback for every generated sample
457 * @param callback Function to call when a new sample is generated
458 */
459 void on_tick(const NodeHook& callback) override;
460
461 /**
462 * @brief Registers a conditional callback for generated samples
463 * @param callback Function to call when condition is met
464 * @param condition Predicate that determines when callback is triggered
465 */
466 void on_tick_if(const NodeCondition& condition, const NodeHook& callback) override;
467
468 /**
469 * @brief Registers a callback that executes continuously while output is true
470 * @param callback Function to call on each tick when output is true (1.0)
471 */
472 void while_true(const NodeHook& callback);
473
474 /**
475 * @brief Registers a callback that executes continuously while output is false
476 * @param callback Function to call on each tick when output is false (0.0)
477 */
478 void while_false(const NodeHook& callback);
479
480 /**
481 * @brief Registers a callback for when output changes to a specific state
482 * @param target_state The state to detect (true for 1.0, false for 0.0)
483 * @param callback Function to call when state changes to target_state
484 */
485 void on_change_to(bool target_state, const NodeHook& callback);
486
487 /**
488 * @brief Registers a callback for any state change (true↔false)
489 * @param callback Function to call when output changes state
490 */
491 void on_change(const NodeHook& callback);
492
493 /**
494 * @brief Removes a previously registered callback
495 * @param callback The callback function to remove
496 * @return True if the callback was found and removed, false otherwise
497 */
498 bool remove_hook(const NodeHook& callback) override;
499
500 /**
501 * @brief Removes a previously registered conditional callback
502 * @param callback The condition function to remove
503 * @return True if the callback was found and removed, false otherwise
504 */
505 bool remove_conditional_hook(const NodeCondition& callback) override;
506
507 /**
508 * @brief Removes all registered callbacks
509 *
510 * Clears all standard and conditional callbacks, effectively
511 * disconnecting all external components from this oscillator's
512 * notification system. Useful when reconfiguring the processing
513 * graph or shutting down components.
514 */
515 inline void remove_all_hooks() override
516 {
517 m_all_callbacks.clear();
518 }
519
520 void remove_hooks_of_type(LogicEventType type);
521
525 std::optional<NodeCondition> condition; // Only used for CONDITIONAL type
526
527 LogicCallback(const NodeHook& cb, LogicEventType type, std::optional<NodeCondition> cond = std::nullopt)
528 : callback(cb)
529 , event_type(type)
530 , condition(std::move(cond))
531 {
532 }
533 };
534
535 void save_state() override;
536 void restore_state() override;
537
538 /**
539 * @brief Retrieves the last created context object
540 * @return Reference to the last LogicContext object
541 *
542 * This method provides access to the most recent LogicContext object
543 * created by the logic node. This context contains information about
544 * the node's state at the time of the last output generation.
545 */
546 NodeContext& get_last_context() override;
547
548protected:
549 /**
550 * @brief Updates the context with the latest sample value
551 * @param value The current generated sample
552 */
553 void update_context(double value) override;
554
555 /**
556 * @brief Notifies all registered callbacks about a new sample
557 * @param value The newly generated sample
558 *
559 * This method is called internally whenever a new sample is generated,
560 * creating the appropriate context and invoking all registered callbacks
561 * that should receive notification about this sample.
562 */
563 void notify_tick(double value) override;
564
565private:
566 LogicMode m_mode; ///< Current processing mode
567 LogicOperator m_operator; ///< Current logic operator
568 DirectFunction m_direct_function; ///< Function for direct mode
569 MultiInputFunction m_multi_input_function; ///< Function for recursive/feedforward mode
570 SequentialFunction m_sequential_function; ///< Function for sequential mode
571 TemporalFunction m_temporal_function; ///< Function for temporal mode
572 size_t m_history_head {}; ///< Head index for the history ring buffer
573 size_t m_history_count {}; ///< Number of valid entries in the history buffer
574 size_t m_history_size; ///< Maximum size of the history buffer
575 size_t m_input_count; ///< Expected number of inputs for multi-input mode
576 double m_threshold; ///< Threshold for boolean conversion
577 double m_low_threshold; ///< Low threshold for hysteresis
578 double m_high_threshold; ///< High threshold for hysteresis
579 EdgeType m_edge_type; ///< Type of edge to detect
580 bool m_edge_detected {}; ///< Whether an edge was detected in the last processing
581 bool m_hysteresis_state {}; ///< State for hysteresis operator
582 double m_temporal_time {}; ///< Time tracking for temporal mode
583 double m_input {}; ///< Current input value for multi-input mode
584 std::vector<double> m_input_buffer; // Buffer for multi-input mode
585 std::shared_ptr<Node> m_input_node; ///< Input node for processing
586 std::vector<uint8_t> m_history_ring; ///< Ring buffer for history storage
587 std::vector<uint8_t> m_history_linear; ///< Linear view of history for easy access
588
589 // Helper method for multi-input mode
590 void add_input(double input, size_t index);
591
592 /**
593 * @brief Adds a callback to the list of all callbacks
594 * @param callback The callback function to add
595 * @param type The type of event to trigger the callback
596 * @param condition Optional condition for conditional callbacks
597 */
598 void add_callback(const NodeHook& callback, LogicEventType type, const std::optional<NodeCondition>& condition = std::nullopt)
599 {
600 m_all_callbacks.emplace_back(callback, type, condition);
601 }
602
603 void history_push(bool val);
604
605 std::span<bool> history_linearized_view();
606
607 std::span<double> external_context_view(double input);
608
609 /**
610 * @brief Collection of all callback functions
611 *
612 * Stores the registered callback functions that will be notified
613 * whenever the oscillator produces a new sample. These callbacks
614 * enable external components to monitor and react to the oscillator's
615 * output without interrupting the generation process.
616 */
617 std::vector<LogicCallback> m_all_callbacks;
618
619 std::vector<uint8_t> m_saved_history_ring;
620 size_t m_saved_history_head {};
621 size_t m_saved_history_count {};
622
623 bool m_saved_hysteresis_state {};
624 bool m_saved_edge_detected {};
625 double m_saved_temporal_time {};
626 double m_saved_last_output {};
629};
630
631} // namespace MayaFlux::Nodes::Generator
Base class for all signal and pattern generators in Maya Flux.
LogicContextGpu(double value, LogicMode mode, LogicOperator operator_type, std::span< bool > history, double threshold, bool edge_detected, EdgeType edge_type, const std::vector< double > &inputs, std::span< const float > gpu_data)
Definition Logic.hpp:127
GPU-accelerated context for logic node callbacks.
Definition Logic.hpp:125
std::span< bool > get_history() const
Definition Logic.hpp:96
std::span< bool > m_history
History of boolean states.
Definition Logic.hpp:109
LogicContext(double value, LogicMode mode, LogicOperator operator_type, std::span< bool > history, double threshold, bool edge_detected=false, EdgeType edge_type=EdgeType::BOTH, const std::vector< double > &inputs={})
Constructs a LogicContext with complete state information.
Definition Logic.hpp:73
LogicMode m_mode
Current computational model.
Definition Logic.hpp:107
LogicOperator m_operator
Current boolean operator.
Definition Logic.hpp:108
const std::vector< double > & m_inputs
Current input values (for multi-input mode)
Definition Logic.hpp:113
double m_input
Current input value for multi-input mode.
Definition Logic.hpp:114
const std::vector< double > & get_inputs() const
Definition Logic.hpp:100
EdgeType m_edge_type
Type of transition being monitored.
Definition Logic.hpp:112
bool m_edge_detected
Whether a state transition was detected.
Definition Logic.hpp:111
const double & get_value() const
Definition Logic.hpp:101
LogicOperator get_operator() const
Definition Logic.hpp:95
double m_threshold
Decision boundary for binary quantization.
Definition Logic.hpp:110
SequentialFunction m_sequential_function
Function for sequential mode.
Definition Logic.hpp:570
TemporalFunction m_temporal_function
Function for temporal mode.
Definition Logic.hpp:571
std::vector< uint8_t > m_saved_history_ring
Definition Logic.hpp:619
DirectFunction m_direct_function
Function for direct mode.
Definition Logic.hpp:568
bool was_edge_detected() const
Checks if a state transition was detected.
Definition Logic.hpp:437
std::vector< uint8_t > m_history_linear
Linear view of history for easy access.
Definition Logic.hpp:587
size_t m_history_size
Maximum size of the history buffer.
Definition Logic.hpp:574
EdgeType m_edge_type
Type of edge to detect.
Definition Logic.hpp:579
void set_input_node(const std::shared_ptr< Node > &input_node)
Sets the input node to generate logic values from.
Definition Logic.hpp:395
double m_threshold
Threshold for boolean conversion.
Definition Logic.hpp:576
std::function< bool(double)> DirectFunction
Function type for stateless boolean evaluation.
Definition Logic.hpp:169
double m_high_threshold
High threshold for hysteresis.
Definition Logic.hpp:578
std::vector< double > m_input_buffer
Definition Logic.hpp:584
std::shared_ptr< Node > m_input_node
Input node for processing.
Definition Logic.hpp:585
LogicMode get_mode() const
Gets the current computational model.
Definition Logic.hpp:401
std::span< double > external_context_view(double input)
LogicOperator m_operator
Current logic operator.
Definition Logic.hpp:567
void printGraph() override
Prints a visual representation of the logic function.
Definition Logic.hpp:448
std::function< bool(const std::vector< double > &)> MultiInputFunction
Function type for parallel input evaluation.
Definition Logic.hpp:174
void add_callback(const NodeHook &callback, LogicEventType type, const std::optional< NodeCondition > &condition=std::nullopt)
Adds a callback to the list of all callbacks.
Definition Logic.hpp:598
double m_low_threshold
Low threshold for hysteresis.
Definition Logic.hpp:577
MultiInputFunction m_multi_input_function
Function for recursive/feedforward mode.
Definition Logic.hpp:569
std::function< bool(std::span< bool >)> SequentialFunction
Function type for state-based evaluation.
Definition Logic.hpp:179
std::vector< LogicCallback > m_all_callbacks
Collection of all callback functions.
Definition Logic.hpp:617
void printCurrent() override
Prints the current state and parameters.
Definition Logic.hpp:453
std::vector< uint8_t > m_history_ring
Ring buffer for history storage.
Definition Logic.hpp:586
void remove_all_hooks() override
Removes all registered callbacks.
Definition Logic.hpp:515
double get_threshold() const
Gets the decision boundary for binary quantization.
Definition Logic.hpp:413
EdgeType get_edge_type() const
Gets the type of transitions being monitored.
Definition Logic.hpp:443
size_t get_input_count() const
Gets the number of parallel inputs expected.
Definition Logic.hpp:431
LogicOperator get_operator() const
Gets the current boolean operator.
Definition Logic.hpp:407
LogicMode m_mode
Current processing mode.
Definition Logic.hpp:566
std::function< bool(double, double)> TemporalFunction
Function type for time-dependent evaluation.
Definition Logic.hpp:184
size_t get_history_size() const
Gets the state history buffer capacity.
Definition Logic.hpp:419
size_t m_input_count
Expected number of inputs for multi-input mode.
Definition Logic.hpp:575
Digital signal processor implementing boolean logic operations.
Definition Logic.hpp:164
GPU-uploadable 1D array data interface.
Base context class for node callbacks.
Definition Node.hpp:30
EdgeType
Digital transition patterns to detect.
Definition Logic.hpp:40
@ FALLING
High-to-low transition (1→0)
@ RISING
Low-to-high transition (0→1)
LogicMode
Defines the computational model for digital signal evaluation.
Definition Logic.hpp:11
@ SEQUENTIAL
State-based evaluation using history of inputs (sequential logic)
@ DIRECT
Stateless evaluation of current input only (combinational logic)
@ TEMPORAL
Time-dependent evaluation with timing constraints.
@ MULTI_INPUT
Parallel evaluation of multiple input signals.
LogicEventType
Events that can trigger callbacks.
Definition Logic.hpp:50
LogicOperator
Digital operators for boolean computation.
Definition Logic.hpp:22
@ NOT
Logical NOT - inverts the input.
@ NOR
Logical NOR - inverted OR operation.
@ OR
Logical OR - true when any input is true.
@ IMPLIES
Logical implication - false only when A is true and B is false.
@ NAND
Logical NAND - inverted AND operation.
@ THRESHOLD
Binary quantization - true when input exceeds threshold.
@ AND
Logical AND - true only when all inputs are true.
@ EDGE
Transition detector - identifies state changes.
@ HYSTERESIS
Threshold with memory - prevents rapid oscillation at boundary.
@ CUSTOM
User-defined boolean function.
@ XOR
Logical XOR - true when odd number of inputs are true.
std::function< void(NodeContext &)> NodeHook
Callback function type for node processing events.
Definition NodeUtils.hpp:25
std::function< bool(NodeContext &)> NodeCondition
Predicate function type for conditional callbacks.
Definition NodeUtils.hpp:43
LogicCallback(const NodeHook &cb, LogicEventType type, std::optional< NodeCondition > cond=std::nullopt)
Definition Logic.hpp:527
std::optional< NodeCondition > condition
Definition Logic.hpp:525