MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / createNodeFromXML

Method createNodeFromXML

src/xml_parsing.cpp:742–1040  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

740}
741
742TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
743 const Blackboard::Ptr& blackboard,
744 const TreeNode::Ptr& node_parent,
745 const std::string& prefix_path,
746 Tree& output_tree)
747{
748 const auto element_name = element->Name();
749 const auto element_ID = element->Attribute("ID");
750
751 auto node_type = convertFromString<NodeType>(element_name);
752 // name used by the factory
753 std::string type_ID;
754
755 if(node_type == NodeType::UNDEFINED)
756 {
757 // This is the case of nodes like <MyCustomAction>
758 // check if the factory has this name
759 if(factory->builders().count(element_name) == 0)
760 {
761 throw RuntimeError(element_name, " is not a registered node");
762 }
763 type_ID = element_name;
764
765 if(element_ID != nullptr)
766 {
767 throw RuntimeError("Attribute [ID] is not allowed in <", type_ID, ">");
768 }
769 }
770 else
771 {
772 // in this case, it is mandatory to have a field "ID"
773 if(element_ID == nullptr)
774 {
775 throw RuntimeError("Attribute [ID] is mandatory in <", type_ID, ">");
776 }
777 type_ID = element_ID;
778 }
779
780 // By default, the instance name is equal to ID, unless the
781 // attribute [name] is present.
782 const char* attr_name = element->Attribute("name");
783 const std::string instance_name = (attr_name != nullptr) ? attr_name : type_ID;
784
785 // Validate instance name if explicitly provided
786 if(attr_name != nullptr)
787 {
788 validateInstanceName(instance_name, element->GetLineNum());
789 }
790
791 const TreeNodeManifest* manifest = nullptr;
792
793 auto manifest_it = factory->manifests().find(type_ID);
794 if(manifest_it != factory->manifests().end())
795 {
796 manifest = &manifest_it->second;
797 }
798
799 PortsRemapping port_remap;

Callers

nothing calls this directly

Calls 15

RuntimeErrorClass · 0.85
validateInstanceNameFunction · 0.85
IsAllowedPortNameFunction · 0.85
StrCatFunction · 0.85
LogicErrorClass · 0.85
IsReservedAttributeFunction · 0.85
stringFunction · 0.85
demangleFunction · 0.85
NameMethod · 0.80
AttributeMethod · 0.80
ValueMethod · 0.80
isStronglyTypedMethod · 0.80

Tested by

no test coverage detected