wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ElementPorts.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
10#include <QString>
11#include <QVector>
12
13class GraphicElement;
14class Port;
15class InputPort;
16class OutputPort;
17
30{
31public:
34 : m_owner(owner)
35 {
36 }
37
38 // --- Read access ---
39
41 const QVector<InputPort *> &inputs() const { return m_inputPorts; }
42
44 const QVector<OutputPort *> &outputs() const { return m_outputPorts; }
45
47 InputPort *inputPort(int index) const;
48
50 OutputPort *outputPort(int index) const;
51
53 int inputSize() const { return static_cast<int>(m_inputPorts.size()); }
54
56 int outputSize() const { return static_cast<int>(m_outputPorts.size()); }
57
59 QVector<Port *> allPorts() const;
60
61 // --- Mutation ---
62
66 void setInputs(const QVector<InputPort *> &inputs);
67
69 void addPort(const QString &name, bool isOutput);
70
72 void addInputPort(const QString &name = {}) { addPort(name, false); }
73
75 void addOutputPort(const QString &name = {}) { addPort(name, true); }
76
79 void resizeInputs(int size);
80
82 void resizeOutputs(int size);
83
86 InputPort *takeLastInput();
87
89 OutputPort *takeLastOutput();
90
91private:
92 GraphicElement *m_owner;
93
94 QVector<InputPort *> m_inputPorts;
95 QVector<OutputPort *> m_outputPorts;
96};
void addOutputPort(const QString &name={})
Appends a new output port with optional name.
void setInputs(const QVector< InputPort * > &inputs)
InputPort * takeLastInput()
const QVector< OutputPort * > & outputs() const
Returns the output port vector.
QVector< Port * > allPorts() const
Returns a combined list of all input and output ports as Port pointers.
int outputSize() const
Returns the current number of output ports.
void addInputPort(const QString &name={})
Appends a new input port with optional name.
InputPort * inputPort(int index) const
Returns the input port at index, or nullptr if out of range.
int inputSize() const
Returns the current number of input ports.
ElementPorts(GraphicElement *owner)
Constructs the port store bound to its owning owner element.
void addPort(const QString &name, bool isOutput)
Appends a new port (parented to the owner) with name; isOutput selects direction.
const QVector< InputPort * > & inputs() const
Returns the input port vector.
OutputPort * takeLastOutput()
Removes and returns the last output port WITHOUT deleting it. Returns nullptr if empty.
void resizeOutputs(int size)
Grows or shrinks the output list to exactly size.
void resizeInputs(int size)
OutputPort * outputPort(int index) const
Returns the output port at index, or nullptr if out of range.
Abstract base class for all graphical circuit elements in wiRedPanda.
A port that receives a signal (the destination end of a wire).
Definition Port.h:229
A port that drives a signal (the source end of a wire).
Definition Port.h:261
Abstract base class for circuit element ports (connection endpoints).
Definition Port.h:39