ros2_control - foxy
Loading...
Searching...
No Matches
helpers.hpp
1// Copyright (c) 2021, Stogl Robotics Consulting UG (haftungsbeschränkt)
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#ifndef CONTROLLER_INTERFACE__HELPERS_HPP_
16#define CONTROLLER_INTERFACE__HELPERS_HPP_
17
18#include <functional>
19#include <string>
20#include <vector>
21
23{
25
37template <typename T>
39 std::vector<T> & unordered_interfaces, const std::vector<std::string> & ordered_names,
40 const std::string & interface_type, std::vector<std::reference_wrapper<T>> & ordered_interfaces)
41{
42 ordered_interfaces.reserve(ordered_names.size());
43 for (const auto & name : ordered_names)
44 {
45 for (auto & interface : unordered_interfaces)
46 {
47 if (!interface_type.empty())
48 {
49 if ((name == interface.get_name()) && (interface_type == interface.get_interface_name()))
50 {
51 ordered_interfaces.push_back(std::ref(interface));
52 }
53 }
54 else
55 {
56 if (name == interface.get_full_name())
57 {
58 ordered_interfaces.push_back(std::ref(interface));
59 }
60 }
61 }
62 }
63
64 return ordered_names.size() == ordered_interfaces.size();
65}
66
67inline bool interface_list_contains_interface_type(
68 const std::vector<std::string> & interface_type_list, const std::string & interface_type)
69{
70 return std::find(interface_type_list.begin(), interface_type_list.end(), interface_type) !=
71 interface_type_list.end();
72}
73
74} // namespace controller_interface
75
76#endif // CONTROLLER_INTERFACE__HELPERS_HPP_
Definition controller_interface.hpp:32
bool get_ordered_interfaces(std::vector< T > &unordered_interfaces, const std::vector< std::string > &ordered_names, const std::string &interface_type, std::vector< std::reference_wrapper< T > > &ordered_interfaces)
Reorder interfaces with references according to joint names or full interface names.
Definition helpers.hpp:38