AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
node_registration_factory.hpp
Go to the documentation of this file.
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
18#include <boost/core/demangle.hpp>
19
21{
22
23template <typename T,
24 bool requires_ros_node_params =
25 std::is_constructible<T, const std::string&, const BT::NodeConfig&, const RosNodeContext&>::value>
27{
28public:
30 virtual ~NodeRegistrationFactory() = default;
31
32 bool requiresROSNodeParams() const override
33 {
34 return requires_ros_node_params;
35 }
36
37 void registerWithBehaviorTreeFactory(BT::BehaviorTreeFactory& factory, const std::string& registration_name,
38 const RosNodeContext* const params_ptr = nullptr) const override
39 {
40 if constexpr (requires_ros_node_params)
41 {
42 if (!params_ptr)
43 {
44 throw std::runtime_error(boost::core::demangle(typeid(T).name()) +
45 " requires a valid RosNodeContext object to be passed via argument 'params_ptr'.");
46 }
47 factory.registerNodeType<T>(registration_name, *params_ptr);
48 }
49 else
50 {
51 factory.registerNodeType<T>(registration_name);
52 }
53 }
54};
55
56} // namespace auto_apms_behavior_tree
void registerWithBehaviorTreeFactory(BT::BehaviorTreeFactory &factory, const std::string &registration_name, const RosNodeContext *const params_ptr=nullptr) const override