77 lines
2.3 KiB
C++
77 lines
2.3 KiB
C++
#include "connection.h"
|
|
|
|
namespace domain {
|
|
|
|
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)
|
|
{}
|
|
|
|
ConnectionComponent Connection::getComponent() {
|
|
return first;
|
|
}
|
|
std::optional<ConnectionComponent> Connection::getSecondComponent() {
|
|
return second;
|
|
}
|
|
|
|
std::string Connection::getBus() {
|
|
return bus;
|
|
}
|
|
|
|
std::vector<Attribute> Connection::getAttributes() {
|
|
return attributes;
|
|
}
|
|
std::vector<Value> Connection::getWires() {
|
|
return firstWires;
|
|
}
|
|
std::optional<std::vector<Value>> 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::exception();
|
|
}
|
|
|
|
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
|