From 3b8bb88fbbdce7dc557159d67ff0a1ae7b1cb28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sun, 30 Mar 2025 22:48:08 +0200 Subject: [PATCH] changes --- CMakeLists.txt | 1 + src/imports/import_base.hpp | 27 ++++++++-------- src/imports/import_mentor.cpp | 59 +++++++++++++++++++++++++++++++++-- src/imports/import_mentor.hpp | 2 +- src/main.cpp | 2 +- src/system/connect.cpp | 4 +-- src/system/modules.cpp | 4 +-- src/system/modules.hpp | 9 +++--- src/system/parts.cpp | 4 +-- src/system/parts.hpp | 3 +- src/system/pins.cpp | 4 +-- src/system/signals.cpp | 4 +-- src/system/signals.hpp | 3 +- src/system/syselmts.hpp | 4 +++ src/system/system.cpp | 8 +---- src/system/system.hpp | 5 ++- 16 files changed, 93 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bceb476..4555e27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ add_executable( ) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) target_link_libraries( essim PRIVATE ${LIB_FTXUI} diff --git a/src/imports/import_base.hpp b/src/imports/import_base.hpp index 20f16d8..4954b5c 100644 --- a/src/imports/import_base.hpp +++ b/src/imports/import_base.hpp @@ -2,29 +2,28 @@ #define _IMPORT_BASE_HPP_ #include +#include -#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; } }; diff --git a/src/imports/import_mentor.cpp b/src/imports/import_mentor.cpp index dedb03e..92120d4 100644 --- a/src/imports/import_mentor.cpp +++ b/src/imports/import_mentor.cpp @@ -1,14 +1,67 @@ #include "import_mentor.hpp" +#include "system/parts.hpp" +#include "system/pins.hpp" -ImportMentor::ImportMentor() { +#include +#include + +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); + } + } } \ No newline at end of file diff --git a/src/imports/import_mentor.hpp b/src/imports/import_mentor.hpp index 0a7824a..30547d4 100644 --- a/src/imports/import_mentor.hpp +++ b/src/imports/import_mentor.hpp @@ -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_ \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 1d3a206..4d81784 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include "signals.hpp" +#include "system/signals.hpp" using namespace std; diff --git a/src/system/connect.cpp b/src/system/connect.cpp index 6074343..784aeb2 100644 --- a/src/system/connect.cpp +++ b/src/system/connect.cpp @@ -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("connections") {} diff --git a/src/system/modules.cpp b/src/system/modules.cpp index 30d1204..5b1d6c0 100644 --- a/src/system/modules.cpp +++ b/src/system/modules.cpp @@ -1,8 +1,6 @@ #include "modules.hpp" -Module::Module(std::string name) : SystemElement(name) { - -}; +Module::Module(std::string name) : SystemElementContainer(name) {}; Modules::Modules(void): SystemElementContainer("modules") {} diff --git a/src/system/modules.hpp b/src/system/modules.hpp index bd634e5..4a11a75 100644 --- a/src/system/modules.hpp +++ b/src/system/modules.hpp @@ -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 { public: Module(std::string name); @@ -16,4 +17,4 @@ public: Modules(std::vector pins); }; -#endif // _PINS_HPP_ \ No newline at end of file +#endif // _MODULES_HPP_ \ No newline at end of file diff --git a/src/system/parts.cpp b/src/system/parts.cpp index 31532f2..9e2ecc9 100644 --- a/src/system/parts.cpp +++ b/src/system/parts.cpp @@ -1,8 +1,6 @@ #include "parts.hpp" -Part::Part(std::string name) : SystemElement(name) { - -}; +Part::Part(std::string name) : SystemElementContainer(name) {}; Parts::Parts(void): SystemElementContainer("parts") {} diff --git a/src/system/parts.hpp b/src/system/parts.hpp index 39ef872..6f4205c 100644 --- a/src/system/parts.hpp +++ b/src/system/parts.hpp @@ -2,8 +2,9 @@ #define _PARTS_HPP_ #include "syselmts.hpp" +#include "pins.hpp" -class Part : public SystemElement +class Part : public SystemElementContainer { public: Part(std::string name); diff --git a/src/system/pins.cpp b/src/system/pins.cpp index 1ec57bf..2a50a73 100644 --- a/src/system/pins.cpp +++ b/src/system/pins.cpp @@ -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("pins") {} diff --git a/src/system/signals.cpp b/src/system/signals.cpp index af9ca71..3d2f05d 100644 --- a/src/system/signals.cpp +++ b/src/system/signals.cpp @@ -1,9 +1,7 @@ #include "signals.hpp" -Signal::Signal(std::string name) : SystemElement(name) { - -}; +Signal::Signal(std::string name) : SystemElementContainer(name) {}; Signals::Signals(void): SystemElementContainer("signals") {} diff --git a/src/system/signals.hpp b/src/system/signals.hpp index 79e1293..d1649d6 100644 --- a/src/system/signals.hpp +++ b/src/system/signals.hpp @@ -2,8 +2,9 @@ #define _SIGNALS_HPP_ #include "syselmts.hpp" +#include "pins.hpp" -class Signal : public SystemElement +class Signal : public SystemElementContainer { public: Signal(std::string name); diff --git a/src/system/syselmts.hpp b/src/system/syselmts.hpp index 8373fa6..e8807a6 100644 --- a/src/system/syselmts.hpp +++ b/src/system/syselmts.hpp @@ -44,6 +44,10 @@ public: } content.insert({element.name, element}); } + void add(SystemElementContainer elements) + { + add(elements.content); + } void add(std::vector elements) { for (auto &element : elements) diff --git a/src/system/system.cpp b/src/system/system.cpp index 0015a25..8febe14 100644 --- a/src/system/system.cpp +++ b/src/system/system.cpp @@ -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) { - } \ No newline at end of file diff --git a/src/system/system.hpp b/src/system/system.hpp index 67c2947..0b52ec3 100644 --- a/src/system/system.hpp +++ b/src/system/system.hpp @@ -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_ \ No newline at end of file