Mentor import done.

This commit is contained in:
2025-04-21 18:19:37 +02:00
parent 6448972fd8
commit d0bf09aa63
14 changed files with 238 additions and 56 deletions

70
doc/classes.puml Normal file
View File

@@ -0,0 +1,70 @@
@startuml
' Base class
class SystemElement {
- string name
+ SystemElement(string name)
}
' Template container class
class SystemElementContainer<T> {
- unsigned int iter_count
- unordered_map<string, T*> content
+ SystemElementContainer(string name)
+ SystemElementContainer(string name, vector<T*> elements)
+ bool exists(string name)
+ void add(T* element)
+ void add(SystemElementContainer<T>* elements)
+ void add(vector<T*> elements)
+ T* get(string name)
+ T* merge(string name)
+ iterator begin()
+ iterator end()
+ const_iterator begin() const
+ const_iterator end() const
}
SystemElementContainer --|> SystemElement
' Part and Pin classes
class Part {
+ Part(string name)
+ void add(Pin* pin)
}
class Pin {
+ Pin(string name)
+ void connect(Signal* signal)
}
Part --* Pin
' Signal class
class Signal {
+ Signal(string name)
+ void connect(Pin* pin)
}
Pin --> Signal
' Module and Modules classes
class Module {
+ Signals* signals
+ Modules* prnt
+ Module(string name)
+ ~Module()
}
class Modules {
+ Modules()
+ Modules(vector<Module*> parts)
+ void add(Module* module)
+ ~Modules()
}
Module --|> SystemElementContainer
Modules --|> SystemElementContainer
Module --> Modules
Module --> Signals
@enduml

View File

@@ -106,7 +106,9 @@ void ImportMentor::parse(Signals *signals)
auto pin = new Pin(names[0]); // Create a new pin with the first name.
Signal *s = nullptr;
prt->add(pin); // Add the pin to the current part.
pin->connect(signals->merge(names[2])); // Connect the pin to a signal.
s = signals->merge(names[2]); // Merge the signal with module signals.
s->add(pin); // Add the pin to the signal pins list.
pin->connect(s); // Connect the pin to a signal.
}
}
break;

View File

@@ -3,8 +3,9 @@
using namespace std;
int main() {
System sys = System();
System *sys = new System();
string ment_filename = "/home/francois/Projets/twinsys/test/BPB-2177_Netlist_2_3.qcv";
sys.Load("bpb", ment_filename, ImportType::IMPORT_MENTOR);
sys->Load("bpb", ment_filename, ImportType::IMPORT_MENTOR);
delete sys;
};

View File

@@ -1,7 +1,30 @@
#include "modules.hpp"
Module::Module(std::string name) : SystemElementContainer<Part>(name) {}
#include "signals.hpp"
Module::Module(std::string name) : SystemElementContainer<Part>(name), prnt(nullptr) {
signals = new Signals();
}
Module::~Module() {
for (const auto& [key, value] : content) {
delete value;
}
delete signals;
}
Modules::Modules(void): SystemElementContainer<Module>("modules") {}
Modules::Modules(std::vector<Module *> modules): SystemElementContainer<Module>("modules", modules) {}
Modules::Modules(std::vector<Module *> modules): SystemElementContainer<Module>("modules", modules) {}
void Modules::add(Module *module)
{
SystemElementContainer<Module>::add(module);
module->prnt = this;
}
Modules::~Modules() {
for (const auto& [key, value] : content) {
delete value;
}
}

View File

@@ -3,20 +3,28 @@
#include "syselmts.hpp"
#include "parts.hpp"
#include "signals.hpp"
#pragma once
class Modules; ///< Forward declaration of the Modules class.
class Signals; ///< Forward declaration of the Signals class.
class Module : public SystemElementContainer<Part>
{
public:
Signals sigs;
Signals *signals;
Modules *prnt;
Module(std::string name);
~Module();
};
class Modules : public SystemElementContainer<Module>
{
public:
Modules(void);
Modules(std::vector<Module *> pins);
Modules(std::vector<Module *> parts);
void add(Module *module);
~Modules();
};
#endif // _MODULES_HPP_

View File

