-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCTopologyNodeList.cpp
186 lines (133 loc) · 3.46 KB
/
CTopologyNodeList.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// CTopologyNodeList.cpp
//
// CTopologyNodeList class
#include "PreComp.h"
void CTopologyNodeList::Delete (CTopologyNode *pNode)
// Delete
//
// Delete the given node
{
int iIndex;
if (FindNode(pNode, &iIndex))
m_List.Delete(iIndex);
}
ALERROR CTopologyNodeList::Filter (CTopologyNode::SCriteriaCtx &Ctx, CXMLElement *pCriteria, CTopologyNodeList *retList, CString *retsError)
// Filter
//
// Filters the list based on the criteria and returns a new list
{
ALERROR error;
// Parse the filter
CTopologyNode::SCriteria Crit;
if (error = CTopologyNode::ParseCriteria(pCriteria, &Crit, retsError))
return error;
// Filter
if (error = Filter(Ctx, Crit, retList))
{
*retsError = CONSTLIT("Error filtering nodes.");
return error;
}
return NOERROR;
}
ALERROR CTopologyNodeList::Filter (CTopologyNode::SCriteriaCtx &Ctx, CTopologyNode::SCriteria &Crit, CTopologyNodeList *ioList)
// Filter
//
// Filters the list based on the criteria and returns a new list
{
int i;
// Loop over all nodes and generate a filtered list
for (i = 0; i < m_List.GetCount(); i++)
{
if (m_List[i]->MatchesCriteria(Ctx, Crit))
ioList->Insert(m_List[i]);
}
return NOERROR;
}
bool CTopologyNodeList::FindNode (CTopologyNode *pNode, int *retiIndex) const
// FindNode
//
// Finds the given node
{
int i;
for (i = 0; i < m_List.GetCount(); i++)
if (pNode == m_List[i])
{
if (retiIndex)
*retiIndex = i;
return true;
}
return false;
}
bool CTopologyNodeList::FindNode (const CString &sID, int *retiIndex) const
// FindNode
//
// Finds the given node
{
int i;
for (i = 0; i < m_List.GetCount(); i++)
if (strEquals(sID, m_List[i]->GetID()))
{
if (retiIndex)
*retiIndex = i;
return true;
}
return false;
}
bool CTopologyNodeList::IsNodeInRangeOf (CTopologyNode *pNode, int iMin, int iMax, const CTopologyNode::SAttributeCriteria &AttribCriteria, CTopologyNodeList &Checked) const
// IsNodeInRangeOf
//
// Returns TRUE if pNode is >= iMin and <= iMax of a node that has AttribsRequired
// and doesn't have AttribsNotAllowed, and is not in Checked.
{
int i;
// Add ourselves to the Checked list
Checked.Insert(pNode);
// If iMin is 0, then check the current node
if (iMin <= 0)
{
// If we match the criteria, then we're OK (since we've satified the distance
// criteria).
if (pNode->MatchesAttributeCriteria(AttribCriteria))
return true;
}
// If any adjacent nodes are in range, then we are also in range
if (iMax > 0)
{
for (i = 0; i < pNode->GetStargateCount(); i++)
{
CTopologyNode *pDest = pNode->GetStargateDest(i);
// Skip if we've already checked this node
if (Checked.FindNode(pDest))
continue;
// If this node is in range, then we're done
if (IsNodeInRangeOf(pDest, iMin - 1, iMax - 1, AttribCriteria, Checked))
return true;
}
}
// Otherwise, we're not in range
return false;
}
void CTopologyNodeList::RestoreMarks (TArray<bool> &Saved)
// RestoreMarks
//
// Restore node marks from array
{
int i;
int iCount = Min(Saved.GetCount(), m_List.GetCount());
for (i = 0; i < iCount; i++)
m_List[i]->SetMarked(Saved[i]);
}
void CTopologyNodeList::SaveAndSetMarks (bool bMark, TArray<bool> *retSaved)
// SaveAndSetMarks
//
// Saves the marks and sets them all to the new value
{
int i;
retSaved->DeleteAll();
retSaved->InsertEmpty(m_List.GetCount());
for (i = 0; i < m_List.GetCount(); i++)
{
retSaved->GetAt(i) = m_List[i]->IsMarked();
m_List[i]->SetMarked(bMark);
}
}