wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ElementSimState Class Reference

Owns a GraphicElement's simulation runtime state, decoupled from its graphics. More...

#include <ElementSimState.h>

Classes

struct  InputConnection
 A single simulation-graph edge: which element/output port feeds one input slot. More...

Public Member Functions

void beginDeferredCommit ()
void clearOutputChanged ()
 Clears the output-changed flag.
void commitDeferredOutputs ()
void connectPredecessor (int inputIndex, GraphicElement *source, int outputPort)
 Records that simulation input inputIndex is driven by source output outputPort.
int decodeSelectValue (int offset, int count) const
 Decodes count select-line statuses starting at offset into a binary index.
void initVectors (int inputCount, int outputCount, const QVector< OutputPort * > &outputPorts)
 Allocates the I/O vectors and seeds outputs from outputPorts default statuses.
const QVector< Status > & inputs () const
 Read-only view of the cached simulation input values.
bool outputChanged () const
 Returns true if any output changed since the flag was last cleared.
const QVector< Status > & outputs () const
qsizetype outputSize () const
 Returns the number of simulation output slots.
Status outputValue (const int index=0) const
 Returns the four-state value on output slot index (Unknown if out of range).
void reset (const QVector< OutputPort * > &outputPorts)
 Resets each output slot to its port's power-on default (Unknown coerced to Inactive).
void setOutputValue (const int index, const Status value)
 Sets output slot index to value, flagging a change when it differs.
bool updateInputs (bool allowUnknown, const QVector< InputPort * > &inputPorts)
 Snapshots each predecessor's output into the input cache, reading inputPorts for unconnected-input defaults and multi-driver conflict detection.

Detailed Description

Owns a GraphicElement's simulation runtime state, decoupled from its graphics.

Holds the cached input/output four-state values, the output-changed flag, and the simulation-graph edges feeding each input. The propagation logic reads the owning element's ports only through parameters (no back-pointer), so this type carries no Qt graphics dependency. GraphicElement holds one as a value member and forwards its direct-simulation interface to it.

Definition at line 30 of file ElementSimState.h.

Member Function Documentation

◆ beginDeferredCommit()

void ElementSimState::beginDeferredCommit ( )
inline

Begins a deferred (non-blocking) commit window: seeds the staging buffer from current outputs and routes subsequent setOutputValue() calls to it.

Definition at line 101 of file ElementSimState.h.

◆ clearOutputChanged()

void ElementSimState::clearOutputChanged ( )
inline

Clears the output-changed flag.

Definition at line 88 of file ElementSimState.h.

◆ commitDeferredOutputs()

void ElementSimState::commitDeferredOutputs ( )
inline

Ends the deferred-commit window and publishes staged outputs via the normal change-detecting path so visuals refresh correctly.

Definition at line 117 of file ElementSimState.h.

References setOutputValue().

◆ connectPredecessor()

void ElementSimState::connectPredecessor ( int inputIndex,
GraphicElement * source,
int outputPort )

Records that simulation input inputIndex is driven by source output outputPort.

Definition at line 24 of file ElementSimState.cpp.

◆ decodeSelectValue()

int ElementSimState::decodeSelectValue ( int offset,
int count ) const

Decodes count select-line statuses starting at offset into a binary index.

Definition at line 87 of file ElementSimState.cpp.

◆ initVectors()

void ElementSimState::initVectors ( int inputCount,
int outputCount,
const QVector< OutputPort * > & outputPorts )

Allocates the I/O vectors and seeds outputs from outputPorts default statuses.

Definition at line 32 of file ElementSimState.cpp.

◆ inputs()

const QVector< Status > & ElementSimState::inputs ( ) const
inline

Read-only view of the cached simulation input values.

Definition at line 91 of file ElementSimState.h.

◆ outputChanged()

bool ElementSimState::outputChanged ( ) const
inline

Returns true if any output changed since the flag was last cleared.

Definition at line 85 of file ElementSimState.h.

◆ outputs()

const QVector< Status > & ElementSimState::outputs ( ) const
inline

Read-only view of the current simulation output values. During a deferred-commit window returns the staged (in-progress) outputs so a sequential element re-evaluated multiple times within one tick sees the value it already staged rather than its stale committed output.

Definition at line 97 of file ElementSimState.h.

◆ outputSize()

qsizetype ElementSimState::outputSize ( ) const
inline

Returns the number of simulation output slots.

Definition at line 82 of file ElementSimState.h.

◆ outputValue()

Status ElementSimState::outputValue ( const int index = 0) const
inline

Returns the four-state value on output slot index (Unknown if out of range).

Definition at line 61 of file ElementSimState.h.

◆ reset()

void ElementSimState::reset ( const QVector< OutputPort * > & outputPorts)

Resets each output slot to its port's power-on default (Unknown coerced to Inactive).

Definition at line 9 of file ElementSimState.cpp.

◆ setOutputValue()

void ElementSimState::setOutputValue ( const int index,
const Status value )
inline

Sets output slot index to value, flagging a change when it differs.

Definition at line 68 of file ElementSimState.h.

Referenced by commitDeferredOutputs().

◆ updateInputs()

bool ElementSimState::updateInputs ( bool allowUnknown,
const QVector< InputPort * > & inputPorts )

Snapshots each predecessor's output into the input cache, reading inputPorts for unconnected-input defaults and multi-driver conflict detection.

Parameters
allowUnknownWhen true, only a truly unconnected Unknown input fails (combinational domination rules can still short-circuit); when false any Unknown/Error fails.
Returns
true if simulation can proceed; false (all outputs set Unknown) otherwise.

Definition at line 53 of file ElementSimState.cpp.


The documentation for this class was generated from the following files: