15#include "auto_apms_behavior_tree_core/behavior.hpp"
20bool isInternalBehaviorCategory(
const std::string & category_name)
22 const char * suffix = _AUTO_APMS_BEHAVIOR_TREE_CORE__INTERNAL_BEHAVIOR_CATEGORY_SUFFIX;
23 size_t suffix_len = std::strlen(suffix);
24 return category_name.size() >= suffix_len &&
25 category_name.compare(category_name.size() - suffix_len, suffix_len, suffix) == 0;
30 if (identity.empty()) {
31 throw auto_apms_util::exceptions::ResourceIdentityFormatError(
32 "Behavior resource identity string must not be empty.");
34 std::string resource_part;
35 if (std::size_t pos = identity.find(_AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_IDENTITY_CATEGORY_SEP);
36 pos == std::string::npos) {
38 resource_part = identity;
42 identity.substr(pos + std::string(_AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_IDENTITY_CATEGORY_SEP).size());
44 if (resource_part.empty()) {
45 throw auto_apms_util::exceptions::ResourceIdentityFormatError(
46 "Behavior resource identity string '" + identity +
"' is invalid: You must specify more than just the category.");
48 if (std::size_t pos = resource_part.find(_AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_IDENTITY_ALIAS_SEP);
49 pos == std::string::npos) {
56 resource_part.substr(pos + std::string(_AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_IDENTITY_ALIAS_SEP).size());
59 throw auto_apms_util::exceptions::ResourceIdentityFormatError(
60 "Behavior resource identity string '" + identity +
61 "' is invalid. Package name and behavior alias must not be empty.");
70 category_name = default_category;
81bool BehaviorResourceIdentity::operator<(
const BehaviorResourceIdentity & other)
const {
return str() < other.str(); }
87 str +=
category_name + _AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_IDENTITY_CATEGORY_SEP;
96 const std::set<std::string> & include_categories,
bool include_internal,
97 const std::set<std::string> & exclude_packages)
99 std::set<BehaviorResourceIdentity> identities;
101 _AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_TYPE_NAME__BEHAVIOR, exclude_packages)) {
103 std::string base_path;
104 if (ament_index_cpp::get_resource(
105 _AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_TYPE_NAME__BEHAVIOR, p, content, &base_path)) {
106 for (
const auto & line :
109 line, _AUTO_APMS_BEHAVIOR_TREE_CORE__RESOURCE_MARKER_FILE_FIELD_PER_LINE_SEP,
false);
110 if (parts.size() > 1) {
115 if (include_categories.empty()) {
116 if (!include_internal && isInternalBehaviorCategory(i.
category_name))
119 if (include_categories.find(i.
category_name) == include_categories.end())
122 identities.insert(i);
std::set< BehaviorResourceIdentity > getBehaviorResourceIdentities(const std::set< std::string > &include_categories={}, bool include_internal=false, const std::set< std::string > &exclude_packages={})
Get all registered behavior resource identities.
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...
std::set< std::string > getPackagesWithResourceType(const std::string &resource_type, const std::set< std::string > &exclude_packages={})
Get a list of all package names that register a certain type of ament_index resources.
Core API for AutoAPMS's behavior tree implementation.
Struct that encapsulates the identity string for a registered behavior.
std::string category_name
Name of the category this behavior resource belongs to.
BehaviorResourceIdentity(const std::string &identity)
Constructor of a behavior resource identity object.
std::string behavior_alias
Alias for a single registered behavior.
bool empty() const
Determine whether this behavior resource identity object is considered empty.
BehaviorResourceIdentity()=default
Constructor of an empty behavior resource identity object.
std::string package_name
Name of the package that registers the behavior resource.
std::string str() const
Create the corresponding identity string.