-
Notifications
You must be signed in to change notification settings - Fork 1
/
WP.cpp
54 lines (40 loc) · 1.03 KB
/
WP.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
#include"WP.h"
#include"stdafx.h"
Exec^ WP::getExecutable(__int64 i){ if (i<getExecutableCount()) { return execList[i]; } };
void WP::addExecutable(Exec^ e) { execList->Add(e); };
__int64 WP::getExecutableCount() { return execList->Count; };
WP::WP(String^ n, __int64 ID, __int64 in, WP^p) :Exec(n, ID, in, p, true) {
execList = gcnew List<Exec^>();
};
ToolPath ^ WP::firstPath() {
return firstPath(this);
}
ToolPath ^ WP::firstPath(WP^ root) {
if (root == nullptr) {
root = this;
}
Exec^tempExec;
WP^ tempWP;
WS^ tempWS;
for (int i = 0; i<root->getExecutableCount(); i++) {
tempExec = root->getExecutable(i);
if (tempExec->isWP()) {
tempWP = dynamic_cast<WP^>(tempExec);
return firstPath(tempWP);
}
else {
tempWS = dynamic_cast<WS^>(tempExec);
return tempWS->getPath(0);
}
}
return nullptr;
};
__int64 WP::distanceAbove(WP^ ancestor) {
WP^ temp = this;
__int64 count = 0;
while (temp!=nullptr&&temp->getId() != ancestor->getId()) {
temp = temp->getParent();
count += 1;
}
return count;
}