This commit is contained in:
2025-03-30 22:48:08 +02:00
parent a61f24e08c
commit 3b8bb88fbb
16 changed files with 93 additions and 50 deletions

View File

@@ -2,29 +2,28 @@
#define _IMPORT_BASE_HPP_
#include <string>
#include <fstream>
#include "connect.hpp"
#include "modules.hpp"
#include "system/connect.hpp"
#include "system/parts.hpp"
class ImportBase
{
Connections *connects;
Modules *mods;
protected:
Parts *prts;
virtual void parse(std::fstream lines) = 0;
public:
ImportBase()
{
connects = new Connections();
mods = new Modules();
prts = new Parts();
}
virtual void load(std::string file_name) = 0;
Connections *connections()
void load(std::string file_name) {
std::ifstream file(file_name);
};
Parts *parts()
{
return connects;
}
Modules *modules()
{
return mods;
return prts;
}
};

View File

@@ -1,14 +1,67 @@
#include "import_mentor.hpp"
#include "system/parts.hpp"
#include "system/pins.hpp"
ImportMentor::ImportMentor() {
#include <string>
#include <regex>
enum class State {
NO_PART,
IS_PART,
};
ImportMentor::ImportMentor(): ImportBase() {
}
ImportMentor::~ImportMentor() {
ImportBase::~ImportBase();
}
void ImportMentor::load(std::string filename) {
void ImportMentor::parse(std::fstream lines) {
std::string line;
auto state = State::NO_PART;
const std::regex name_regex("\\'([^\\']*)\\'");
const std::regex part_regex("^COMP:");
const std::regex pin_regex("^Explicit Pin:");
while (std::getline(lines, line))
{
Part *prt = nullptr;
std::smatch name_match;
bool is_name_match = std::regex_match(line, name_match, part_regex);
bool is_part_match = std::regex_match(line, part_regex);
bool is_pin_match = std::regex_match(line, pin_regex);
switch (state)
{
case State::NO_PART:
if (is_part_match) {
if (is_name_match) {
prt = new Part(name_match[0]);
state = State::IS_PART;
}
}
break;
default:
if (is_part_match) {
if (is_name_match) {
prts->add(*prt);
prt = new Part(name_match[0]);
}
}
else if (is_pin_match)
{
if (is_name_match) {
auto pin = new Pin(name_match[0]);
prt->add(*pin);
}
}
break;
}
if (state == State::IS_PART) {
prts->add(*prt);
}
}
}

View File

@@ -7,10 +7,10 @@
class ImportMentor : public ImportBase
{
void parse(std::fstream lines);
public:
ImportMentor();
~ImportMentor();
void load(std::string file_name);
};
#endif // _IMPORT_MENTOR_HPP_

View File

@@ -1,4 +1,4 @@
#include "signals.hpp"
#include "system/signals.hpp"
using namespace std;

View File

@@ -1,8 +1,6 @@
#include "connect.hpp"
Connection::Connection(std::string name) : SystemElement(name) {
};
Connection::Connection(std::string name) : SystemElement(name) {};
Connections::Connections(void): SystemElementContainer<Connection>("connections") {}

View File

@@ -1,8 +1,6 @@
#include "modules.hpp"
Module::Module(std::string name) : SystemElement(name) {
};
Module::Module(std::string name) : SystemElementContainer<Part>(name) {};
Modules::Modules(void): SystemElementContainer<Module>("modules") {}

View File

@@ -1,9 +1,10 @@
#ifndef _PINS_HPP_
#define _PINS_HPP_
#ifndef _MODULES_HPP_
#define _MODULES_HPP_
#include "syselmts.hpp"
#include "parts.hpp"
class Module : public SystemElement
class Module : public SystemElementContainer<Part>
{
public:
Module(std::string name);
@@ -16,4 +17,4 @@ public:
Modules(std::vector<Module> pins);
};
#endif // _PINS_HPP_
#endif // _MODULES_HPP_

View File

@@ -1,8 +1,6 @@
#include "parts.hpp"
Part::Part(std::string name) : SystemElement(name) {
};
Part::Part(std::string name) : SystemElementContainer<Pin>(name) {};
Parts::Parts(void): SystemElementContainer<Part>("parts") {}

View File

@@ -2,8 +2,9 @@
#define _PARTS_HPP_
#include "syselmts.hpp"
#include "pins.hpp"
class Part : public SystemElement
class Part : public SystemElementContainer<Pin>
{
public:
Part(std::string name);

View File

@@ -1,8 +1,6 @@
#include "pins.hpp"
Pin::Pin(std::string name) : SystemElement(name) {
};
Pin::Pin(std::string name) : SystemElement(name) {};
Pins::Pins(void): SystemElementContainer<Pin>("pins") {}

View File

@@ -1,9 +1,7 @@
#include "signals.hpp"
Signal::Signal(std::string name) : SystemElement(name) {
};
Signal::Signal(std::string name) : SystemElementContainer<Pin>(name) {};
Signals::Signals(void): SystemElementContainer<Signal>("signals") {}

View File

@@ -2,8 +2,9 @@
#define _SIGNALS_HPP_
#include "syselmts.hpp"
#include "pins.hpp"
class Signal : public SystemElement
class Signal : public SystemElementContainer<Pin>
{
public:
Signal(std::string name);

View File

@@ -44,6 +44,10 @@ public:
}
content.insert({element.name, element});
}
void add(SystemElementContainer<T> elements)
{
add(elements.content);
}
void add(std::vector<T> elements)
{
for (auto &element : elements)

View File

@@ -1,9 +1,7 @@
#include "system.hpp"
using namespace std;
System::System(void): mods(nullptr), conns(nullptr) {
System::System(): mods(nullptr), conns(nullptr) {
mods = new Modules();
conns = new Connections();
}
@@ -11,8 +9,4 @@ System::System(void): mods(nullptr), conns(nullptr) {
System::~System() {
delete mods;
delete conns;
}
void System::add_mentor(ifstream lines) {
}

View File

@@ -4,15 +4,14 @@
#include "connect.hpp"
#include "modules.hpp"
class System
{
Modules *mods;
Connections *conns;
public:
System(void);
void add_mentor(std::ifstream lines);
System();
~System();
};
#endif // _SYSTEM_HPP_