schema_editor/comdel/domain/connection.h

77 lines
2.1 KiB
C++

#ifndef DOMAIN_CONNECTION_H
#define DOMAIN_CONNECTION_H
#include "attribute.h"
#include <string>
#include <vector>
namespace domain {
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) {
return true;
} else if (component == rhs.component) {
if (pin < rhs.pin) {
return true;
}
}
return false;
}
};
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);
ConnectionComponent getComponent();
std::optional<ConnectionComponent> getSecondComponent();
std::string getBus();
std::vector<Attribute> getAttributes();
std::vector<Value> getWires();
std::optional<std::vector<Value>> getSecondWires();
Attribute getAttribute(std::string name);
bool hasAttribute(std::string name);
};
} // namespace domain
#endif // DOMAIN_CONNECTION_H