Moved connection determination to schema
This commit is contained in:
1 parent
1ec8b10ef5
commit
1759adf25a
7 files changed
+119
-41
No files matched your search
@@ -16,7 +16,7 @@ namespace domain {
|
||||
return second;
|
||||
}
|
||||
|
||||
std::string Connection::getBus() {
|
||||
std::string &Connection::getBus() {
|
||||
return bus;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,12 +53,15 @@ namespace domain {
|
||||
|
||||
bool isConnecting(ConnectionComponent first, ConnectionComponent second);
|
||||
|
||||
bool operator==(const Connection& connection) {
|
||||
return (first == connection.first && bus == connection.bus && second == connection.second);
|
||||
}
|
||||
|
||||
ConnectionComponent getComponent();
|
||||
|
||||
std::optional<ConnectionComponent> getSecondComponent();
|
||||
|
||||
std::string getBus();
|
||||
std::string &getBus();
|
||||
|
||||
std::vector<Attribute>& getAttributes();
|
||||
|
||||
|
||||
@@ -39,4 +39,72 @@ namespace domain {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<ConnectionEntry> Schema::availableConnections(std::string instanceName, std::string pinName, bool onlyConnectable) {
|
||||
std::vector<ConnectionEntry> entries;
|
||||
|
||||
auto instance = getComponentInstance(instanceName);
|
||||
|
||||
ConnectionComponent connectionComponent{instance->component.getName(), pinName};
|
||||
for(auto &conn: library.getConnections()) {
|
||||
if(conn.isConnecting(connectionComponent)) {
|
||||
// if bus connection
|
||||
if(library.getBus(conn.getBus()).getType() == Bus::REGULAR) {
|
||||
for(auto& bus: busInstances) {
|
||||
if(bus->bus.getName() == conn.getBus()) {
|
||||
ConnectionEntry entry{ConnectionEntry::BUS, bus.get(), nullopt, nullopt, conn};
|
||||
entries.emplace_back(entry);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(auto& component: componentInstances) {
|
||||
for(auto& pin: component->component.getPins()) {
|
||||
if(conn.isConnecting(connectionComponent, {component->component.getName(), pin.getName()})) {
|
||||
ConnectionEntry entry{ConnectionEntry::COMPONENT, nullopt, component.get(), pin, conn};
|
||||
entries.emplace_back(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(onlyConnectable) {
|
||||
entries.erase(
|
||||
std::remove_if(
|
||||
entries.begin(),
|
||||
entries.end(),
|
||||
[this, instance](ConnectionEntry &entry) {
|
||||
auto& bus = this->library.getBus(entry.connection.getBus());
|
||||
// we allow duplicates of single automatic connections
|
||||
if(bus.getType() == Bus::SINGLE_AUTOMATIC) {
|
||||
return false;
|
||||
}
|
||||
for(auto& conn: this->connections) {
|
||||
if(conn->connection == entry.connection) {
|
||||
if(bus.getType() == Bus::REGULAR) {
|
||||
if(entry.busInstance.value()->bus.getName() == conn->connection.getBus()) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
auto *directInstance = dynamic_cast<DirectConnectionInstance*>(conn.get());
|
||||
ComponentInstance* secondInstance;
|
||||
if(directInstance->instance == instance) {
|
||||
secondInstance = directInstance->secondInstance;
|
||||
} else {
|
||||
secondInstance = directInstance->instance;
|
||||
}
|
||||
|
||||
return entry.componentInstance == secondInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}),
|
||||
entries.end()
|
||||
);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
} // namespace domain
|
||||
+22
-1
@@ -3,14 +3,33 @@
|
||||
|
||||
#include "connection_instance.h"
|
||||
#include "instance.h"
|
||||
#include "library.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace domain {
|
||||
|
||||
struct ConnectionEntry {
|
||||
enum Type {
|
||||
BUS,
|
||||
COMPONENT
|
||||
};
|
||||
|
||||
Type type;
|
||||
|
||||
std::optional<BusInstance*> busInstance;
|
||||
std::optional<ComponentInstance*> componentInstance;
|
||||
std::optional<Pin> pin;
|
||||
|
||||
Connection connection;
|
||||
};
|
||||
|
||||
class Schema {
|
||||
private:
|
||||
Library library;
|
||||
public:
|
||||
Schema() = default;
|
||||
Schema(Library library): library(std::move(library)) {}
|
||||
|
||||
std::vector<shared_ptr<BusInstance>> busInstances;
|
||||
std::vector<shared_ptr<ComponentInstance>> componentInstances;
|
||||
@@ -21,6 +40,8 @@ namespace domain {
|
||||
ComponentInstance *getComponentInstance(std::string &name);
|
||||
bool hasConnection(string &component, string &pin);
|
||||
ConnectionInstance *getConnection(string &component, string &pin);
|
||||
|
||||
std::vector<ConnectionEntry> availableConnections(std::string instance, std::string pin, bool onlyConnectable);
|
||||
};
|
||||
|
||||
} // namespace domain
|
||||
|
||||
@@ -866,7 +866,7 @@ namespace domain {
|
||||
|
||||
|
||||
Schema *SchemaCreator::loadSchema(SchemaNode node, Library &library) {
|
||||
auto *schema = new Schema();
|
||||
auto *schema = new Schema(library);
|
||||
|
||||
for (auto &instance: node.instances) {
|
||||
if (library.hasComponent(instance.component.value)) {
|
||||
|
||||
Reference in new issue
Block a user