147 lines
4.6 KiB
C++
147 lines
4.6 KiB
C++
#include "library.h"
|
|
#include <stdexcept>
|
|
|
|
namespace domain {
|
|
|
|
Library::Library(string name, string libraryInfo, string header, string componentDirectory,
|
|
std::optional<std::string> componentHeader,
|
|
vector<AddressSpace> addressSpaces, vector<Component> components, vector<Bus> buses,
|
|
vector<Connection> connections, map<string, string> 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<std::string> Library::getComponentHeader() {
|
|
return componentHeader;
|
|
}
|
|
|
|
std::vector<AddressSpace> Library::getAddressSpaces() {
|
|
return addressSpaces;
|
|
}
|
|
|
|
std::vector<Component> Library::getComponents() {
|
|
return components;
|
|
}
|
|
|
|
std::vector<Bus> Library::getBuses() {
|
|
return buses;
|
|
}
|
|
|
|
std::vector<Connection> Library::getConnections() {
|
|
return connections;
|
|
}
|
|
|
|
std::map<std::string, std::string> 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<Connection> 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<Connection>
|
|
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<Connection>
|
|
Library::getConnection(ConnectionComponent component, ConnectionComponent secondComponent) {
|
|
for (auto &connection: connections) {
|
|
if (connection.isConnecting(component, secondComponent)) {
|
|
return connection;
|
|
}
|
|
}
|
|
return nullopt;
|
|
}
|
|
|
|
} // namespace domain
|