#include "connection.h" #include namespace domain { Connection::Connection(ConnectionComponent first, std::optional second, std::string bus, std::vector attributes, std::vector firstWires, std::optional> secondWires) : first(first), second(second), bus(bus), attributes(attributes), firstWires(firstWires), secondWires(secondWires) {} ConnectionComponent Connection::getComponent() { return first; } std::optional Connection::getSecondComponent() { return second; } std::string &Connection::getBus() { return bus; } std::vector& Connection::getAttributes() { return attributes; } std::vector Connection::getWires() { return firstWires; } std::optional> Connection::getSecondWires() { return secondWires; } Attribute Connection::getAttribute(std::string name) { for (unsigned int i = 0; i < attributes.size(); i++) { if (attributes[i].getName() == name) { return attributes[i]; } } throw std::runtime_error("no attribute with name '" + name + "'"); } bool Connection::hasAttribute(std::string name) { for (unsigned int i = 0; i < attributes.size(); i++) { if (attributes[i].getName() == name) { return true; } } return false; } bool Connection::isConnecting(ConnectionComponent component) { return first == component || (second.has_value() && *second == component); } bool Connection::isConnecting(ConnectionComponent component, std::string bus) { return this->bus == bus && (first == component || (second.has_value() && *second == component)); } bool Connection::isConnecting(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent) { if (!second.has_value()) { return false; } return (this->first == component && this->bus == bus && this->second == secondComponent) || (this->first == secondComponent && this->bus == bus && this->second == component); } bool Connection::isConnecting(ConnectionComponent component, ConnectionComponent secondComponent) { if (!second.has_value()) { return false; } return (this->first == component && this->second == secondComponent) || (this->first == secondComponent && this->second == component); } } // namespace domain