35 std::string package_name =
"";
36 std::string file_name;
37 switch (tokens.size()) {
39 file_name = tokens[0];
42 package_name = tokens[0];
43 file_name = tokens[1];
46 throw auto_apms_util::exceptions::ResourceIdentityFormatError(
47 "Mission configuration resource identity string '" + identity +
48 "' has wrong format. Must be '<package_name>::<file_name>'.");
51 std::set<std::string> search_packages;
52 if (!package_name.empty()) {
53 search_packages.insert(package_name);
59 std::vector<std::string> matching_file_paths;
60 for (
const auto & p : search_packages) {
62 std::string base_path;
63 if (ament_index_cpp::get_resource(_AUTO_APMS_MISSION__RESOURCE_TYPE_NAME__MISSION_CONFIG, p, content, &base_path)) {
65 for (
const std::string & line : lines) {
66 if (std::filesystem::path(line).stem() == std::filesystem::path(file_name).stem()) {
67 matching_file_paths.push_back(base_path +
"/" + line);
73 if (matching_file_paths.empty()) {
74 throw auto_apms_util::exceptions::ResourceError(
75 "No mission configuration resource was found using identity '" + identity +
"'.");
77 if (matching_file_paths.size() > 1) {
78 throw auto_apms_util::exceptions::ResourceError(
79 "There are multiple mission configuration resources with file name '" + file_name +
"'.");
81 return fromFile(matching_file_paths[0]);
std::vector< std::string > splitString(const std::string &str, const std::string &delimiter, bool remove_empty=true)
Split a string into multiple tokens using a specific delimiter string (Delimiter may consist of multi...