21#include "ament_index_cpp/get_resource.hpp"
32 std::string base_path;
33 std::vector<TreeResource> resources;
34 if (ament_index_cpp::get_resource(_AUTO_APMS_BEHAVIOR_TREE__RESOURCE_TYPE_NAME__TREE,
package_name, content,
38 auto make_absolute_path = [base_path](
const std::string& s) {
return base_path +
"/" + s; };
39 for (
const auto& line : lines)
42 if (parts.size() != 4)
44 throw std::runtime_error(
"Invalid behavior tree resource file (Package: '" +
package_name +
"').");
52 r.
tree_names = { tree_ids_vec.begin(), tree_ids_vec.end() };
53 resources.push_back(r);
61 std::set<std::string> search_packages;
71 std::vector<TreeResource> matching_resources;
76 if (r.tree_names.find(tree_name) != r.tree_names.end())
78 matching_resources.push_back(r);
83 if (matching_resources.empty())
86 "' was registered." };
88 if (matching_resources.size() > 1)
91 "' exists multiple times. Use the 'package_name' argument "
92 "to narrow down the search." };
95 return matching_resources[0];
100 const std::string file_stem = std::filesystem::path{ file_name }.stem().string();
101 std::set<std::string> search_packages;
111 std::vector<TreeResource> matching_resources;
116 if (r.tree_file_stem == file_stem)
118 matching_resources.push_back(r);
123 if (matching_resources.empty())
126 ".xml' was registered." };
128 if (matching_resources.size() > 1)
131 ".xml' are registered. Use the 'package_name' argument to "
132 "narrow down the search." };
135 return matching_resources[0];
141 if (tokens.size() != 3)
144 "' has wrong format. Number of string tokens separated by '::' must "
148 const std::string& tree_name = tokens[1];
150 if (tree_name.empty())
161 "' but no tree with name '" + tree_name +
"' exists in that file.");
168 tinyxml2::XMLDocument doc;
169 if (doc.LoadFile(
tree_file_path.c_str()) != tinyxml2::XMLError::XML_SUCCESS)
173 tinyxml2::XMLPrinter printer;
175 return printer.CStr();
std::vector< std::string > splitString(const std::string &str, const std::string &delimiter, bool preserve_empty=true)
Split a string into multiple tokens using a specific delimiter string (Delimiter may consist of multi...
std::set< std::string > getAllPackagesWithResource(const std::string &resource_type)
Collect all package names that register a certain type of ament_index resources.
Struct containing behavior tree resource data.
static TreeResource fromString(const std::string &identity)
Find a behavior tree resource using an identity string.
std::string node_manifest_file_path
static TreeResource selectByFileName(const std::string &file_name, const std::string &package_name="")
static std::vector< TreeResource > collectFromPackage(const std::string &package_name)
Collect all behavior tree resources registered by a certain package.
std::set< std::string > tree_names
std::string writeTreeToString() const
static TreeResource selectByTreeName(const std::string &tree_name, const std::string &package_name="")
std::string tree_file_stem
std::string tree_file_path