schema_editor/comdel/domain/library.cpp

147 lines
4.6 KiB
C++
Raw Normal View History

2022-03-31 21:20:41 +00:00
#include "library.h"
2022-06-27 09:39:13 +00:00
#include <stdexcept>
2022-03-31 21:20:41 +00:00
namespace domain {
2022-05-27 06:18:17 +00:00
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) {
2022-06-27 09:39:13 +00:00
for (unsigned int i = 0; i < components.size(); i++) {
2022-05-27 06:18:17 +00:00
if (components[i].getName() == name) {
return true;
}
2022-04-05 21:48:07 +00:00
}
2022-05-27 06:18:17 +00:00
return false;
2022-04-05 21:48:07 +00:00
}
2022-05-27 06:18:17 +00:00
bool Library::hasBus(std::string name) {
2022-06-27 09:39:13 +00:00
for (unsigned int i = 0; i < buses.size(); i++) {
2022-05-27 06:18:17 +00:00
if (buses[i].getName() == name) {
return true;
}
2022-04-05 21:48:07 +00:00
}
2022-05-27 06:18:17 +00:00
return false;
2022-04-05 21:48:07 +00:00
}
2022-05-27 06:18:17 +00:00
AddressSpace &Library::getAddressSpace(std::string addressSpace) {
2022-06-27 09:39:13 +00:00
for (unsigned int i = 0; i < addressSpaces.size(); i++) {
2022-05-27 06:18:17 +00:00
if (addressSpaces[i].getName() == addressSpace) {
return addressSpaces[i];
}
2022-03-31 21:20:41 +00:00
}
2022-06-27 09:39:13 +00:00
throw std::runtime_error("no address space with name '" + addressSpace + "'");
2022-03-31 21:20:41 +00:00
}
2022-05-27 06:18:17 +00:00
Component &Library::getComponent(std::string component) {
2022-06-27 09:39:13 +00:00
for (unsigned int i = 0; i < components.size(); i++) {
2022-05-27 06:18:17 +00:00
if (components[i].getName() == component) {
return components[i];
}
2022-03-31 21:20:41 +00:00
}
2022-06-27 09:39:13 +00:00
throw std::runtime_error("no component with name '" + component + "'");
2022-03-31 21:20:41 +00:00
}
2022-05-27 06:18:17 +00:00
Bus &Library::getBus(std::string bus) {
2022-06-27 09:39:13 +00:00
for (unsigned int i = 0; i < buses.size(); i++) {
2022-05-27 06:18:17 +00:00
if (buses[i].getName() == bus) {
return buses[i];
}
2022-03-31 21:20:41 +00:00
}
2022-06-27 09:39:13 +00:00
throw std::runtime_error("no bus with name '" + bus + "'");
2022-05-27 06:18:17 +00:00
2022-03-31 21:20:41 +00:00
}
2022-05-27 06:18:17 +00:00
bool Library::hasConnection(ConnectionComponent component, std::string bus) {
return getConnection(component, bus).has_value();
}
2022-04-09 17:44:02 +00:00
2022-05-27 06:18:17 +00:00
std::optional<Connection> Library::getConnection(ConnectionComponent component, std::string bus) {
2022-06-27 09:39:13 +00:00
for (unsigned int i = 0; i < connections.size(); i++) {
2022-05-27 06:18:17 +00:00
if (connections[i].isConnecting(component, bus)) {
return connections[i];
}
2022-03-31 21:20:41 +00:00
}
2022-05-27 06:18:17 +00:00
return nullopt;
}
bool Library::hasConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent) {
return getConnection(component, bus, secondComponent).has_value();
2022-03-31 21:20:41 +00:00
}
2022-04-09 17:44:02 +00:00
2022-05-27 06:18:17 +00:00
std::optional<Connection>
Library::getConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent) {
2022-06-27 09:39:13 +00:00
for (unsigned int i = 0; i < connections.size(); i++) {
2022-05-27 06:18:17 +00:00
if (connections[i].isConnecting(component, bus, secondComponent)) {
return connections[i];
}
2022-04-09 17:44:02 +00:00
}
2022-05-27 06:18:17 +00:00
return nullopt;
2022-04-09 17:44:02 +00:00
}
2022-04-05 21:48:07 +00:00
2022-05-27 06:18:17 +00:00
std::string Library::getMessage(std::string key) {
return messages[key];
}
2022-03-31 21:20:41 +00:00
2022-05-25 05:39:45 +00:00
bool Library::hasConnection(ConnectionComponent component, ConnectionComponent secondComponent) {
return getConnection(component, secondComponent).has_value();
}
std::optional<Connection>
Library::getConnection(ConnectionComponent component, ConnectionComponent secondComponent) {
2022-05-27 06:18:17 +00:00
for (auto &connection: connections) {
if (connection.isConnecting(component, secondComponent)) {
2022-05-25 05:39:45 +00:00
return connection;
}
}
return nullopt;
}
2022-03-31 21:20:41 +00:00
} // namespace domain