schema_editor/comdel/domain/connection.cpp

67 lines
2.0 KiB
C++
Raw Permalink Normal View History

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) {
2022-04-12 21:37:05 +00:00
for(unsigned int i=0; i<attributes.size(); i++) {
2022-03-31 21:20:41 +00:00
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) {
2022-04-12 21:37:05 +00:00
for(unsigned int i=0; i<attributes.size(); i++) {
2022-04-05 21:48:07 +00:00
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