wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
Or.cpp
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
5
9
10template<>
11struct ElementInfo<Or> {
13 .type = ElementType::Or,
14 .group = ElementGroup::Gate,
15 .minInputSize = 2,
16 .maxInputSize = 8,
17 .minOutputSize = 1,
18 .maxOutputSize = 1,
19 .canChangeAppearance = true,
20 };
21 static_assert(validate(constraints));
22
24 {
26 meta.pixmapPath = []{ return QStringLiteral(":/Components/Logic/or.svg"); };
27 meta.titleText = QT_TRANSLATE_NOOP("Or", "OR");
28 meta.translatedName = QT_TRANSLATE_NOOP("Or", "Or");
29 meta.trContext = "Or";
30 // Seed appearance lists from the constructor-supplied pixmap path (see And.cpp for details).
31 meta.defaultAppearances = QStringList({":/Components/Logic/or.svg"});
32 return meta;
33 }
34
35 static inline const bool registered = []() {
37 ElementFactory::registerCreator(constraints.type, [] { return new Or(); });
38 return true;
39 }();
40};
41
42Or::Or(QGraphicsItem *parent)
43 : GraphicElement(ElementType::Or, parent)
44{
45 // Skip full initialisation when building a property-probe instance (see ElementFactory).
46}
47
Singleton factory for all circuit element types.
Self-registering element trait template and compile-time constraint validation.
ElementMetadata metadataFromConstraints(const ElementConstraints &c)
Converts ElementConstraints to an ElementMetadata with all constraint-derived fields set.
Definition ElementInfo.h:80
constexpr bool validate(const ElementConstraints &c)
Validates element constraints at compile time.
Definition ElementInfo.h:48
Enums::ElementType ElementType
Definition Enums.h:107
Graphic element for the OR gate.
Four-state logic operations for gate evaluation.
static void registerCreator(ElementType type, std::function< GraphicElement *()> creator)
Registers a creator lambda for type, used by buildElement().
static void registerMetadata(const ElementMetadata &meta)
Registers meta in the global map (called once per element type at startup).
GraphicElement(ElementType type, QGraphicsItem *parent=nullptr)
Constructs a graphic element of the given type, fetching all properties from the metadata registry.
const QVector< Status > & simInputs() const
Read-only view of the cached simulation input values.
bool simUpdateInputsAllowUnknown()
Like simUpdateInputs(), but allows Unknown/Error values through.
void setOutputValue(const int index, const Status value)
Sets simulation output port index to value.
Graphical representation of an OR gate (2–8 inputs, 1 output).
Definition Or.h:17
void updateLogic() override
Sets output to the logical OR of all inputs.
Definition Or.cpp:48
Or(QGraphicsItem *parent=nullptr)
Constructs an Or gate element with default 2 inputs.
Definition Or.cpp:42
Status statusOrAll(const QVector< Status > &inputs)
Fold OR over a range. Active dominates.
Definition StatusOps.h:100
Compile-time-validatable subset of ElementMetadata.
Definition ElementInfo.h:21
static const bool registered
Definition Or.cpp:35
static ElementMetadata metadata()
Definition Or.cpp:23
static constexpr ElementConstraints constraints
Definition Or.cpp:12
Self-registering element information trait.
Compile-time-registered properties for one element type.