35 std::atomic<uint64_t> nextPortIdentity{1};
37 constexpr std::string_view PORT_ORIENTATION_PROPERTY =
"portOrientation";
38 constexpr std::array<std::string_view, 4> PORT_ORIENTATIONS = {
"UP",
"DOWN",
"LEFT",
43 options.reserve(PORT_ORIENTATIONS.size());
44 for (
const auto orientation : PORT_ORIENTATIONS)
45 options.emplace_back(orientation);
49 [[nodiscard]]
int normalizedBusSize(
const int size)
51 return std::clamp(size, 1,
52 static_cast<int>(std::numeric_limits<unsigned short>::max()));
56 const std::size_t width,
57 const bool fillScalarUnknown)
60 throw std::invalid_argument(
"Bus value must not be empty");
62 throw std::invalid_argument(
"State::ERROR cannot be used as an editable value");
64 const State extension =
76 return setSize(std::get<int>(value));
79 return setValue(std::get<BusValue>(value));
90 if (output.
size() == 0)
91 throw std::invalid_argument(
"Constant output bus must not be empty");
99 const int normalizedSize = std::clamp(
100 newSize, 1,
static_cast<int>(std::numeric_limits<unsigned short>::max()));
102 outputs[0].setSize(
static_cast<unsigned short>(normalizedSize));
107 return normalizedSize;
116 return normalizedEditableValue(value, width,
true);
127 0, weak_from_this());
131 std::vector<Bus>
outputs, std::string name)
137 this->outputs.empty() ?
"LEFT" :
"RIGHT",
138 orientationOptions());
143 if (
id == 0 ||
id == std::numeric_limits<uint64_t>::max())
144 throw std::invalid_argument(
"Boundary port identity must be a nonzero integer");
147 auto next = nextPortIdentity.load(std::memory_order_relaxed);
149 && !nextPortIdentity.compare_exchange_weak(next,
id + 1,
150 std::memory_order_relaxed)) {}
156 portIdentity = nextPortIdentity.fetch_add(1, std::memory_order_relaxed);
163 return normalizedEditableValue(std::get<BusValue>(value), 1,
true);
176 "size",
static_cast<int>(outputs[0].size()),
177 [
this](
const PropertyValue& value) {
return setSize(std::get<int>(value)); });
180 const auto width = outputs.empty() ? 1 : outputs[0].size();
181 return normalizedEditableValue(std::get<BusValue>(value), width,
true);
192 const int size = normalizedBusSize(newSize);
194 bus.
setSize(
static_cast<unsigned short>(size));
215 "size",
static_cast<int>(inputs[0].size()),
216 [
this](
const PropertyValue& value) {
return setSize(std::get<int>(value)); });
227 const int size = normalizedBusSize(newSize);
229 bus.
setSize(
static_cast<unsigned short>(size));
BoundaryIoComponent(std::vector< Bus > inputs, std::vector< Bus > outputs, std::string name)
void setPortId(uint64_t id)
void setSize(unsigned short size)
void setInput(unsigned int index, const Bus &bus, bool checkSize=false)
Sets an input bus at a specific index.
std::optional< T > getPropertyValue(std::string_view key) const
Gets a property value with type deduction.
std::vector< Bus > outputs
Output buses produced by this component.
void setProperty(std::string_view key, const PropertyValue &value)
Sets a property value.
std::vector< Bus > inputs
Input buses connected to this component.
void defineStringListProperty(std::string key, std::string defaultValue, StringPropertyOptions allowedValues, PropertyCallback callback=nullptr)
Defines a string property constrained to a fixed set of values.
void setOutput(unsigned int index, const Bus &bus)
Sets an output bus at a specific index.
void defineProperty(std::string key, T &&defaultValue, PropertyCallback callback=nullptr)
Defines a property with a default value and optional callback.
void notifyIOListeners()
Notifies all registered I/O listeners of a change.
BusValue setValue(const BusValue &value) const
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
DummyBusOutputComponent()
Executes event-driven simulation of a Circuit.
void updateBus(const Bus &bus, const BusValue &value, uint64_t delay, const Component_weakPtr &source)
Updates a bus to a new value through the normal wire-update path.
std::shared_ptr< Wire > Wire_ptr
std::variant< int, bool, std::string, BusValue > PropertyValue
Variant type for component properties.
std::vector< std::string > StringPropertyOptions
Allowed values for a constrained string property.
std::vector< State > BusValue
QVariant value(const QSettings &settings, const Definition &setting)
Reads a setting value, falling back to its declared default when unset.
BusValue normalizeBusValue(const BusValue &value, const std::size_t width, const State extension)
Resize an LSB-first value to an exact bus width.