Refactored instances

This commit is contained in:
Borna Rajković committed 2022-05-08 15:47:47 +02:00
1 parent fb8aafb2a9
commit 74a7ef3e7a
7 files changed
+37 -41

No files matched your search

+2 -2
View File
@@ -8,14 +8,14 @@ namespace domain {
struct ValidationError
{
Instance *instance;
ComponentInstance *instance;
InstanceAttribute *attribute;
Action::ActionType type;
std::string message;
};
struct ValidationContext {
Instance *instance;
ComponentInstance *instance;
InstanceAttribute *attribute;
std::map<std::string, AddressSpace> addressSpaces;
std::map<std::string, Value> attributes;
+2 -6
View File
@@ -2,15 +2,11 @@
namespace domain {
Instance::Instance(std::string name, std::vector<InstanceAttribute> attributes, std::pair<int, int> position)
: name(name), attributes(attributes), position(position)
{}
BusInstance::BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size)
: Instance(name, vector<InstanceAttribute>(), position), bus(bus), size(size)
: name(name), position(position), bus(bus), size(size)
{}
ComponentInstance::ComponentInstance(std::string name, std::vector<InstanceAttribute> attributes, std::pair<int, int> position, Component component)
: Instance(name, attributes, position), component(component)
: name(name), attributes(std::move(attributes)), position(position), component(component)
{}
+16 -25
View File
@@ -12,41 +12,32 @@
namespace domain {
class Instance
class BusInstance
{
public:
std::string name;
std::pair<int, int> position;
Bus bus;
int size;
BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size);
virtual ~BusInstance() = default;
};
class ComponentInstance
{
public:
std::string name;
std::vector<InstanceAttribute> attributes;
std::pair<int, int> position;
virtual ~Instance() {};
Instance(std::string name, std::vector<InstanceAttribute> attributes, std::pair<int, int> position);
};
class BusInstance: public Instance
{
public:
Bus bus;
int size;
BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size);
virtual ~BusInstance() {
Instance::~Instance();
}
};
class ComponentInstance: public Instance
{
public:
Component component;
ComponentInstance(std::string name, std::vector<InstanceAttribute> attributes, std::pair<int, int> position, Component component);
virtual ~ComponentInstance() {
Instance::~Instance();
}
virtual ~ComponentInstance() = default;
};
} // namespace domain
+2 -1
View File
@@ -15,10 +15,11 @@ class InstanceAttribute
public:
InstanceAttribute(std::string name, Value value, Attribute attribute);
std::string name;
std::string name = "";
Value value;
Attribute attribute;
~InstanceAttribute() = default;
};
} // namespace domain
+4 -2
View File
@@ -14,18 +14,20 @@ class Schema
public:
Schema();
std::vector<shared_ptr<BusInstance>> busInstances;
std::vector<shared_ptr<ComponentInstance>> componentInstances;
std::vector<shared_ptr<ConnectionInstance>> connections;
Instance *getInstance(std::string& name) {
BusInstance *getBusInstance(std::string& name) {
for(auto& instance: busInstances) {
if (instance->name == name) {
return instance.get();
}
}
return nullptr;
}
ComponentInstance *getComponentInstance(std::string& name) {
for(auto& instance: componentInstances) {
if (instance->name == name) {
return instance.get();
+3 -3
View File
@@ -787,7 +787,7 @@ Schema* SchemaCreator::loadSchema(SchemaNode node, Library &library)
}
for(auto &conn: node.connections) {
auto firstComponent = dynamic_cast<ComponentInstance*>(schema->getInstance(conn.first.instance.value));
auto firstComponent = schema->getComponentInstance(conn.first.instance.value);
if(firstComponent == nullptr) {
errors.emplace_back(conn.first.instance.span, "unknown component");
continue;
@@ -800,7 +800,7 @@ Schema* SchemaCreator::loadSchema(SchemaNode node, Library &library)
ComponentInstance *secondComponent = nullptr;
if(conn.second.has_value()) {
secondComponent = dynamic_cast<ComponentInstance*>(schema->getInstance(conn.second->instance.value));
secondComponent = schema->getComponentInstance(conn.second->instance.value);
if(secondComponent == nullptr) {
errors.emplace_back(conn.second->instance.span, "unknown component");
continue;
@@ -811,7 +811,7 @@ Schema* SchemaCreator::loadSchema(SchemaNode node, Library &library)
}
}
auto bus = dynamic_cast<BusInstance*>(schema->getInstance(conn.bus.value));
auto bus = schema->getBusInstance(conn.bus.value);
if(bus == nullptr) {
errors.emplace_back(conn.bus.span, "unknown bus");
continue;