Autoware.Auto
message_adapters.hpp
Go to the documentation of this file.
1 // Copyright 2017-2019 the Autoware Foundation
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 // Co-developed by Tier IV, Inc. and Apex.AI, Inc.
18 
19 #ifndef HELPER_FUNCTIONS__MESSAGE_ADAPTERS_HPP_
20 #define HELPER_FUNCTIONS__MESSAGE_ADAPTERS_HPP_
21 
22 #include <builtin_interfaces/msg/time.hpp>
23 #include <string>
24 
25 namespace autoware
26 {
27 namespace common
28 {
29 namespace helper_functions
30 {
31 namespace message_field_adapters
32 {
34 using TimeStamp = builtin_interfaces::msg::Time;
35 
38 template<typename T, typename = nullptr_t>
39 struct HasHeader : std::false_type {};
40 
41 template<typename T>
42 struct HasHeader<T, decltype((void) T::header, nullptr)>: std::true_type {};
43 
45 
51 template<typename T, nullptr_t>
52 const std::string & get_frame_id(const T & msg) noexcept;
53 
60 template<typename T, nullptr_t>
61 std::string & get_frame_id(T & msg) noexcept;
62 
68 template<typename T, nullptr_t>
69 const TimeStamp & get_stamp(const T & msg) noexcept;
70 
77 template<typename T, nullptr_t>
78 TimeStamp & get_stamp(T & msg) noexcept;
79 
80 
82 template<class T, typename std::enable_if<HasHeader<T>::value, nullptr_t>::type = nullptr>
83 const std::string & get_frame_id(const T & msg) noexcept
84 {
85  return msg.header.frame_id;
86 }
87 
88 template<class T, typename std::enable_if<HasHeader<T>::value, nullptr_t>::type = nullptr>
89 std::string & get_frame_id(T & msg) noexcept
90 {
91  return msg.header.frame_id;
92 }
93 
94 template<class T, typename std::enable_if<HasHeader<T>::value, nullptr_t>::type = nullptr>
95 TimeStamp & get_stamp(T & msg) noexcept
96 {
97  return msg.header.stamp;
98 }
99 
100 template<class T, typename std::enable_if<HasHeader<T>::value, nullptr_t>::type = nullptr>
101 TimeStamp get_stamp(const T & msg) noexcept
102 {
103  return msg.header.stamp;
104 }
105 
106 } // namespace message_field_adapters
107 } // namespace helper_functions
108 } // namespace common
109 } // namespace autoware
110 
111 #endif // HELPER_FUNCTIONS__MESSAGE_ADAPTERS_HPP_
autoware::common::helper_functions::message_field_adapters::get_stamp
const TimeStamp & get_stamp(const T &msg) noexcept
Definition: message_adapters.hpp:101
catr_diff.T
T
Definition: catr_diff.py:22
autoware::common::helper_functions::message_field_adapters::TimeStamp
builtin_interfaces::msg::Time TimeStamp
Using alias for Time message.
Definition: message_adapters.hpp:34
autoware::common::helper_functions::message_field_adapters::HasHeader
Helper class to check existance of header file in compile time: https://stackoverflow....
Definition: message_adapters.hpp:39
autoware::common::helper_functions::message_field_adapters::get_frame_id
const std::string & get_frame_id(const T &msg) noexcept
Definition: message_adapters.hpp:83
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24