schema_editor/comdel/domain/connection.cpp

80 lines
2.6 KiB
C++
Raw Normal View History

2022-03-31 21:20:41 +00:00
#include "connection.h"
namespace domain {
2022-05-27 06:18:17 +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) {}
ConnectionComponent Connection::getComponent() {
return first;
}
std::optional<ConnectionComponent> Connection::getSecondComponent() {
return second;
}
std::string &Connection::getBus() {
2022-05-27 06:18:17 +00:00
return bus;
}
std::vector<Attribute>& Connection::getAttributes() {
2022-05-27 06:18:17 +00:00
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];
}
2022-03-31 21:20:41 +00:00
}
2022-05-27 06:18:17 +00:00
throw std::exception();
2022-03-31 21:20:41 +00:00
}
2022-05-27 06:18:17 +00:00
bool Connection::hasAttribute(std::string name) {
for (unsigned int i = 0; i < attributes.size(); i++) {
if (attributes[i].getName() == name) {
return true;
}
2022-04-05 21:48:07 +00:00
}
2022-05-27 06:18:17 +00:00
return false;
2022-04-05 21:48:07 +00:00
}
2022-05-27 06:18:17 +00:00
bool Connection::isConnecting(ConnectionComponent component) {
return first == component || (second.has_value() && *second == component);
}
2022-04-09 17:44:02 +00:00
2022-05-27 06:18:17 +00:00
bool Connection::isConnecting(ConnectionComponent component, std::string bus) {
return this->bus == bus && (first == component || (second.has_value() && *second == component));
}
2022-04-09 17:44:02 +00:00
2022-05-27 06:18:17 +00:00
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-04-09 17:44:02 +00:00
}
2022-05-25 05:39:45 +00:00
bool Connection::isConnecting(ConnectionComponent component, ConnectionComponent secondComponent) {
2022-05-27 06:18:17 +00:00
if (!second.has_value()) {
2022-05-25 05:39:45 +00:00
return false;
}
2022-05-27 06:18:17 +00:00
return (this->first == component && this->second == secondComponent) ||
(this->first == secondComponent && this->second == component);
2022-05-25 05:39:45 +00:00
}
2022-03-31 21:20:41 +00:00
} // namespace domain