AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
node_registration_template.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 <boost/core/demangle.hpp>
18#include <stdexcept>
19#include <type_traits>
20
21#include "auto_apms_behavior_tree_core/node/node_registration_interface.hpp"
22
24{
25
27
33template <
34 class T, typename = std::enable_if_t<std::is_base_of_v<BT::TreeNode, T>>,
35 bool requires_ros_node_params =
36 std::is_constructible_v<T, const std::string &, const BT::NodeConfig &, RosNodeContext>>
37class NodeRegistrationTemplate : public NodeRegistrationInterface
38{
39public:
40 NodeRegistrationTemplate() = default;
41 virtual ~NodeRegistrationTemplate() = default;
42
43 bool requiresRosNodeContext() const override { return requires_ros_node_params; }
44
45 void registerWithBehaviorTreeFactory(
46 BT::BehaviorTreeFactory & factory, const std::string & registration_name,
47 const RosNodeContext * const context_ptr = nullptr) const override
48 {
49 if constexpr (requires_ros_node_params) {
50 if (!context_ptr) {
51 throw std::invalid_argument(
52 boost::core::demangle(typeid(T).name()) +
53 " requires a valid RosNodeContext object to be passed via argument 'context_ptr'.");
54 }
55 factory.registerNodeType<T>(registration_name, *context_ptr);
56 } else {
57 factory.registerNodeType<T>(registration_name);
58 }
59 }
60};
61
63
64} // namespace auto_apms_behavior_tree::core
Core API for AutoAPMS's behavior tree implementation.
Definition builder.hpp:30