-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemberPtr.hpp
More file actions
40 lines (38 loc) · 874 Bytes
/
memberPtr.hpp
File metadata and controls
40 lines (38 loc) · 874 Bytes
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
#pragma once
#include <string>
#include <map>
#include "classes.hpp"
namespace pl {
auto getPtr(std::string name, std::map<std::string, pl::RtVar>& RtVars) -> RtVar* {
RtVar* finded = nullptr;
bool isFirst = true;
std::string RtNow;
for (size_t i = 3; i < name.length(); i++) {
if (name[i] == ':') {
if (isFirst) {
isFirst = false;
finded = &RtVars[RtNow];
}
else {
if ('0' <= RtNow[0] && RtNow[0] <= '9')
finded = &(finded->children[stoi(RtNow)]);
else finded = &(finded->member[RtNow]);
}
RtNow.clear();
}
else RtNow += name[i];
}
if (!RtNow.empty()) {
if (isFirst) {
isFirst = false;
finded = &RtVars[RtNow];
}
else {
if ('0' <= RtNow[0] && RtNow[0] <= '9')
finded = &(finded->children[stoi(RtNow)]);
else finded = &(finded->member[RtNow]);
}
}
return finded;
}
}