2022-05-27 06:18:17 +00:00
|
|
|
#include "connection_instance.h"
|
2022-06-27 09:39:13 +00:00
|
|
|
#include <stdexcept>
|
2022-05-27 06:18:17 +00:00
|
|
|
|
|
|
|
namespace domain {
|
|
|
|
|
|
|
|
|
|
|
|
ConnectionInstance::ConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute> attributes,
|
|
|
|
Connection connection)
|
|
|
|
: instance(instance), attributes(attributes), connection(connection) {}
|
|
|
|
|
|
|
|
InstanceAttribute ConnectionInstance::getAttribute(string attribute) {
|
|
|
|
for (auto &attr: attributes) {
|
|
|
|
if (attr.name == attribute) {
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
}
|
2022-06-27 09:39:13 +00:00
|
|
|
throw std::runtime_error("no attribute with name '" + attribute + "'");
|
2022-05-27 06:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BusConnectionInstance::BusConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute> attributes,
|
|
|
|
BusInstance *bus, Connection connection)
|
|
|
|
: ConnectionInstance(instance, attributes, connection), bus(bus) {}
|
|
|
|
|
|
|
|
DirectConnectionInstance::DirectConnectionInstance(ComponentInstance *instance, ComponentInstance *secondInstance,
|
|
|
|
std::vector<InstanceAttribute> attributes, BusInstance *bus,
|
|
|
|
Connection connection)
|
|
|
|
: ConnectionInstance(instance, attributes, connection), secondInstance(secondInstance), bus(bus) {}
|
|
|
|
|
2022-06-19 18:10:44 +00:00
|
|
|
int DirectConnectionInstance::getSelected(ConnectionComponent conn) {
|
|
|
|
if(this->instance->name == conn.component) {
|
|
|
|
auto selected = attributes[0].value.asString();
|
|
|
|
for(int i=0; i<connection.getWires().size(); i++) {
|
|
|
|
if(connection.getWires()[i].isType(Value::STRING) && connection.getWires()[i].asString() == selected) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
auto selected = attributes[1].value.asString();
|
|
|
|
for(int i=0; i<connection.getSecondWires()->size(); i++) {
|
|
|
|
if(connection.getSecondWires().value()[i].isType(Value::STRING) && connection.getSecondWires().value()[i].asString() == selected) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-05-27 06:18:17 +00:00
|
|
|
} // namespace domain
|