-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdProvider.cpp
85 lines (73 loc) · 2.02 KB
/
IdProvider.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "IdProvider.h"
#include "Utils.h"
unsigned int nodeId = 1;
unsigned int slotId = 0;
unsigned int parameterId = 0;
std::string parameter = "parameter_";
namespace IdProvider
{
void reset()
{
nodeId = 0;
slotId = 0;
parameterId = 0;
}
void init(const Graph& graph)
{
int largestParameter = 0;
int largestNode = 0;
int largestSlot = 0;
for (size_t i = 0; i < graph.parameters.size(); i++)
{
int p = graph.parameters[i].name.find(parameter);
if (p == 0)
{
std::string number = graph.parameters[i].name.substr(parameter.size());
if (Utils::isNumber(number))
{
int value = std::stoi(number);
if (value > largestParameter)
{
largestParameter = value;
}
}
}
}
for (auto it = graph.nodes.begin(); it != graph.nodes.end(); it++)
{
if (it->first > largestNode)
{
largestNode = it->first;
}
for (int i = 0; i < it->second.input_slots.size(); i++)
{
if (it->second.input_slots[i].guid > largestSlot)
{
largestSlot = it->second.input_slots[i].guid;
}
}
for (int i = 0; i < it->second.output_slots.size(); i++)
{
if (it->second.output_slots[i].guid > largestSlot)
{
largestSlot = it->second.output_slots[i].guid;
}
}
}
parameterId = ++largestParameter;
nodeId = ++largestNode;
slotId = ++largestSlot;
}
unsigned int getNodeId()
{
return nodeId++;
}
unsigned int getSlotId()
{
return slotId++;
}
std::string getUniformName()
{
return parameter + std::to_string(parameterId++);
}
}