@@ -97,43 +97,38 @@ mx::NodeGraphPtr UiNode::getNodeGraph() const
9797
9898void UiNode::buildUiTokenMap ()
9999{
100+ // Helper inline lambda function to avoid repeating code for mapping of tokens declared on element itself vs on element's corresponding nodedef
101+ auto handleTokenMapping = [&](const mx::ConstInterfaceElementPtr& interfaceElem, mx::ElementPtr sourceElem)
102+ {
103+ std::vector<mx::TokenPtr> tokens = interfaceElem->getActiveTokens ();
104+ for (auto token : tokens)
105+ {
106+ std::string key = token->getName ();
107+
108+ // Insert into map, but do not allow parent values to override child values
109+ _uiTokenMap.try_emplace (key, std::make_shared<UiToken>(token, sourceElem));
110+ }
111+ };
112+
100113 _uiTokenMap.clear (); // Assume we want clean slate
101114
102- mx::ElementPtr currNode = getNode ();
103- while (currNode )
115+ mx::ElementPtr currElem = getNode ();
116+ while (currElem )
104117 {
105- if (mx::ConstInterfaceElementPtr interfaceElem = currNode ->asA <mx::InterfaceElement>())
118+ if (mx::ConstInterfaceElementPtr interfaceElem = currElem ->asA <mx::InterfaceElement>())
106119 {
107- std::vector<mx::TokenPtr> tokens = interfaceElem->getActiveTokens ();
108- for (auto token : tokens)
109- {
110- std::string key = token->getName ();
111- if (!_uiTokenMap.count (key)) // Do not allow parent values to override child values
112- {
113- // Create a new entry in map
114- _uiTokenMap[key] = std::make_shared<UiToken>(token, currNode);
115- }
116- }
120+ handleTokenMapping (interfaceElem, currElem);
117121
118122 // If the node is a nodegraph, also check for tokens on corresponding nodedef
119- if (mx::ConstNodeGraphPtr nodegraph = currNode ->asA <mx::NodeGraph>())
123+ if (mx::ConstNodeGraphPtr nodegraph = currElem ->asA <mx::NodeGraph>())
120124 {
121125 if (mx::NodeDefPtr nodedef = nodegraph->getNodeDef ())
122126 {
123- tokens = nodedef->getActiveTokens ();
124- for (auto token : tokens)
125- {
126- std::string key = token->getName ();
127- if (!_uiTokenMap.count (key)) // Do not allow parent values to override child values
128- {
129- // Create a new entry in map
130- _uiTokenMap[key] = std::make_shared<UiToken>(token, currNode);
131- }
132- }
127+ handleTokenMapping (nodedef, nodedef);
133128 }
134129 }
135130 }
136- currNode = currNode ->getParent ();
131+ currElem = currElem ->getParent ();
137132 }
138133
139134 // Traverse through inputs and determine which tokens their value depends on
0 commit comments