From c123001f79539046b67e487b985463da5a44e354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sun, 30 Mar 2025 17:15:35 +0200 Subject: [PATCH] wip --- src/connect.cpp | 9 +++++++++ src/connect.hpp | 19 +++++++++++++++++++ src/main.cpp | 14 ++++++++++++++ src/modules.cpp | 9 +++++++++ src/modules.hpp | 19 +++++++++++++++++++ src/parts.cpp | 9 +++++++++ src/parts.hpp | 19 +++++++++++++++++++ src/pins.cpp | 9 +++++++++ src/pins.hpp | 19 +++++++++++++++++++ src/signals.cpp | 6 +++--- src/signals.hpp | 16 +++++++++++++--- src/syselmts.hpp | 47 ++++++++++++++++++++++++++++++----------------- src/system.cpp | 18 ++++++++++++++++++ src/system.hpp | 18 ++++++++++++++++++ 14 files changed, 208 insertions(+), 23 deletions(-) create mode 100644 src/modules.cpp create mode 100644 src/modules.hpp create mode 100644 src/parts.hpp create mode 100644 src/pins.cpp create mode 100644 src/pins.hpp diff --git a/src/connect.cpp b/src/connect.cpp index e69de29..6074343 100644 --- a/src/connect.cpp +++ b/src/connect.cpp @@ -0,0 +1,9 @@ +#include "connect.hpp" + +Connection::Connection(std::string name) : SystemElement(name) { + +}; + +Connections::Connections(void): SystemElementContainer("connections") {} + +Connections::Connections(std::vector conns): SystemElementContainer("connections", conns) {} \ No newline at end of file diff --git a/src/connect.hpp b/src/connect.hpp index e69de29..aa00bcc 100644 --- a/src/connect.hpp +++ b/src/connect.hpp @@ -0,0 +1,19 @@ +#ifndef _CONNECT_HPP_ +#define _CONNECT_HPP_ + +#include "syselmts.hpp" + +class Connection : public SystemElement +{ +public: + Connection(std::string name); +}; + +class Connections : public SystemElementContainer +{ +public: + Connections(void); + Connections(std::vector connections); +}; + +#endif // _CONNECT_HPP_ \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index c3c88b4..1d3a206 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,18 @@ +#include "signals.hpp" + +using namespace std; int main() { + auto sigs = Signals(); + Signal *sig = nullptr; + int i=0; + string sname = ""; + + while (i < 10) { + sname = "signal" + to_string(i); + sig = new Signal(sname); + sigs.add(*sig); + i++; + } }; diff --git a/src/modules.cpp b/src/modules.cpp new file mode 100644 index 0000000..30d1204 --- /dev/null +++ b/src/modules.cpp @@ -0,0 +1,9 @@ +#include "modules.hpp" + +Module::Module(std::string name) : SystemElement(name) { + +}; + +Modules::Modules(void): SystemElementContainer("modules") {} + +Modules::Modules(std::vector modules): SystemElementContainer("modules", modules) {} \ No newline at end of file diff --git a/src/modules.hpp b/src/modules.hpp new file mode 100644 index 0000000..bd634e5 --- /dev/null +++ b/src/modules.hpp @@ -0,0 +1,19 @@ +#ifndef _PINS_HPP_ +#define _PINS_HPP_ + +#include "syselmts.hpp" + +class Module : public SystemElement +{ +public: + Module(std::string name); +}; + +class Modules : public SystemElementContainer +{ +public: + Modules(void); + Modules(std::vector pins); +}; + +#endif // _PINS_HPP_ \ No newline at end of file diff --git a/src/parts.cpp b/src/parts.cpp index e69de29..31532f2 100644 --- a/src/parts.cpp +++ b/src/parts.cpp @@ -0,0 +1,9 @@ +#include "parts.hpp" + +Part::Part(std::string name) : SystemElement(name) { + +}; + +Parts::Parts(void): SystemElementContainer("parts") {} + +Parts::Parts(std::vector parts): SystemElementContainer("parts", parts) {} \ No newline at end of file diff --git a/src/parts.hpp b/src/parts.hpp new file mode 100644 index 0000000..39ef872 --- /dev/null +++ b/src/parts.hpp @@ -0,0 +1,19 @@ +#ifndef _PARTS_HPP_ +#define _PARTS_HPP_ + +#include "syselmts.hpp" + +class Part : public SystemElement +{ +public: + Part(std::string name); +}; + +class Parts : public SystemElementContainer +{ +public: + Parts(void); + Parts(std::vector parts); +}; + +#endif // _PARTS_HPP_ \ No newline at end of file diff --git a/src/pins.cpp b/src/pins.cpp new file mode 100644 index 0000000..1ec57bf --- /dev/null +++ b/src/pins.cpp @@ -0,0 +1,9 @@ +#include "pins.hpp" + +Pin::Pin(std::string name) : SystemElement(name) { + +}; + +Pins::Pins(void): SystemElementContainer("pins") {} + +Pins::Pins(std::vector pins): SystemElementContainer("pins", pins) {} \ No newline at end of file diff --git a/src/pins.hpp b/src/pins.hpp new file mode 100644 index 0000000..ea2fb68 --- /dev/null +++ b/src/pins.hpp @@ -0,0 +1,19 @@ +#ifndef _PINS_HPP_ +#define _PINS_HPP_ + +#include "syselmts.hpp" + +class Pin : public SystemElement +{ +public: + Pin(std::string name); +}; + +class Pins : public SystemElementContainer +{ +public: + Pins(void); + Pins(std::vector pins); +}; + +#endif // _PINS_HPP_ \ No newline at end of file diff --git a/src/signals.cpp b/src/signals.cpp index 83f8842..af9ca71 100644 --- a/src/signals.cpp +++ b/src/signals.cpp @@ -5,7 +5,7 @@ Signal::Signal(std::string name) : SystemElement(name) { }; -Signals::Signals(std::vector signals): SystemElementContainer("signals") { - add(signals); -} +Signals::Signals(void): SystemElementContainer("signals") {} + +Signals::Signals(std::vector signals): SystemElementContainer("signals", signals) {} diff --git a/src/signals.hpp b/src/signals.hpp index 365e3d1..79e1293 100644 --- a/src/signals.hpp +++ b/src/signals.hpp @@ -1,9 +1,19 @@ +#ifndef _SIGNALS_HPP_ +#define _SIGNALS_HPP_ + #include "syselmts.hpp" -class Signal: public SystemElement { +class Signal : public SystemElement +{ +public: Signal(std::string name); }; -class Signals: public SystemElementContainer { +class Signals : public SystemElementContainer +{ +public: + Signals(void); Signals(std::vector signals); -}; \ No newline at end of file +}; + +#endif // _SIGNALS_HPP_ \ No newline at end of file diff --git a/src/syselmts.hpp b/src/syselmts.hpp index 8226f80..8373fa6 100644 --- a/src/syselmts.hpp +++ b/src/syselmts.hpp @@ -1,4 +1,3 @@ - #ifndef _SYSELEMENTS_HPP_ #define _SYSELEMENTS_HPP_ @@ -11,7 +10,7 @@ class SystemElement { public: std::string name; - SystemElement(std::string name): name(name) {}; + SystemElement(std::string name) : name(name) {}; }; template @@ -22,31 +21,45 @@ private: unsigned int iter_count; std::unordered_map content; - bool name_exists(std::string name) { + bool name_exists(std::string name) + { return get(name) != nullptr; } public: SystemElementContainer(std::string name) : SystemElement(name) {}; - void add(const T element) { - if ("" == element.name) { - throw std::runtime_error("Elements with empty names are forbidden"); - } - if name_exists(element.name) { - throw std::runtime_error("Elements of same names are forbidden"); - } - content[element.name] = element; + SystemElementContainer(std::string name, std::vector elements) : SystemElement(name) + { + add(elements); } - void add(const std::vector elements) { - for (const auto& element: elements) { - + void add(T element) + { + if ("" == element.name) + { + throw std::runtime_error("System elements with empty names are forbidden"); + } + if (name_exists(element.name)) + { + throw std::runtime_error("System elements of same names are forbidden"); + } + content.insert({element.name, element}); + } + void add(std::vector elements) + { + for (auto &element : elements) + { + add(element); } } - T* get(std::string name) { + T *get(std::string name) + { auto it = content.find(name); - if (it != content.end()) { + if (it != content.end()) + { return &it->second; - } else { + } + else + { return nullptr; } } diff --git a/src/system.cpp b/src/system.cpp index e69de29..0015a25 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -0,0 +1,18 @@ + +#include "system.hpp" + +using namespace std; + +System::System(void): mods(nullptr), conns(nullptr) { + mods = new Modules(); + conns = new Connections(); +} + +System::~System() { + delete mods; + delete conns; +} + +void System::add_mentor(ifstream lines) { + +} \ No newline at end of file diff --git a/src/system.hpp b/src/system.hpp index e69de29..67c2947 100644 --- a/src/system.hpp +++ b/src/system.hpp @@ -0,0 +1,18 @@ +#ifndef _SYSTEM_HPP_ +#define _SYSTEM_HPP_ + +#include "connect.hpp" +#include "modules.hpp" + + +class System +{ + Modules *mods; + Connections *conns; + +public: + System(void); + void add_mentor(std::ifstream lines); +}; + +#endif // _SYSTEM_HPP_ \ No newline at end of file