schema_editor/comdel/domain/connection.h

80 lines
2.2 KiB
C
Raw Normal View History

2022-03-31 21:20:41 +00:00
#ifndef DOMAIN_CONNECTION_H
#define DOMAIN_CONNECTION_H
#include "attribute.h"
#include <string>
#include <vector>
namespace domain {
2022-05-27 06:18:17 +00:00
struct ConnectionComponent {
std::string component;
std::string pin;
bool operator==(const ConnectionComponent &rhs) const {
return (component == rhs.component) && (pin == rhs.pin);
}
bool operator!=(const ConnectionComponent &rhs) const {
return !operator==(rhs);
}
bool operator<(const ConnectionComponent &rhs) const {
if (component < rhs.component) {
2022-05-25 05:39:45 +00:00
return true;
2022-05-27 06:18:17 +00:00
} else if (component == rhs.component) {
if (pin < rhs.pin) {
return true;
}
2022-05-25 05:39:45 +00:00
}
2022-05-27 06:18:17 +00:00
return false;
2022-05-25 05:39:45 +00:00
}
2022-05-27 06:18:17 +00:00
};
class Connection {
ConnectionComponent first;
std::optional<ConnectionComponent> second;
std::string bus;
std::vector<Attribute> attributes;
std::vector<Value> firstWires;
std::optional<std::vector<Value>> secondWires;
public:
Connection(ConnectionComponent first, std::optional<ConnectionComponent> second,
std::string bus, std::vector<Attribute> attributes,
std::vector<Value> firstWires, std::optional<std::vector<Value>> secondWires);
bool isConnecting(ConnectionComponent first);
bool isConnecting(ConnectionComponent first, std::string bus);
bool isConnecting(ConnectionComponent first, std::string bus, ConnectionComponent second);
bool isConnecting(ConnectionComponent first, ConnectionComponent second);
2022-04-09 17:44:02 +00:00
bool operator==(const Connection& connection) {
return (first == connection.first && bus == connection.bus && second == connection.second);
}
2022-04-09 17:44:02 +00:00
2022-05-27 06:18:17 +00:00
ConnectionComponent getComponent();
2022-04-09 17:44:02 +00:00
2022-05-27 06:18:17 +00:00
std::optional<ConnectionComponent> getSecondComponent();
2022-03-31 21:20:41 +00:00
std::string &getBus();
2022-03-31 21:20:41 +00:00
std::vector<Attribute>& getAttributes();
2022-04-09 17:44:02 +00:00
2022-05-27 06:18:17 +00:00
std::vector<Value> getWires();
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
std::optional<std::vector<Value>> getSecondWires();
2022-04-09 17:44:02 +00:00
2022-05-27 06:18:17 +00:00
Attribute getAttribute(std::string name);
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
bool hasAttribute(std::string name);
};
2022-03-31 21:20:41 +00:00
} // namespace domain
#endif // DOMAIN_CONNECTION_H