wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
Xor.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::Xor,
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/xor.svg"); };
27 meta.titleText = QT_TRANSLATE_NOOP("Xor", "XOR");
28 meta.translatedName = QT_TRANSLATE_NOOP("Xor", "Xor");
29 meta.trContext = "Xor";
30 // Seed appearance lists from the constructor-supplied pixmap path (see And.cpp for details).
31 meta.defaultAppearances = QStringList({":/Components/Logic/xor.svg"});
32 return meta;
33 }
34
35 static inline const bool registered = []() {
37 ElementFactory::registerCreator(constraints.type, [] { return new Xor(); });
38 return true;
39 }();
40};
41
42Xor::Xor(QGraphicsItem *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
Four-state logic operations for gate evaluation.
Graphic element for the XOR gate.
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 XOR gate (2–8 inputs, 1 output).
Definition Xor.h:17
void updateLogic() override
Sets output to the logical XOR of all inputs.
Definition Xor.cpp:48
Xor(QGraphicsItem *parent=nullptr)
Constructs an Xor gate element with default 2 inputs.
Definition Xor.cpp:42
Status statusXorAll(const QVector< Status > &inputs)
Definition StatusOps.h:120
Compile-time-validatable subset of ElementMetadata.
Definition ElementInfo.h:21
static constexpr ElementConstraints constraints
Definition Xor.cpp:12
static ElementMetadata metadata()
Definition Xor.cpp:23
static const bool registered
Definition Xor.cpp:35
Self-registering element information trait.
Compile-time-registered properties for one element type.