2022-03-31 21:20:41 +00:00
|
|
|
#include "connection.h"
|
|
|
|
|
|
|
|
namespace domain {
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
Connection::Connection(ConnectionComponent first, std::optional<ConnectionComponent> second,
|
|
|
|
std::string bus, std::vector<Attribute> attributes,
|
|
|
|
std::vector<Value> firstWires, std::optional<std::vector<Value>> secondWires)
|
|
|
|
: first(first), second(second), bus(bus), attributes(attributes), firstWires(firstWires), secondWires(secondWires)
|
2022-03-31 21:20:41 +00:00
|
|
|
{}
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
ConnectionComponent Connection::getComponent() {
|
|
|
|
return first;
|
2022-03-31 21:20:41 +00:00
|
|
|
}
|
2022-04-09 17:44:02 +00:00
|
|
|
std::optional<ConnectionComponent> Connection::getSecondComponent() {
|
|
|
|
return second;
|
2022-03-31 21:20:41 +00:00
|
|
|
}
|
2022-04-09 17:44:02 +00:00
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
std::string Connection::getBus() {
|
|
|
|
return bus;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Attribute> Connection::getAttributes() {
|
|
|
|
return attributes;
|
|
|
|
}
|
|
|
|
std::vector<Value> Connection::getWires() {
|
2022-04-09 17:44:02 +00:00
|
|
|
return firstWires;
|
|
|
|
}
|
|
|
|
std::optional<std::vector<Value>> Connection::getSecondWires() {
|
|
|
|
return secondWires;
|
2022-03-31 21:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Attribute Connection::getAttribute(std::string name) {
|
|
|
|
for(uint i=0; i<attributes.size(); i++) {
|
|
|
|
if(attributes[i].getName() == name) {
|
|
|
|
return attributes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw std::exception();
|
|
|
|
}
|
|
|
|
|
2022-04-05 21:48:07 +00:00
|
|
|
bool Connection::hasAttribute(std::string name) {
|
|
|
|
for(uint i=0; i<attributes.size(); i++) {
|
|
|
|
if(attributes[i].getName() == name) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-09 17:44:02 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-03-31 21:20:41 +00:00
|
|
|
} // namespace domain
|