Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d055f2

Browse files
authored
Add XML parsing support for custom Control Nodes (BehaviorTree#194)
Signed-off-by: Sarathkrishnan Ramesh <[email protected]>
1 parent 0799e8f commit 4d055f2

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/xml_parsing.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void VerifyXML(const std::string& xml_text,
251251
{
252252
const char* name = node->Name();
253253
if (StrEqual(name, "Action") || StrEqual(name, "Decorator") ||
254-
StrEqual(name, "SubTree") || StrEqual(name, "Condition"))
254+
StrEqual(name, "SubTree") || StrEqual(name, "Condition") || StrEqual(name, "Control"))
255255
{
256256
const char* ID = node->Attribute("ID");
257257
if (!ID)
@@ -309,6 +309,19 @@ void VerifyXML(const std::string& xml_text,
309309
"The node <Condition> must have the attribute [ID]");
310310
}
311311
}
312+
else if (StrEqual(name, "Control"))
313+
{
314+
if (children_count == 0)
315+
{
316+
ThrowError(node->GetLineNum(),
317+
"The node <Control> must have at least 1 child");
318+
}
319+
if (!node->Attribute("ID"))
320+
{
321+
ThrowError(node->GetLineNum(),
322+
"The node <Control> must have the attribute [ID]");
323+
}
324+
}
312325
else if (StrEqual(name, "Sequence") ||
313326
StrEqual(name, "SequenceStar") ||
314327
StrEqual(name, "Fallback") )
@@ -443,7 +456,8 @@ TreeNode::Ptr XMLParser::Pimpl::createNodeFromXML(const XMLElement *element,
443456
std::string instance_name;
444457

445458
// Actions and Decorators have their own ID
446-
if (element_name == "Action" || element_name == "Decorator" || element_name == "Condition")
459+
if (element_name == "Action" || element_name == "Decorator" ||
460+
element_name == "Condition" || element_name == "Control")
447461
{
448462
ID = element->Attribute("ID");
449463
}

0 commit comments

Comments
 (0)