@@ -1,7 +1,19 @@
#include "parts.hpp"
Part::Part(std::string name) : SystemElementContainer<Pin>(name) {};
Part::Part(std::string name) : SystemElementContainer<Pin>(name), prnt(nullptr) {};
void Part::add(Pin *pin)
{
SystemElementContainer<Pin>::add(pin);
pin->prnt = this;
}
Part::~Part() {
for (const auto& [key, value] : content) {
delete value;
}
}
Parts::Parts(void): SystemElementContainer<Part>("parts") {}
Parts::Parts(std::vector<Part *> parts): SystemElementContainer<Part>("parts", parts) {}
Parts::Parts(std::vector<Part *> parts): SystemElementContainer<Part>("parts", parts) {}

View File

@@ -4,10 +4,16 @@
#include "syselmts.hpp"
#include "pins.hpp"
#pragma once
class Module; ///< Forward declaration of the Module class.
class Part : public SystemElementContainer<Pin>
{
public:
Part(std::string name);
~Part();
Module *prnt; ///< Pointer to the parent module.
void add(Pin *pin) override;
};
class Parts : public SystemElementContainer<Part>

View File

@@ -1,8 +1,11 @@
#include "pins.hpp"
#include "parts.hpp"
#include "signals.hpp"
Pin::Pin(std::string name) : SystemElement(name), sig(nullptr) {};
Pin::Pin(std::string name) : SystemElement(name), sig(nullptr), prnt(nullptr) {};
bool Pin::connected() {
bool Pin::connected()
{
return sig != nullptr;
}
@@ -11,6 +14,6 @@ void Pin::connect(Signal *signal)
sig = signal;
}
Pins::Pins(void): SystemElementContainer<Pin>("pins") {}
Pins::Pins(void) : SystemElementContainer<Pin>("pins") {}
Pins::Pins(std::vector<Pin *> pins): SystemElementContainer<Pin>("pins", pins) {}
Pins::Pins(std::vector<Pin *> pins) : SystemElementContainer<Pin>("pins", pins) {}

View File

@@ -2,13 +2,19 @@
#define _PINS_HPP_
#include "syselmts.hpp"
#include "signals.hpp"
#pragma once
class Part;
#pragma once
class Signal;
class Pin : public SystemElement
{
Signal *sig;
public:
Pin(std::string name);
Part *prnt; ///< Pointer to the parent part.
bool connected();
void connect(Signal *signal);
};

View File

@@ -1,11 +1,27 @@
#include "signals.hpp"
#include "parts.hpp"
Signal::Signal(std::string name) : SystemElementContainer<Pin>(name) {};
Signal::Signal(std::string name) : SystemElementContainer<Pin>(name), prnt(nullptr) {};
void Signal::add(Pin *pin)
{
string pname = pin->prnt->name + "." + pin->name;
SystemElementContainer<Pin>::add(pname, pin);
}
Signals::Signals(void): SystemElementContainer<Signal>("signals") {}
Signals::Signals(std::vector<Signal *> signals): SystemElementContainer<Signal>("signals", signals) {}
Signals::~Signals() {}
Signals::~Signals() {
for (const auto& [key, value] : content) {
delete value;
}
}
void Signals::add(Signal *signal)
{
SystemElementContainer<Signal>::add(signal);
signal->prnt = this;
}

View File

@@ -2,14 +2,17 @@
#define _SIGNALS_HPP_
#include "syselmts.hpp"
#include "pins.hpp"
#pragma once
class Pin;
class Signals;
class Signal : public SystemElementContainer<Pin>
{
public:
Signals *prnt; ///< Pointer to the parent signals object.
Signal(std::string name);
void add(Pin *pin) override;
};
class Signals : public SystemElementContainer<Signal>
@@ -17,6 +20,7 @@ class Signals : public SystemElementContainer<Signal>
public:
Signals(void);
Signals(std::vector<Signal *> signals);
void add(Signal *signal) override;
~Signals();
};

View File

