AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
tree_resource.hpp
1// Copyright 2024 Robin Müller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <set>
18#include <string>
19#include <vector>
20
21#include "auto_apms_behavior_tree_core/behavior.hpp"
22#include "auto_apms_util/yaml.hpp"
23
25{
26
43{
51 TreeResourceIdentity(const std::string & identity);
52
60 TreeResourceIdentity(const char * identity);
61
68
70 std::string file_stem;
72 std::string tree_name;
73};
74
145class TreeResource : public BehaviorResourceTemplate<TreeResourceIdentity>
146{
147 friend class TreeDocument;
148 friend class TreeBuilder;
149
150public:
157 TreeResource(const TreeResourceIdentity & search_identity);
158
167 TreeResource(const std::string & search_identity);
168
177 TreeResource(const char * search_identity);
178
191 bool hasRootTreeName() const;
192
206 std::string getRootTreeName() const;
207
214 TreeResourceIdentity createIdentityForTree(const std::string & tree_name = "") const;
215
228 static TreeResource findByTreeName(const std::string & tree_name, const std::string & package_name = "");
229
242 static TreeResource findByFileStem(const std::string & file_stem, const std::string & package_name = "");
243
244private:
245 std::string doc_root_tree_name_;
246};
247
248} // namespace auto_apms_behavior_tree::core
249
251namespace YAML
252{
253template <>
255{
257 static Node encode(const Identity & rhs)
258 {
259 Node node;
260 node = rhs.str();
261 return node;
262 }
263 static bool decode(const Node & node, Identity & rhs)
264 {
265 if (!node.IsScalar()) return false;
266 rhs = Identity(node.Scalar());
267 return true;
268 }
269};
270} // namespace YAML
TreeResourceIdentity createIdentityForTree(const std::string &tree_name="") const
Create a valid identity string for a specific behavior tree of this resource.
std::string getRootTreeName() const
Get the name of the root tree of this behavior tree resource.
static TreeResource findByTreeName(const std::string &tree_name, const std::string &package_name="")
Find an installed behavior tree resource using a specific behavior tree name.
static TreeResource findByFileStem(const std::string &file_stem, const std::string &package_name="")
Find an installed behavior tree resource using an XML file stem.
TreeResource(const TreeResourceIdentity &search_identity)
Assemble a behavior tree resource using a TreeResourceIdentity.
bool hasRootTreeName() const
Determine if this behavior tree resource specifies a root tree.
Core API for AutoAPMS's behavior tree implementation.
Definition behavior.hpp:32
Powerful tooling for incorporating behavior trees for task development.
Definition behavior.hpp:32
BehaviorResourceIdentity(const std::string &identity)
Constructor of a behavior resource identity object.
Definition behavior.cpp:28
std::string str() const
Create the corresponding identity string.
Definition behavior.cpp:83
Struct that encapsulates the identity string for a registered behavior tree.
std::string tree_name
Name of a specific tree inside the resource's tree document.
std::string file_stem
Name of the file (without extension) that contains the resource's tree document.
TreeResourceIdentity()=default
Constructor of an empty behavior tree resource identity object.
TreeResourceIdentity(const std::string &identity)
Constructor of a tree resource identity object.