.. _program_listing_file_include_rclcpp_type_adapter.hpp: Program Listing for File type_adapter.hpp ========================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/rclcpp/type_adapter.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2021 Open Source Robotics Foundation, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef RCLCPP__TYPE_ADAPTER_HPP_ #define RCLCPP__TYPE_ADAPTER_HPP_ #include namespace rclcpp { template struct TypeAdapter { using is_specialized = std::false_type; using custom_type = CustomType; // In this case, the CustomType is the only thing given, or there is no specialization. // Assign ros_message_type to CustomType for the former case. using ros_message_type = CustomType; }; template struct is_type_adapter : std::false_type {}; template struct is_type_adapter>: std::true_type {}; template struct TypeAdapter::value>>: T {}; namespace detail { template struct assert_type_pair_is_specialized_type_adapter { using type_adapter = TypeAdapter; static_assert( type_adapter::is_specialized::value, "No type adapter for this custom type/ros message type pair"); }; } // namespace detail template struct adapt_type { template using as = typename ::rclcpp::detail::assert_type_pair_is_specialized_type_adapter< CustomType, ROSMessageType >::type_adapter; }; template struct ImplicitTypeAdapter { using is_specialized = std::false_type; }; template struct TypeAdapter::is_specialized::value>> : ImplicitTypeAdapter {}; #define RCLCPP_USING_CUSTOM_TYPE_AS_ROS_MESSAGE_TYPE(CustomType, ROSMessageType) \ template<> \ struct rclcpp::ImplicitTypeAdapter \ : public rclcpp::TypeAdapter \ { \ static_assert( \ is_specialized::value, \ "Cannot use custom type as ros type when there is no TypeAdapter for that pair"); \ } } // namespace rclcpp #endif // RCLCPP__TYPE_ADAPTER_HPP_