42 std::filesystem::path& relative_filepath)
44 std::filesystem::path sub_path = path;
45 if (std::filesystem::is_regular_file(sub_path))
47 relative_filepath = sub_path.filename();
48 sub_path = sub_path.parent_path();
52 relative_filepath = sub_path;
57 while (!sub_path.empty() && sub_path != sub_path.root_path())
59 if (std::filesystem::is_regular_file(sub_path /
"package.xml"))
64 package_name = sub_path.filename().string();
65 tinyxml2::XMLDocument package_xml_file;
66 auto is_open = package_xml_file.LoadFile((sub_path /
"package.xml").c_str());
67 if (is_open == tinyxml2::XML_SUCCESS)
70 package_xml_file.FirstChildElement(
"package")->FirstChildElement(
"name")->FirstChild()->ToText()->Value();
74 package_name = name_potential;
79 relative_filepath = sub_path.filename() / relative_filepath;
80 sub_path = sub_path.parent_path();
105tinyxml2::XMLElement*
uniqueInsert(tinyxml2::XMLDocument& doc, tinyxml2::XMLElement& element,
const char* tag,
106 const std::vector<XMLAttribute>& attributes,
const char* text)
109 tinyxml2::XMLElement* result = element.FirstChildElement(tag);
111 result = result->NextSiblingElement(tag);
115 result = doc.NewElement(tag);
116 element.InsertEndChild(result);
120 for (
const auto& attr : attributes)
122 if (!result->Attribute(attr.name))
123 result->SetAttribute(attr.name, attr.value);
127 if (text && !result->GetText())
129 tinyxml2::XMLText* text_el = doc.NewText(text);
130 result->InsertEndChild(text_el);
tinyxml2::XMLElement * uniqueInsert(tinyxml2::XMLDocument &doc, tinyxml2::XMLElement &element, const char *tag, const std::vector< XMLAttribute > &attributes={}, const char *text=nullptr)
Insert a new XML element with a given tag, attributes, and text.