-
Notifications
You must be signed in to change notification settings - Fork 0
/
netlist.h
110 lines (86 loc) · 3.07 KB
/
netlist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef NETLIST_H
#define NETLIST_H
#include <QObject>
#include <QMap>
// Объявления используемых классов
class Net;
class Node;
// Класс узла цепи нетлиста
class Node : public QObject
{
Q_OBJECT
public:
// Конструктор
Node(const QString &displayName, QObject *parent = 0);
// Get-метод цепи, к которой относится узел
Net *net() const { return m_net; }
// Get-метод унифицированного имени узла
QString name() const { return m_name; }
// Get-метод отображаемого имени узла
QString displayName() const { return m_displayName; }
private:
// Унифицированное имя узла
QString m_name;
// Отображаемое имя узла
QString m_displayName;
// Цепь, к которой относится узел
Net *m_net;
public slots:
// Слот задания цепи
void setNet(Net *net) { m_net = net; }
};
// Класс цепи нетлиста
class Net : public QObject
{
Q_OBJECT
public:
// Конструктор
Net(const QString &name, QObject *parent = 0) :
QObject(parent), m_name(name) {}
// Get-метод имени цепи
QString name() const { return m_name; }
// Get-метод ассоциативного массива узлов
const QMap <QString, Node *> &nodeMap() const { return m_nodeMap; }
private:
// Имя цепи
QString m_name;
// Ассоциативный массив узлов
QMap <QString, Node *> m_nodeMap;
public slots:
// Слот добавления узла
void addNode(Node *node)
{ m_nodeMap[node->name()] = node; node->setNet(this); }
};
// Класс нетлиста
class Netlist : public QObject
{
Q_OBJECT
public:
// Конструктор
Netlist(QObject *parent = 0);
// Get-метод ассоциативного массива цепей
const QMap <QString, Net *> &netMap() const { return m_netMap; }
// Get-метод ассоциативного массива узлов
const QMap <QString, Node *> &nodeMap() const { return m_nodeMap; }
// Метод, возвращающий информацию о том, является ли нетлист пустым
bool isEmpty() const { return m_netMap.isEmpty(); }
private:
// Ассоциативный массив цепей
QMap <QString, Net *> m_netMap;
// Ассоциативный массив узлов
QMap <QString, Node *> m_nodeMap;
public slots:
// Метод загрузки нетлиста из файла
void readFromFile(const QString &filename);
// Метод добавления цепи в нетлист
void addNet(Net *net)
{ if (m_netMap.contains(net->name()))
m_netMap[net->name()]->deleteLater();
m_netMap[net->name()] = net; }
// Метод добавления узла в цепь
void addNode(Net *net, Node *node)
{ if (!m_nodeMap.contains(node->name())) {
m_nodeMap[node->name()] = node; net->addNode(node);
} else node->deleteLater(); }
};
#endif // NETLIST_H