schema_editor/comdel/domain/component.cpp

106 lines
3.2 KiB
C++
Raw Normal View History

2022-03-31 21:20:41 +00:00
#include "component.h"
2022-06-27 09:39:13 +00:00
#include <stdexcept>
2022-03-31 21:20:41 +00:00
namespace domain {
2022-06-14 19:27:40 +00:00
Component::Component(string name, optional<string> displayName, string tooltip, string source, ComponentType type,
2022-05-27 06:18:17 +00:00
vector<Rule> rules, string instanceName, pair<int, int> count, Display display,
vector<Pin> pins, vector<Attribute> attributes)
2022-06-14 19:27:40 +00:00
: name(name), displayName(displayName), tooltip(tooltip), source(source), type(type), rules(rules), instanceName(instanceName),
2022-05-27 06:18:17 +00:00
count(count), display(display), pins(pins), attributes(attributes) {}
std::string Component::getName() {
return name;
2022-03-31 21:20:41 +00:00
}
2022-06-14 19:27:40 +00:00
std::string Component::getDisplayName() {
if(displayName.has_value()) {
return displayName.value();
}
return name;
}
2022-05-27 06:18:17 +00:00
std::string Component::getTooltip() {
return tooltip;
2022-04-05 21:48:07 +00:00
}
2022-05-27 06:18:17 +00:00
std::string Component::getSource() {
return source;
}
Component::ComponentType Component::getType() {
return type;
}
std::vector<Rule> Component::getRules() {
return rules;
}
std::string Component::getInstanceName() {
return instanceName;
}
std::pair<int, int> Component::getCount() {
return count;
2022-03-31 21:20:41 +00:00
}
2022-05-27 06:18:17 +00:00
Display Component::getDisplay() {
return display;
}
std::vector<Pin> Component::getPins() {
return pins;
}
Pin Component::getPin(std::string pin) {
for (auto & p: pins) {
if (p.getName() == pin) {
return p;
}
2022-05-15 21:55:03 +00:00
}
2022-06-27 09:39:13 +00:00
throw std::runtime_error("no pin with name '" + pin + "'");
2022-05-27 06:18:17 +00:00
}
bool Component::hasPin(std::string name) {
for (auto pin: pins) {
if (pin.getName() == name) {
return true;
}
2022-05-15 21:55:03 +00:00
}
2022-05-27 06:18:17 +00:00
return false;
}
std::vector<Attribute>& Component::getAttributes() {
2022-05-27 06:18:17 +00:00
return attributes;
}
Attribute Component::getAttribute(std::string attribute) {
for (auto & attr : attributes) {
if (attr.getName() == attribute) {
return attr;
}
2022-04-05 21:48:07 +00:00
}
2022-06-27 09:39:13 +00:00
throw std::runtime_error("no attribute with name '" + attribute + "'");
2022-04-05 21:48:07 +00:00
}
2022-05-27 06:18:17 +00:00
bool Component::hasAttribute(std::string name, Value::ValueType type) {
for (auto & attribute : attributes) {
if (attribute.getName() == name && attribute.getDefault().getType() == type) {
return true;
}
if (attribute.getName() == name && (type == Value::NIL &&
(attribute.getDefault().getType() == Value::MEMORY_REFERENCE ||
attribute.getDefault().getType() == Value::WIRE_REFERENCE))) {
return true;
}
if (attribute.getName() == name && (type == Value::UNDEFINED &&
(attribute.getDefault().getType() == Value::MEMORY_REFERENCE ||
attribute.getDefault().getType() == Value::WIRE_REFERENCE))) {
return true;
}
}
return false;
}
2022-03-31 21:20:41 +00:00
} // namespace domain