AutoAPMS
Resilient Robot Mission Management
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// https://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/node/node_manifest.hpp"
22#include "auto_apms_util/yaml.hpp"
23
25{
26
33{
41 TreeResourceIdentity(const std::string & identity);
42
50 TreeResourceIdentity(const char * identity);
51
58
59 bool operator==(const TreeResourceIdentity & other) const;
60
61 bool operator<(const TreeResourceIdentity & other) const;
62
67 std::string str() const;
68
73 bool empty() const;
74
76 std::string package_name;
78 std::string file_stem;
80 std::string tree_name;
81};
82
169{
170 friend class TreeDocument;
171 friend class TreeBuilder;
172
173public:
174 using Identity = TreeResourceIdentity;
175
182 TreeResource(const Identity & identity);
183
192 TreeResource(const std::string & identity);
193
202 TreeResource(const char * identity);
203
216 static TreeResource selectByTreeName(const std::string & tree_name, const std::string & package_name = "");
217
231 static TreeResource selectByFileStem(const std::string & file_stem, const std::string & package_name = "");
232
245 bool hasRootTreeName() const;
246
260 std::string getRootTreeName() const;
261
267
272 std::string getPackageName() const;
273
278 std::string getFileStem() const;
279
286 Identity createIdentity(const std::string & tree_name = "") const;
287
288private:
289 const TreeResourceIdentity identity_;
290 std::string package_name_;
291 std::string tree_file_path_;
292 std::vector<std::string> node_manifest_file_paths_;
293 std::string doc_root_tree_name_;
294};
295
296} // namespace auto_apms_behavior_tree::core
297
299namespace YAML
300{
301template <>
303{
305 static Node encode(const Identity & rhs)
306 {
307 Node node;
308 node = rhs.str();
309 return node;
310 }
311 static bool decode(const Node & node, Identity & rhs)
312 {
313 if (!node.IsScalar()) return false;
314 rhs = Identity(node.Scalar());
315 return true;
316 }
317};
318} // namespace YAML
Data structure for information about which behavior tree node plugin to load and how to configure the...
std::string getRootTreeName() const
Get the name of the root tree of this behavior tree resource.
static TreeResource selectByFileStem(const std::string &file_stem, const std::string &package_name="")
Find an installed behavior tree resource using a specific behavior tree XML file stem.
TreeResource(const Identity &identity)
Assemble a behavior tree resource using a TreeResourceIdentity.
std::string getPackageName() const
Get the name of the package this resource was registered by.
std::string getFileStem() const
Get the file stem of the XML file containing the tree document associated with this resource.
Identity createIdentity(const std::string &tree_name="") const
Create a valid tree resource identity string representing this resource.
static TreeResource selectByTreeName(const std::string &tree_name, const std::string &package_name="")
Find an installed behavior tree resource using a specific behavior tree name.
NodeManifest getNodeManifest() const
Get the node manifest associated with this resource.
bool hasRootTreeName() const
Determine if this behavior tree resource specifies a root tree.
Core API for AutoAPMS's behavior tree implementation.
Definition builder.hpp:30
Useful tooling for incorporating behavior trees for task development.
Definition builder.hpp:30
Struct that encapsulates the identity string for a declared behavior tree.
std::string tree_name
Name of a specific tree inside the resource's tree document.
bool empty() const
Determine whether this tree resource identity object is considered empty.
std::string file_stem
Name of the file (without extension) that contains the resource's tree document.
TreeResourceIdentity()=default
Constructor of an empty tree resource identity object.
TreeResourceIdentity(const std::string &identity)
Constructor of a behavior tree resource identity object.
std::string package_name
Name of the package that registers the resource.
std::string str() const
Create the corresponding identity string.