#include "library.h" #include namespace domain { Library::Library(string name, string libraryInfo, string header, string componentDirectory, std::optional componentHeader, vector addressSpaces, vector components, vector buses, vector connections, map messages) : name(name), libraryInfo(libraryInfo), header(header), componentDirectory(componentDirectory), componentHeader(componentHeader), addressSpaces(addressSpaces), components(components), buses(buses), connections(connections), messages(messages) {} std::string Library::getName() { return name; } std::string Library::getLibraryInfo() { return libraryInfo; } std::string Library::getHeader() { return header; } std::string Library::getComponentDirectory() { return componentDirectory; } std::optional Library::getComponentHeader() { return componentHeader; } std::vector Library::getAddressSpaces() { return addressSpaces; } std::vector Library::getComponents() { return components; } std::vector Library::getBuses() { return buses; } std::vector Library::getConnections() { return connections; } std::map Library::getMessages() { return messages; } bool Library::hasComponent(std::string name) { for (unsigned int i = 0; i < components.size(); i++) { if (components[i].getName() == name) { return true; } } return false; } bool Library::hasBus(std::string name) { for (unsigned int i = 0; i < buses.size(); i++) { if (buses[i].getName() == name) { return true; } } return false; } AddressSpace &Library::getAddressSpace(std::string addressSpace) { for (unsigned int i = 0; i < addressSpaces.size(); i++) { if (addressSpaces[i].getName() == addressSpace) { return addressSpaces[i]; } } throw std::runtime_error("no address space with name '" + addressSpace + "'"); } Component &Library::getComponent(std::string component) { for (unsigned int i = 0; i < components.size(); i++) { if (components[i].getName() == component) { return components[i]; } } throw std::runtime_error("no component with name '" + component + "'"); } Bus &Library::getBus(std::string bus) { for (unsigned int i = 0; i < buses.size(); i++) { if (buses[i].getName() == bus) { return buses[i]; } } throw std::runtime_error("no bus with name '" + bus + "'"); } bool Library::hasConnection(ConnectionComponent component, std::string bus) { return getConnection(component, bus).has_value(); } std::optional Library::getConnection(ConnectionComponent component, std::string bus) { for (unsigned int i = 0; i < connections.size(); i++) { if (connections[i].isConnecting(component, bus)) { return connections[i]; } } return nullopt; } bool Library::hasConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent) { return getConnection(component, bus, secondComponent).has_value(); } std::optional Library::getConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent) { for (unsigned int i = 0; i < connections.size(); i++) { if (connections[i].isConnecting(component, bus, secondComponent)) { return connections[i]; } } return nullopt; } std::string Library::getMessage(std::string key) { return messages[key]; } bool Library::hasConnection(ConnectionComponent component, ConnectionComponent secondComponent) { return getConnection(component, secondComponent).has_value(); } std::optional Library::getConnection(ConnectionComponent component, ConnectionComponent secondComponent) { for (auto &connection: connections) { if (connection.isConnecting(component, secondComponent)) { return connection; } } return nullopt; } } // namespace domain