-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCApplySystemProc.cpp
119 lines (82 loc) · 2.36 KB
/
CApplySystemProc.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
// CApplySystemProc.cpp
//
// CApplySystemProc class
// Copyright (c) 2017 Kronosaur Productions, LLC. All Rights Reserved.
#include "PreComp.h"
#define ATTRIBUTES_TAG CONSTLIT("Attributes")
#define SYSTEM_TAG CONSTLIT("System")
#define ATTRIBUTES_ATTRIB CONSTLIT("attributes")
CApplySystemProc::~CApplySystemProc (void)
// CApplySystemProc destructor
{
}
ALERROR CApplySystemProc::OnInitFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, const CString &sUNID)
// OnInitFromXML
//
// Initialize from XML element
{
ALERROR error;
// Treat the content as a system definition
const CString &sTag = pDesc->GetTag();
// Load it based on its tag
if (strEquals(sTag, SYSTEM_TAG))
{
if (error = m_SystemDesc.InitFromXML(Ctx, pDesc))
return error;
}
else if (strEquals(sTag, ATTRIBUTES_TAG))
{
m_sAttributes = pDesc->GetAttribute(ATTRIBUTES_ATTRIB);
}
// Otherwise, unknown tag. This should never happen because we don't create
// this processor unless it's one of these two tags.
else
{
Ctx.sError = strPatternSubst(CONSTLIT("Unknown element: %s"), sTag);
return ERR_FAIL;
}
// See if we have any children (e.g., <Criteria>)
for (int i = 0; i < pDesc->GetContentElementCount(); i++)
{
CXMLElement *pItem = pDesc->GetContentElement(i);
// See if this is an element handled by our base class
if ((error = InitBaseItemXML(Ctx, pItem)) != ERR_NOTFOUND)
{
if (error != NOERROR)
return error;
}
}
return NOERROR;
}
ALERROR CApplySystemProc::OnProcess (SProcessCtx &Ctx, CTopologyNodeList &NodeList, CString *retsError)
// OnProcess
//
// Process on topology
{
int i;
CTopologyNodeList Remaining;
CTopologyNode::SCriteriaCtx MatchCtx;
MatchCtx.pTopology = &Ctx.Topology;
// Apply system properties to all nodes in list
for (i = 0; i < NodeList.GetCount(); i++)
{
CTopologyNode *pNode = NodeList[i];
// Make sure we match criteria
if (!pNode->MatchesCriteria(MatchCtx, m_Criteria))
{
// Add to remaining (unprocessed list).
if (Ctx.bReduceNodeList)
Remaining.Insert(pNode);
continue;
}
// Apply
if (!m_sAttributes.IsBlank())
pNode->AddAttributes(m_sAttributes);
if (!m_SystemDesc.IsEmpty())
m_SystemDesc.Apply(Ctx.Topology, pNode);
}
// Modify original list to have only remaining (unprocessed) nodes.
if (Ctx.bReduceNodeList)
NodeList = Remaining;
return NOERROR;
}