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
44{
52 TreeResourceIdentity(const std::string & identity);
53
61 TreeResourceIdentity(const char * identity);
62
69
71 std::string file_stem;
73 std::string tree_name;
74};
75
146class TreeResource : public BehaviorResourceTemplate<TreeResourceIdentity>
147{
148 friend class TreeDocument;
149 friend class TreeBuilder;
150
151public:
158 TreeResource(const TreeResourceIdentity & search_identity);
159
168 TreeResource(const std::string & search_identity);
169
178 TreeResource(const char * search_identity);
179
192 bool hasRootTreeName() const;
193
207 std::string getRootTreeName() const;
208
215 TreeResourceIdentity createIdentityForTree(const std::string & tree_name = "") const;
216
229 static TreeResource findByTreeName(const std::string & tree_name, const std::string & package_name = "");
230
243 static TreeResource findByFileStem(const std::string & file_stem, const std::string & package_name = "");
244
245private:
246 std::string doc_root_tree_name_;
247};
248
249} // namespace auto_apms_behavior_tree::core
250
252namespace YAML
253{
254template <>
256{
258 static Node encode(const Identity & rhs)
259 {
260 Node node;
261 node = rhs.str();
262 return node;
263 }
264 static bool decode(const Node & node, Identity & rhs)
265 {
266 if (!node.IsScalar()) return false;
267 rhs = Identity(node.Scalar());
268 return true;
269 }
270};
271} // 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.