-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPI.cpp
69 lines (68 loc) · 1.66 KB
/
API.cpp
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
#include "API.h"
bool API::readJson(string fileName)
{
try {
topology* newTopology = new topology();
topologies.push_back(newTopology);
JP.store(JP.read(fileName), newTopology);
}
catch (exception&)
{
return 0;
}
return 1;
}
bool API::writeJson(string topologyID, string fileName)
{
topology* targetTopology = NULL;
for (topology* topo : topologies)
if (topo->hasThatId(topologyID))
{
targetTopology = topo;
break;
}
if (!targetTopology)
return 0;
try
{
JP.write(targetTopology, fileName);
}
catch (const std::exception&)
{
return 0;
}
return 1;
}
vector<topology*> API::queryTopology()
{
return topologies;
}
bool API::deleteTopology(string TopologyID)
{
for (int i = 0; i < topologies.size(); i++)
if (topologies[i]->hasThatId(TopologyID))
{
swap(topologies[i], topologies[topologies.size() - 1]);
topologies.pop_back();
return 1;
}
return 0;
}
vector<component*> API::queryDevices(string topologyID)
{
for (topology* singleTopology : topologies)
if (singleTopology->hasThatId(topologyID))
return singleTopology->getComponents();
vector<component*> noResult;
return noResult;
}
vector<component*> API::queryDevicesWithNetlistNode(string topologyID, string NetlistNode)
{
for (topology* singleTopology : topologies)
if (singleTopology->hasThatId(topologyID))
{
return singleTopology->getComponentsWithNetlistId(NetlistNode);
}
vector<component*> noResult;
return noResult;
}