@@ -32,13 +32,13 @@ template <typename T>
class SystemElementContainer : public SystemElement
{
public:
using MapType = unordered_map<string, T *>; // Map to store elements by name.
using iterator = typename MapType::iterator; // Iterator for the map.
using MapType = unordered_map<string, T *>; // Map to store elements by name.
using iterator = typename MapType::iterator; // Iterator for the map.
using const_iterator = typename MapType::const_iterator; // Const iterator for the map.
private:
protected:
unsigned int iter_count; // Counter for iterations (currently unused).
MapType content; // Container for storing elements.
MapType content; // Container for storing elements.
/**
* @brief Adds elements from a map to the container.
@@ -69,6 +69,35 @@ public:
add(elements);
}
/**
* @brief Adds a single element to the container with a given name.
* @param name Name of the element to add.
* @param element Pointer to the element to add.
* @throws runtime_error If the element's name is empty or already exists.
*/
virtual void add(string name, T *element)
{
if ("" == name)
{
throw runtime_error("System elements with empty names are forbidden");
}
if (exists(name))
{
throw runtime_error("System elements of same names are forbidden");
}
content.insert({name, element});
}
/**
* @brief Adds a single element to the container.
* @param element Pointer to the element to add.
* @throws runtime_error If the element's name is empty or already exists.
*/
virtual void add(T *element)
{
add (element->name, element);
}
/**
* @brief Checks if an element exists in the container.
* @param name Name of the element to check.
@@ -87,24 +116,6 @@ public:
}
}
/**
* @brief Adds a single element to the container.
* @param element Pointer to the element to add.
* @throws runtime_error If the element's name is empty or already exists.
*/
void add(T *element)
{
if ("" == element->name)
{
throw runtime_error("System elements with empty names are forbidden");
}
if (exists(element->name))
{
throw runtime_error("System elements of same names are forbidden");
}
content.insert({element->name, element});
}
/**
* @brief Adds elements from another container.
* @param elements Pointer to another container.
@@ -150,14 +161,15 @@ public:
* @param name Name of the element.
* @return Pointer to the merged or newly created element.
*/
T* merge(string name)
T *merge(string name)
{
if (exists(name)) {
if (exists(name))
{
return get(name);
}
else
{
T* ret = new T(name);
T *ret = new T(name);
add(ret);
return ret;
}
@@ -167,25 +179,25 @@ public:
* @brief Returns an iterator to the beginning of the container.
* @return Iterator to the beginning.
*/
iterator begin() { return content.begin(); }
iterator begin() { return std::begin(content); }
/**
* @brief Returns an iterator to the end of the container.
* @return Iterator to the end.
*/
iterator end() { return content.end(); }
iterator end() { return std::end(content); }
/**
* @brief Returns a constant iterator to the beginning of the container.
* @return Constant iterator to the beginning.
*/
const_iterator begin() const { return content.begin(); }
const_iterator begin() const { return std::begin(content); }
/**
* @brief Returns a constant iterator to the end of the container.
* @return Constant iterator to the end.
*/
const_iterator end() const { return content.end(); }
const_iterator end() const { return std::end(content); }
};
#endif

View File

@@ -1,28 +1,43 @@
#include "system.hpp"
#include "connect.hpp"
#include "modules.hpp"
#include "imports/import_mentor.hpp"
System::System(): mods(nullptr), conns(nullptr) {
System::System() : mods(nullptr), conns(nullptr)
{
mods = new Modules();
conns = new Connections();
}
System::~System() {
System::~System()
{
delete mods;
delete conns;
}
void System::Load(std::string module_name, std::string file_name, ImportType type) {
void System::Load(std::string module_name, std::string file_name, ImportType type)
{
ImportBase *imp;
Module *mod = nullptr;
Parts *prts = nullptr;
Module mod = Module(module_name);
if (!mods->exists(module_name))
{
mod = new Module(module_name);
mods->add(mod);
}
else
{
mod = mods->get(module_name);
}
switch (type)
{
case ImportType::IMPORT_MENTOR :
case ImportType::IMPORT_MENTOR:
imp = new ImportMentor(file_name);
imp->parse();
imp->parse(mod->signals);
prts = imp->parts();
mod.add(prts);
mod->add(prts);
break;
default:

View File

@@ -1,8 +1,12 @@
#ifndef _SYSTEM_HPP_
#define _SYSTEM_HPP_
#include "connect.hpp"
#include "modules.hpp"
#include "imports/import_base.hpp"
#pragma once
class Modules; ///< Forward declaration of the Modules class.
class Connections; ///< Forward declaration of the Connections class.
enum class ImportType {
IMPORT_MENTOR,