wip
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
#include "connect.hpp"
|
||||
|
||||
Connection::Connection(std::string name) : SystemElement(name) {
|
||||
|
||||
};
|
||||
|
||||
Connections::Connections(void): SystemElementContainer<Connection>("connections") {}
|
||||
|
||||
Connections::Connections(std::vector<Connection> conns): SystemElementContainer<Connection>("connections", conns) {}
|
||||
@@ -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<Connection>
|
||||
{
|
||||
public:
|
||||
Connections(void);
|
||||
Connections(std::vector<Connection> connections);
|
||||
};
|
||||
|
||||
#endif // _CONNECT_HPP_
|
||||
14
src/main.cpp
14
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++;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
9
src/modules.cpp
Normal file
9
src/modules.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "modules.hpp"
|
||||
|
||||
Module::Module(std::string name) : SystemElement(name) {
|
||||
|
||||
};
|
||||
|
||||
Modules::Modules(void): SystemElementContainer<Module>("modules") {}
|
||||
|
||||
Modules::Modules(std::vector<Module> modules): SystemElementContainer<Module>("modules", modules) {}
|
||||
19
src/modules.hpp
Normal file
19
src/modules.hpp
Normal file
@@ -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<Module>
|
||||
{
|
||||
public:
|
||||
Modules(void);
|
||||
Modules(std::vector<Module> pins);
|
||||
};
|
||||
|
||||
#endif // _PINS_HPP_
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "parts.hpp"
|
||||
|
||||
Part::Part(std::string name) : SystemElement(name) {
|
||||
|
||||
};
|
||||
|
||||
Parts::Parts(void): SystemElementContainer<Part>("parts") {}
|
||||
|
||||
Parts::Parts(std::vector<Part> parts): SystemElementContainer<Part>("parts", parts) {}
|
||||
19
src/parts.hpp
Normal file
19
src/parts.hpp
Normal file
@@ -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<Part>
|
||||
{
|
||||
public:
|
||||
Parts(void);
|
||||
Parts(std::vector<Part> parts);
|
||||
};
|
||||
|
||||
#endif // _PARTS_HPP_
|
||||
9
src/pins.cpp
Normal file
9
src/pins.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "pins.hpp"
|
||||
|
||||
Pin::Pin(std::string name) : SystemElement(name) {
|
||||
|
||||
};
|
||||
|
||||
Pins::Pins(void): SystemElementContainer<Pin>("pins") {}
|
||||
|
||||
Pins::Pins(std::vector<Pin> pins): SystemElementContainer<Pin>("pins", pins) {}
|
||||
19
src/pins.hpp
Normal file
19
src/pins.hpp
Normal file
@@ -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<Pin>
|
||||
{
|
||||
public:
|
||||
Pins(void);
|
||||
Pins(std::vector<Pin> pins);
|
||||
};
|
||||
|
||||
#endif // _PINS_HPP_
|
||||
@@ -5,7 +5,7 @@ Signal::Signal(std::string name) : SystemElement(name) {
|
||||
|
||||
};
|
||||
|
||||
Signals::Signals(std::vector<Signal> signals): SystemElementContainer<Signal>("signals") {
|
||||
add(signals);
|
||||
}
|
||||
Signals::Signals(void): SystemElementContainer<Signal>("signals") {}
|
||||
|
||||
Signals::Signals(std::vector<Signal> signals): SystemElementContainer<Signal>("signals", signals) {}
|
||||
|
||||
|
||||
@@ -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<Signal> {
|
||||
class Signals : public SystemElementContainer<Signal>
|
||||
{
|
||||
public:
|
||||
Signals(void);
|
||||
Signals(std::vector<Signal> signals);
|
||||
};
|
||||
};
|
||||
|
||||
#endif // _SIGNALS_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 <typename T>
|
||||
@@ -22,31 +21,45 @@ private:
|
||||
unsigned int iter_count;
|
||||
std::unordered_map<std::string, T> 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<T> elements) : SystemElement(name)
|
||||
{
|
||||
add(elements);
|
||||
}
|
||||
void add(const std::vector<T> 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<T> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
@@ -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_
|
||||
Reference in New Issue
Block a user