wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
And.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<>
13 .type = ElementType::And,
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/and.svg"); };
27 meta.titleText = QT_TRANSLATE_NOOP("And", "AND");
28 meta.translatedName = QT_TRANSLATE_NOOP("And", "And");
29 meta.trContext = "And";
30 // m_pixmapPath was set by the base-class constructor from the argument above.
31 // Seed both appearance lists from it so that index 0 always points to the default art.
32 // m_alternativeAppearances starts as a copy of m_defaultAppearances; the user can replace
33 // entries in m_alternativeAppearances without losing the originals in m_defaultAppearances.
34 meta.defaultAppearances = QStringList({":/Components/Logic/and.svg"});
35 return meta;
36 }
37
38 static inline const bool registered = []() {
40 ElementFactory::registerCreator(constraints.type, [] { return new And(); });
41 return true;
42 }();
43};
44
45And::And(QGraphicsItem *parent)
47{
48}
49
Graphic element for the AND gate.
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
Four-state logic operations for gate evaluation.
Graphical representation of an AND gate (2–8 inputs, 1 output).
Definition And.h:17
void updateLogic() override
Sets output to the logical AND of all inputs.
Definition And.cpp:50
And(QGraphicsItem *parent=nullptr)
Constructs an And gate element with default 2 inputs.
Definition And.cpp:45
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.
Status statusAndAll(const QVector< Status > &inputs)
Fold AND over a range. Inactive dominates.
Definition StatusOps.h:81
Compile-time-validatable subset of ElementMetadata.
Definition ElementInfo.h:21
static const bool registered
Definition And.cpp:38
static ElementMetadata metadata()
Definition And.cpp:23
static constexpr ElementConstraints constraints
Definition And.cpp:12
Self-registering element information trait.
Compile-time-registered properties for one element type.